[sr-dev] git:master: lib/srdb1: introduce helper to convert db_val to pv_spec
Daniel-Constantin Mierla
miconda at gmail.com
Sat Aug 20 13:40:18 CEST 2011
Fixed with commit:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0a8e9ea74191e1231abf431f87212f7508b8cc92
If does not compile now on other OS, just report here.
Cheers,
Daniel
On 8/20/11 1:20 PM, Daniel-Constantin Mierla wrote:
> Hello,
>
> At this moment the code fails to build on Mac OS X:
>
> CC (gcc) [L libsrdb1.1.0.0.dylib] db_ut.o
> In file included from ../../parser/msg_parser.h:63,
> from ../../pvar.h:34,
> from db_ut.h:57,
> from db_ut.c:33:
> ../../parser/../ip_addr.h: In function ‘ip_addr_loopback’:
> ../../parser/../ip_addr.h:283: error: ‘INADDR_LOOPBACK’ undeclared
> (first use in this function)
> ../../parser/../ip_addr.h:283: error: (Each undeclared identifier is
> reported only once
> ../../parser/../ip_addr.h:283: error: for each function it appears in.)
> make[2]: *** [db_ut.o] Error 1
> make[1]: *** [../../lib/srdb1/libsrdb1.dylib] Error 2
> make: *** [modules] Error 1
>
> Cheers,
> Daniel
>
> On 8/20/11 10:25 AM, Alex Hermann wrote:
>> Module: sip-router
>> Branch: master
>> Commit: ed78c0967b69abc6e8333924460641de08b73e8f
>> URL:
>> http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ed78c0967b69abc6e8333924460641de08b73e8f
>>
>> Author: Alex Hermann<alex at speakup.nl>
>> Committer: Alex Hermann<alex at speakup.nl>
>> Date: Sat Aug 20 09:48:00 2011 +0200
>>
>> lib/srdb1: introduce helper to convert db_val to pv_spec
>>
>> ---
>>
>> lib/srdb1/db_ut.c | 99
>> +++++++++++++++++++++++++++++++++++++++++++++++++++++
>> lib/srdb1/db_ut.h | 12 ++++++
>> 2 files changed, 111 insertions(+), 0 deletions(-)
>>
>> diff --git a/lib/srdb1/db_ut.c b/lib/srdb1/db_ut.c
>> index 16e2f4f..fbc037c 100644
>> --- a/lib/srdb1/db_ut.c
>> +++ b/lib/srdb1/db_ut.c
>> @@ -34,6 +34,7 @@
>>
>> #include "../../mem/mem.h"
>> #include "../../dprint.h"
>> +#include "../../pvar.h"
>> #include<limits.h>
>> #include<errno.h>
>> #include<stdio.h>
>> @@ -371,3 +372,101 @@ int db_print_set(const db1_con_t* _c, char* _b,
>> const int _l, const db_key_t* _k
>> LM_ERR("Error in snprintf\n");
>> return -1;
>> }
>> +
>> +/*
>> + * Convert db_val to pv_spec
>> + */
>> +int db_val2pv_spec(struct sip_msg* msg, db_val_t *dbval, pv_spec_t
>> *pvs)
>> +{
>> + pv_value_t pv;
>> + str sv = {NULL, 0};
>> + static str _str_empty = { "", 0 };
>> +
>> + if(dbval->nul)
>> + {
>> + pv.flags = PV_VAL_NULL;
>> + } else
>> + {
>> + switch(dbval->type)
>> + {
>> + case DB1_STRING:
>> + pv.flags = PV_VAL_STR;
>> + sv.s = (char*)dbval->val.string_val;
>> + sv.len = strlen(sv.s);
>> + break;
>> + case DB1_STR:
>> + pv.flags = PV_VAL_STR;
>> + sv.s = (char*)dbval->val.str_val.s;
>> + sv.len = dbval->val.str_val.len;
>> + break;
>> + case DB1_BLOB:
>> + pv.flags = PV_VAL_STR;
>> + sv.s = (char*)dbval->val.blob_val.s;
>> + sv.len = dbval->val.blob_val.len;
>> + break;
>> + case DB1_INT:
>> + pv.flags = PV_VAL_INT | PV_TYPE_INT;
>> + pv.ri = (int)dbval->val.int_val;
>> + break;
>> + case DB1_DATETIME:
>> + pv.flags = PV_VAL_INT | PV_TYPE_INT;
>> + pv.ri = (int)dbval->val.time_val;
>> + break;
>> + case DB1_BITMAP:
>> + pv.flags = PV_VAL_INT | PV_TYPE_INT;
>> + pv.ri = (int)dbval->val.bitmap_val;
>> + break;
>> + case DB1_BIGINT:
>> + /* BIGINT is stored as string */
>> + pv.flags = PV_VAL_STR;
>> + pv.rs.len = 21*sizeof(char);
>> + pv.rs.s = (char*)pkg_malloc(pv.rs.len);
>> + if (pv.rs.s==NULL)
>> + {
>> + LM_ERR("no more memory\n");
>> + return -1;
>> + }
>> + db_longlong2str(dbval->val.ll_val, pv.rs.s,&pv.rs.len);
>> + break;
>> + default:
>> + LM_NOTICE("unknown field type: %d, setting value to
>> null\n",
>> + dbval->type);
>> + pv.flags = PV_VAL_NULL;
>> + }
>> + }
>> +
>> + /* null values are ignored for avp type PV */
>> + if (pv.flags == PV_VAL_NULL&& pvs->type == PVT_AVP)
>> + return 0;
>> +
>> + /* handle string values */
>> + if(pv.flags == PV_VAL_STR&& sv.s)
>> + {
>> + if(sv.len==0)
>> + {
>> + pv.rs = _str_empty;
>> + } else
>> + {
>> + /* create copy of string value in pkg mem */
>> + pv.rs.s = (char*)pkg_malloc(sv.len*sizeof(char));
>> + if(pv.rs.s==NULL)
>> + {
>> + LM_ERR("no more memory\n");
>> + return -1;
>> + }
>> + memcpy(pv.rs.s, sv.s, sv.len);
>> + pv.rs.len = sv.len;
>> + }
>> + }
>> +
>> + /* add value to result pv */
>> + if (pv_set_spec_value(msg, pvs, 0,&pv) != 0)
>> + {
>> + LM_ERR("Failed to add value to spec\n");
>> + if (pv.flags == PV_VAL_STR)
>> + pkg_free(pv.rs.s);
>> + return -1;
>> + }
>> +
>> + return 0;
>> +}
>> diff --git a/lib/srdb1/db_ut.h b/lib/srdb1/db_ut.h
>> index 85cbe48..0531dc4 100644
>> --- a/lib/srdb1/db_ut.h
>> +++ b/lib/srdb1/db_ut.h
>> @@ -54,6 +54,7 @@
>>
>> #include "db_key.h"
>> #include "db.h"
>> +#include "../../pvar.h"
>>
>>
>> /**
>> @@ -204,4 +205,15 @@ int db_print_set(const db1_con_t* _c, char* _b,
>> const int _l,
>> const db_key_t* _k, const db_val_t* _v, const int _n, int
>> (*val2str)
>> (const db1_con_t*, const db_val_t*, char*, int*));
>>
>> +
>> +/**
>> + * Convert db_val to pv_spec_t
>> + *
>> + * \param msg sip msg structure
>> + * \param dbval database value
>> + * \param pvs pv_spec wher to put the database value
>> + * \return 1 on success, 0 on failure
>> + */
>> +int db_val2pv_spec(struct sip_msg* msg, db_val_t *dbval, pv_spec_t
>> *pvs);
>> +
>> #endif
>>
>>
>> _______________________________________________
>> sr-dev mailing list
>> sr-dev at lists.sip-router.org
>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
--
Daniel-Constantin Mierla -- http://www.asipto.com
Kamailio Advanced Training, Oct 10-13, Berlin: http://asipto.com/u/kat
http://linkedin.com/in/miconda -- http://twitter.com/miconda
More information about the sr-dev
mailing list