MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / new_avp

Function new_avp

usr_avp.c:100–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98
99
100struct usr_avp* new_avp(unsigned short flags, int id, int_str val)
101{
102 struct usr_avp *avp;
103 str *s;
104 int len;
105
106 assert( crt_avps!=0 );
107
108 if (id < 0) {
109 LM_ERR("invalid AVP name!\n");
110 goto error;
111 }
112
113 /* compute the required mem size */
114 len = sizeof(struct usr_avp);
115 if (flags & AVP_VAL_STR)
116 len += sizeof(str)-sizeof(void*) + (val.s.len+1);
117
118 avp = (struct usr_avp*)shm_malloc( len );
119 if (avp==0) {
120 LM_ERR("no more shm mem\n");
121 goto error;
122 }
123
124 avp->flags = flags;
125 avp->id = id ;
126
127 if (flags & AVP_VAL_STR) {
128 /* avp type ID, str value */
129 s = (str *)&avp->data;
130 s->len = val.s.len;
131 s->s = (char*)s + sizeof(str);
132 memcpy( s->s, val.s.s , s->len);
133 s->s[s->len] = 0;
134 } else if (flags & AVP_VAL_NULL) {
135 avp->data = NULL;
136 } else {
137 avp->data = (void *)(long)val.n;
138 }
139
140 return avp;
141error:
142 return NULL;
143}
144
145int add_avp(unsigned short flags, int name, int_str val)
146{

Callers 8

add_avpFunction · 0.85
add_avp_lastFunction · 0.85
replace_avpFunction · 0.85
clone_avp_listFunction · 0.85
ds_check_timerFunction · 0.85
get_report_rt_avpsFunction · 0.85
pn_trim_pn_paramsFunction · 0.85

Calls 1

shm_mallocFunction · 0.85

Tested by

no test coverage detected