MMAPString* mmap_string_assign (MMAPString *string, const char *rval) { mmap_string_truncate (string, 0); if (mmap_string_append (string, rval) == NULL) return NULL; return string; }
static void display_sub_tree(MMAPString * prefix, struct mailmessage_tree * msg_tree, int level, int has_next, unsigned int * pcount) { carray * list; uint32_t cur; if (msg_tree->node_msg != NULL) { print_mail_info(prefix->str, msg_tree->node_msg); (* pcount) ++; } list = msg_tree->node_children; if (carray_count(list) != 0) { char old_prefix[2]; if (level > 1) { memcpy(old_prefix, prefix->str + prefix->len - 2, 2); if (has_next) memcpy(prefix->str + prefix->len - 2, "| ", 2); else memcpy(prefix->str + prefix->len - 2, " ", 2); } for(cur = 0 ; cur < carray_count(list) ; cur ++) { int sub_has_next; if (cur != carray_count(list) - 1) { if (level > 0) { if (mmap_string_append(prefix, "+-") == NULL) return; } sub_has_next = 1; } else { if (level > 0) { if (mmap_string_append(prefix, "\\-") == NULL) return; } sub_has_next = 0; } display_sub_tree(prefix, carray_get(list, cur), level + 1, sub_has_next, pcount); if (mmap_string_truncate(prefix, prefix->len - 2) == NULL) { return; } } if (level > 1) { memcpy(prefix->str + prefix->len - 2, old_prefix, 2); } } }
oxws_result oxws_write_response_to_buffer(oxws* oxws, size_t buffer_size_hint) { if(oxws == NULL) return OXWS_ERROR_INVALID_PARAMETER; oxws_internal* internal = OXWS_INTERNAL(oxws); if(internal == NULL) return OXWS_ERROR_INTERNAL; curl_easy_setopt(internal->curl, CURLOPT_WRITEFUNCTION, oxws_write_response_to_buffer_callback); curl_easy_setopt(internal->curl, CURLOPT_WRITEDATA, internal); /* (re)allocate and clear response buffer */ if(internal->response_buffer) { mmap_string_set_size(internal->response_buffer, buffer_size_hint); mmap_string_truncate(internal->response_buffer, 0); } else { internal->response_buffer = mmap_string_sized_new(buffer_size_hint); } return OXWS_NO_ERROR; }
void newsfeed_parser_atom03_end(void *data, const char * el) { struct newsfeed_parser_context * ctx; struct newsfeed * feed; char * text; int r; ctx = data; feed = ctx->feed; text = ctx->str->str; ctx->depth --; switch (ctx->depth) { case 0: if (strcasecmp(el, "feed") == 0) { /* We have finished parsing the feed. */ } break; case 1: /* decide if we just received </entry>, so we can * add a complete item to feed */ if (strcasecmp(el, "entry") == 0) { /* append the complete feed item */ r = newsfeed_add_item(ctx->feed, ctx->curitem); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } /* since it's in the linked list, lose this pointer */ ctx->curitem = NULL; } else if (strcasecmp(el, "title") == 0) { /* so it wasn't end of item */ r = newsfeed_set_title(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "summary") == 0) { r = newsfeed_set_description(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "tagline") == 0) { r = newsfeed_set_description(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "modified") == 0) { time_t date; date = newsfeed_iso8601_date_parse(text); newsfeed_set_date(feed, date); } /* TODO: add more later */ break; case 2: if( ctx->curitem == NULL ) break; switch(ctx->location) { case FEED_LOC_ATOM03_ENTRY: /* We're in feed/entry */ if (strcasecmp(el, "title") == 0) { r = newsfeed_item_set_title(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "summary") == 0) { r = newsfeed_item_set_summary(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "content") == 0) { r = newsfeed_item_set_text(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "id") == 0) { r = newsfeed_item_set_id(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "issued") == 0) { time_t date; date = newsfeed_iso8601_date_parse(text); newsfeed_item_set_date_published(ctx->curitem, date); } else if (strcasecmp(el, "modified") == 0) { time_t date; date = newsfeed_iso8601_date_parse(text); newsfeed_item_set_date_modified(ctx->curitem, date); } break; case FEED_LOC_ATOM03_AUTHOR: /* We're in feed/author */ if (strcasecmp(el, "name") == 0) { r = newsfeed_item_set_author(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } /* TODO: construct a "Na Me <*****@*****.**>" string * from available tags */ break; } break; case 3: if (ctx->curitem == NULL) break; if (ctx->location == FEED_LOC_ATOM03_AUTHOR) { /* We're in feed/entry/author */ if (strcasecmp(el, "name") == 0) { r = newsfeed_item_set_author(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } } break; } mmap_string_truncate(ctx->str, 0); }
void newsfeed_parser_rss20_end(void * data, const char * el) { struct newsfeed_parser_context * ctx; struct newsfeed * feed; char * text; int r; ctx = data; feed = ctx->feed; text = ctx->str->str; ctx->depth--; switch (ctx->depth) { case 0: if (strcasecmp(el, "rss") == 0) { /* we finished parsing the feed */ } break; case 2: /* decide if we just received </item>, so we can * add a complete item to feed */ if (strcasecmp(el, "item") == 0) { /* append the complete feed item */ r = newsfeed_add_item(ctx->feed, ctx->curitem); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; } /* since it's in the linked list, lose this pointer */ ctx->curitem = NULL; } else if (strcasecmp(el, "title") == 0) { /* so it wasn't end of item */ r = newsfeed_set_title(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "description") == 0) { r = newsfeed_set_description(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "dc:language") == 0) { r = newsfeed_set_language(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "dc:creator") == 0) { r = newsfeed_set_author(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "admin:generatorAgent") == 0) { r = newsfeed_set_generator(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "dc:date") == 0) { time_t date; date = newsfeed_iso8601_date_parse(text); newsfeed_set_date(feed, date); } else if (strcasecmp(el, "pubDate") == 0) { time_t date; date = newsfeed_rfc822_date_parse(text); newsfeed_set_date(feed, date); } break; case 3: if ( ctx->curitem == NULL) { break; } /* decide which field did we just get */ if (strcasecmp(el, "title") == 0) { r = newsfeed_item_set_title(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "dc:creator") == 0) { r = newsfeed_item_set_author(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "author") == 0) { r = newsfeed_item_set_author(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "description") == 0) { r = newsfeed_item_set_text(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "content:encoded") == 0) { r = newsfeed_item_set_text(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "link") == 0) { r = newsfeed_item_set_url(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "guid") == 0) { r = newsfeed_item_set_id(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "dc:date") == 0) { time_t date; date = newsfeed_iso8601_date_parse(text); newsfeed_item_set_date_modified(ctx->curitem, date); } else if (strcasecmp(el, "pubDate") == 0) { time_t date; date = newsfeed_rfc822_date_parse(text); newsfeed_item_set_date_modified(ctx->curitem, date); } break; } mmap_string_truncate(ctx->str, 0); }
void newsfeed_parser_rdf_end(void *data, const char *el) { struct newsfeed_parser_context * ctx; struct newsfeed * feed; char * text; int r; ctx = data; feed = ctx->feed; text = ctx->str->str; ctx->depth --; switch (ctx->depth) { case 0: if (strcasecmp(el, "rdf") == 0) { /* we finished parsing the feed */ } break; case 1: /* <item></item> block just ended, so ... */ if (strcasecmp(el, "item") == 0) { /* add the complete feed item to our feed struct */ r = newsfeed_add_item(feed, ctx->curitem); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } /* since it's in the linked list, lose this pointer */ ctx->curitem = NULL; } break; case 2: switch(ctx->location) { case FEED_LOC_RDF_CHANNEL: /* We're inside introductory <channel></channel> */ if (strcasecmp(el, "title") == 0) { r = newsfeed_set_title(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "description") == 0) { r = newsfeed_set_description(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "dc:language") == 0) { r = newsfeed_set_language(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "dc:creator") == 0) { r = newsfeed_set_author(feed, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "dc:date") == 0) { time_t date; date = newsfeed_iso8601_date_parse(text); newsfeed_set_date(feed, date); } else if (strcasecmp(el, "pubDate") == 0) { time_t date; date = newsfeed_rfc822_date_parse(text); newsfeed_set_date(feed, date); } break; case FEED_LOC_RDF_ITEM: /* We're inside an <item></item> */ if (ctx->curitem == NULL) { break; } /* decide which field did we just get */ if (strcasecmp(el, "title") == 0) { r = newsfeed_item_set_title(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "dc:creator") == 0) { r = newsfeed_item_set_author(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "description") == 0) { r = newsfeed_item_set_text(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "content:encoded") == 0) { r = newsfeed_item_set_text(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "link") == 0) { r = newsfeed_item_set_url(ctx->curitem, text); if (r < 0) { ctx->error = NEWSFEED_ERROR_MEMORY; return; } } else if (strcasecmp(el, "dc:date") == 0) { time_t date; date = newsfeed_iso8601_date_parse(text); newsfeed_item_set_date_modified(ctx->curitem, date); } else if (strcasecmp(el, "pubDate") == 0) { time_t date; date = newsfeed_rfc822_date_parse(text); newsfeed_item_set_date_modified(ctx->curitem, date); } break; } break; } mmap_string_truncate(ctx->str, 0); }