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

Function cachedb_add

cachedb/cachedb.c:517–574  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

515}
516
517int cachedb_add(str* cachedb_name, str* attr, int val,int expires,int *new_val)
518{
519 cachedb_engine* cde;
520 str cde_engine,grp_name;
521 char *p;
522 cachedb_con *con;
523 int ret;
524
525 if(cachedb_name == NULL || attr == NULL)
526 {
527 LM_ERR("null arguments\n");
528 return -1;
529 }
530
531 p = memchr(cachedb_name->s,':',cachedb_name->len);
532 if (p == NULL) {
533 cde_engine = *cachedb_name;
534 grp_name.s = NULL;
535 grp_name.len = 0;
536 LM_DBG("from script [%.*s] - no grp\n",cde_engine.len,cde_engine.s);
537 } else {
538 cde_engine.s = cachedb_name->s;
539 cde_engine.len = p - cde_engine.s;
540 grp_name.s = p+1;
541 grp_name.len = cachedb_name->len - cde_engine.len -1;
542 LM_DBG("from script [%.*s] - with grp [%.*s]\n",cde_engine.len,
543 cde_engine.s,grp_name.len,grp_name.s);
544
545 }
546
547 cde = lookup_cachedb(&cde_engine);
548 if(cde == NULL)
549 {
550 LM_ERR("Wrong argument <%.*s> - no cachedb system with"
551 " this name registered\n",
552 cde_engine.len,cde_engine.s);
553 return -1;
554 }
555
556 if (!CACHEDB_CAPABILITY(&cde->cdb_func,CACHEDB_CAP_ADD)) {
557 LM_ERR("Engine %.*s does not support add ops\n",
558 cde_engine.len,cde_engine.s);
559 return -1;
560 }
561
562 con = cachedb_get_connection(cde,&grp_name);
563 if (con == NULL) {
564 LM_ERR("failed to get connection for grp name [%.*s] : check db_url\n",
565 grp_name.len,grp_name.s);
566 return -1;
567 }
568
569 ret = cde->cdb_func.add(con,attr,val,expires,new_val);
570 if (ret == 0)
571 ret++;
572
573 return ret;
574}

Callers 1

w_cache_addFunction · 0.85

Calls 2

lookup_cachedbFunction · 0.85
cachedb_get_connectionFunction · 0.85

Tested by

no test coverage detected