Beispiel #1
0
static List *unpack_new_headers(WSPMachine *sm, Octstr *hdrs) {
	List *new_headers;

	if (hdrs && octstr_len(hdrs) > 0) {
		new_headers = wsp_headers_unpack(hdrs, 0);
		if (sm->http_headers == NULL)
			sm->http_headers = http_create_empty_headers();
		http_header_combine(sm->http_headers, new_headers);
		return new_headers;
	}
	return NULL;
}
Beispiel #2
0
int mime_decompile(Octstr *binary_mime, Octstr **mime)
{ 
    char *boundary = "kannel_boundary";
    ParseContext *context;
    long mime_parts;
    long i, j;
    unsigned long headers_len, data_len;

    i = mime_parts = headers_len = data_len = 0;

    debug("wap.wsp.multipart.form.data", 0, "MIMEDEC: begining decoding");

    if(binary_mime == NULL || octstr_len(binary_mime) < 1) {
        warning(0, "MIMEDEC: invalid mime, ending");
        return -1;
    }
    *mime = octstr_create("");

    /* already dumped in deconvert_content
    debug("mime", 0, "MMSDEC: binary mime dump:");
    octstr_dump(binary_mime, 0);
    */

    context = parse_context_create(binary_mime);
    debug("mime", 0, "MIMEDEC: context created");

    mime_parts = parse_get_uintvar(context);
    debug("mime", 0, "MIMEDEC: mime has %ld multipart entities", mime_parts);
    if(mime_parts == 0) {
        debug("mime", 0, "MIMEDEC: mime has none multipart entities, ending");
        return 0;
    }

    while(parse_octets_left(context) > 0) {
        Octstr *headers, *data;
        List *gwlist_headers;
        i++;
    
        octstr_append(*mime, octstr_imm("--"));
        octstr_append(*mime, octstr_imm(boundary));
        octstr_append(*mime, octstr_imm("\n"));

        headers_len = parse_get_uintvar(context);
        data_len = parse_get_uintvar(context);
        debug("mime", 0, "MIMEDEC[%ld]: headers length <0x%02lx>, "
                         "data length <0x%02lx>", i, headers_len, data_len);

        if((headers = parse_get_octets(context, headers_len)) != NULL) {
            gwlist_headers = wsp_headers_unpack(headers, 1);
            for(j=0; j<gwlist_len(gwlist_headers);j++) {
                octstr_append(*mime, gwlist_get(gwlist_headers, j));
                octstr_append(*mime, octstr_imm("\n"));
            }
        } else {
            error(0, "MIMEDEC[%ld]: headers length is out of range, ending", i);
            return -1; 
        }

        if((data = parse_get_octets(context, data_len)) != NULL ||
           (i = mime_parts && /* XXX SE-T610 eats last byte, which is generally null */
	    (data = parse_get_octets(context, data_len - 1)) != NULL)) { 
            debug("mime", 0, "MMSDEC[%ld]: body [%s]", i, octstr_get_cstr(data));
            octstr_append(*mime, octstr_imm("\n"));
            octstr_append(*mime, data);
            octstr_append(*mime, octstr_imm("\n"));
        } else {
            error(0, "MIMEDEC[%ld]: data length is out of range, ending", i);
            return -1;
        }
    }
    octstr_append(*mime, octstr_imm("--"));
    octstr_append(*mime, octstr_imm(boundary));
    octstr_append(*mime, octstr_imm("--\n"));

    /* already dumped in deconvert_content
    debug("mime", 0, "MMSDEC: text mime dump:");
    octstr_dump(*mime, 0);
    */

    return 0;
}