Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
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
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
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
00134 foo = msg->reply_lump;
00135 prev = 0;
00136 while( foo && foo!=lump ) {
00137 prev = foo;
00138 foo = foo->next;
00139 }
00140
00141
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