static void mime_entity_dump_real(MIMEEntity *m, unsigned int level) { long i, items; Octstr *prefix, *type, *charset; Octstr *tmp; unsigned int j; gw_assert(m != NULL && m->headers != NULL); prefix = octstr_create(""); for (j = 0; j < level * 2; j++) octstr_append_cstr(prefix, " "); http_header_get_content_type(m->headers, &type, &charset); debug("mime.dump",0,"%sContent-Type `%s'", octstr_get_cstr(prefix), octstr_get_cstr(type)); for(i = 0; i < gwlist_len(m->headers); i++) { tmp = gwlist_get(m->headers,i); debug("mime.dump",0, "Header: %s", octstr_get_cstr(tmp)); } if (m->start != NULL) { Octstr *cid = http_header_value(m->start->headers, octstr_imm("Content-ID")); debug("mime.dump",0,"%sRelated to Content-ID <%s> MIMEEntity at address `%p'", octstr_get_cstr(prefix), octstr_get_cstr(cid), m->start); octstr_destroy(cid); } items = gwlist_len(m->multiparts); debug("mime.dump",0,"%sBody contains %ld MIME entities, size %ld", octstr_get_cstr(prefix), items, (items == 0 && m->body) ? octstr_len(m->body) : -1); octstr_destroy(prefix); octstr_destroy(type); octstr_destroy(charset); for (i = 0; i < items; i++) { MIMEEntity *e = gwlist_get(m->multiparts, i); mime_entity_dump_real(e, level + 1); } }
static int receive_reply(HTTPCaller *caller) { void *id; int ret; Octstr *final_url; List *replyh; Octstr *replyb; Octstr *type; Octstr *charset; Octstr *os; id = http_receive_result(caller, &ret, &final_url, &replyh, &replyb); octstr_destroy(final_url); if (id == NULL || ret == -1) { error(0, "http GET failed"); gw_free(id); return -1; } debug("", 0, "Done with request %ld", *(long *) id); gw_free(id); http_header_get_content_type(replyh, &type, &charset); debug("", 0, "Content-type is <%s>, charset is <%s>", octstr_get_cstr(type), octstr_get_cstr(charset)); octstr_destroy(type); octstr_destroy(charset); if (verbose) debug("", 0, "Reply headers:"); while ((os = gwlist_extract_first(replyh)) != NULL) { if (verbose) octstr_dump(os, 1); octstr_destroy(os); } gwlist_destroy(replyh, NULL); if (verbose) { debug("", 0, "Reply body:"); octstr_dump(replyb, 1); } octstr_destroy(replyb); return 0; }
Numhash *numhash_create(char *seek_url) { int loc, lines = 0; List *request_headers, *reply_headers; Octstr *url, *final_url, *reply_body; Octstr *type, *charset; char *data, *ptr, numbuf[100]; int status; Numhash *table; url = octstr_create(seek_url); request_headers = gwlist_create(); status = http_get_real(HTTP_METHOD_GET, url, request_headers, &final_url, &reply_headers, &reply_body); octstr_destroy(url); octstr_destroy(final_url); gwlist_destroy(request_headers, NULL); if (status != HTTP_OK) { http_destroy_headers(reply_headers); octstr_destroy(reply_body); error(0, "Cannot load numhash!"); return NULL; } http_header_get_content_type(reply_headers, &type, &charset); octstr_destroy(charset); http_destroy_headers(reply_headers); if (octstr_str_compare(type, "text/plain") != 0) { octstr_destroy(reply_body); error(0, "Strange content type <%s> for numhash - expecting 'text/plain'" ", operatiom fails", octstr_get_cstr(type)); octstr_destroy(type); return NULL; } octstr_destroy(type); ptr = data = octstr_get_cstr(reply_body); while(*ptr) { if (*ptr == '\n') lines++; ptr++; } debug("numhash", 0, "Total %d lines in %s", lines, seek_url); table = numhash_init(lines+10, NUMHASH_AUTO_HASH); /* automatic hash */ /* now, parse the number information */ lines = 0; while((ptr = strchr(data, '\n'))) { /* each line is ended with linefeed */ *ptr = '\0'; while(*data != '\0' && isspace(*data)) data++; if (*data != '#') { loc = 0; while (*data != '\0') { if (isdigit(*data)) numbuf[loc++] = *data; else if (*data == ' ' || *data == '+' || *data == '-') ; else break; data++; } if (loc) { numbuf[loc] = '\0'; numhash_add_number(table, numbuf); lines++; } else warning(0, "Corrupted line '%s'", data); } data = ptr+1; /* next row... */ } octstr_destroy(reply_body); info(0, "Read from <%s> total of %ld numbers", seek_url, table->number_total); return table; }