static MsgInfo *news_parse_xover(struct newsnntp_xover_resp_item *item) { MsgInfo *msginfo; /* set MsgInfo */ msginfo = procmsg_msginfo_new(); msginfo->msgnum = item->ovr_article; msginfo->size = item->ovr_size; msginfo->date = g_strdup(item->ovr_date); msginfo->date_t = procheader_date_parse(NULL, item->ovr_date, 0); msginfo->from = conv_unmime_header(item->ovr_author, NULL, TRUE); msginfo->fromname = procheader_get_fromname(msginfo->from); msginfo->subject = conv_unmime_header(item->ovr_subject, NULL, TRUE); remove_return(msginfo->from); remove_return(msginfo->fromname); remove_return(msginfo->subject); if (item->ovr_message_id) { gchar *tmp = g_strdup(item->ovr_message_id); extract_parenthesis(tmp, '<', '>'); remove_space(tmp); if (*tmp != '\0') msginfo->msgid = g_strdup(tmp); g_free(tmp); } /* FIXME: this is a quick fix; references' meaning was changed * into having the actual list of references in the References: header. * We need a GSList here, so msginfo_free() and msginfo_copy() can do * their things properly. */ if (item->ovr_references && *(item->ovr_references)) { gchar **ref_tokens = g_strsplit(item->ovr_references, " ", -1); guint i = 0; char *tmp; char *p; while (ref_tokens[i]) { gchar *cur_ref = ref_tokens[i]; msginfo->references = references_list_append(msginfo->references, cur_ref); i++; } g_strfreev(ref_tokens); tmp = g_strdup(item->ovr_references); eliminate_parenthesis(tmp, '(', ')'); if ((p = strrchr(tmp, '<')) != NULL) { extract_parenthesis(p, '<', '>'); remove_space(p); if (*p != '\0') msginfo->inreplyto = g_strdup(p); } g_free(tmp); } return msginfo; }
void feed_parser_atom10_end(void *data, const gchar *el) { FeedParserCtx *ctx = (FeedParserCtx *)data; Feed *feed = ctx->feed; gchar *text = NULL, *tmp; if( ctx->str != NULL ) text = g_strstrip(g_strdup(ctx->str->str)); else text = ""; switch( ctx->depth ) { case 0: /* Just in case. */ break; case 1: if( !strcmp(el, "feed") ) { /* We have finished parsing the feed, reverse the list * so it's not upside down. */ feed->items = g_slist_reverse(ctx->feed->items); } break; case 2: /* decide if we just received </entry>, so we can * add a complete item to feed */ if( !strcmp(el, "entry") ) { /* Fix up URL, if it is relative */ if (ctx->curitem->url != NULL && !strstr(ctx->curitem->url, "://") && ctx->feed->link != NULL) { tmp = g_strconcat(ctx->feed->link, (ctx->curitem->url[0] == '/' ? "" : "/"), ctx->curitem->url, NULL); feed_item_set_url(ctx->curitem, tmp); g_free(tmp); } /* append the complete feed item */ if( ctx->curitem->id && ctx->curitem->title && ctx->curitem->date_modified ) { feed->items = g_slist_prepend(feed->items, (gpointer)ctx->curitem); } /* since it's in the linked list, lose this pointer */ ctx->curitem = NULL; } else if( !strcmp(el, "title") ) { /* so it wasn't end of item */ FILL(feed->title) } else if( !strcmp(el, "summary" ) ) { FILL(feed->description) } else if( !strcmp(el, "updated" ) ) { feed->date = procheader_date_parse(NULL, text, 0); } /* FIXME: add more later */ break; case 3: if( ctx->curitem == NULL ) break; switch(ctx->location) { /* We're in feed/entry */ case FEED_LOC_ATOM10_ENTRY: if( !strcmp(el, "title") ) { FILL(ctx->curitem->title) } else if( !strcmp(el, "summary") ) { FILL(ctx->curitem->summary) } else if( !strcmp(el, "id") ) { FILL(ctx->curitem->id) feed_item_set_id_permalink(ctx->curitem, TRUE); } else if( !strcmp(el, "published") ) { ctx->curitem->date_published = procheader_date_parse(NULL, text, 0); } else if( !strcmp(el, "updated") ) { ctx->curitem->date_modified = procheader_date_parse(NULL, text, 0); } break; /* We're in feed/author or about to leave feed/entry/author */ case FEED_LOC_ATOM10_AUTHOR: if( !strcmp(el, "author" ) ) { /* We just finished parsing <author> */ ctx->curitem->author = g_strdup_printf("%s%s%s%s%s", ctx->name ? ctx->name : "", ctx->name && ctx->mail ? " <" : ctx->mail ? "<" : "", ctx->mail ? ctx->mail : "", ctx->mail ? ">" : "", !ctx->name && !ctx->mail ? "N/A" : ""); ctx->location = FEED_LOC_ATOM10_ENTRY; } else if( !strcmp(el, "name") ) { FILL(feed->author) } break; case FEED_LOC_ATOM10_CONTENT: if( !strcmp(el, "content") ) { if (ctx->curitem->xhtml_content) { /* Just in case the <content> tag itself also has some * content of its own, not just the <div> it should, * let's append it to the end. */ g_string_append(ctx->xhtml_str, text); ctx->curitem->text = g_string_free(ctx->xhtml_str, FALSE); ctx->xhtml_str = NULL; } else { FILL(ctx->curitem->text) } ctx->location = FEED_LOC_ATOM10_ENTRY; } break; } break; case 4: if( ctx->curitem == NULL ) break; switch(ctx->location) { /* We're in feed/entry/author */ case FEED_LOC_ATOM10_AUTHOR: if( !strcmp(el, "name") ) { FILL(ctx->name) } else if( !strcmp(el, "email") ) { FILL(ctx->mail) } break; /* We're in feed/entry/source */ case FEED_LOC_ATOM10_SOURCE: if( !strcmp(el, "title" ) ) { FILL(ctx->curitem->sourcetitle) } else if( !strcmp(el, "id" ) ) { FILL(ctx->curitem->sourceid) } else if( !strcmp(el, "updated" ) ) { ctx->curitem->sourcedate = procheader_date_parse(NULL, text, 0); } break; case FEED_LOC_ATOM10_CONTENT: if (ctx->curitem->xhtml_content) { g_string_append(ctx->xhtml_str, text); g_string_append_printf(ctx->xhtml_str, "</%s>", el); } break; } break; default: if (ctx->location == FEED_LOC_ATOM10_CONTENT && ctx->curitem->xhtml_content) { g_string_append(ctx->xhtml_str, text); g_string_append_printf(ctx->xhtml_str, "</%s>", el); } break; } if( ctx->str != NULL ) { g_free(text); g_string_free(ctx->str, TRUE); ctx->str = NULL; } ctx->str = NULL; ctx->depth--; }