[Serdev] Module Assistance - How to modify payload contents.

Greenwell, Gary L, JR, ALABS ggreenwell at att.com
Fri Apr 7 13:56:52 UTC 2006


That was exactly the information I was looking for.  
 
Thanks.

________________________________

From: Andrei Pelinescu-Onciul [mailto:andrei at iptel.org]
Sent: Fri 4/7/2006 8:45 AM
To: Greenwell, Gary L, JR, ALABS
Cc: serdev at lists.iptel.org
Subject: Re: [Serdev] Module Assistance - How to modify payload contents.



On Apr 06, 2006 at 17:39, Greenwell, Gary L, JR, ALABS <ggreenwell at att.com> wrote:
> First - ser-0.9.6 on Linux. 
> 
> That being said, here is what I would like to do: 


Take a look at the textops module, in particular the remove_hf , the
replace_f and the search_append_f functions. You can use them as an
example for using the data lumps api.

> 
> On an INVITE, replace the Content-Type: application/SDP with Content-Type: multipart/mixed; boundary=unique-boundary-1

First you need to make sure the Content-Type header is parsed/found (so
that you will know its position).
In general you would need to use something like:

 if ((msg->content_type==0) &&
      (parse_headers(msg, HDR_CONTENTTYPE,0)==-1 || msg->from==0) ){
      /* error content_type is either missing ( parse_header(...) !=-1
       * and after running it msg->from is still 0), or is  bad
       * (parse_header(...)==-1 */
      goto error;
  }

OTOH if you want to change also the message body, you'll have to parse
all the headers anyway (to find out where the headers end and the body
starts), so the above code can be replaced by a much simpler version,
 which takes advantage of the implicit parsing of the message triggered
 by the call to get_body():

    char* body;

    body=get_body(msg);
    /* get_body calls internally parse_headers(msg, HDR_EOH) which
       parses all the headers, so you don't need to call parse_headers
       for the the content type header */
   if (body==0){
    /* the message either doesn't have a body, or the message is
     * broken and cannot be parsed */
     goto no_body; ...
   }
   /* msg->content_type is filled by parse_headers(...) which is called
      from get_body() */
   if (msg->content_type==0){
     /* missing content_type */
     goto ...
   }

To change the Content-Type value, you'll have first to remove the
current value and then add the new one:

  struct lump *l;

 /* remove */
 l=del_lump(msg, msg->content_type->body.s-msg->buf /* offset in the msg*/,
                 msg->content_type->body.len /* size */,
                 HDR_CONTENTTYPE /* type */);

 if (l==0) /* error, probably out of memory... */

 /* add */
 if (insert_new_lump_after(l, NEW_STR, NEW_STR_LEN, HDR_CONTENTTYPE)==0)
   /* error insert, probably our of mem. */


> 
> Next I want to modify the payload to contain:
> 
> --unique-boundary-1
> Content-Type: application/SDP

  /* insert the above strings at the beginning of the body */
  l=anchor_lump(msg, body-msg->buf /* start of body offset */, 0, 0);
  if (l==0) /* error */
  if (insert_new_lump_after(l, ABOVE_STR, ABOVE_STR_LEN, 0)==0)
     /* error */


> *** Original SDP Information ***

 /* nothing to do */

> --unique-boundary-1
> Content-Type: application/ISUP; version=nxv3; base=etsi121
> Content-Disposition: signal; handling=optional
> *** A Kludged ISUP IAM ***
> --unique-boundary-1--

  /* append the above strings at the end of the message */
  l=anchor_lump(msg, msg->len /* end of message */, 0, 0);
  if (l==0) /* error */
  if (insert_new_lump_after(l, ABOVE_STR, ABOVE_STR_LEN, 0)==0)
     /* error */

> 
> Then obviously update the Content-Length to reflect the additional payload.

This is done automatically.
> 
> I am guessing this is achieved by using the data_lump API, but after that I am at a loss.
> Any advice would be appreciated.
> 



Andrei





More information about the Serdev mailing list