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

Function mq_item_add

modules/mqueue/mqueue_api.c:291–387  ·  view source on GitHub ↗

* */

Source from the content-addressed store, hash-verified

289 *
290 */
291int mq_item_add(str *qname, str *key, str *val)
292{
293 mq_head_t *mh = NULL;
294 mq_item_t *mi = NULL;
295 mq_item_t *miter = NULL;
296 mq_item_t *miter_prev = NULL;
297 int oplock = 0;
298 int len;
299
300 mh = mq_head_get(qname);
301 if(mh == NULL) {
302 LM_ERR("mqueue not found: %.*s\n", qname->len, qname->s);
303 return -1;
304 }
305
306 if(mh->addmode == 1 || mh->addmode == 2) {
307 lock_get(&mh->lock);
308 oplock = 1;
309 miter = mh->ifirst;
310 miter_prev = mh->ifirst;
311 while(miter) {
312 // found mqueue item
313 if(miter->key.len == key->len
314 && strncmp(miter->key.s, key->s, key->len) == 0) {
315 // mode unique and keep oldest: just return
316 if(mh->addmode == 1) {
317 lock_release(&mh->lock);
318 return 0;
319 }
320
321 // mode unique and keep newest: free oldest and further add newest
322 if(miter == mh->ifirst && miter == mh->ilast) {
323 mh->ifirst = NULL;
324 mh->ilast = NULL;
325 } else if(miter == mh->ifirst) {
326 mh->ifirst = miter->next;
327 } else if(miter == mh->ilast) {
328 mh->ilast = miter_prev;
329 mh->ilast->next = NULL;
330 } else {
331 miter_prev->next = miter->next;
332 }
333
334 shm_free(miter);
335 mh->csize--;
336
337 break;
338 }
339 miter_prev = miter;
340 miter = miter->next;
341 }
342 }
343
344 // mode default
345 len = sizeof(mq_item_t) + key->len + val->len + 2;
346 mi = (mq_item_t *)shm_malloc(len);
347 if(mi == NULL) {
348 LM_ERR("no more shm to add to: %.*s\n", qname->len, qname->s);

Callers 2

mqueue_db_load_queueFunction · 0.85
w_mq_addFunction · 0.85

Calls 5

mq_head_getFunction · 0.85
lock_getFunction · 0.85
lock_releaseFunction · 0.85
shm_freeFunction · 0.85
shm_mallocFunction · 0.85

Tested by

no test coverage detected