static void astream_parse_header(struct attachment_istream *astream, struct message_header_line *hdr) { if (!hdr->continued) { stream_add_data(astream, hdr->name, hdr->name_len); stream_add_data(astream, hdr->middle, hdr->middle_len); } stream_add_data(astream, hdr->value, hdr->value_len); if (!hdr->no_newline) { if (hdr->crlf_newline) stream_add_data(astream, "\r\n", 2); else stream_add_data(astream, "\n", 1); } if (hdr->continues) { hdr->use_full_value = TRUE; return; } if (strcasecmp(hdr->name, "Content-Type") == 0) parse_content_type(astream, hdr); else if (strcasecmp(hdr->name, "Content-Disposition") == 0) parse_content_disposition(astream, hdr); }
static int cpl_process_register(struct sip_msg* msg, int no_rpl) { struct disposition *disp; struct disposition_param *param; int ret; int mime; int *mimes; /* make sure that is a REGISTER ??? */ /* here should be the CONTACT- hack */ /* is there a CONTENT-TYPE hdr ? */ mime = parse_content_type_hdr( msg ); if (mime==-1) goto error; /* check the mime type */ LM_DBG("Content-Type mime found %u, %u\n", mime>>16,mime&0x00ff); if ( mime && mime==(TYPE_APPLICATION<<16)+SUBTYPE_CPLXML ) { /* can be an upload or remove -> check for the content-purpose and * content-action headers */ LM_DBG("carrying CPL -> look at Content-Disposition\n"); if (parse_content_disposition( msg )!=0) { LM_ERR("Content-Disposition missing or corrupted\n"); goto error; } disp = get_content_disposition(msg); print_disposition( disp ); /* just for DEBUG */ /* check if the type of disposition is SCRIPT */ if (disp->type.len!=CPL_SCRIPT_LEN || strncasecmp(disp->type.s,CPL_SCRIPT,CPL_SCRIPT_LEN) ) { LM_ERR("bogus message - Content-Type" "says CPL_SCRIPT, but Content-Disposition something else\n"); goto error; } /* disposition type is OK -> look for action parameter */ for(param=disp->params;param;param=param->next) { if (param->name.len==ACTION_PARAM_LEN && !strncasecmp(param->name.s,ACTION_PARAM,ACTION_PARAM_LEN)) break; } if (param==0) { LM_ERR("bogus message - " "Content-Disposition has no action param\n"); goto error; } /* action param found -> check its value: store or remove */ if (param->body.len==STORE_ACTION_LEN && !strncasecmp( param->body.s, STORE_ACTION, STORE_ACTION_LEN)) { /* it's a store action -> get the script from body message and store * it into database (CPL and BINARY format) */ if (do_script_action( msg, STORE_SCRIPT)==-1) goto error; } else if (param->body.len==REMOVE_ACTION_LEN && !strncasecmp( param->body.s, REMOVE_ACTION, REMOVE_ACTION_LEN)) { /* it's a remove action -> remove the script from database */ if (do_script_action( msg, REMOVE_SCRIPT)==-1) goto error; } else { LM_ERR("unknown action <%.*s>\n", param->body.len,param->body.s); goto error; } /* do I have to send to reply? */ if (no_rpl) goto resume_script; /* send a 200 OK reply back */ cpl_fct.sigb.reply( msg, 200, &cpl_ok_rpl,NULL); /* I send the reply and I don't want to return to script execution, so * I return 0 to do break */ goto stop_script; } /* is there an ACCEPT hdr ? */ if ( (ret=parse_accept_hdr(msg))<0) goto error; if (ret==0 || (mimes=get_accept(msg))==0 ) /* accept header not present or no mimes found */ goto resume_script; /* looks if the REGISTER accepts cpl-xml or * */ while (*mimes) { LM_DBG("accept mime found %u, %u\n", (*mimes)>>16,(*mimes)&0x00ff); if (*mimes==(TYPE_ALL<<16)+SUBTYPE_ALL || *mimes==(TYPE_APPLICATION<<16)+SUBTYPE_CPLXML ) break; mimes++; } if (*mimes==0) /* no accept mime that matched cpl */ goto resume_script; /* get the user name from msg, retrieve the script from db * and appended to reply */ if (do_script_download( msg )==-1) goto error; /* do I have to send to reply? */ if (no_rpl) goto resume_script; /* send a 200 OK reply back */ cpl_fct.sigb.reply( msg, 200, &cpl_ok_rpl,NULL); stop_script: return 0; resume_script: return 1; error: /* send a error reply back */ cpl_fct.sigb.reply( msg, cpl_err->err_code, &cpl_err->err_msg, NULL); /* I don't want to return to script execution, so I return 0 to do break */ return 0; }
static struct _bodystruct * bodystruct_part_decode (unsigned char **in, unsigned char *inend, bodystruct_t *parent, gint num, GError **err) { struct _bodystruct *part, *list, *tail, *n; unsigned char *inptr; inptr = *in; while (inptr < inend && *inptr == ' ') inptr++; if (inptr == inend || *inptr != '(') { *in = inptr; return NULL; } inptr++; /* My '(' */ part = bodystruct_new (); part->part_spec = NULL; part->parent = parent; if (parent) { if (parent->part_spec && *parent->part_spec) { if (!strcasecmp (parent->content.type, "message") && !strcasecmp (parent->content.subtype, "rfc822")) { part->part_spec = g_strdup (parent->part_spec); } else { part->part_spec = g_strdup_printf ("%s.%d", parent->part_spec, num); } } else { part->part_spec = g_strdup_printf ("%d", num); } } else { part->part_spec = g_strdup (""); } if (*inptr == '(') { gint cnt = 1; part->content.type = g_strdup ("MULTIPART"); list = NULL; tail = (struct _bodystruct *) &list; while ((n = bodystruct_part_decode (&inptr, inend, part, cnt, err)) != NULL) { tail->next = n; tail = n; cnt++; while (inptr < inend && *inptr == ' ') inptr++; if (*inptr == ')') break; } part->subparts = list; if (*inptr != ')') { part->content.subtype = decode_qstring (&inptr, inend, err); debug_printf ("contensubtype: %s\n", PRINT_NULL (part->content.subtype)); } if (*inptr != ')') { part->content.params = decode_params (&inptr, inend, err); print_params (part->content.params); } /* if (*inptr != ')') { * parse_something_unknown (&inptr, inend, err); * } */ if (*inptr != ')') { parse_content_disposition (&inptr, inend, &part->disposition, err); } if (*inptr != ')') { parse_lang (&inptr, inend, part, err); } if (*inptr != ')') { end_this_piece (&inptr, inend, err); } } else { part->next = NULL; part->content.type = decode_qstring (&inptr, inend, err); if (!part->content.type) part->content.type = g_strdup ("TEXT"); debug_printf ("contentype: %s\n", PRINT_NULL (part->content.type)); part->content.subtype = decode_qstring (&inptr, inend, err); if (!part->content.subtype) part->content.subtype = g_strdup ("PLAIN"); debug_printf ("contensubtype: %s\n", PRINT_NULL (part->content.subtype)); part->disposition.type = NULL; part->disposition.params = NULL; part->encoding = NULL; part->envelope = NULL; part->subparts = NULL; if (!strcasecmp (part->content.type, "message") && !strcasecmp (part->content.subtype, "rfc822")) { if (*inptr != ')') { part->content.params = decode_params (&inptr, inend, err); print_params (part->content.params); } if (*inptr != ')') { part->content.cid = decode_qstring (&inptr, inend, err); debug_printf ("content.cid: %s\n", PRINT_NULL (part->content.cid)); } if (*inptr != ')') { part->description = decode_qstring (&inptr, inend, err); debug_printf ("description: %s\n", PRINT_NULL (part->description)); } if (*inptr != ')') { part->encoding = decode_qstring (&inptr, inend, err); if (!part->encoding) part->encoding = g_strdup ("7BIT"); debug_printf ("encoding: %s\n", PRINT_NULL (part->encoding)); } if (*inptr != ')') { part->octets = decode_num (&inptr, inend, err); debug_printf ("octets: %d\n", part->octets); } if (*inptr != ')') { part->envelope = decode_envelope (&inptr, inend, err); } if (*inptr != ')') { part->subparts = bodystruct_part_decode (&inptr, inend, part, 1, err); } if (*inptr != ')') { part->lines = decode_num (&inptr, inend, err); debug_printf ("lines: %d\n", part->lines); } if (*inptr != ')') { read_unknown_qstring (&inptr, inend, err); } if (*inptr != ')') { parse_content_disposition (&inptr, inend, &part->disposition, err); } if (*inptr != ')') { parse_lang (&inptr, inend, part, err); } if (*inptr != ')') { end_this_piece (&inptr, inend, err); } } else if (!strcasecmp (part->content.type, "text")) { if (*inptr != ')') { part->content.params = decode_params (&inptr, inend, err); print_params (part->content.params); } if (*inptr != ')') { part->content.cid = decode_qstring (&inptr, inend, err); debug_printf ("content.cid: %s\n", PRINT_NULL (part->content.cid)); } if (*inptr != ')') { part->description = decode_qstring (&inptr, inend, err); debug_printf ("description: %s\n", PRINT_NULL (part->description)); } if (*inptr != ')') { part->encoding = decode_qstring (&inptr, inend, err); debug_printf ("encoding: %s\n", PRINT_NULL (part->encoding)); } if (*inptr != ')') { part->octets = decode_num (&inptr, inend, err); debug_printf ("octets: %d\n", part->octets); } if (*inptr != ')') { part->lines = decode_num (&inptr, inend, err); debug_printf ("lines: %d\n", part->lines); } if (*inptr != ')') { read_unknown_qstring (&inptr, inend, err); } if (*inptr != ')') { parse_content_disposition (&inptr, inend, &part->disposition, err); } if (*inptr != ')') { parse_lang (&inptr, inend, part, err); } if (*inptr != ')') { end_this_piece (&inptr, inend, err); } } else if (!strcasecmp (part->content.type, "APPLICATION")|| !strcasecmp (part->content.type, "IMAGE") || !strcasecmp (part->content.type, "VIDEO") || !strcasecmp (part->content.type, "AUDIO")) { if (*inptr != ')') { part->content.params = decode_params (&inptr, inend, err); print_params (part->content.params); } if (*inptr != ')') { part->content.cid = decode_qstring (&inptr, inend, err); debug_printf ("content.cid: %s\n", PRINT_NULL (part->content.cid)); } if (*inptr != ')') { part->description = decode_qstring (&inptr, inend, err); debug_printf ("description: %s\n", PRINT_NULL (part->description)); } if (*inptr != ')') { part->encoding = decode_qstring (&inptr, inend, err); debug_printf ("encoding: %s\n", PRINT_NULL (part->encoding)); } if (*inptr != ')') { part->octets = decode_num (&inptr, inend, err); debug_printf ("octets: %d\n", part->octets); } if (*inptr != ')') { read_unknown_qstring (&inptr, inend, err); } if (*inptr != ')') { parse_content_disposition (&inptr, inend, &part->disposition, err); } if (*inptr != ')') { parse_lang (&inptr, inend, part, err); } if (*inptr != ')') { end_this_piece (&inptr, inend, err); } } else { /* I don't know how it looks, so I just read it away */ end_this_piece (&inptr, inend, err); } } if (*inptr != ')') { *in = inptr; set_error (err, in); bodystruct_free (part); return NULL; } inptr++; /* My ')' */ *in = inptr; return part; }