PRIVATE int parseFeed(rss_feeds *feeds, const char* feedstr) { rss_feed* feed = NULL; int32_t result = SUCCESS; /* be optimistic */ simple_list option_list = NULL; NODE * current = NULL; suboption_t *opt_item = NULL; option_list = parseMultiOption(feedstr); current = option_list; while (current != NULL) { opt_item = (suboption_t*)current->data; if(opt_item != NULL) { if(!feed) { feed = feed_new(); assert(feed && "feed_new() failed!"); } if(!strncmp(opt_item->option, "url_pattern", 11)) { feed->url_pattern = trim(opt_item->value); } else if(!strncmp(opt_item->option, "url_replace", 11)) { feed->url_replace = trim(opt_item->value); } else if(!strncmp(opt_item->option, "url", 3)) { feed->url = trim(opt_item->value); } else if(!strncmp(opt_item->option, "cookies", 6)) { feed->cookies = trim(opt_item->value); } else if(!strncmp(opt_item->option, "id", 2)) { feed->id = trim(opt_item->value); } else { dbg_printf(P_ERROR, "Unknown suboption '%s'!", opt_item->option); } } else { assert(0 && "opt_item == NULL"); } current = current->next; } if(feed && feed->url) { /* Maybe the cookies are encoded within the URL */ if(feed->cookies == NULL) { parseCookiesFromURL(feed); } feed_add(feed, feeds); } else { dbg_printf(P_ERROR, "Invalid feed: '%s'", feedstr); feed_free(feed); result = FAILURE; } if(option_list != NULL) { freeList(&option_list, freeOptionItem); } return result; }
PRIVATE int parseFeed(rss_feeds *feeds, const char* feedstr) { char *line = NULL, *option = NULL, *param = NULL; char *saveptr; char *str = NULL; rss_feed* feed = NULL; int result = SUCCESS; /* be optimistic */ str = shorten(feedstr); line = strtok_r(str, AM_DELIMITER, &saveptr); while (line) { if(!feed) { feed = feed_new(); assert(feed && "feed_new() failed!"); } if(parseSubOption(line, &option, ¶m) == 0) { if(!strncmp(option, "url", 3)) { feed->url = shorten(param); } else if(!strncmp(option, "cookies", 6)) { feed->cookies = shorten(param); } else { dbg_printf(P_ERROR, "Unknown suboption '%s'!", option); } am_free(option); am_free(param); } else { dbg_printf(P_ERROR, "Invalid suboption string: '%s'!", line); } line = strtok_r(NULL, AM_DELIMITER, &saveptr); } if(feed && feed->url) { /* Maybe the cookies are encoded within the URL */ if(feed->cookies == NULL) { parseCookiesFromURL(feed); } feed->id = listCount(*feeds); feed_add(feed, feeds); } else { dbg_printf(P_ERROR, "Invalid feed: '%s'", str); result = FAILURE; } am_free(str); return result; }
PRIVATE int getFeeds(NODE **head, const char* strlist) { char *p = NULL; char *str; str = shorten(strlist); assert(head != NULL); p = strtok(str, AM_DELIMITER); while (p) { rss_feed* feed = feed_new(); assert(feed && "feed_new() failed!"); feed->url = strdup(p); feed->id = listCount(*head); /* Maybe the cookies are encoded within the URL */ parseCookiesFromURL(feed); feed_add(feed, head); p = strtok(NULL, AM_DELIMITER); } am_free(str); return 0; }