summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave <vdr@pickles.me.uk>2012-05-09 12:42:51 +0100
committerDave <vdr@pickles.me.uk>2012-05-09 12:42:51 +0100
commit0f16beb1727cb47cc46b8da94a71778a212a58af (patch)
treef7728d8c3bc969e5b17566f45b8f9e9e577891f3
parentc465e7debbd105784335142afbb6c8969f50ece6 (diff)
downloadvdrtva-0f16beb1727cb47cc46b8da94a71778a212a58af.tar.gz
vdrtva-0f16beb1727cb47cc46b8da94a71778a212a58af.tar.bz2
Add 'delete series link' SVDRP command.
-rw-r--r--vdrtva.c68
-rw-r--r--vdrtva.h2
2 files changed, 55 insertions, 15 deletions
diff --git a/vdrtva.c b/vdrtva.c
index aecfdb6..93bc54b 100644
--- a/vdrtva.c
+++ b/vdrtva.c
@@ -315,6 +315,8 @@ const char **cPluginvdrTva::SVDRPHelpPages(void)
{
// Return help text for SVDRP commands this plugin implements
static const char *HelpPages[] = {
+ "DELL <sCrid>\n"
+ " Delete series link by series CRID",
"LLOG\n"
" Print the action log.",
"LSTL\n"
@@ -343,7 +345,13 @@ cString cPluginvdrTva::SVDRPCommand(const char *Command, const char *Option, int
// Process SVDRP commands this plugin implements
cTvaLog reply;
isyslog ("vdrtva: processing command %s", Command);
- if (strcasecmp(Command, "LLOG") == 0) {
+ if (strcasecmp(Command, "DELL") == 0) {
+ if (Links && Links->DeleteItem(Option)) {
+ return cString::sprintf("Series %s deleted", Option);
+ }
+ else return cString::sprintf("Series %s not found in links file", Option);
+ }
+ else if (strcasecmp(Command, "LLOG") == 0) {
ReplyCode = 250;
if (tvalog.Length() > 0) return cString(tvalog.Buffer());
else return cString::sprintf("Nothing in the buffer!");
@@ -475,6 +483,11 @@ void cPluginvdrTva::Expire()
SuggestCRIDs->DeDup();
SuggestCRIDs->Expire();
}
+ if (Links) {
+ if(Links->Expire()) {
+ SaveLinksFile();
+ }
+ }
}
void cPluginvdrTva::Update()
@@ -563,21 +576,12 @@ bool cPluginvdrTva::SaveLinksFile()
cString oldlinks = AddDirectory(configDir, "links.old");
FILE *f = fopen(newlinks, "w");
if (f) {
- cLinkItem *Item = Links->First();
- while (Item) {
- cLinkItem *next = Links->Next(Item);
- if ((Item->ModTime() + seriesLifetime) > time(NULL)) {
- fprintf(f, "%s,%d;%s", Item->sCRID(), Item->ModTime(), Item->iCRIDs());
- if (Item->Path()) {
- fprintf(f, ";%s\n", Item->Path());
- }
- else fprintf(f, "\n");
- }
- else {
- isyslog ("vdrtva: Expiring series %s", Item->sCRID());
- Links->Del(Item);
+ for (cLinkItem *Item = Links->First(); Item; Item = Links->Next(Item)) {
+ fprintf(f, "%s,%d;%s", Item->sCRID(), Item->ModTime(), Item->iCRIDs());
+ if (Item->Path()) {
+ fprintf(f, ";%s\n", Item->Path());
}
- Item = next;
+ else fprintf(f, "\n");
}
fclose(f);
unlink (oldlinks); // Allow to fail if the save file does not exist
@@ -1458,4 +1462,38 @@ cLinkItem *cLinks::NewLinkItem(const char *sCRID, int ModTime, const char *iCRID
return NewLinkItem;
}
+bool cLinks::DeleteItem(const char *sCRID)
+{
+ if (maxNumber == 0) return false;
+ cLinkItem *Item = Links->First();
+ while (Item) {
+ cLinkItem *next = Links->Next(Item);
+ if (!strcmp(Item->sCRID(), sCRID)) {
+ Links->Del(Item);
+ maxNumber--;
+ return true;
+ }
+ Item = next;
+ }
+ return false;
+}
+
+bool cLinks::Expire(void)
+{
+ bool status = false;
+ if (maxNumber == 0) return false;
+ cLinkItem *Item = Links->First();
+ while (Item) {
+ cLinkItem *next = Links->Next(Item);
+ if ((Item->ModTime() + seriesLifetime) < time(NULL)) {
+ isyslog ("vdrtva: Expiring series %s", Item->sCRID());
+ Links->Del(Item);
+ maxNumber--;
+ status = true;
+ }
+ Item = next;
+ }
+ return status;
+}
+
VDRPLUGINCREATOR(cPluginvdrTva); // Don't touch this!
diff --git a/vdrtva.h b/vdrtva.h
index 2c3502d..815c924 100644
--- a/vdrtva.h
+++ b/vdrtva.h
@@ -184,4 +184,6 @@ class cLinks : public cRwLock, public cConfig<cLinkItem> {
cLinks(void);
int MaxNumber(void) { return maxNumber; }
cLinkItem *NewLinkItem(const char *sCRID, int ModTime, const char *iCRIDs, const char *Path);
+ bool DeleteItem(const char *sCRID);
+ bool Expire(void);
};