• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

data_lump_rpl.c

Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  *
00005  * Copyright (C) 2001-2003 FhG Fokus
00006  *
00007  * This file is part of ser, a free SIP server.
00008  *
00009  * ser is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * For a license to use the ser software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact iptel.org by e-mail at the following addresses:
00017  *    info@iptel.org
00018  *
00019  * ser is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License 
00025  * along with this program; if not, write to the Free Software 
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  *
00028  * History:
00029  * 2002-02-14 : created by bogdan
00030  * 2003-09-11 : lump_rpl type added - LUMP_RPL_BODY & LUMP_RPL_HDR (bogdan)
00031  * 2003-11-11 : build_lump_rpl merged into add_lump_rpl; types -> flags ;
00032  *              flags LUMP_RPL_NODUP and LUMP_RPL_NOFREE added (bogdan)
00033  * 2006-10-16   add_lump_rpl2 added: same as the old add_lump_rpl, but
00034  *               returns a lump_rpl**, making a specific lump removal much
00035  *               more easy (andrei)
00036  */
00046 #include <string.h>
00047 #include "dprint.h"
00048 #include "mem/mem.h"
00049 #include "data_lump_rpl.h"
00050 
00051 
00052 
00053 struct lump_rpl** add_lump_rpl2(struct sip_msg *msg, char *s, 
00054                                                                         int len, int flags)
00055 {
00056         struct lump_rpl *lump = 0;
00057         struct lump_rpl *foo;
00058         struct lump_rpl** ret;
00059 
00060         /* some checking */
00061         if ( (flags&(LUMP_RPL_HDR|LUMP_RPL_BODY))==(LUMP_RPL_HDR|LUMP_RPL_BODY)
00062         || (flags&(LUMP_RPL_HDR|LUMP_RPL_BODY))==0 || (flags&LUMP_RPL_SHMEM) ) {
00063                 LOG(L_ERR,"ERROR:add_lump_rpl: bad flags combination (%d)!\n",flags);
00064                 goto error;
00065         }
00066         if (len<=0 || s==0) {
00067                 LOG(L_ERR,"ERROR:add_lump_rpl: I won't add an empty lump!\n");
00068                 goto error;
00069         }
00070 
00071         /* build the lump */
00072         lump = (struct lump_rpl*) pkg_malloc
00073                 ( sizeof(struct lump_rpl) + ((flags&LUMP_RPL_NODUP)?0:len) );
00074         if (!lump) {
00075                 LOG(L_ERR,"ERROR:add_lump_rpl : no free pkg memory !\n");
00076                 goto error;
00077         }
00078 
00079         if (flags&LUMP_RPL_NODUP) {
00080                 lump->text.s = s;
00081         } else {
00082                 lump->text.s = ((char*)lump)+sizeof(struct lump_rpl);
00083                 memcpy( lump->text.s, s, len);
00084         }
00085         lump->text.len = len;
00086         lump->flags = flags;
00087         lump->next = 0;
00088 
00089         /* add the lump to the msg */
00090         if (!msg->reply_lump) {
00091                 msg->reply_lump = lump;
00092                 ret=&msg->reply_lump;
00093         }else{
00094                 if (!(flags&LUMP_RPL_BODY))
00095                         for(foo=msg->reply_lump;foo->next;foo=foo->next);
00096                 else
00097                         for(foo=msg->reply_lump; ;foo=foo->next) {
00098                                 if (foo->flags&LUMP_RPL_BODY) {
00099                                         LOG(L_ERR,"ERROR:add_lump_rpl: LUMP_RPL_BODY "
00100                                                 "already added!\n");
00101                                         pkg_free(lump);
00102                                         goto error;
00103                                 }
00104                                 if (foo->next==0)
00105                                         break;
00106                         }
00107                 foo->next = lump;
00108                 ret= &(foo->next);
00109         }
00110 
00111         return ret;
00112 error:
00113         return 0;
00114 }
00115 
00116 
00117 
00118 void free_lump_rpl(struct lump_rpl* lump)
00119 {
00120         if (lump) {
00121                 if (!((lump->flags)&LUMP_RPL_NOFREE) && ((lump->flags)&LUMP_RPL_NODUP)
00122                 && lump->text.s)
00123                         pkg_free(lump->text.s);
00124                 pkg_free(lump);
00125         }
00126 }
00127 
00128 
00129 void unlink_lump_rpl(struct sip_msg * msg, struct lump_rpl* lump)
00130 {
00131         struct lump_rpl *foo,*prev;
00132 
00133         /* look for the lump to be unlink */
00134         foo = msg->reply_lump;
00135         prev = 0;
00136         while( foo && foo!=lump ) {
00137                 prev = foo;
00138                 foo = foo->next;
00139         }
00140 
00141         /* if the lump was found into the list -> unlink it */
00142         if (foo) {
00143                 if (prev)
00144                         prev->next = foo->next;
00145                 else
00146                         msg->reply_lump = foo->next;
00147         }
00148 }
00149 
00150 void del_nonshm_lump_rpl(struct lump_rpl** list)
00151 {
00152         struct lump_rpl* it, *tmp;
00153         struct lump_rpl** pred;
00154 
00155         it = *list;
00156         pred = list;
00157 
00158         while(it) {
00159                 if (!(it->flags & LUMP_RPL_SHMEM)) {
00160                         tmp = it;
00161                         *pred = it->next;
00162                         it = it->next;
00163                         free_lump_rpl(tmp);
00164                         continue;
00165                 }
00166 
00167                 pred = &it->next;
00168                 it = it->next;
00169         }
00170 }
00171 

Generated on Tue May 22 2012 13:10:05 for SIP Router by  doxygen 1.7.1