New upstream version 4.4.4

changes/83/9683/1 upstream/4.4.4
Victor Seva 9 years ago
parent c742e1becc
commit 69d108737b

File diff suppressed because it is too large Load Diff

@ -89,6 +89,11 @@ endif
WITHAS ?= 1
# enable core hooks for SCTP
SCTP ?= 1
# enable raw sockets
RAW_SOCKS ?= yes
ifeq ($(RAW_SOCKS),1)
RAW_SOCKS = yes
endif
# what to install
INSTALL_FLAVOUR=$(FLAVOUR)
@ -96,7 +101,7 @@ INSTALL_FLAVOUR=$(FLAVOUR)
# version number
VERSION = 4
PATCHLEVEL = 4
SUBLEVEL = 3
SUBLEVEL = 4
# memory manager switcher
# 0 - f_malloc (fast malloc)
@ -1716,7 +1721,10 @@ ifeq ($(OS), linux)
use_futex= yes
C_DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
-DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
-DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER -DUSE_RAW_SOCKS
-DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER
ifneq ($(RAW_SOCKS), yes)
C_DEFS+= -DUSE_RAW_SOCKS
endif
ifneq ($(found_lock_method), yes)
#C_DEFS+= -DUSE_POSIX_SEM
C_DEFS+=-DUSE_PTHREAD_MUTEX
@ -1763,7 +1771,10 @@ ifeq ($(OS), gnu_kfreebsd)
use_futex= yes
C_DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
-DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
-DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER -DUSE_RAW_SOCKS
-DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER
ifneq ($(RAW_SOCKS), yes)
C_DEFS+= -DUSE_RAW_SOCKS
endif
ifneq ($(found_lock_method), yes)
#C_DEFS+= -DUSE_POSIX_SEM
C_DEFS+=-DUSE_PTHREAD_MUTEX
@ -1844,7 +1855,10 @@ ifeq ($(OS), freebsd)
C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
-DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
-DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
-DHAVE_NETINET_IN_SYSTM -DUSE_RAW_SOCKS
-DHAVE_NETINET_IN_SYSTM
ifneq ($(RAW_SOCKS), yes)
C_DEFS+= -DUSE_RAW_SOCKS
endif
ifneq ($(found_lock_method), yes)
C_DEFS+= -DUSE_PTHREAD_MUTEX # try pthread sems
found_lock_method=yes

@ -2,6 +2,6 @@
* DO NOT EDIT IT
*/
#define REPO_VER "5a2195"
#define REPO_HASH "5a2195"
#define REPO_VER "852c47"
#define REPO_HASH "852c47"
#define REPO_STATE ""

@ -496,7 +496,7 @@ COLON ":"
STAR \*
DOT \.
CR \n
EVENT_RT_NAME [a-zA-Z][0-9a-zA-Z-]*(":"[a-zA-Z][0-9a-zA-Z-]*)+
EVENT_RT_NAME [a-zA-Z][0-9a-zA-Z-]*(":"[a-zA-Z][0-9a-zA-Z_-]*)+
COM_LINE "#"|"//"

@ -90,13 +90,16 @@
#define SERVER_HDR_LEN (sizeof(SERVER_HDR)-1)
#define MAX_WARNING_LEN 256
#define MY_BRANCH ";branch="
#define MY_BRANCH_LEN (sizeof(MY_BRANCH) - 1)
#define MAX_PORT_LEN 7 /* ':' + max 5 letters + \0 */
#define CRLF "\r\n"
#define CRLF_LEN (sizeof(CRLF) - 1)
#define CRLFCRLF "\r\n\r\n"
#define CRLFCRLF_LEN (sizeof(CRLFCRLF) - 1)
#define RECEIVED ";received="
#define RECEIVED_LEN (sizeof(RECEIVED) - 1)

@ -743,13 +743,19 @@ int sr_hdr_add(sip_msg_t *msg, str *sname, str *sbody)
struct lump* anchor;
str h;
parse_headers(msg, HDR_EOH_F, 0);
if(msg->last_header == 0) {
LM_ERR("failed to parse headers\n");
return -1;
}
h.len = sname->len + 2 + sbody->len + CRLF_LEN;
h.s = (char*)pkg_malloc(h.len+1);
if(h.s == 0) {
LM_ERR("no more pkg\n");
return -1;
}
anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0);
anchor = anchor_lump(msg, msg->last_header->name.s + msg->last_header->len
- msg->buf, 0, 0);
if(anchor == 0)
{
LM_ERR("cannot get the anchor\n");
@ -767,7 +773,7 @@ int sr_hdr_add(sip_msg_t *msg, str *sname, str *sbody)
pkg_free(h.s);
return -1;
}
LM_DBG("added new header [%s]\n", h.s);
LM_DBG("added new header (%d) [%s]\n", h.len, h.s);
return 0;
}

@ -13,11 +13,11 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* send commands using binrpc
*
@ -67,7 +67,7 @@ static void (*internal_free)(void* ptr) = free;
static char binrpc_last_errs[1024] = "";
static int verbose = 0;
char *binrpc_get_last_errs()
char *binrpc_get_last_errs()
{
return binrpc_last_errs;
}
@ -213,28 +213,29 @@ static int connect_tcpudp_socket(char* address, int port, int type)
struct sockaddr_in addr;
struct hostent* he;
int sock;
sock=-1;
/* resolve destination */
he=gethostbyname(address);
if (he==0){
snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
"connect_tcpudp_socket: could not resolve %s", address);
goto error;
}
/* open socket*/
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_family=he->h_addrtype;
addr.sin_port=htons(port);
memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
sock = socket(he->h_addrtype, type, 0);
if (sock==-1){
snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
"connect_tcpudp_socket: socket: %s", strerror(errno));
goto error;
}
if (connect(sock, (struct sockaddr*) &addr, sizeof(struct sockaddr))!=0){
snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
snprintf(binrpc_last_errs, sizeof(binrpc_last_errs)-1,
"connect_tcpudp_socket: connect: %s", strerror(errno));
goto error;
}
@ -246,7 +247,7 @@ error:
/* on exit cleanup */
static void cleanup(struct sockaddr_un* mysun)
{
{
if (mysun->sun_path[0] != '\0') {
if (unlink(mysun->sun_path) < 0) {
fprintf(stderr, "ERROR: failed to delete %s: %s\n",
@ -259,7 +260,7 @@ int binrpc_open_connection(struct binrpc_handle* handle, char* name, int port, i
char* reply_socket, char* sock_dir)
{
struct sockaddr_un mysun;
binrpc_last_errs[0] = '\0';
binrpc_last_errs[sizeof(binrpc_last_errs)-1] = '\0'; /* snprintf safe terminator */

@ -358,7 +358,7 @@ int db_print_where(const db1_con_t* _c, char* _b, const int _l, const db_key_t*
if (_o && strncmp(_o[i], OP_BITWISE_AND, 1) == 0) {
char tmp_buf[16];
int tmp_len = 15;
memset(tmp_buf, '0', 16);
memset(tmp_buf, 0, 16);
if ((*val2str)(_c, &(_v[i]), tmp_buf, &tmp_len) < 0) {
LM_ERR("Error while converting value to string\n");
return -1;

@ -193,7 +193,6 @@ static const char *parse_number(srjson_doc_t *doc, srjson_t *item, const char *n
* 10^+/- exponent */
item->valuedouble = n;
item->valueint = (int) n;
item->type = srjson_Number;
return num;
}
@ -203,12 +202,13 @@ static char *print_number(srjson_doc_t *doc, srjson_t *item)
{
char *str;
double d = item->valuedouble;
if (fabs(((double) item->valueint) - d) <= DBL_EPSILON && d <= INT_MAX && d >= INT_MIN) {
int i = (int)d;
if (fabs(((double) i) - d) <= DBL_EPSILON && d <= INT_MAX && d >= INT_MIN) {
str = (char *) doc->malloc_fn(21); /* 2^64+1 can be
* represented in 21
* chars. */
if (str)
sprintf(str, "%d", item->valueint);
sprintf(str, "%d", i);
} else {
str = (char *) doc->malloc_fn(64); /* This is a nice
* tradeoff. */
@ -444,15 +444,17 @@ static const char *parse_value(srjson_doc_t *doc, srjson_t *item, const char *va
return 0; /* Fail on null. */
if (!strncmp(value, "null", 4)) {
item->type = srjson_NULL;
item->valuedouble = 0;
return value + 4;
}
if (!strncmp(value, "false", 5)) {
item->type = srjson_False;
item->valuedouble = 0;
return value + 5;
}
if (!strncmp(value, "true", 4)) {
item->type = srjson_True;
item->valueint = 1;
item->valuedouble = 1;
return value + 4;
}
if (*value == '\"') {
@ -956,7 +958,6 @@ srjson_t *srjson_CreateNumber(srjson_doc_t *doc, double num) {
if (item) {
item->type = srjson_Number;
item->valuedouble = num;
item->valueint = (int) num;
} return item;
}

@ -47,6 +47,13 @@ extern "C"
#define srjson_IsReference 256
/* helper macros */
#define SRJSON_GET_INT(sj) ((int)((sj)->valuedouble))
#define SRJSON_GET_UINT(sj) ((unsigned int)((sj)->valuedouble))
#define SRJSON_GET_LONG(sj) ((long)((sj)->valuedouble))
#define SRJSON_GET_ULONG(sj) ((unsigned long)((sj)->valuedouble))
/* The srjson node structure: */
typedef struct srjson {
struct srjson *parent;
@ -64,8 +71,6 @@ typedef struct srjson {
int type; /* The type of the item, as above. */
char *valuestring; /* The item's string, if
* type==srjson_String */
int valueint; /* The item's number, if
* type==srjson_Number */
double valuedouble; /* The item's number, if
* type==srjson_Number */
char *string; /* The item's name string, if this

@ -37,6 +37,8 @@
/*
** gcc 3.4 and above have builtin support, specialized for architecture.
** Some compilers masquerade as gcc; patchlevel test filters them out.
**
** Note: clang is compatible with GCC builtins and will also define those macros
*/
#if defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \
&& defined (__GNUC_PATCHLEVEL__)
@ -52,78 +54,13 @@ tlsf_decl int tlsf_fls(unsigned int word)
return bit - 1;
}
#elif defined (_MSC_VER) && (_MSC_VER >= 1400) && (defined (_M_IX86) || defined (_M_X64))
/* Microsoft Visual C++ support on x86/X64 architectures. */
#include <intrin.h>
#pragma intrinsic(_BitScanReverse)
#pragma intrinsic(_BitScanForward)
tlsf_decl int tlsf_fls(unsigned int word)
{
unsigned long index;
return _BitScanReverse(&index, word) ? index : -1;
}
tlsf_decl int tlsf_ffs(unsigned int word)
{
unsigned long index;
return _BitScanForward(&index, word) ? index : -1;
}
#elif defined (_MSC_VER) && defined (_M_PPC)
/* Microsoft Visual C++ support on PowerPC architectures. */
#include <ppcintrinsics.h>
tlsf_decl int tlsf_fls(unsigned int word)
{
const int bit = 32 - _CountLeadingZeros(word);
return bit - 1;
}
tlsf_decl int tlsf_ffs(unsigned int word)
{
const unsigned int reverse = word & (~word + 1);
const int bit = 32 - _CountLeadingZeros(reverse);
return bit - 1;
}
#elif defined (__ARMCC_VERSION)
/* RealView Compilation Tools for ARM */
tlsf_decl int tlsf_ffs(unsigned int word)
{
const unsigned int reverse = word & (~word + 1);
const int bit = 32 - __clz(reverse);
return bit - 1;
}
tlsf_decl int tlsf_fls(unsigned int word)
{
const int bit = word ? 32 - __clz(word) : 0;
return bit - 1;
}
#elif defined (__ghs__)
/* Green Hills support for PowerPC */
#include <ppc_ghs.h>
tlsf_decl int tlsf_ffs(unsigned int word)
{
const unsigned int reverse = word & (~word + 1);
const int bit = 32 - __CLZ32(reverse);
return bit - 1;
}
tlsf_decl int tlsf_fls(unsigned int word)
#if defined (TLSF_64BIT)
tlsf_decl int tlsf_fls_sizet(size_t size)
{
const int bit = word ? 32 - __CLZ32(word) : 0;
const int bit = size ? 64 - __builtin_clzl(size) : 0;
return bit - 1;
}
#endif
#else
/* Fall back to generic implementation. */
@ -152,9 +89,6 @@ tlsf_decl int tlsf_fls(unsigned int word)
return tlsf_fls_generic(word) - 1;
}
#endif
/* Possibly 64-bit version of tlsf_fls. */
#if defined (TLSF_64BIT)
tlsf_decl int tlsf_fls_sizet(size_t size)
{
@ -171,7 +105,12 @@ tlsf_decl int tlsf_fls_sizet(size_t size)
}
return bits;
}
#else
#endif /* defined (TLSF_64BIT) */
#endif /* GNUC */
#if !defined (TLSF_64BIT)
#define tlsf_fls_sizet tlsf_fls
#endif

@ -742,6 +742,12 @@ static int lua_sr_hdr_append (lua_State *L)
memcpy(hdr, txt, len);
anchor = anchor_lump(env_L->msg,
hf->name.s + hf->len - env_L->msg->buf, 0, 0);
if(anchor==NULL)
{
LM_ERR("unable to get the anchor\n");
pkg_free(hdr);
return 0;
}
if(insert_new_lump_before(anchor, hdr, len, 0) == 0)
{
LM_ERR("can't insert lump\n");

@ -104,8 +104,20 @@ static int mod_init(void)
}
dname = strdup(dirname(dname_src));
if (strlen(dname) == 0)
dname = ".";
if(dname==NULL) {
LM_ERR("no more system memory\n");
return -1;
}
if (strlen(dname) == 0) {
free(dname);
dname = malloc(2);
if(dname==NULL) {
LM_ERR("no more system memory\n");
return -1;
}
dname[0] = '.';
dname[1] = '\0';
}
bname = strdup(basename(bname_src));
i = strlen(bname);
if (bname[i - 1] == 'c' || bname[i - 1] == 'o')

@ -334,17 +334,17 @@ int autheph_www2(struct sip_msg *_m, char *_realm, char *_method)
return AUTH_ERROR;
}
if (_m->REQ_METHOD == METHOD_ACK || _m->REQ_METHOD == METHOD_CANCEL)
{
return AUTH_OK;
}
if(_m == NULL || _realm == NULL)
{
LM_ERR("invalid parameters\n");
return AUTH_ERROR;
}
if (_m->REQ_METHOD == METHOD_ACK || _m->REQ_METHOD == METHOD_CANCEL)
{
return AUTH_OK;
}
if (get_str_fparam(&srealm, _m, (fparam_t*)_realm) < 0)
{
LM_ERR("failed to get realm value\n");

@ -37,6 +37,7 @@
#include <openssl/sha.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <openssl/crypto.h>
#include <openssl/x509_vfy.h>
#include "../../mem/mem.h"
@ -115,7 +116,11 @@ int check_x509_subj(X509 *pcert, str* sdom)
if (actname->type == GEN_DNS || actname->type == GEN_URI) {
/* we've found one */
#if OPENSSL_VERSION_NUMBER >= 0x010100000L
altptr = (char *)ASN1_STRING_get0_data(actname->d.ia5);
#else
altptr = (char *)ASN1_STRING_data(actname->d.ia5);
#endif
if (actname->type == GEN_URI) {
if (parse_uri(altptr, strlen(altptr), &suri) != 0) {
continue;
@ -163,22 +168,30 @@ int check_x509_subj(X509 *pcert, str* sdom)
int verify_x509(X509 *pcert, X509_STORE *pcacerts)
{
X509_STORE_CTX ca_ctx;
X509_STORE_CTX *ca_ctx = NULL;
char *strerr;
ca_ctx = X509_STORE_CTX_new();
if(ca_ctx==NULL) {
LM_ERR("cannot get a x509 context\n");
return -1;
}
if (X509_STORE_CTX_init(&ca_ctx, pcacerts, pcert, NULL) != 1) {
if (X509_STORE_CTX_init(ca_ctx, pcacerts, pcert, NULL) != 1) {
LOG(L_ERR, "AUTH_IDENTITY:verify_x509: Unable to init X509 store ctx\n");
X509_STORE_CTX_free(ca_ctx);
return -1;
}
if (X509_verify_cert(&ca_ctx) != 1) {
strerr = (char *) X509_verify_cert_error_string(ca_ctx.error);
if (X509_verify_cert(ca_ctx) != 1) {
strerr = (char *)X509_verify_cert_error_string(X509_STORE_CTX_get_error(ca_ctx));
LOG(L_ERR, "AUTH_IDENTITY VERIFIER: Certificate verification error: %s\n", strerr);
X509_STORE_CTX_cleanup(&ca_ctx);
X509_STORE_CTX_cleanup(ca_ctx);
X509_STORE_CTX_free(ca_ctx);
return -2;
}
X509_STORE_CTX_cleanup(&ca_ctx);
X509_STORE_CTX_cleanup(ca_ctx);
X509_STORE_CTX_free(ca_ctx);
LOG(AUTH_DBG_LEVEL, "AUTH_IDENTITY VERIFIER: Certificate is valid\n");

@ -449,7 +449,7 @@ int digeststr_asm(dynstr *sout, struct sip_msg *msg, str *sdate, int iflags)
/* there was an error or the required header is missing */
if (iRes==AUTH_ERROR
|| (iRes==AUTH_NOTFOUND && (pactpart[i1].iflag & DS_REQUIRED)))
|| (iRes==AUTH_NOTFOUND && (pactpart[i1].iflag & DS_REQUIRED)))
return -1;
switch (pactpart[i1].itype) {
@ -552,7 +552,7 @@ int append_date(str *sdate, int idatesize, time_t *tout, struct sip_msg *msg)
}
ilen=strftime(date_str, sizeof(date_str), AUTH_TIME_FORMAT, bd_time);
if (ilen > sizeof(date_hf) - strlen("Date: \r\n") || ilen==0) {
if (ilen >= sizeof(date_hf) - strlen("Date: \r\n.") || ilen==0) {
LOG(L_ERR, "AUTH_IDENTITY:append_date: unexpected time length\n");
return -3;
}
@ -569,10 +569,12 @@ int append_date(str *sdate, int idatesize, time_t *tout, struct sip_msg *msg)
if (sdate && idatesize >= ilen) {
memcpy(sdate->s, date_str, ilen);
sdate->len=ilen;
} else
} else {
return -5;
if (tout)
*tout=tdate_now;
}
if (tout)
*tout=tdate_now;
return 0;
}
@ -667,24 +669,24 @@ dc_end:
goto other;
} else {
return (p + 1);
}
}
/* Unknown header type */
other:
p = q_memchr(p, ':', end - p);
if (!p) { /* No double colon found, error.. */
if (!p) { /* No double colon found, error.. */
*type = HDR_ERROR_T;
return 0;
} else {
} else {
*type = HDR_OTHER_T;
return (p + 1);
}
}
return p;
}
/* parses buffer that contains a SIP message header, looks for "Contact"
header field and returns the value of that */
* header field and returns the value of that */
static int get_contact_body(char *buf, unsigned int len, str *sout)
{
char *end, *s, *tmp, *match;

@ -341,6 +341,10 @@ static int w_file_read(sip_msg_t *msg, char *fn, char *vn)
}
fseek(f, 0, SEEK_END);
fsize = ftell(f);
if(fsize<0) {
LM_ERR("ftell failed on file: %.*s\n", fname.len, fname.s);
return -1;
}
fseek(f, 0, SEEK_SET);
content = pkg_malloc(fsize + 1);

@ -24,9 +24,9 @@
/*!
* \defgroup counters Counters/statistics
*
*
*/
#include "../../modparam.h"
#include "../../dprint.h"
#include "../../compiler_opt.h"
@ -239,7 +239,7 @@ static int cnt_int_fixup(void** param, int param_no)
static int cnt_inc_f(struct sip_msg* msg, char* handle, char* bar)
{
counter_handle_t h;
h.id = (long)(void*)handle;
counter_inc(h);
return 1;
@ -251,7 +251,7 @@ static int cnt_add_f(struct sip_msg* msg, char* handle, char* val)
{
counter_handle_t h;
int v;
h.id = (long)(void*)handle;
if (unlikely(get_int_fparam(&v, msg, (fparam_t*)val) < 0)) {
ERR("non integer parameter\n");
@ -266,7 +266,7 @@ static int cnt_add_f(struct sip_msg* msg, char* handle, char* val)
static int cnt_reset_f(struct sip_msg* msg, char* handle, char* bar)
{
counter_handle_t h;
h.id = (long)(void*)handle;
counter_reset(h);
return 1;
@ -284,12 +284,13 @@ static void cnt_get_rpc(rpc_t* rpc, void* c)
char* name;
counter_val_t v;
counter_handle_t h;
if (rpc->scan(c, "s", &group) < 1)
return;
if (rpc->scan(c, "*s", &name) < 1)
if (rpc->scan(c, "*s", &name) < 1) {
cnt_grp_get_all(rpc, c, group);
return;
}
/* group & name read */
if (counter_lookup(&h, group, name) < 0) {
rpc->fault(c, 400, "non-existent counter %s.%s\n", group, name);
@ -308,7 +309,7 @@ static void cnt_get_raw_rpc(rpc_t* rpc, void* c)
char* name;
counter_val_t v;
counter_handle_t h;
if (rpc->scan(c, "ss", &group, &name) < 2) {
/* rpc->fault(c, 400, "group and counter name required"); */
return;
@ -329,7 +330,7 @@ static void cnt_reset_rpc(rpc_t* rpc, void* c)
char* group;
char* name;
counter_handle_t h;
if (rpc->scan(c, "ss", &group, &name) < 2) {
/* rpc->fault(c, 400, "group and counter name required"); */
return;
@ -383,7 +384,7 @@ static void rpc_print_name_val(void* param, str* g, str* n,
static void cnt_grps_list_rpc(rpc_t* rpc, void* c)
{
struct rpc_list_params packed_params;
packed_params.rpc = rpc;
packed_params.ctx = c;
counter_iterate_grp_names(rpc_print_name, &packed_params);
@ -395,7 +396,7 @@ static void cnt_var_list_rpc(rpc_t* rpc, void* c)
{
char* group;
struct rpc_list_params packed_params;
if (rpc->scan(c, "s", &group) < 1) {
/* rpc->fault(c, 400, "group name required"); */
return;
@ -411,7 +412,7 @@ static void cnt_grp_get_all(rpc_t* rpc, void* c, char* group)
{
void* s;
struct rpc_list_params packed_params;
if (rpc->add(c, "{", &s) < 0) return;
packed_params.rpc = rpc;
packed_params.ctx = s;
@ -423,7 +424,7 @@ static void cnt_grp_get_all(rpc_t* rpc, void* c, char* group)
static void cnt_grp_get_all_rpc(rpc_t* rpc, void* c)
{
char* group;
if (rpc->scan(c, "s", &group) < 1) {
/* rpc->fault(c, 400, "group name required"); */
return;
@ -439,7 +440,7 @@ static void cnt_help_rpc(rpc_t* rpc, void* ctx)
char* name;
char* desc;
counter_handle_t h;
if (rpc->scan(ctx, "ss", &group, &name) < 2) {
/* rpc->fault(c, 400, "group and counter name required"); */
return;

@ -110,7 +110,7 @@ modparam("crypto", "salt", "l0Bh2M8a")
Set it to 1 in order to register a callback to core for generation of
callid values for requests generated by Kamailio tm module.
This callid genrator uses libssl random and hashing functions for
This callid generator uses libssl random and hashing functions for
generating RFC 4122 version 4 UUID with high quality entropy. It is
useful when wanting to have new callids that cannot be predicted from
previous values.

@ -158,7 +158,7 @@ static int w_crypto_aes_encrypt(sip_msg_t* msg, char* inb, char* keyb, char* out
str keys;
pv_spec_t *dst;
pv_value_t val;
EVP_CIPHER_CTX en;
EVP_CIPHER_CTX *en = NULL;
str etext;
if (fixup_get_svalue(msg, (gparam_t*)inb, &ins) != 0) {
@ -169,17 +169,24 @@ static int w_crypto_aes_encrypt(sip_msg_t* msg, char* inb, char* keyb, char* out
LM_ERR("cannot get key value\n");
return -1;
}
en = EVP_CIPHER_CTX_new();
if(en==NULL) {
LM_ERR("cannot get new cipher context\n");
return -1;
}
dst = (pv_spec_t*)outb;
/* gen key and iv. init the cipher ctx object */
if (crypto_aes_init((unsigned char *)keys.s, keys.len,
(unsigned char*)((_crypto_salt_param)?_crypto_salt:0), &en, NULL)) {
(unsigned char*)((_crypto_salt_param)?_crypto_salt:0), en, NULL)) {
EVP_CIPHER_CTX_free(en);
LM_ERR("couldn't initialize AES cipher\n");
return -1;
}
etext.len = ins.len;
etext.s = (char *)crypto_aes_encrypt(&en, (unsigned char *)ins.s, &etext.len);
etext.s = (char *)crypto_aes_encrypt(en, (unsigned char *)ins.s, &etext.len);
if(etext.s==NULL) {
EVP_CIPHER_CTX_free(en);
LM_ERR("AES encryption failed\n");
return -1;
}
@ -189,6 +196,7 @@ static int w_crypto_aes_encrypt(sip_msg_t* msg, char* inb, char* keyb, char* out
val.rs.len = base64_enc((unsigned char *)etext.s, etext.len,
(unsigned char *)val.rs.s, pv_get_buffer_size()-1);
if (val.rs.len < 0) {
EVP_CIPHER_CTX_free(en);
LM_ERR("base64 output of encrypted value is too large (need %d)\n",
-val.rs.len);
goto error;
@ -198,12 +206,14 @@ static int w_crypto_aes_encrypt(sip_msg_t* msg, char* inb, char* keyb, char* out
dst->setf(msg, &dst->pvp, (int)EQ_T, &val);
free(etext.s);
EVP_CIPHER_CTX_cleanup(&en);
EVP_CIPHER_CTX_cleanup(en);
EVP_CIPHER_CTX_free(en);
return 1;
error:
free(etext.s);
EVP_CIPHER_CTX_cleanup(&en);
EVP_CIPHER_CTX_cleanup(en);
EVP_CIPHER_CTX_free(en);
return -1;
}
@ -238,7 +248,7 @@ static int w_crypto_aes_decrypt(sip_msg_t* msg, char* inb, char* keyb, char* out
str keys;
pv_spec_t *dst;
pv_value_t val;
EVP_CIPHER_CTX de;
EVP_CIPHER_CTX *de=NULL;
str etext;
if (fixup_get_svalue(msg, (gparam_t*)inb, &ins) != 0) {
@ -249,11 +259,17 @@ static int w_crypto_aes_decrypt(sip_msg_t* msg, char* inb, char* keyb, char* out
LM_ERR("cannot get key value\n");
return -1;
}
de = EVP_CIPHER_CTX_new();
if(de==NULL) {
LM_ERR("cannot get new cipher context\n");
return -1;
}
dst = (pv_spec_t*)outb;
/* gen key and iv. init the cipher ctx object */
if (crypto_aes_init((unsigned char *)keys.s, keys.len,
(unsigned char*)((_crypto_salt_param)?_crypto_salt:0), NULL, &de)) {
(unsigned char*)((_crypto_salt_param)?_crypto_salt:0), NULL, de)) {
EVP_CIPHER_CTX_free(de);
LM_ERR("couldn't initialize AES cipher\n");
return -1;
}
@ -263,14 +279,16 @@ static int w_crypto_aes_decrypt(sip_msg_t* msg, char* inb, char* keyb, char* out
etext.len = base64_dec((unsigned char *)ins.s, ins.len,
(unsigned char *)etext.s, pv_get_buffer_size()-1);
if (etext.len < 0) {
EVP_CIPHER_CTX_free(de);
LM_ERR("base64 inpuy with encrypted value is too large (need %d)\n",
-etext.len);
return -1;
}
val.rs.len = etext.len;
val.rs.s = (char *)crypto_aes_decrypt(&de, (unsigned char *)etext.s,
val.rs.s = (char *)crypto_aes_decrypt(de, (unsigned char *)etext.s,
&val.rs.len);
if(val.rs.s==NULL) {
EVP_CIPHER_CTX_free(de);
LM_ERR("AES decryption failed\n");
return -1;
}
@ -279,7 +297,8 @@ static int w_crypto_aes_decrypt(sip_msg_t* msg, char* inb, char* keyb, char* out
dst->setf(msg, &dst->pvp, (int)EQ_T, &val);
free(val.rs.s);
EVP_CIPHER_CTX_cleanup(&de);
EVP_CIPHER_CTX_cleanup(de);
EVP_CIPHER_CTX_free(de);
return 1;
}
@ -433,7 +452,8 @@ int crypto_aes_test(void)
{
/* "opaque" encryption, decryption ctx structures
* that libcrypto uses to record status of enc/dec operations */
EVP_CIPHER_CTX en, de;
EVP_CIPHER_CTX *en = NULL;
EVP_CIPHER_CTX *de = NULL;
/* The salt paramter is used as a salt in the derivation:
@ -448,12 +468,23 @@ int crypto_aes_test(void)
NULL
};
en = EVP_CIPHER_CTX_new();
if(en==NULL) {
LM_ERR("cannot get new cipher context\n");
return -1;
}
de = EVP_CIPHER_CTX_new();
if(de==NULL) {
EVP_CIPHER_CTX_free(en);
LM_ERR("cannot get new cipher context\n");
return -1;
}
/* the key_data for testing */
key_data = (unsigned char *)"kamailio-sip-server";
key_data_len = strlen((const char *)key_data);
/* gen key and iv. init the cipher ctx object */
if (crypto_aes_init(key_data, key_data_len, salt, &en, &de)) {
if (crypto_aes_init(key_data, key_data_len, salt, en, de)) {
LM_ERR("couldn't initialize AES cipher\n");
return -1;
}
@ -471,8 +502,8 @@ int crypto_aes_test(void)
* a legal C string */
olen = len = strlen(input[i])+1;
ciphertext = crypto_aes_encrypt(&en, (unsigned char *)input[i], &len);
plaintext = (char *)crypto_aes_decrypt(&de, ciphertext, &len);
ciphertext = crypto_aes_encrypt(en, (unsigned char *)input[i], &len);
plaintext = (char *)crypto_aes_decrypt(de, ciphertext, &len);
if (strncmp(plaintext, input[i], olen))
LM_ERR("FAIL: enc/dec failed for \"%s\"\n", input[i]);
@ -483,8 +514,10 @@ int crypto_aes_test(void)
free(plaintext);
}
EVP_CIPHER_CTX_cleanup(&de);
EVP_CIPHER_CTX_cleanup(&en);
EVP_CIPHER_CTX_cleanup(de);
EVP_CIPHER_CTX_free(de);
EVP_CIPHER_CTX_cleanup(en);
EVP_CIPHER_CTX_free(en);
return 0;
}

@ -91,7 +91,7 @@ modparam("crypto", "salt", "l0Bh2M8a")
of callid values for requests generated by &kamailio; tm module.
</para>
<para>
This callid genrator uses libssl random and hashing functions
This callid generator uses libssl random and hashing functions
for generating RFC 4122 version 4 UUID with high quality entropy.
It is useful when wanting to have new callids that cannot be
predicted from previous values.

@ -503,7 +503,7 @@ static int rpc_fault_prepare(struct binrpc_ctx* ctx, int code, char* fmt, ...)
}
va_start(ap, fmt);
len=vsnprintf(buf, MAX_FAULT_LEN, fmt, ap); /* ignore trunc. errors */
if ((len<0) || (len > MAX_FAULT_LEN))
if ((len<0) || (len >= MAX_FAULT_LEN))
len=MAX_FAULT_LEN-1;
va_end(ap);

@ -211,11 +211,12 @@ error:
return -1;
}
#define CTL_SOCKET_PATH_SIZE 128
static int mod_init(void)
{
struct id_list* l;
char ctl_socket_path[CTL_SOCKET_PATH_SIZE];
binrpc_callbacks_init();
@ -227,7 +228,21 @@ static int mod_init(void)
binrpc_struct_max_body_size *= 1024;
if (listen_lst==0) {
add_binrpc_socket(PARAM_STRING, DEFAULT_CTL_SOCKET);
if(strcmp(runtime_dir, RUN_DIR)==0) {
add_binrpc_socket(PARAM_STRING, DEFAULT_CTL_SOCKET);
} else {
if(sizeof(DEFAULT_CTL_SOCKET_PROTO)
+ sizeof(DEFAULT_CTL_SOCKET_NAME)
+ strlen(runtime_dir) + 4 > CTL_SOCKET_PATH_SIZE) {
LM_ERR("ctl socket path is too big\n");
return -1;
}
strcpy(ctl_socket_path, DEFAULT_CTL_SOCKET_PROTO);
strcat(ctl_socket_path, runtime_dir);
strcat(ctl_socket_path, "/");
strcat(ctl_socket_path, DEFAULT_CTL_SOCKET_NAME);
add_binrpc_socket(PARAM_STRING, ctl_socket_path);
}
}
DBG("listening on:\n");
for (l=listen_lst; l; l=l->next){

@ -2,13 +2,19 @@
#ifndef __ctl_defaults_h
#define __ctl_defaults_h
/*listen by default on: */
#define DEFAULT_CTL_SOCKET_PROTO "unixs:"
#ifdef SRNAME
/* this is used when compiling sercmd tool */
#define DEFAULT_CTL_SOCKET "unixs:" RUN_DIR "/" SRNAME "_ctl"
#define DEFAULT_CTL_SOCKET_NAME SRNAME "_ctl"
#else
/* this is used when compiling sip server */
#define DEFAULT_CTL_SOCKET "unixs:" RUN_DIR "/" NAME "_ctl"
#define DEFAULT_CTL_SOCKET_NAME NAME "_ctl"
#endif
#define DEFAULT_CTL_SOCKET DEFAULT_CTL_SOCKET_PROTO RUN_DIR "/" DEFAULT_CTL_SOCKET_NAME
/* port used by default for tcp/udp if no port is explicitely specified */
#define DEFAULT_CTL_PORT 2049

@ -37,7 +37,7 @@
* including decreasing ref cnt
*/
inline long IV2int(SV *in) {
long IV2int(SV *in) {
int ret = -1;
if (SvOK(in)) {

@ -125,11 +125,11 @@ static inline int sb_add(struct string_buffer *sb, str *nstr)
int rsize = sb->len + nstr->len;
int asize;
char *newp;
if (rsize > sb->size) {
asize = rsize - sb->size;
new_size = sb->size + (asize / sb->increment +
(asize % sb->increment > 0)) * sb->increment;
new_size = sb->size + (asize / sb->increment
+ (asize % sb->increment > 0)) * sb->increment;
newp = pkg_malloc(new_size);
if (!newp) {
ERR("postgres: No memory left\n");
@ -142,8 +142,10 @@ static inline int sb_add(struct string_buffer *sb, str *nstr)
sb->s = newp;
sb->size = new_size;
}
memcpy(sb->s + sb->len, nstr->s, nstr->len);
sb->len += nstr->len;
if(sb->s) {
memcpy(sb->s + sb->len, nstr->s, nstr->len);
sb->len += nstr->len;
}
return 0;
}

@ -93,7 +93,7 @@ int _dbg_xavp_dump_lookup(pv_param_t *param)
xname = (pv_xavp_name_t*)param->pvn.u.dname;
while(_dbg_xavp_dump[i]!=NULL&&i<DBG_XAVP_DUMP_SIZE)
while(i<DBG_XAVP_DUMP_SIZE && _dbg_xavp_dump[i]!=NULL)
{
if(_dbg_xavp_dump[i]->len==xname->name.len)
{

@ -53,12 +53,9 @@ static str _dlg_cseq_diff_var_name = str_init("cseq_diff");
/**
*
*/
int dlg_cseq_prepare_msg(sip_msg_t *msg)
static int dlg_cseq_prepare_msg(sip_msg_t *msg)
{
if (parse_msg(msg->buf, msg->len, msg)!=0) {
LM_DBG("outbuf buffer parsing failed!");
return 1;
}
LM_DBG("prepare msg for cseq update operations\n");
if(msg->first_line.type==SIP_REQUEST) {
if(!IS_SIP(msg))
@ -106,6 +103,19 @@ int dlg_cseq_prepare_msg(sip_msg_t *msg)
return 0;
}
/**
*
*/
static int dlg_cseq_prepare_new_msg(sip_msg_t *msg)
{
LM_DBG("prepare new msg for cseq update operations\n");
if (parse_msg(msg->buf, msg->len, msg)!=0) {
LM_DBG("outbuf buffer parsing failed!");
return 1;
}
return dlg_cseq_prepare_msg(msg);
}
/**
*
*/
@ -247,11 +257,9 @@ int dlg_cseq_refresh(sip_msg_t *msg, dlg_cell_t *dlg,
sr_hdr_add_zs(msg, "P-K-CSeq-Refresh", &nval);
done:
if(dlg!=NULL) dlg_release(dlg);
return 0;
error:
if(dlg!=NULL) dlg_release(dlg);
return -1;
}
@ -270,7 +278,7 @@ int dlg_cseq_msg_received(void *data)
msg.buf = obuf->s;
msg.len = obuf->len;
if(dlg_cseq_prepare_msg(&msg)!=0) {
if(dlg_cseq_prepare_new_msg(&msg)!=0) {
goto done;
}
@ -352,7 +360,7 @@ int dlg_cseq_msg_sent(void *data)
msg.buf = obuf->s;
msg.len = obuf->len;
if(dlg_cseq_prepare_msg(&msg)!=0) {
if(dlg_cseq_prepare_new_msg(&msg)!=0) {
goto done;
}

@ -894,10 +894,12 @@ void link_dlg(struct dlg_cell *dlg, int n, int mode)
* \param dlg dialog
* \param cnt increment for the reference counter
*/
void dlg_ref(dlg_cell_t *dlg, unsigned int cnt)
void dlg_ref_helper(dlg_cell_t *dlg, unsigned int cnt, const char *fname,
int fline)
{
dlg_entry_t *d_entry;
LM_DBG("ref op on %p with %d from %s:%d\n", dlg, cnt, fname, fline);
d_entry = &(d_table->entries[dlg->h_entry]);
dlg_lock( d_table, d_entry);
@ -912,10 +914,12 @@ void dlg_ref(dlg_cell_t *dlg, unsigned int cnt)
* \param dlg dialog
* \param cnt decrement for the reference counter
*/
void dlg_unref(dlg_cell_t *dlg, unsigned int cnt)
void dlg_unref_helper(dlg_cell_t *dlg, unsigned int cnt, const char *fname,
int fline)
{
dlg_entry_t *d_entry;
LM_DBG("unref op on %p with %d from %s:%d\n", dlg, cnt, fname, fline);
d_entry = &(d_table->entries[dlg->h_entry]);
dlg_lock( d_table, d_entry);

@ -387,8 +387,10 @@ void link_dlg(struct dlg_cell *dlg, int n, int mode);
* \param dlg dialog
* \param cnt decrement for the reference counter
*/
void dlg_unref(dlg_cell_t *dlg, unsigned int cnt);
void dlg_unref_helper(dlg_cell_t *dlg, unsigned int cnt, const char *fname,
int fline);
#define dlg_unref(dlg, cnt) dlg_unref_helper((dlg), (cnt), __FILE__, __LINE__)
/*!
* \brief Refefence a dialog with locking
@ -396,8 +398,10 @@ void dlg_unref(dlg_cell_t *dlg, unsigned int cnt);
* \param dlg dialog
* \param cnt increment for the reference counter
*/
void dlg_ref(dlg_cell_t *dlg, unsigned int cnt);
void dlg_ref_helper(dlg_cell_t *dlg, unsigned int cnt, const char *fname,
int fline);
#define dlg_ref(dlg, cnt) dlg_ref_helper((dlg), (cnt), __FILE__, __LINE__)
/*!
* \brief Release a dialog from ref counter by 1

@ -1278,9 +1278,9 @@ int dlg_json_to_profiles(dlg_cell_t *dlg, srjson_doc_t *jdoc)
puid.s = jt->valuestring;
puid.len = strlen(puid.s);
} else if(strcmp(jt->string, "expires")==0) {
expires = (time_t)jt->valueint;
expires = (time_t)SRJSON_GET_ULONG(jt);
} else if(strcmp(jt->string, "flags")==0) {
flags = jt->valueint;
flags = SRJSON_GET_UINT(jt);
}
}
if(name.s==NULL)

@ -292,7 +292,7 @@ static inline int build_extra_hdr(struct dlg_cell * cell, str *extra_hdrs,
if(extra_hdrs && extra_hdrs->len>0)
str_hdr->len += extra_hdrs->len;
blen = str_hdr->len + 1 /* '\0' */;
blen = str_hdr->len + 3 /* '\r\n\0' */;
/* reserve space for callee headers in local requests */
if(dlg_lreq_callee_headers.len>0)

@ -687,7 +687,7 @@ Note
code=408 or class=400 will never set a backend down even if it is,
because internally the Kamailio transaction layer generates a 408 in
the case of no response from the remote server, and this internal code
408 is accepted as vaild value.
408 is accepted as valid value.
Default value is “” (only 200 OK is accepted).

@ -1449,7 +1449,8 @@ int ds_get_leastloaded(ds_set_t *dset)
for(j=0; j<dset->nr; j++)
{
if(!ds_skip_dst(dset->dlist[j].flags)
&& dset->dlist[j].dload<dset->dlist[j].attrs.maxload)
&& (dset->dlist[j].attrs.maxload == 0
|| dset->dlist[j].dload<dset->dlist[j].attrs.maxload))
{
if(dset->dlist[j].dload<t)
{

@ -641,7 +641,7 @@ modparam("dispatcher", "force_dst", 1)
that are generated locally. E.g.: setting code=408 or class=400 will never set
a backend down even if it is, because internally the Kamailio transaction layer
generates a 408 in the case of no response from the remote server, and this
internal code 408 is accepted as vaild value.
internal code 408 is accepted as valid value.
</para>
<para>
<emphasis>

@ -298,10 +298,12 @@ int usrloc_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t*
srjson_t *it = NULL;
static ucontact_info_t ci;
int action, expires, cseq, flags, cflags, q, last_modified, methods, reg_id;
unsigned int action, expires, cseq, flags, cflags, q, last_modified,
methods, reg_id;
str aor, ruid, c, received, path, callid, user_agent, instance;
action = expires = cseq = flags = cflags = q = last_modified = methods = reg_id = 0;
action = expires = cseq = flags = cflags = q = last_modified
= methods = reg_id = 0;
parse_from_header(msg);
body = ((struct to_body*)msg->from->parsed)->uri;
@ -342,7 +344,7 @@ int usrloc_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t*
if (it->string == NULL) continue;
if (strcmp(it->string, "action")==0) {
action = it->valueint;
action = SRJSON_GET_UINT(it);
} else if (strcmp(it->string, "aor")==0) {
aor.s = it->valuestring;
aor.len = strlen(aor.s);
@ -368,21 +370,21 @@ int usrloc_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t*
instance.s = it->valuestring;
instance.len = strlen(instance.s);
} else if (strcmp(it->string, "expires")==0) { //
expires = it->valueint;
expires = SRJSON_GET_UINT(it);
} else if (strcmp(it->string, "cseq")==0) {
cseq = it->valueint;
cseq = SRJSON_GET_UINT(it);
} else if (strcmp(it->string, "flags")==0) {
flags = it->valueint;
flags = SRJSON_GET_UINT(it);
} else if (strcmp(it->string, "cflags")==0) {
cflags = it->valueint;
cflags = SRJSON_GET_UINT(it);
} else if (strcmp(it->string, "q")==0) {
q = it->valueint;
q = SRJSON_GET_UINT(it);
} else if (strcmp(it->string, "last_modified")==0) {
last_modified = it->valueint;
last_modified = SRJSON_GET_UINT(it);
} else if (strcmp(it->string, "methods")==0) {
methods = it->valueint;
methods = SRJSON_GET_UINT(it);
} else if (strcmp(it->string, "reg_id")==0) {
reg_id = it->valueint;
reg_id = SRJSON_GET_UINT(it);
} else {
LM_ERR("unrecognized field in json object\n");
}

@ -15,8 +15,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
@ -91,18 +91,18 @@ gen_lock_t *reload_lock;
*/
static cmd_export_t cmds[] = {
{"is_from_local", (cmd_function)is_from_local, 0, 0, 0,
REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
{"is_uri_host_local", (cmd_function)is_uri_host_local, 0, 0, 0,
REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|LOCAL_ROUTE},
{"is_domain_local", (cmd_function)w_is_domain_local, 1, fixup_pvar_null,
fixup_free_pvar_null,
REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
fixup_free_pvar_null,
REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
{"lookup_domain", (cmd_function)w_lookup_domain_no_prefix, 1,
fixup_pvar_null, fixup_free_pvar_null,
REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
fixup_pvar_null, fixup_free_pvar_null,
REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
{"lookup_domain", (cmd_function)w_lookup_domain, 2, fixup_pvar_str,
fixup_free_pvar_str,
REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
fixup_free_pvar_str,
REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
{"bind_domain", (cmd_function)bind_domain, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0}
};
@ -129,9 +129,9 @@ static param_export_t params[] = {
* Exported MI functions
*/
static mi_export_t mi_cmds[] = {
{ MI_DOMAIN_RELOAD, mi_domain_reload, MI_NO_INPUT_FLAG, 0, 0 },
{ MI_DOMAIN_DUMP, mi_domain_dump, MI_NO_INPUT_FLAG, 0, 0 },
{ 0, 0, 0, 0, 0}
{ MI_DOMAIN_RELOAD, mi_domain_reload, MI_NO_INPUT_FLAG, 0, 0 },
{ MI_DOMAIN_DUMP, mi_domain_dump, MI_NO_INPUT_FLAG, 0, 0 },
{ 0, 0, 0, 0, 0}
};
@ -156,125 +156,126 @@ struct module_exports exports = {
static int mod_init(void)
{
LM_DBG("initializing\n");
if (register_mi_mod(exports.name, mi_cmds) != 0) {
LM_ERR("failed to register MI commands\n");
return -1;
}
if (domain_init_rpc() != 0) {
LM_ERR("failed to register RPC commands\n");
return -1;
}
LM_DBG("initializing\n");
if (domain_reg_myself !=0 ) {
if (register_check_self_func(domain_check_self) <0 ) {
LM_ERR("failed to register check self function\n");
return -1;
if (register_mi_mod(exports.name, mi_cmds) != 0) {
LM_ERR("failed to register MI commands\n");
return -1;
}
if (domain_init_rpc() != 0) {
LM_ERR("failed to register RPC commands\n");
return -1;
}
}
/* Bind database */
if (domain_db_bind(&d_db_url)) {
LM_DBG("Usign db_url [%.*s]\n", d_db_url.len, d_db_url.s);
LM_ERR("no database module found. Have you configure thed \"db_url\" modparam properly?\n");
return -1;
}
if (domain_reg_myself !=0 ) {
if (register_check_self_func(domain_check_self) <0 ) {
LM_ERR("failed to register check self function\n");
return -1;
}
}
/* Check table versions */
if (domain_db_init(&d_db_url) < 0) {
LM_ERR("unable to open database connection\n");
return -1;
}
if (domain_db_ver(&domain_table, DOMAIN_TABLE_VERSION) < 0) {
LM_ERR("error during check of domain table version\n");
domain_db_close();
goto error;
}
if (domain_db_ver(&domain_attrs_table, DOMAIN_ATTRS_TABLE_VERSION) < 0) {
LM_ERR("error during check of domain_attrs table version\n");
/* Bind database */
if (domain_db_bind(&d_db_url)) {
LM_DBG("Usign db_url [%.*s]\n", d_db_url.len, d_db_url.s);
LM_ERR("no database module found. Have you configure"
" the \"db_url\" modparam properly?\n");
return -1;
}
/* Check table versions */
if (domain_db_init(&d_db_url) < 0) {
LM_ERR("unable to open database connection\n");
return -1;
}
if (domain_db_ver(&domain_table, DOMAIN_TABLE_VERSION) < 0) {
LM_ERR("error during check of domain table version\n");
domain_db_close();
goto error;
}
if (domain_db_ver(&domain_attrs_table, DOMAIN_ATTRS_TABLE_VERSION) < 0) {
LM_ERR("error during check of domain_attrs table version\n");
domain_db_close();
goto error;
}
domain_db_close();
goto error;
}
domain_db_close();
/* Initializing hash tables and hash table variable */
hash_table = (struct domain_list ***)shm_malloc
(sizeof(struct domain_list *));
hash_table_1 = (struct domain_list **)shm_malloc
(sizeof(struct domain_list *) * (DOM_HASH_SIZE + 1));
hash_table_2 = (struct domain_list **)shm_malloc
(sizeof(struct domain_list *) * (DOM_HASH_SIZE + 1));
if ((hash_table == 0) || (hash_table_1 == 0) || (hash_table_2 == 0)) {
LM_ERR("no memory for hash table\n");
goto error;
}
memset(hash_table_1, 0, sizeof(struct domain_list *) *
(DOM_HASH_SIZE + 1));
memset(hash_table_2, 0, sizeof(struct domain_list *) *
(DOM_HASH_SIZE + 1));
*hash_table = hash_table_1;
/* Allocate and initialize locks */
reload_lock = lock_alloc();
if (reload_lock == NULL) {
LM_ERR("cannot allocate reload_lock\n");
goto error;
}
if (lock_init(reload_lock) == NULL) {
LM_ERR("cannot init reload_lock\n");
goto error;
}
/* First reload */
lock_get(reload_lock);
if (reload_tables() == -1) {
/* Initializing hash tables and hash table variable */
hash_table = (struct domain_list ***)shm_malloc
(sizeof(struct domain_list **));
hash_table_1 = (struct domain_list **)shm_malloc
(sizeof(struct domain_list *) * (DOM_HASH_SIZE + 1));
hash_table_2 = (struct domain_list **)shm_malloc
(sizeof(struct domain_list *) * (DOM_HASH_SIZE + 1));
if ((hash_table == 0) || (hash_table_1 == 0) || (hash_table_2 == 0)) {
LM_ERR("no memory for hash table\n");
goto error;
}
memset(hash_table_1, 0, sizeof(struct domain_list *) *
(DOM_HASH_SIZE + 1));
memset(hash_table_2, 0, sizeof(struct domain_list *) *
(DOM_HASH_SIZE + 1));
*hash_table = hash_table_1;
/* Allocate and initialize locks */
reload_lock = lock_alloc();
if (reload_lock == NULL) {
LM_ERR("cannot allocate reload_lock\n");
goto error;
}
if (lock_init(reload_lock) == NULL) {
LM_ERR("cannot init reload_lock\n");
goto error;
}
/* First reload */
lock_get(reload_lock);
if (reload_tables() == -1) {
lock_release(reload_lock);
LM_CRIT("domain reload failed\n");
goto error;
}
lock_release(reload_lock);
LM_CRIT("domain reload failed\n");
goto error;
}
lock_release(reload_lock);
return 0;
return 0;
error:
destroy();
return -1;
destroy();
return -1;
}
static int child_init(int rank)
{
return 0;
return 0;
}
static void destroy(void)
{
/* Destroy is called from the main process only,
* there is no need to close database here because
* it is closed in mod_init already
*/
if (hash_table) {
shm_free(hash_table);
hash_table = 0;
}
if (hash_table_1) {
hash_table_free(hash_table_1);
shm_free(hash_table_1);
hash_table_1 = 0;
}
if (hash_table_2) {
hash_table_free(hash_table_2);
shm_free(hash_table_2);
hash_table_2 = 0;
}
/* Destroy is called from the main process only,
* there is no need to close database here because
* it is closed in mod_init already
*/
if (hash_table) {
shm_free(hash_table);
hash_table = 0;
}
if (hash_table_1) {
hash_table_free(hash_table_1);
shm_free(hash_table_1);
hash_table_1 = 0;
}
if (hash_table_2) {
hash_table_free(hash_table_2);
shm_free(hash_table_2);
hash_table_2 = 0;
}
}
static const char* domain_rpc_reload_doc[2] = {
"Reload domain tables from database",
0
"Reload domain tables from database",
0
};
@ -283,17 +284,17 @@ static const char* domain_rpc_reload_doc[2] = {
*/
static void domain_rpc_reload(rpc_t* rpc, void* ctx)
{
lock_get(reload_lock);
if (reload_tables() < 0) {
rpc->fault(ctx, 400, "Reload of domain tables failed");
}
lock_release(reload_lock);
lock_get(reload_lock);
if (reload_tables() < 0) {
rpc->fault(ctx, 400, "Reload of domain tables failed");
}
lock_release(reload_lock);
}
static const char* domain_rpc_dump_doc[2] = {
"Return the contents of domain and domain_attrs tables",
0
"Return the contents of domain and domain_attrs tables",
0
};
@ -302,56 +303,56 @@ static const char* domain_rpc_dump_doc[2] = {
*/
static void domain_rpc_dump(rpc_t* rpc, void* ctx)
{
int i;
struct domain_list *np;
struct attr_list *ap;
struct domain_list **ht;
void* st;
if(hash_table==0 || *hash_table==0) {
rpc->fault(ctx, 404, "Server Domain Cache Empty");
return;
}
ht = *hash_table;
for (i = 0; i < DOM_HASH_SIZE; i++) {
np = ht[i];
while (np) {
if (rpc->add(ctx, "{", &st) < 0) return;
rpc->struct_add(st, "SS",
"domain", &np->domain,
"did", &np->did);
np = np->next;
int i;
struct domain_list *np;
struct attr_list *ap;
struct domain_list **ht;
void* st;
if(hash_table==0 || *hash_table==0) {
rpc->fault(ctx, 404, "Server Domain Cache Empty");
return;
}
}
np = ht[DOM_HASH_SIZE];
while (np) {
if (rpc->add(ctx, "{", &st) < 0) return;
rpc->struct_add(st, "S",
"did", &np->did);
ap = np->attrs;
while (ap) {
rpc->struct_add(st, "S",
"attr", &ap->name);
ap = ap->next;
ht = *hash_table;
for (i = 0; i < DOM_HASH_SIZE; i++) {
np = ht[i];
while (np) {
if (rpc->add(ctx, "{", &st) < 0) return;
rpc->struct_add(st, "SS",
"domain", &np->domain,
"did", &np->did);
np = np->next;
}
}
np = ht[DOM_HASH_SIZE];
while (np) {
if (rpc->add(ctx, "{", &st) < 0) return;
rpc->struct_add(st, "S",
"did", &np->did);
ap = np->attrs;
while (ap) {
rpc->struct_add(st, "S",
"attr", &ap->name);
ap = ap->next;
}
np = np->next;
}
np = np->next;
}
return;
return;
}
rpc_export_t domain_rpc_list[] = {
{"domain.reload", domain_rpc_reload, domain_rpc_reload_doc, 0},
{"domain.dump", domain_rpc_dump, domain_rpc_dump_doc, 0},
{0, 0, 0, 0}
{"domain.reload", domain_rpc_reload, domain_rpc_reload_doc, 0},
{"domain.dump", domain_rpc_dump, domain_rpc_dump_doc, 0},
{0, 0, 0, 0}
};
static int domain_init_rpc(void)
{
if (rpc_register_array(domain_rpc_list) != 0) {
LM_ERR("failed to register RPC commands\n");
return -1;
}
return 0;
if (rpc_register_array(domain_rpc_list) != 0) {
LM_ERR("failed to register RPC commands\n");
return -1;
}
return 0;
}

@ -104,6 +104,8 @@ int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq
/* received dmq message */
LM_DBG("dmq message received\n");
srjson_InitDoc(&jdoc, NULL);
if(!msg->content_length) {
LM_ERR("no content length header found\n");
goto invalid;
@ -125,7 +127,6 @@ int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq
/* parse body */
LM_DBG("body: %.*s\n", body.len, body.s);
srjson_InitDoc(&jdoc, NULL);
jdoc.buf = body;
if(jdoc.root == NULL) {
@ -141,7 +142,7 @@ int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq
{
LM_DBG("found field: %s\n", it->string);
if (strcmp(it->string, "action")==0) {
action = it->valueint;
action = SRJSON_GET_INT(it);
} else if (strcmp(it->string, "htname")==0) {
htname.s = it->valuestring;
htname.len = strlen(htname.s);
@ -149,14 +150,14 @@ int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq
cname.s = it->valuestring;
cname.len = strlen(cname.s);
} else if (strcmp(it->string, "type")==0) {
type = it->valueint;
type = SRJSON_GET_INT(it);
} else if (strcmp(it->string, "strval")==0) {
val.s.s = it->valuestring;
val.s.len = strlen(val.s.s);
} else if (strcmp(it->string, "intval")==0) {
val.n = it->valueint;
val.n = SRJSON_GET_INT(it);
} else if (strcmp(it->string, "mode")==0) {
mode = it->valueint;
mode = SRJSON_GET_INT(it);
} else {
LM_ERR("unrecognized field in json object\n");
goto invalid;

@ -133,6 +133,7 @@ static cmd_export_t cmds[] = {
fixup_free_curl_connect_post,
REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
{"bind_http_client", (cmd_function)bind_httpc_api, 0, 0, 0, 0},
{0,0,0,0,0,0}
};

@ -135,7 +135,7 @@ int janssonmod_set(unsigned int append, struct sip_msg* msg, char* type_in,
json_t* result_json = NULL;
json_t* value = NULL;
char* freeme = NULL;
json_error_t parsing_error;
json_error_t parsing_error = {0};
char* endptr;
/* check the type */

@ -428,15 +428,19 @@ int jsonrpc_send(str conn, jsonrpc_request_t* req, bool notify_only)
if(ns) pkg_free(ns);
if(json) free(json);
if (sent && notify_only == false) {
const struct timeval tv = ms_to_tv(req->timeout);
if (sent) {
if (notify_only == true) { // free the request if using janssonrpc_notification function
free_req_cmd(req->cmd);
free_request(req);
} else {
const struct timeval tv = ms_to_tv(req->timeout);
req->timeout_ev = evtimer_new(global_ev_base, timeout_cb, (void*)req);
if(event_add(req->timeout_ev, &tv)<0) {
ERR("event_add failed while setting request timer (%s).",
strerror(errno));
return -1;
req->timeout_ev = evtimer_new(global_ev_base, timeout_cb, (void*)req);
if(event_add(req->timeout_ev, &tv)<0) {
ERR("event_add failed while setting request timer (%s).",
strerror(errno));
return -1;
}
}
}

@ -141,12 +141,14 @@ int netstring_read_fd(int fd, netstring_t **netstring)
int bytes, offset;
size_t read_len;
char *temp_buffer;
int total;
int i, len;
char peek[10]={0};
temp_buffer = NULL;
offset = 0;
if (*netstring == NULL) {
/* No buffer yet. Peek at first 10 bytes, to get length and colon. */
char peek[10]={0};
bytes = recv(fd,peek,10,MSG_PEEK);
if (bytes < 3) return NETSTRING_INCOMPLETE;
@ -158,7 +160,6 @@ int netstring_read_fd(int fd, netstring_t **netstring)
/* The netstring must start with a number */
if (!isdigit(peek[0])) return NETSTRING_ERROR_NO_LENGTH;
int i, len;
len = i = 0;
/* Read the number of bytes */
@ -194,7 +195,8 @@ int netstring_read_fd(int fd, netstring_t **netstring)
/* Read from the socket */
bytes = recv(fd, temp_buffer, read_len, 0);
int total = (*netstring)->read += bytes;
(*netstring)->read += bytes;
total = (*netstring)->read;
/* See if we have the whole netstring yet */
if (read_len > bytes) {

@ -327,7 +327,7 @@ static int jsonrpc_send(jsonrpc_ctx_t* ctx)
nj->valuestring, strlen(nj->valuestring));
} else {
srjson_AddNumberToObject(ctx->jrpl, ctx->jrpl->root, "id",
nj->valueint);
nj->valuedouble);
}
}
@ -519,14 +519,20 @@ static int jsonrpc_scan(jsonrpc_ctx_t* ctx, char* fmt, ...)
auto_convert = 1;
continue;
case 'b': /* Bool */
uint_ptr = va_arg(ap, unsigned int*);
*uint_ptr = SRJSON_GET_UINT(ctx->req_node);
break;
case 't': /* Date and time */
uint_ptr = va_arg(ap, unsigned int*);
*uint_ptr = SRJSON_GET_UINT(ctx->req_node);
break;
case 'd': /* Integer */
int_ptr = va_arg(ap, int*);
*int_ptr = ctx->req_node->valueint;
*int_ptr = SRJSON_GET_INT(ctx->req_node);
break;
case 'u': /* Integer */
case 'u': /* Unsigned Integer */
uint_ptr = va_arg(ap, unsigned int*);
*uint_ptr = (unsigned int)ctx->req_node->valueint;
*uint_ptr = SRJSON_GET_UINT(ctx->req_node);
break;
case 'f': /* double */
double_ptr = va_arg(ap, double*);
@ -538,7 +544,8 @@ static int jsonrpc_scan(jsonrpc_ctx_t* ctx, char* fmt, ...)
*char_ptr = ctx->req_node->valuestring;
} else if(auto_convert == 1) {
if(ctx->req_node->type==srjson_Number) {
*char_ptr = int2str(ctx->req_node->valueint, &stmp.len);
*char_ptr = int2str(SRJSON_GET_ULONG(ctx->req_node),
&stmp.len);
} else {
*char_ptr = NULL;
goto error;
@ -555,7 +562,7 @@ static int jsonrpc_scan(jsonrpc_ctx_t* ctx, char* fmt, ...)
str_ptr->len = strlen(ctx->req_node->valuestring);
} else if(auto_convert == 1) {
if(ctx->req_node->type==srjson_Number) {
str_ptr->s = int2str(ctx->req_node->valueint,
str_ptr->s = int2str(SRJSON_GET_ULONG(ctx->req_node),
&str_ptr->len);
} else {
str_ptr->s = NULL;

@ -29,8 +29,6 @@
#include <ctype.h>
#include "ldap_escape.h"
static const char hex[] = "0123456789ABCDEF";
/*
* escape string following RFC 4515 (LDAP filter syntax) escaping rules:
*
@ -48,8 +46,8 @@ static const char hex[] = "0123456789ABCDEF";
int ldap_rfc4515_escape(str *sin, str *sout, int url_encode)
{
char *src, *dst;
if (sin == NULL || sout == NULL || sin->s == NULL || sout->s == NULL
if (sin == NULL || sout == NULL || sin->s == NULL || sout->s == NULL
|| sin->len <= 0 || sout->len < 3*sin->len+1)
{
return -1;

@ -200,7 +200,7 @@ static int mi_mod_init(void)
LM_ERR("invalid port number; must be in [1024,%d]\n",MAX_NB_PORT);
return -1;
}
if(! (host = resolvehost(host_s)) ) {
LM_ERR("failed to resolve %s\n", host_s);
return -1;
@ -212,10 +212,10 @@ static int mi_mod_init(void)
}
mi_socket_domain = host->h_addrtype;
goto done;
}
}
/* in case of a Unix socket*/
LM_DBG("we have an UNIX socket\n");
n=stat(mi_socket, &filestat);
if( n==0) {
LM_INFO("the socket %s already exists, trying to delete it...\n", mi_socket);
@ -235,14 +235,14 @@ static int mi_mod_init(void)
LM_WARN("cannot specify mi_unix_socket_mode = 0, forcing it to rw-------\n");
mi_unix_socket_mode = S_IRUSR| S_IWUSR;
}
if (mi_unix_socket_uid_s) {
if (user2uid(&mi_unix_socket_uid, &mi_unix_socket_gid, mi_unix_socket_uid_s)<0) {
LM_ERR("bad user name %s\n", mi_unix_socket_uid_s);
return -1;
}
}
if (mi_unix_socket_gid_s) {
if (group2gid(&mi_unix_socket_gid, mi_unix_socket_gid_s)<0) {
LM_ERR("bad group name %s\n", mi_unix_socket_gid_s);
@ -252,7 +252,11 @@ static int mi_mod_init(void)
/*create the unix socket address*/
mi_dtgram_addr.unix_addr.sun_family = AF_LOCAL;
memcpy( mi_dtgram_addr.unix_addr.sun_path, mi_socket, strlen(mi_socket));
if(strlen(mi_socket)>=sizeof(mi_dtgram_addr.unix_addr.sun_path)-1) {
LM_ERR("mi socket path is too long\n");
return -1;
}
memcpy(mi_dtgram_addr.unix_addr.sun_path, mi_socket, strlen(mi_socket));
done:
/* add space for extra processes */
@ -369,7 +373,7 @@ static int mi_destroy(void)
if (n==0) {
if(config_check==0) {
if (unlink(mi_socket)<0){
LM_ERR("cannot delete the socket (%s): %s\n",
LM_ERR("cannot delete the socket (%s): %s\n",
mi_socket, strerror(errno));
goto error;
}

@ -108,15 +108,18 @@ FILE *mi_init_fifo_server(char *fifo_name, int mi_fifo_mode,
mi_fifo_write=open( fifo_name, O_WRONLY|O_NONBLOCK, 0);
if (mi_fifo_write<0) {
LM_ERR("fifo_write did not open: %s\n", strerror(errno));
fclose(fifo_stream);
return 0;
}
/* set read fifo blocking mode */
if ((opt=fcntl(mi_fifo_read, F_GETFL))==-1){
LM_ERR("fcntl(F_GETFL) failed: %s [%d]\n", strerror(errno), errno);
fclose(fifo_stream);
return 0;
}
if (fcntl(mi_fifo_read, F_SETFL, opt & (~O_NONBLOCK))==-1){
LM_ERR("cntl(F_SETFL) failed: %s [%d]\n", strerror(errno), errno);
fclose(fifo_stream);
return 0;
}
@ -125,6 +128,7 @@ FILE *mi_init_fifo_server(char *fifo_name, int mi_fifo_mode,
reply_fifo_s = pkg_malloc(MAX_MI_FILENAME);
if ( mi_buf==NULL|| reply_fifo_s==NULL) {
LM_ERR("no more private memory\n");
fclose(fifo_stream);
return 0;
}
@ -146,7 +150,7 @@ static int mi_fifo_check(int fd, char* fname)
{
struct stat fst;
struct stat lst;
if (fstat(fd, &fst)<0){
LM_ERR("security: fstat on %s failed: %s\n", fname, strerror(errno));
return -1;
@ -200,7 +204,7 @@ static FILE *mi_open_reply_pipe( char *pipe_name )
}
tryagain:
/* open non-blocking to make sure that a broken client will not
/* open non-blocking to make sure that a broken client will not
* block the FIFO server forever */
fifofd=open( pipe_name, O_WRONLY | O_NONBLOCK );
if (fifofd==-1) {
@ -225,7 +229,7 @@ tryagain:
return 0;
}
/* security checks: is this really a fifo?, is
/* security checks: is this really a fifo?, is
* it hardlinked? is it a soft link? */
if (mi_fifo_check(fifofd, pipe_name)<0)
goto error;
@ -280,7 +284,7 @@ retry:
kill(0, SIGTERM);
}
/* if we did not read whole line, our buffer is too small
and we cannot process the request; consume the remainder of
and we cannot process the request; consume the remainder of
request
*/
@ -407,13 +411,17 @@ void mi_fifo_server(FILE *fifo_stream)
int line_len;
char *file_sep, *command, *file;
struct mi_cmd *f;
FILE *reply_stream;
FILE *reply_stream = NULL;
while(1) {
/* update the local config framework structures */
cfg_update();
reply_stream = NULL;
if(reply_stream) {
fclose(reply_stream);
reply_stream = NULL;
}
/* commands must look this way ':<command>:[filename]' */
if (mi_read_line(mi_buf,MAX_MI_FIFO_BUFFER,fifo_stream, &line_len)) {
@ -428,7 +436,7 @@ void mi_fifo_server(FILE *fifo_stream)
line_len--;
mi_buf[line_len]=0;
} else break;
}
}
if (line_len==0) {
LM_DBG("fifo command empty\n");
@ -525,6 +533,7 @@ void mi_fifo_server(FILE *fifo_stream)
free_async_handler(hdl);
/* close reply fifo */
fclose(reply_stream);
reply_stream = NULL;
/* destroy request tree */
if (mi_cmd)
free_mi_tree( mi_cmd );
@ -542,9 +551,11 @@ failure:
consume3:
free_async_handler(hdl);
if (reply_stream)
consume2:
fclose(reply_stream);
if (reply_stream) {
fclose(reply_stream);
reply_stream = NULL;
}
consume1:
mi_do_consume();
}

@ -496,25 +496,28 @@ static struct mi_root* mi_run_rpc(struct mi_root* cmd_tree, void* param)
struct binrpc_handle rpc_handle;
struct binrpc_response_handle resp_handle;
int i;
str *fn;
struct mi_node *node;
char *command = NULL;
int param_count = 0;
char **parameters = NULL;
struct mi_root* result;
int resp_type;
int resp_code;
char *resp;
/* response will be malloced by binrpc_response_to_text.
/* response will be malloced by binrpc_response_to_text.
We do not free it. It must remain after this call.
It will be reused by subsequent calls */
static unsigned char *response = NULL;
static int resp_len = 0;
if (binrpc_open_connection_url(&rpc_handle, rpc_url) != 0)
memset(&rpc_handle, 0, sizeof(struct binrpc_handle));
memset(&resp_handle, 0, sizeof(struct binrpc_response_handle));
if (binrpc_open_connection_url(&rpc_handle, rpc_url) != 0)
{
LM_ERR( "Open connect to %s failed\n", rpc_url);
result = init_mi_tree( 500, (char *)CONNECT_FAILED, strlen(CONNECT_FAILED) );
@ -527,12 +530,12 @@ static struct mi_root* mi_run_rpc(struct mi_root* cmd_tree, void* param)
return( init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN ));
fn = &node->value;
/* find_rpc_exports needs 0 terminated strings */
command = pkg_malloc(fn->len+1);
memcpy(command, fn->s, fn->len);
command[fn->len] = '\0';
/* Count the parameters. */
node = node->next;
while (node) {
@ -564,9 +567,9 @@ static struct mi_root* mi_run_rpc(struct mi_root* cmd_tree, void* param)
result = init_mi_tree( 500, (char *)FAILED, strlen(FAILED) );
goto end;
}
resp_type = binrpc_get_response_type(&resp_handle);
/* If we already have a buffer make it NULL terminated to discard any previous content */
if (resp_len > 0)
response[0]='\0';
@ -582,12 +585,12 @@ static struct mi_root* mi_run_rpc(struct mi_root* cmd_tree, void* param)
/* Some functions don't give a text answer; use a default */
result = init_mi_tree( 200, MI_OK_S, MI_OK_LEN );
break;
case 1:
/* Valid failure */
binrpc_parse_error_response(&resp_handle, &resp_code, &resp);
if (resp_len < strlen(resp) + 1)
{
{
if (resp_len==0)
response = malloc(strlen(resp) + 1);
else
@ -601,7 +604,7 @@ static struct mi_root* mi_run_rpc(struct mi_root* cmd_tree, void* param)
/* Some functions don't give a text answer; use a default */
result = init_mi_tree( resp_code, (char *)FAILED, strlen(FAILED) );
break;
default:
result = init_mi_tree( 500, (char *)FAILED, strlen(FAILED) );
goto end;
@ -610,7 +613,7 @@ static struct mi_root* mi_run_rpc(struct mi_root* cmd_tree, void* param)
end:
if (param_count > 0)
{
for (i=0; i<param_count; i++)
for (i=0; i<param_count; i++)
{
pkg_free(parameters[i]);
}

@ -193,7 +193,7 @@ Chapter 1. Admin Guide
2. NAT pinging types
Currently, the nathelper module supports two types of NAT pings:
* UDP package - 4 bytes (zero filled) UDP packages are sent to the
* UDP packet - 4 bytes (zero filled) UDP packets are sent to the
contact address.
+ Advantages: low bandwitdh traffic, easy to generate by
Kamailio;
@ -334,7 +334,7 @@ modparam("nathelper", "received_avp", "$avp(i:42)")
Which branch flag should be used by the module to identify NATed
contacts for which it should perform NAT ping via a SIP request instead
if dummy UDP package.
of dummy UDP packet.
Default value is -1 (disabled).

@ -49,8 +49,8 @@
<itemizedlist>
<listitem>
<para>
<emphasis>UDP package</emphasis> - 4 bytes (zero filled) UDP
packages are sent to the contact address.
<emphasis>UDP packet</emphasis> - 4 bytes (zero filled) UDP
packets are sent to the contact address.
</para>
<itemizedlist>
<listitem>
@ -265,7 +265,7 @@ modparam("nathelper", "received_avp", "$avp(i:42)")
<para>
Which branch flag should be used by the module to identify NATed
contacts for which it should perform NAT ping via a SIP request
instead if dummy UDP package.
instead of dummy UDP packet.
</para>
<para>
<emphasis>

@ -348,7 +348,6 @@ int redisc_exec(str *srv, str *res, str *cmd, ...)
va_start(ap, cmd);
va_copy(ap2, ap);
rsrv = redisc_get_server(srv);
if(srv==NULL || cmd==NULL || res==NULL)
{
LM_ERR("invalid parameters");
@ -359,6 +358,7 @@ int redisc_exec(str *srv, str *res, str *cmd, ...)
LM_ERR("invalid parameters");
goto error_exec;
}
rsrv = redisc_get_server(srv);
if(rsrv==NULL)
{
LM_ERR("no redis server found: %.*s\n", srv->len, srv->s);

@ -84,18 +84,20 @@ Emmanuel Schmidbauer
5.1. address_reload
5.2. address_dump
5.3. subnet_dump
5.4. trusted_reload
5.5. trusted_dump
5.6. allow_uri
5.4. perm_domain_dump
5.5. trusted_reload
5.6. trusted_dump
5.7. allow_uri
6. RPC Commands
6.1. addressReload
6.2. addressDump
6.3. subnetDump
6.4. testUri basename uri contact
6.5. trustedReload
6.6. trustedDump
6.4. domainDump
6.5. testUri basename uri contact
6.6. trustedReload
6.7. trustedDump
List of Examples
@ -194,18 +196,20 @@ Chapter 1. Admin Guide
5.1. address_reload
5.2. address_dump
5.3. subnet_dump
5.4. trusted_reload
5.5. trusted_dump
5.6. allow_uri
5.4. perm_domain_dump
5.5. trusted_reload
5.6. trusted_dump
5.7. allow_uri
6. RPC Commands
6.1. addressReload
6.2. addressDump
6.3. subnetDump
6.4. testUri basename uri contact
6.5. trustedReload
6.6. trustedDump
6.4. domainDump
6.5. testUri basename uri contact
6.6. trustedReload
6.7. trustedDump
1. Overview
@ -555,7 +559,7 @@ modparam("permissions", "mask_col", "subnet_length")
Example 1.11. Set port_col parameter
...
modparam("permissions", "port_col", "prt")
modparam("permissions", "port_col", "port")
...
3.12. db_mode (integer)
@ -975,9 +979,10 @@ if (allow_trusted("$si", "$proto")) {
5.1. address_reload
5.2. address_dump
5.3. subnet_dump
5.4. trusted_reload
5.5. trusted_dump
5.6. allow_uri
5.4. perm_domain_dump
5.5. trusted_reload
5.6. trusted_dump
5.7. allow_uri
5.1. address_reload
@ -1002,21 +1007,28 @@ if (allow_trusted("$si", "$proto")) {
Parameters: none
5.4. trusted_reload
5.4. perm_domain_dump
Causes permissions module to dump contents of cache memory domain
table.
Parameters: none
5.5. trusted_reload
Causes the permissions module to re-read the contents of trusted table
into cache memory.
Parameters: none
5.5. trusted_dump
5.6. trusted_dump
Causes the permissions module to dump the contents of trusted table
from cache memory.
Parameters: none
5.6. allow_uri
5.7. allow_uri
Tests if (URI, Contact) pair is allowed according to the allow/deny
files. The files must already have been loaded by Kamailio.
@ -1033,9 +1045,10 @@ if (allow_trusted("$si", "$proto")) {
6.1. addressReload
6.2. addressDump
6.3. subnetDump
6.4. testUri basename uri contact
6.5. trustedReload
6.6. trustedDump
6.4. domainDump
6.5. testUri basename uri contact
6.6. trustedReload
6.7. trustedDump
6.1. addressReload
@ -1060,7 +1073,14 @@ if (allow_trusted("$si", "$proto")) {
Parameters: none
6.4. testUri basename uri contact
6.4. domainDump
Causes permissions module to dump contents of cache memory domain
table.
Parameters: none
6.5. testUri basename uri contact
Tests if the (URI, Contact) pair is allowed according to allow/deny
files. The files must already have been loaded by Kamailio.
@ -1072,14 +1092,14 @@ if (allow_trusted("$si", "$proto")) {
* URI - URI to be tested
* Contact - Contact to be tested
6.5. trustedReload
6.6. trustedReload
Causes the permissions module to re-read the contents of the trusted
database table into cache memory.
Parameters: none
6.6. trustedDump
6.7. trustedDump
Causes the permissions module to dump contents of the trusted database
table from cache memory.

@ -19,22 +19,22 @@
The Permissions module provides functions for handling
IP based access control lists (ACL) in a number of ways.
<itemizedlist>
<listitem><para>
Call Routing
</para></listitem>
<listitem><para>
Registration permissions
</para></listitem>
<listitem><para>
URI permissions
</para></listitem>
<listitem><para>
Address permissions
</para></listitem>
<listitem><para>
Trusted Requests
</para></listitem>
</itemizedlist>
<listitem><para>
Call Routing
</para></listitem>
<listitem><para>
Registration permissions
</para></listitem>
<listitem><para>
URI permissions
</para></listitem>
<listitem><para>
Address permissions
</para></listitem>
<listitem><para>
Trusted Requests
</para></listitem>
</itemizedlist>
The Address permissions and Trusted request handling supports
using a database to load ACLs into RAM for fast processing.
</para>
@ -269,7 +269,7 @@
<para>
Rules are stored in a database table specified by the module
parameters. There is a module parameter called
<varname>db_mode</varname> that
<varname>db_mode</varname> that
determines if the rules are cached into memory for faster
matching or if the database is consulted for each invocation
of the allow_trusted() function call.
@ -458,8 +458,8 @@ modparam("permissions", "db_url", "&exampledb;")
<para>
The name of the database table containing IP subnets and DNS domain names used by
<function moreinfo="none">allow_address</function> and
<function moreinfo="none">allow_source_address</function>
functions.
<function moreinfo="none">allow_source_address</function>
functions.
</para>
<para>
<emphasis>
@ -551,7 +551,7 @@ modparam("permissions", "mask_col", "subnet_length")
<title>Set <varname>port_col</varname> parameter</title>
<programlisting format="linespecific">
...
modparam("permissions", "port_col", "prt")
modparam("permissions", "port_col", "port")
...
</programlisting>
</example>
@ -690,7 +690,7 @@ modparam("permissions", "ruri_col", "regexp")
Name of the column in the <quote>address</quote> or
<quote>trusted</quote> table containing a string
that is added as value to peer_tag AVP if peer_tag AVP
has been defined and if the address or peer matches.
has been defined and if the address or peer matches.
</para>
<para>
<emphasis>
@ -711,8 +711,8 @@ modparam("permissions", "tag_col", "peer_tag")
<para>
The column name used to store the priority of the corresponding rule from the database
row. Priority values should be integer. When db_mode is set to 1 (caching), priorities
are ordered from highest to lowest. In non-caching mode, priority order (ASC vs DESC)
is determined by database.
are ordered from highest to lowest. In non-caching mode, priority order (ASC vs DESC)
is determined by database.
</para>
<para>
<emphasis>
@ -732,7 +732,7 @@ modparam("permissions", "priority_col", "column_name")
<title><varname>peer_tag_avp</varname> (AVP string)</title>
<para>
If defined, the AVP will be
set as a side effect of <function moreinfo="none">allow_trusted</function>
set as a side effect of <function moreinfo="none">allow_trusted</function>
call to not NULL tag column value of the matching peer.
</para>
<para>
@ -1172,7 +1172,7 @@ if ($var(group) != -1) {
as described in <xref linkend="sec-trusted-requests"/>
and <quote>-1</quote> otherwise. If a match is found
and <varname>peer_tag_avp</varname> has been defined, adds a
non-NULL tag column value of the
non-NULL tag column value of the
matching peer to AVP peer_tag_avp.
</para>
<para>
@ -1212,10 +1212,9 @@ if (allow_trusted("$si", "$proto")) {
address database table into cache memory.
The in-cache memory entries are
for performance reasons stored in two
different tables: address table and
different tables: address table and
subnet table depending on the value of
the mask field (32 or smaller).
</para>
<para>Parameters: <emphasis>none</emphasis></para>
</section>
@ -1226,8 +1225,7 @@ if (allow_trusted("$si", "$proto")) {
</title>
<para>
Causes permissions module to dump
contents of cache memory address table.
contents of cache memory address table.
</para>
<para>Parameters: <emphasis>none</emphasis></para>
</section>
@ -1238,9 +1236,19 @@ if (allow_trusted("$si", "$proto")) {
</title>
<para>
Causes permissions module to dump
contents of cache memory subnet table.
contents of cache memory subnet table.
</para>
<para>Parameters: <emphasis>none</emphasis></para>
</section>
</para>
<section id ="permissions.m.perm_domain_dump">
<title>
<function moreinfo="none">perm_domain_dump</function>
</title>
<para>
Causes permissions module to dump
contents of cache memory domain table.
</para>
<para>Parameters: <emphasis>none</emphasis></para>
</section>
@ -1249,8 +1257,8 @@ if (allow_trusted("$si", "$proto")) {
<function moreinfo="none">trusted_reload</function>
</title>
<para>
Causes the permissions module to re-read the contents of
trusted table into cache memory.
Causes the permissions module to re-read the contents of
trusted table into cache memory.
</para>
<para>Parameters: <emphasis>none</emphasis></para>
</section>
@ -1260,8 +1268,8 @@ if (allow_trusted("$si", "$proto")) {
<function moreinfo="none">trusted_dump</function>
</title>
<para>
Causes the permissions module to dump the
contents of trusted table from cache memory.
Causes the permissions module to dump the
contents of trusted table from cache memory.
</para>
<para>Parameters: <emphasis>none</emphasis></para>
</section>
@ -1273,22 +1281,22 @@ if (allow_trusted("$si", "$proto")) {
<para>
Tests if (URI, Contact) pair is allowed according to
the allow/deny files. The files must already have been
loaded by &kamailio;.
loaded by &kamailio;.
</para>
<para>Parameters: </para>
<itemizedlist>
<listitem><para>
<emphasis>basename</emphasis> -
Basename from which allow and deny filenames will be created by
appending contents of <varname>allow_suffix</varname> and <varname>deny_suffix</varname>
parameters.
Basename from which allow and deny filenames will be created by
appending contents of <varname>allow_suffix</varname>
and <varname>deny_suffix</varname>
parameters.
</para></listitem>
<listitem><para>
<emphasis>URI</emphasis> - URI to be tested
</para></listitem>
<listitem><para>
<emphasis>Contact</emphasis> - Contact
to be tested
<emphasis>Contact</emphasis> - Contact to be tested
</para></listitem>
</itemizedlist>
@ -1306,7 +1314,7 @@ if (allow_trusted("$si", "$proto")) {
address database table into cache
memory. In cache memory the entries are
for performance reasons stored in two
different tables: address table and
different tables: address table and
subnet table depending on the value of
the mask field (32 or smaller).
@ -1320,7 +1328,7 @@ if (allow_trusted("$si", "$proto")) {
</title>
<para>
Causes the permissions module to dump
the contents of cache memory address table.
the contents of cache memory address table.
(Not the subnet table).
</para>
@ -1333,10 +1341,22 @@ if (allow_trusted("$si", "$proto")) {
</title>
<para>
Causes permissions module to dump
contents of cache memory subnet table.
contents of cache memory subnet table.
</para>
<para>Parameters: <emphasis>none</emphasis></para>
</section>
<section id ="permissions.r.domainDump">
<title>
<function moreinfo="none">domainDump</function>
</title>
<para>
Causes permissions module to dump
contents of cache memory domain table.
</para>
<para>Parameters: <emphasis>none</emphasis></para>
</section>
<section id ="permissions.r.testUri">
<title>
<function moreinfo="none">testUri basename uri contact</function>

@ -13,8 +13,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
@ -22,7 +22,7 @@
/*!
* \file
* \brief Kamailio presence module :: Events
* \ingroup presence
* \ingroup presence
*/
@ -31,9 +31,9 @@
#include <string.h>
#include "../../str.h"
#include "../../dprint.h"
#include "../../parser/parse_event.h"
#include "../../mem/shm_mem.h"
#include "../../mem/mem.h"
#include "../../parser/parse_event.h"
#include "../../mem/shm_mem.h"
#include "../../mem/mem.h"
#include "event_list.h"
#include "hash.h"
@ -89,7 +89,7 @@ event_t* shm_copy_event(event_t* e)
ev->params.hooks.event_dialog.from_tag = p2;
if (e->params.hooks.event_dialog.to_tag == p1)
ev->params.hooks.event_dialog.to_tag = p2;
if (e->params.hooks.event_dialog.include_session_description == p1)
if (e->params.hooks.event_dialog.include_session_description == p1)
ev->params.hooks.event_dialog.include_session_description = p2;
if (e->params.hooks.event_dialog.sla == p1)
ev->params.hooks.event_dialog.sla = p2;
@ -109,7 +109,7 @@ void shm_free_event(event_t* ev)
{
if(ev== NULL)
return;
if(ev->name.s)
shm_free(ev->name.s);
@ -141,7 +141,7 @@ int add_event(pres_ev_t* event)
LM_ERR("NULL content_type param\n");
return -1;
}
ev= contains_event(&event->name, &parsed_event);
if(ev== NULL)
{
@ -182,7 +182,7 @@ int add_event(pres_ev_t* event)
if(ev->content_type.s== NULL)
{
ERR_MEM(SHARE_MEM);
}
}
ev->content_type.len= event->content_type.len;
memcpy(ev->content_type.s, event->content_type.s, event->content_type.len);
@ -191,7 +191,7 @@ int add_event(pres_ev_t* event)
if(*sep=='.') break;
if(sep>=parsed_event.name.s+parsed_event.name.len) sep=0;
if(sep && strncmp(sep+1, "winfo", 5)== 0)
{
{
ev->type= WINFO_TYPE;
wipeer_name.s= parsed_event.name.s;
wipeer_name.len= sep - parsed_event.name.s;
@ -203,7 +203,7 @@ int add_event(pres_ev_t* event)
}
}
else
{
{
ev->type= PUBL_TYPE;
if (parsed_event.name.len + 6 > 50) {
LM_ERR("buffer too small\n");
@ -221,11 +221,11 @@ int add_event(pres_ev_t* event)
parsed_event.name.len,parsed_event.name.s);
}
}
if(ev->wipeer)
if(ev->wipeer)
ev->wipeer->wipeer= ev;
if(event->req_auth &&
if(event->req_auth &&
( event->get_auth_status==0 ||event->get_rules_doc== 0))
{
LM_ERR("bad event structure\n");
@ -251,7 +251,7 @@ int add_event(pres_ev_t* event)
EvList->events= ev;
}
EvList->ev_count++;
LM_DBG("successfully added event: %.*s - len= %d\n",ev->name.len,
ev->name.s, ev->name.len);
done:
@ -261,7 +261,7 @@ error:
free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
if(ev && not_in_list)
{
free_pres_event(ev);
free_pres_event(ev);
}
return -1;
}
@ -294,16 +294,16 @@ evlist_t* init_evlist(void)
}
list->ev_count= 0;
list->events= NULL;
return list;
}
}
pres_ev_t* contains_event(str* sname, event_t* parsed_event)
{
event_t event;
event_t *pe;
pres_ev_t* e;
pe = (parsed_event)?parsed_event:&event;
memset(pe, 0, sizeof(event_t));
@ -336,7 +336,7 @@ void free_event_params(param_t* params, int mem_type)
pkg_free(t1);
t1= t2;
}
}
pres_ev_t* search_event(event_t* event)
@ -358,11 +358,11 @@ pres_ev_t* search_event(event_t* event)
{
return pres_ev;
}
/* search all parameters in event in ev */
if(search_event_params(event, pres_ev->evp)< 0)
goto cont;
/* search all parameters in ev in event */
if(search_event_params(pres_ev->evp, event)< 0)
goto cont;
@ -386,19 +386,20 @@ int search_event_params(event_t* ev, event_t* searched_ev)
{
p= searched_ev->params.list;
found= 0;
while(p)
{
if(p->name.len== ps->name.len &&
strncmp(p->name.s,ps->name.s, ps->name.len)== 0)
if(p->name.len== ps->name.len &&
strncmp(p->name.s,ps->name.s, ps->name.len)== 0) {
if((p->body.s== 0 && ps->body.s== 0) ||
(p->body.len== ps->body.len &&
(p->body.len== ps->body.len &&
strncmp(p->body.s,ps->body.s,ps->body.len)== 0))
{
found= 1;
break;
}
p= p->next;
}
p= p->next;
}
if(found== 0)
return -1;
@ -409,15 +410,15 @@ int search_event_params(event_t* ev, event_t* searched_ev)
}
int get_event_list(str** ev_list)
{
{
pres_ev_t* ev= EvList->events;
int i;
str* list;
*ev_list= NULL;
if(EvList->ev_count== 0)
return 0;
list= (str*)pkg_malloc(sizeof(str));
if(list== NULL)
{
@ -433,36 +434,34 @@ int get_event_list(str** ev_list)
return -1;
}
list->s[0]= '\0';
for(i= 0; i< EvList->ev_count; i++)
{
if(i> 0)
{
memcpy(list->s+ list->len, ", ", 2);
list->len+= 2;
}
}
memcpy(list->s+ list->len, ev->name.s, ev->name.len );
list->len+= ev->name.len ;
ev= ev->next;
}
*ev_list= list;
return 0;
}
void destroy_evlist(void)
{
pres_ev_t* e1, *e2;
if (EvList)
{
pres_ev_t* e1, *e2;
if (EvList) {
e1= EvList->events;
while(e1)
{
while(e1) {
e2= e1->next;
free_pres_event(e1);
e1= e2;
}
}
shm_free(EvList);
}
}
}

@ -13,8 +13,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
@ -22,7 +22,7 @@
/*!
* \file
* \brief Kamailio presence module :: Events
* \ingroup presence
* \ingroup presence
*/
@ -47,14 +47,14 @@ typedef int (publ_handling_t)(struct sip_msg*);
typedef int (subs_handling_t)(struct sip_msg*);
typedef str* (agg_nbody_t)(str* pres_user, str* pres_domain, str** body_array, int n, int off_index);
/* params for agg_body_t
/* params for agg_body_t
* body_array= an array with all the bodies stored for that resource
* n= the number of bodies
* off_index= the index of the registration(etag) for which a Publish
* with Expires: 0 has just been received
* */
typedef str* (aux_body_processing_t)(struct subscription *subs, str* body);
/* params for agg_body_t
/* params for agg_body_t
* subs= a subscription structure to manipulate the body for a certain watcher
* body= the original body
*
@ -79,16 +79,16 @@ struct pres_ev
str name;
event_t* evp;
str content_type;
int default_expires;
unsigned int default_expires;
int type; /* category type: WINFO_TIPE, PUBL_TYPE, ...*/
int etag_not_new;
/*
* 0 - the standard mechanism (allocating new etag for each Publish)
* 1 - allocating an etag only for an initial Publish
* 1 - allocating an etag only for an initial Publish
* */
/* fileds that deal with authorization rules*/
/*
* req_auth -> flag 0 - if not require
* req_auth -> flag 0 - if not require
* is_watcher_allowed - get subscription state from xcap rules
* apply_auth_nbody - alter the body according to authorization rules
*/
@ -97,17 +97,17 @@ struct pres_ev
get_pidf_doc_t* get_pidf_doc;
apply_auth_t* apply_auth_nbody;
is_allowed_t* get_auth_status;
/* an agg_body_t function should be registered if the event permits having
* multiple published states and requires an aggregation of the information
* otherwise, this field should be NULL and the last published state is taken
* when constructing Notify msg
* otherwise, this field should be NULL and the last published state is taken
* when constructing Notify msg
* */
agg_nbody_t* agg_nbody;
publ_handling_t * evs_publ_handl;
subs_handling_t * evs_subs_handl;
free_body_t* free_body;
/* sometimes it is necessary that a module make changes for a body for each
/* sometimes it is necessary that a module make changes for a body for each
* active watcher (e.g. setting the "version" parameter in an XML document.
* If a module registers the aux_body_processing callback, it gets called for
* each watcher. It either gets the body received by the PUBLISH, or the body
@ -119,9 +119,9 @@ struct pres_ev
*/
aux_body_processing_t* aux_body_processing;
free_body_t* aux_free_body;
struct pres_ev* wipeer;
struct pres_ev* wipeer;
struct pres_ev* next;
};
typedef struct pres_ev pres_ev_t;
@ -129,7 +129,7 @@ typedef struct evlist
{
int ev_count;
pres_ev_t* events;
}evlist_t;
} evlist_t;
evlist_t* init_evlist(void);

@ -583,8 +583,9 @@ error:
str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag,
str* contact)
{
db_key_t query_cols[3];
db_val_t query_vals[3];
db_key_t query_cols[4];
db_val_t query_vals[4];
db_op_t query_ops[4];
db_key_t result_cols[3];
db1_res_t *result = NULL;
int body_col, etag_col= 0, sender_col;
@ -634,18 +635,28 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag,
query_vals[n_query_cols].type = DB1_STR;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.str_val = uri.host;
query_ops[n_query_cols] = OP_EQ;
n_query_cols++;
query_cols[n_query_cols] = &str_username_col;
query_vals[n_query_cols].type = DB1_STR;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.str_val = uri.user;
query_ops[n_query_cols] = OP_EQ;
n_query_cols++;
query_cols[n_query_cols] = &str_event_col;
query_vals[n_query_cols].type = DB1_STR;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.str_val= event->name;
query_ops[n_query_cols] = OP_EQ;
n_query_cols++;
query_cols[n_query_cols] = &str_expires_col;
query_vals[n_query_cols].type = DB1_INT;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.int_val= (int)time(NULL);
query_ops[n_query_cols] = OP_GT;
n_query_cols++;
result_cols[body_col=n_result_cols++] = &str_body_col;
@ -663,7 +674,7 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag,
} else {
query_str = str_received_time_col;
}
if (pa_dbf.query (pa_db, query_cols, 0, query_vals,
if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
result_cols, n_query_cols, n_result_cols, &query_str , &result) < 0)
{
LM_ERR("failed to query %.*s table\n", presentity_table.len, presentity_table.s);

@ -396,9 +396,11 @@ int delete_presentity_if_dialog_id_exists(presentity_t* presentity, char* dialog
if(result == NULL)
return -3;
// No results from query definitely means no dialog exists
if (result->n <= 0)
/* no results from query definitely means no dialog exists */
if (result->n <= 0) {
pa_dbf.free_result(pa_db, result);
return 0;
}
// Loop the rows returned from the DB
for (i=0; i < result->n; i++)
@ -428,11 +430,13 @@ int delete_presentity_if_dialog_id_exists(presentity_t* presentity, char* dialog
pa_dbf.free_result(pa_db, result);
result = NULL;
free(db_dialog_id);
db_dialog_id = NULL;
return 1;
}
free(db_dialog_id);
db_dialog_id = NULL;
}
}
@ -494,7 +498,7 @@ int get_dialog_state(presentity_t* presentity, char** state)
}
if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
result_cols, n_query_cols, n_result_cols, 0, &result) < 0)
result_cols, n_query_cols, n_result_cols, 0, &result) < 0)
{
LM_ERR("unsuccessful sql query\n");
return -2;
@ -503,9 +507,11 @@ int get_dialog_state(presentity_t* presentity, char** state)
if(result == NULL)
return -3;
// No results from query definitely means no dialog exists
if (result->n <= 0)
/* no results from query definitely means no dialog exists */
if (result->n <= 0) {
pa_dbf.free_result(pa_db, result);
return 0;
}
// Loop the rows returned from the DB
for (i=0; i < result->n; i++)
@ -515,7 +521,8 @@ int get_dialog_state(presentity_t* presentity, char** state)
tmp_db_body.s = (char*)row_vals[rez_body_col].val.string_val;
tmp_db_body.len = strlen(tmp_db_body.s);
parse_state_result = parse_dialog_state_from_body(tmp_db_body, &db_is_dialog, state);
parse_state_result = parse_dialog_state_from_body(tmp_db_body,
&db_is_dialog, state);
pa_dbf.free_result(pa_db, result);
result = NULL;
@ -686,13 +693,16 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
}
check_if_dialog(*body, &is_dialog, &dialog_id);
if ( dialog_id ) {
if (delete_presentity_if_dialog_id_exists(presentity, dialog_id) < 0) {
free(dialog_id);
dialog_id = NULL;
goto error;
}
if (delete_presentity_if_dialog_id_exists(presentity, dialog_id) < 0) {
goto error;
free(dialog_id);
dialog_id = NULL;
}
free(dialog_id);
LM_DBG("inserting %d cols into table\n",n_query_cols);
if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols) < 0)
@ -790,6 +800,10 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
if(check_if_dialog(*body, &is_dialog, &dialog_id)< 0)
{
LM_ERR("failed to check if dialog stored\n");
if(dialog_id) {
free(dialog_id);
dialog_id = NULL;
}
goto error;
}
@ -803,13 +817,26 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
if(check_if_dialog(old_body, &is_dialog, &old_dialog_id)< 0)
{
LM_ERR("failed to check if dialog stored\n");
if(old_dialog_id) {
free(old_dialog_id);
old_dialog_id = NULL;
}
goto error;
}
if(is_dialog==0 ) /* if the old body has no dialog - overwrite */
/* if the old body has no dialog - overwrite */
if(is_dialog==0 ) {
if(old_dialog_id) {
free(old_dialog_id);
old_dialog_id = NULL;
}
goto after_dialog_check;
}
free(old_dialog_id);
if(old_dialog_id) {
free(old_dialog_id);
old_dialog_id = NULL;
}
sender.s = (char*)row_vals[rez_sender_col].val.string_val;
sender.len= strlen(sender.s);
@ -966,23 +993,25 @@ after_dialog_check:
else
cur_etag= presentity->etag;
if (is_dialog_terminated(presentity))
{
LM_WARN("Trying to update an already terminated state. Skipping update.\n");
/* send 200OK */
if (publ_send200ok(msg, presentity->expires, cur_etag)< 0)
if (presentity->event->evp->type==EVENT_DIALOG) {
if(is_dialog_terminated(presentity))
{
LM_ERR("sending 200OK reply\n");
goto error;
}
if (sent_reply) *sent_reply= 1;
LM_WARN("Trying to update an already terminated state."
" Skipping update.\n");
if(etag.s)
pkg_free(etag.s);
etag.s= NULL;
/* send 200OK */
if (publ_send200ok(msg, presentity->expires, cur_etag)< 0) {
LM_ERR("sending 200OK reply\n");
goto error;
}
if (sent_reply) *sent_reply= 1;
goto done;
if(etag.s)
pkg_free(etag.s);
etag.s= NULL;
goto done;
}
}
update_keys[n_update_cols] = &str_expires_col;
@ -1224,9 +1253,6 @@ int pres_htable_restore(void)
row = &result->rows[i];
row_vals = ROW_VALUES(row);
if(row_vals[expires_col].val.int_val< (int)time(NULL))
continue;
sphere= NULL;
user.s= (char*)row_vals[user_col].val.string_val;
user.len= strlen(user.s);

@ -56,8 +56,8 @@ static str pu_500_rpl = str_init("Server Internal Error");
static str pu_489_rpl = str_init("Bad Event");
static str pu_423_rpl = str_init("Interval Too Brief");
int send_2XX_reply(struct sip_msg * msg, int reply_code, int lexpire,
str* local_contact)
static int send_2XX_reply(sip_msg_t *msg, int reply_code,
unsigned int lexpire, str *local_contact)
{
str hdr_append = {0, 0};
str tmp;
@ -1335,7 +1335,7 @@ error:
}
int extract_sdialog_info_ex(subs_t* subs,struct sip_msg* msg, uint32_t miexp,
int extract_sdialog_info_ex(subs_t* subs, struct sip_msg* msg, uint32_t miexp,
uint32_t mexp, int* to_tag_gen, str scontact,
str watcher_user, str watcher_domain,
int* reply_code, str* reply_str)
@ -1349,20 +1349,15 @@ int extract_sdialog_info_ex(subs_t* subs,struct sip_msg* msg, uint32_t miexp,
struct sip_uri uri;
/* examine the expire header field */
if(msg->expires && msg->expires->body.len > 0)
{
if (!msg->expires->parsed && (parse_expires(msg->expires) < 0))
{
if(msg->expires && msg->expires->body.len > 0) {
if (!msg->expires->parsed && (parse_expires(msg->expires) < 0)) {
LM_ERR("cannot parse Expires header\n");
goto error;
}
lexpire = ((exp_body_t*)msg->expires->parsed)->val;
LM_DBG("'Expires' header found, value= %d\n", lexpire);
}
else
{
LM_DBG("'expires' not found; default=%d\n",subs->event->default_expires);
LM_DBG("'Expires' header found, value= %u\n", lexpire);
} else {
LM_DBG("'expires' not found; default=%u\n",subs->event->default_expires);
lexpire = subs->event->default_expires;
}
if(lexpire > mexp)
@ -1370,34 +1365,32 @@ int extract_sdialog_info_ex(subs_t* subs,struct sip_msg* msg, uint32_t miexp,
if (lexpire && miexp && lexpire < miexp) {
if(min_expires_action == 1) {
LM_DBG("subscription expiration invalid , requested=%d, minimum=%d, returning error \"423 Interval Too brief\"\n", lexpire, miexp);
LM_DBG("subscription expiration invalid , requested=%u, minimum=%u,"
" returning error \"423 Interval Too brief\"\n",
lexpire, miexp);
*reply_code = INTERVAL_TOO_BRIEF;
*reply_str = pu_423_rpl;
goto error;
} else {
LM_DBG("subscription expiration set to minimum (%d) for requested (%d)\n", lexpire, miexp);
LM_DBG("subscription expiration set to minimum (%u) for requested"
" (%u)\n", lexpire, miexp);
lexpire = miexp;
}
}
subs->expires = lexpire;
if( msg->to==NULL || msg->to->body.s==NULL)
{
if( msg->to==NULL || msg->to->body.s==NULL) {
LM_ERR("cannot parse TO header\n");
goto error;
}
/* examine the to header */
if(msg->to->parsed != NULL)
{
if(msg->to->parsed != NULL) {
pto = (struct to_body*)msg->to->parsed;
LM_DBG("'To' header ALREADY PARSED: <%.*s>\n",pto->uri.len,pto->uri.s);
}
else
{
} else {
parse_to(msg->to->body.s,msg->to->body.s + msg->to->body.len + 1, &TO);
if( TO.uri.len <= 0 )
{
if( TO.uri.len <= 0 ) {
LM_DBG("'To' header NOT parsed\n");
goto error;
}
@ -1405,15 +1398,11 @@ int extract_sdialog_info_ex(subs_t* subs,struct sip_msg* msg, uint32_t miexp,
}
if( pto->parsed_uri.user.s && pto->parsed_uri.host.s &&
pto->parsed_uri.user.len && pto->parsed_uri.host.len)
{
pto->parsed_uri.user.len && pto->parsed_uri.host.len) {
subs->to_user = pto->parsed_uri.user;
subs->to_domain = pto->parsed_uri.host;
}
else
{
if(parse_uri(pto->uri.s, pto->uri.len, &uri)< 0)
{
} else {
if(parse_uri(pto->uri.s, pto->uri.len, &uri)< 0) {
LM_ERR("while parsing uri\n");
goto error;
}
@ -1422,13 +1411,11 @@ int extract_sdialog_info_ex(subs_t* subs,struct sip_msg* msg, uint32_t miexp,
}
/* examine the from header */
if (!msg->from || !msg->from->body.s)
{
if (!msg->from || !msg->from->body.s) {
LM_DBG("cannot find 'from' header!\n");
goto error;
}
if (msg->from->parsed == NULL)
{
if (msg->from->parsed == NULL) {
LM_DBG("'From' header not parsed\n");
/* parsing from header */
if ( parse_from_header( msg )<0 )
@ -1440,15 +1427,11 @@ int extract_sdialog_info_ex(subs_t* subs,struct sip_msg* msg, uint32_t miexp,
pfrom = (struct to_body*)msg->from->parsed;
if( pfrom->parsed_uri.user.s && pfrom->parsed_uri.host.s &&
pfrom->parsed_uri.user.len && pfrom->parsed_uri.host.len)
{
pfrom->parsed_uri.user.len && pfrom->parsed_uri.host.len) {
subs->from_user = pfrom->parsed_uri.user;
subs->from_domain = pfrom->parsed_uri.host;
}
else
{
if(parse_uri(pfrom->uri.s, pfrom->uri.len, &uri)< 0)
{
} else {
if(parse_uri(pfrom->uri.s, pfrom->uri.len, &uri)< 0) {
LM_ERR("while parsing uri\n");
goto error;
}
@ -1460,61 +1443,50 @@ int extract_sdialog_info_ex(subs_t* subs,struct sip_msg* msg, uint32_t miexp,
subs->watcher_domain = watcher_domain;
/* get to_tag if the message does not have a to_tag*/
if (pto->tag_value.s==NULL || pto->tag_value.len==0 )
{
if (pto->tag_value.s==NULL || pto->tag_value.len==0 ) {
LM_DBG("generating to_tag\n");
*to_tag_gen = 1;
rtag_value.len = 0;
if(slb.get_reply_totag(msg, &rtag_value)<0 || rtag_value.len <= 0)
{
if(slb.get_reply_totag(msg, &rtag_value)<0 || rtag_value.len <= 0) {
LM_ERR("while creating to_tag\n");
goto error;
}
}
else
{
} else {
*to_tag_gen = 0;
rtag_value=pto->tag_value;
}
subs->to_tag = rtag_value;
if( msg->callid==NULL || msg->callid->body.s==NULL)
{
if( msg->callid==NULL || msg->callid->body.s==NULL) {
LM_ERR("cannot parse callid header\n");
goto error;
}
subs->callid = msg->callid->body;
if( msg->cseq==NULL || msg->cseq->body.s==NULL)
{
if( msg->cseq==NULL || msg->cseq->body.s==NULL) {
LM_ERR("cannot parse cseq header\n");
goto error;
}
if (str2int( &(get_cseq(msg)->number), &subs->remote_cseq)!=0 )
{
if (str2int( &(get_cseq(msg)->number), &subs->remote_cseq)!=0 ) {
LM_ERR("cannot parse cseq number\n");
goto error;
}
if( msg->contact==NULL || msg->contact->body.s==NULL)
{
if( msg->contact==NULL || msg->contact->body.s==NULL) {
LM_ERR("cannot parse contact header\n");
goto error;
}
if( parse_contact(msg->contact) <0 )
{
if( parse_contact(msg->contact) <0 ) {
LM_ERR(" cannot parse contact"
" header\n");
goto error;
}
b= (contact_body_t* )msg->contact->parsed;
if(b == NULL)
{
if(b == NULL) {
LM_ERR("cannot parse contact header\n");
goto error;
}
if(b->star || b->contacts==NULL)
{
if(b->star || b->contacts==NULL) {
LM_ERR("Wrong contact header\n");
goto error;
}
@ -1524,29 +1496,24 @@ int extract_sdialog_info_ex(subs_t* subs,struct sip_msg* msg, uint32_t miexp,
LM_DBG("subs->contact= %.*s - len = %d\n",subs->contact.len,
subs->contact.s, subs->contact.len);
if (EVENT_DIALOG_SLA(subs->event->evp))
{
if (EVENT_DIALOG_SLA(subs->event->evp)) {
/* user_contact@from_domain */
if(parse_uri(subs->contact.s, subs->contact.len, &uri)< 0)
{
if(parse_uri(subs->contact.s, subs->contact.len, &uri)< 0) {
LM_ERR("failed to parse contact uri\n");
goto error;
}
if(uandd_to_uri(uri.user, subs->from_domain, &subs->pres_uri)< 0)
{
if(uandd_to_uri(uri.user, subs->from_domain, &subs->pres_uri)< 0) {
LM_ERR("failed to construct uri\n");
goto error;
}
LM_DBG("&&&&&&&&&&&&&&& dialog pres_uri= %.*s\n",
LM_DBG("dialog pres_uri= %.*s\n",
subs->pres_uri.len, subs->pres_uri.s);
}
/*process record route and add it to a string*/
if(*to_tag_gen && msg->record_route!=NULL)
{
if(*to_tag_gen && msg->record_route!=NULL) {
rt = print_rr_body(msg->record_route, &rec_route, 0, 0);
if(rt != 0)
{
if(rt != 0) {
LM_ERR("processing the record route [%d]\n", rt);
rec_route.s=NULL;
rec_route.len=0;
@ -1557,8 +1524,7 @@ int extract_sdialog_info_ex(subs_t* subs,struct sip_msg* msg, uint32_t miexp,
subs->sockinfo_str= msg->rcv.bind_address->sock_str;
if( pfrom->tag_value.s ==NULL || pfrom->tag_value.len == 0)
{
if( pfrom->tag_value.s ==NULL || pfrom->tag_value.len == 0) {
LM_ERR("no from tag value present\n");
goto error;
}
@ -1566,16 +1532,14 @@ int extract_sdialog_info_ex(subs_t* subs,struct sip_msg* msg, uint32_t miexp,
subs->version = 1;
if((!scontact.s) || (scontact.len== 0))
{
if(ps_fill_local_contact(msg, &subs->local_contact)<0)
{
if((!scontact.s) || (scontact.len== 0)) {
if(ps_fill_local_contact(msg, &subs->local_contact)<0) {
LM_ERR("cannot get local contact address\n");
goto error;
}
}
else
} else {
subs->local_contact= scontact;
}
if (parse_headers(msg, HDR_USERAGENT_F, 0) != -1 && msg->user_agent &&
msg->user_agent->body.len>0 && msg->user_agent->body.len<MAX_UA_SIZE) {

@ -43,19 +43,6 @@
static const char base64digits[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
#define BAD -1
static const char base64val[] = {
BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD,
BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD,
BAD,BAD,BAD,BAD, BAD,BAD,BAD,BAD, BAD,BAD,BAD, 62, BAD,BAD,BAD, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,BAD,BAD, BAD,BAD,BAD,BAD,
BAD, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,BAD, BAD,BAD,BAD,BAD,
BAD, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,BAD, BAD,BAD,BAD,BAD
};
#define DECODE64(c) (isascii(c) ? base64val[c] : BAD)
void to64frombits(unsigned char *out, const unsigned char *in, int inlen)
{
for (; inlen >= 3; inlen -= 3)

@ -755,14 +755,14 @@ end:
}
ua_pres_t* subscribe_cbparam(subs_info_t* subs, int ua_flag)
{
{
ua_pres_t* hentity= NULL;
int size;
size= sizeof(ua_pres_t)+ 2*sizeof(str)+(subs->pres_uri->len+
subs->watcher_uri->len+ subs->contact->len+ subs->id.len+ 1)*
sizeof(char);
if(subs->outbound_proxy && subs->outbound_proxy->len && subs->outbound_proxy->s )
size+= sizeof(str)+ subs->outbound_proxy->len* sizeof(char);
@ -811,7 +811,7 @@ ua_pres_t* subscribe_cbparam(subs_info_t* subs, int ua_flag)
memcpy(hentity->outbound_proxy->s, subs->outbound_proxy->s, subs->outbound_proxy->len);
hentity->outbound_proxy->len= subs->outbound_proxy->len;
size+= subs->outbound_proxy->len;
}
}
if(subs->expires< 0)
hentity->desired_expires= 0;
else
@ -833,21 +833,21 @@ ua_pres_t* subscribe_cbparam(subs_info_t* subs, int ua_flag)
}
hentity->flag= subs->source_flag;
hentity->event= subs->event;
hentity->ua_flag= hentity->ua_flag;
hentity->ua_flag= ua_flag;
hentity->cb_param= subs->cb_param;
return hentity;
}
}
ua_pres_t* subs_cbparam_indlg(ua_pres_t* subs, int expires, int ua_flag)
{
{
ua_pres_t* hentity= NULL;
int size;
size= sizeof(ua_pres_t)+ 2*sizeof(str)+subs->pres_uri->len+
subs->watcher_uri->len+ subs->contact.len+ subs->id.len+
subs->to_tag.len+ subs->call_id.len+ subs->from_tag.len+ 1;
if(subs->outbound_proxy && subs->outbound_proxy->len && subs->outbound_proxy->s )
size+= sizeof(str)+ subs->outbound_proxy->len;
@ -895,13 +895,13 @@ ua_pres_t* subs_cbparam_indlg(ua_pres_t* subs, int expires, int ua_flag)
memcpy(hentity->outbound_proxy->s, subs->outbound_proxy->s, subs->outbound_proxy->len);
hentity->outbound_proxy->len= subs->outbound_proxy->len;
size+= subs->outbound_proxy->len;
}
}
if(subs->id.s)
{
CONT_COPY(hentity, hentity->id, subs->id)
}
if(subs->remote_contact.s)
{
CONT_COPY(hentity, hentity->remote_contact, subs->remote_contact)
@ -918,11 +918,11 @@ ua_pres_t* subs_cbparam_indlg(ua_pres_t* subs, int expires, int ua_flag)
size+= subs->extra_headers->len;
}
/* copy dialog information */
CONT_COPY(hentity, hentity->to_tag, subs->to_tag)
CONT_COPY(hentity, hentity->from_tag, subs->from_tag)
CONT_COPY(hentity, hentity->call_id, subs->call_id)
if(expires< 0)
hentity->desired_expires= 0;
else
@ -930,12 +930,12 @@ ua_pres_t* subs_cbparam_indlg(ua_pres_t* subs, int expires, int ua_flag)
hentity->flag= subs->flag;
hentity->event= subs->event;
hentity->ua_flag= hentity->ua_flag;
hentity->ua_flag= ua_flag;
hentity->cb_param= subs->cb_param;
return hentity;
}
}
/**

@ -17,8 +17,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* History:
@ -63,7 +63,7 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
int event_flag= 0;
memset(&dialog, 0, sizeof(ua_pres_t));
LM_DBG("start...\n\n");
if( parse_headers(msg,HDR_EOH_F, 0)==-1 )
@ -91,7 +91,7 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
else
{
parse_to(msg->to->body.s,msg->to->body.s + msg->to->body.len + 1, &TO);
if(TO.uri.len <= 0)
if(TO.uri.len <= 0)
{
LM_ERR("'To' header NOT parsed\n");
goto error;
@ -100,7 +100,7 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
}
dialog.watcher_uri= &pto->uri;
uri=(char*)pkg_malloc(sizeof(char)*( pto->uri.len+1));
if(uri== NULL)
{
@ -115,12 +115,12 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
LM_ERR("while decoding sip uri in xmpp\n");
pkg_free(uri);
goto error;
}
}
to_uri.len= strlen(to_uri.s);
pkg_free(uri);
if (pto->tag_value.s==NULL || pto->tag_value.len==0 )
{
{
LM_ERR("to tag value not parsed\n");
goto error;
}
@ -143,7 +143,7 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
{
LM_ERR("'From' header not parsed\n");
/* parsing from header */
if ( parse_from_header( msg )<0 )
if ( parse_from_header( msg )<0 )
{
LM_ERR("ERROR cannot parse From header\n");
goto error;
@ -151,7 +151,7 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
}
pfrom = (struct to_body*)msg->from->parsed;
dialog.pres_uri= &pfrom->uri;
uri=(char*)pkg_malloc(sizeof(char)*( pfrom->uri.len+1));
if(uri== NULL)
{
@ -160,17 +160,17 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
}
memcpy(uri, pfrom->uri.s, pfrom->uri.len);
uri[pfrom->uri.len]= '\0';
from_uri.s= euri_sip_xmpp(uri);
if(from_uri.s== NULL)
{
LM_ERR("while encoding sip uri in xmpp\n");
pkg_free(uri);
goto error;
}
}
from_uri.len= strlen(from_uri.s);
pkg_free(uri);
if( pfrom->tag_value.s ==NULL || pfrom->tag_value.len == 0)
{
LM_ERR("no from tag value present\n");
@ -179,20 +179,20 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
dialog.to_tag= pfrom->tag_value;
dialog.flag|= XMPP_SUBSCRIBE;
if(msg->event->body.len== 8 &&
if(msg->event->body.len== 8 &&
(strncmp(msg->event->body.s,"presence",8 )==0))
event_flag|= PRESENCE_EVENT;
else
if(msg->event->body.len== 14 &&
(strncmp(msg->event->body.s,"presence.winfo",14 )==0))
event_flag|= PWINFO_EVENT;
else
{
LM_ERR("wrong event\n");
goto error;
}
if(msg->event->body.len== 14 &&
(strncmp(msg->event->body.s,"presence.winfo",14 )==0))
event_flag|= PWINFO_EVENT;
else
{
LM_ERR("wrong event\n");
goto error;
}
dialog.event= event_flag;
if(pua_is_dialog(&dialog)< 0) // verify if within a stored dialog
{
LM_ERR("Notify in a non existing dialog\n");
@ -203,11 +203,11 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
{
body.s= NULL;
body.len= 0;
}
}
else
{
body.s=get_body(msg);
if (body.s== NULL)
if (body.s== NULL)
{
LM_ERR("cannot extract body from msg\n");
goto error;
@ -215,9 +215,9 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
body.len = get_content_length( msg );
}
/* treat the two cases: event= presence & event=presence.winfo */
/* treat the two cases: event= presence & event=presence.winfo */
if(event_flag & PRESENCE_EVENT)
{
{
LM_DBG("PRESENCE\n");
hdr = msg->headers;
while (hdr!= NULL)
@ -232,21 +232,21 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
if(strncmp(hdr->body.s+11,"reason=timeout", 14)== 0)
{
LM_DBG("Received Notification with state"
"terminated; reason= timeout=> don't send notification\n");
"terminated; reason= timeout=> don't send notification\n");
return 1;
}
}
is_terminated= 1;
}
if(build_xmpp_content(&to_uri, &from_uri, &body, &id, is_terminated)< 0)
{
LM_ERR("in function build_xmpp_content\n");
LM_ERR("in function build_xmpp_content\n");
goto error;
}
}
}
else
{
{
if(event_flag & PWINFO_EVENT)
{
LM_DBG("PRESENCE.WINFO\n");
@ -259,8 +259,8 @@ int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2)
}
if(hdr && strncmp(hdr->body.s,"terminated", 10)== 0)
{
LM_DBG("Notify for presence.winfo with"
" Subscription-State terminated- should not translate\n");
LM_DBG("Notify for presence.winfo with"
" Subscription-State terminated- should not translate\n");
goto error;
}
if(winfo2xmpp(&to_uri, &body, &id)< 0)
@ -329,7 +329,7 @@ int build_xmpp_content(str* to_uri, str* from_uri, str* body, str* id,
goto error;
}
if(is_terminated)
{
{
attr= xmlNewProp(xmpp_root, BAD_CAST "type", BAD_CAST "unsubscribed");
if(attr== NULL)
{
@ -362,7 +362,7 @@ int build_xmpp_content(str* to_uri, str* from_uri, str* body, str* id,
LM_ERR("while extracting 'presence' node\n");
goto error;
}
node = XMLNodeGetNodeByName(sip_root, "basic", NULL);
if(node== NULL)
{
@ -402,11 +402,11 @@ int build_xmpp_content(str* to_uri, str* from_uri, str* body, str* id,
}
node= XMLNodeGetNodeByName(node, "note", NULL);
if(node== NULL)
{
{
LM_DBG("Person node has no note node\n");
goto done;
}
}
}
}
note= (char*)xmlNodeGetContent(node);
if(note== NULL)
{
@ -423,7 +423,7 @@ int build_xmpp_content(str* to_uri, str* from_uri, str* body, str* id,
{
LM_ERR("while adding node show: away\n");
goto error;
}
}
}
else
if(xmlStrcasecmp((unsigned char*)note, (unsigned char*)"busy")== 0)
@ -434,57 +434,36 @@ int build_xmpp_content(str* to_uri, str* from_uri, str* body, str* id,
{
LM_ERR("while adding node show: away\n");
goto error;
}
}
/*
if(xmlStrcasecmp((unsigned char*)note, (unsigned char*)"on the phone")== 0)
{
new_node = xmlNewChild(xmpp_root, NULL, BAD_CAST "show", BAD_CAST "chat");
if(new_node== NULL)
{
LM_ERR("while adding node show: chat\n");
goto error;
}
}
}
else
if(xmlStrcasecmp((unsigned char*)note, (unsigned char*)"idle")== 0)
else
if((xmlStrcasecmp((unsigned char*)note,
(unsigned char*)"dnd")== 0)||
(xmlStrcasecmp((unsigned char*)note,
(unsigned char*)"do not disturb")== 0)||
(xmlStrcasecmp((unsigned char*)note,
(unsigned char*)"Busy (DND)")== 0))
{
new_node = xmlNewChild(xmpp_root, NULL, BAD_CAST "show", BAD_CAST "idle");
new_node = xmlNewChild(xmpp_root, NULL, BAD_CAST "show",
BAD_CAST "dnd");
if(new_node== NULL)
{
LM_ERR("while adding node: idle\n");
LM_ERR("while adding node show: dnd\n");
goto error;
}
}*/
else
if((xmlStrcasecmp((unsigned char*)note,
(unsigned char*)"dnd")== 0)||
(xmlStrcasecmp((unsigned char*)note,
(unsigned char*)"do not disturb")== 0)||
(xmlStrcasecmp((unsigned char*)note,
(unsigned char*)"Busy (DND)")== 0))
{
new_node = xmlNewChild(xmpp_root, NULL, BAD_CAST "show",
BAD_CAST "dnd");
if(new_node== NULL)
{
LM_ERR("while adding node show: dnd\n");
goto error;
}
}
else
LM_DBG("Not Found Status\n");
}
else
LM_DBG("Not Found Status\n");
/* adding status node */
new_node = xmlNewChild(xmpp_root, NULL, BAD_CAST "status", BAD_CAST note);
if(new_node== NULL)
{
LM_ERR("while adding node status\n");
goto error;
}
}
xmlFree(note);
note= NULL;
@ -520,7 +499,7 @@ done:
LM_ERR("while adding creating new buffer\n");
goto error;
}
xmpp_msg.len= xmlNodeDump(buffer, doc, xmpp_root, 1,1);
if(xmpp_msg.len== -1)
{
@ -533,7 +512,7 @@ done:
LM_ERR("while extracting buffer content\n");
goto error;
}
LM_DBG("xmpp_msg: %.*s\n",xmpp_msg.len, xmpp_msg.s);
if( xmpp_notify(from_uri, to_uri, &xmpp_msg, id)< 0)
{
@ -592,15 +571,15 @@ int winfo2xmpp(str* to_uri, str* body, str* id)
LM_ERR("while extracting 'presence' node\n");
goto error;
}
node = XMLNodeGetNodeByName(pidf_root, "watcher", NULL);
for (; node!=NULL; node = node->next)
{
{
if( xmlStrcasecmp(node->name,(unsigned char*)"watcher"))
continue;
watcher= (char*)xmlNodeGetContent(node->children);
watcher= (char*)xmlNodeGetContent(node->children);
if(watcher== NULL)
{
LM_ERR("while extracting watcher node content\n");
@ -611,7 +590,7 @@ int winfo2xmpp(str* to_uri, str* body, str* id)
{
LM_ERR("while encoding sip uri in xmpp\n");
goto error;
}
}
from_uri.len= strlen(from_uri.s);
xmlFree(watcher);
watcher= NULL;
@ -654,7 +633,7 @@ int winfo2xmpp(str* to_uri, str* body, str* id)
LM_ERR("while adding creating new buffer\n");
goto error;
}
xmpp_msg.len= xmlNodeDump(buffer, doc, root_node, 1,1);
if(xmpp_msg.len== -1)
{
@ -667,9 +646,9 @@ int winfo2xmpp(str* to_uri, str* body, str* id)
LM_ERR("while extracting buffer content\n");
goto error;
}
LM_DBG("xmpp_msg: %.*s\n",xmpp_msg.len, xmpp_msg.s);
if( xmpp_subscribe(&from_uri, to_uri, &xmpp_msg, id)< 0)
{
LM_ERR("while sending xmpp_subscribe\n");
@ -713,7 +692,7 @@ char* get_error_reason(int code, str* reason)
LM_ERR("no more memory\n");
return NULL;
}
switch( code )
{
case 300: { strcpy(err_cond, "redirect"); break;}
@ -761,10 +740,10 @@ char* get_error_reason(int code, str* reason)
}
return err_cond;
}
}
int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
{
char* uri;
/* named according to the direction of the message in xmpp*/
@ -778,7 +757,7 @@ int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
str reason;
char* err_reason= NULL;
xmlBufferPtr buffer= NULL;
LM_DBG("start..\n");
uri=(char*)pkg_malloc(sizeof(char)*( hentity->watcher_uri->len+1));
if(uri== NULL)
@ -793,12 +772,12 @@ int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
{
LM_ERR("whil decoding sip uri in xmpp\n");
pkg_free(uri);
goto error;
}
goto error;
}
to_uri.len= strlen(to_uri.s);
pkg_free(uri);
uri=(char*)pkg_malloc(sizeof(char)*( hentity->pres_uri->len+1));
if(uri== NULL)
{
@ -822,7 +801,7 @@ int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
if(doc==0)
goto error;
root_node = xmlNewNode(NULL, BAD_CAST "presence");
if(root_node==0)
goto error;
xmlDocSetRootElement(doc, root_node);
@ -864,7 +843,7 @@ int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
LM_ERR("couldn't get response phrase\n");
goto error;
}
attr= xmlNewProp(root_node, BAD_CAST "type", BAD_CAST "error");
if(attr== NULL)
{
@ -876,15 +855,15 @@ int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
{
LM_ERR("while adding new node\n");
goto error;
}
}
node= xmlNewChild(node, 0, BAD_CAST err_reason, 0 );
if(node== NULL)
{
LM_ERR("while adding new node\n");
goto error;
}
}
attr= xmlNewProp(node, BAD_CAST "xmlns",
attr= xmlNewProp(node, BAD_CAST "xmlns",
BAD_CAST "urn:ietf:params:xml:ns:xmpp-stanzas");
if(attr== NULL)
{
@ -892,8 +871,7 @@ int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
goto error;
}
}
else
} else {
if(code>=200 )
{
LM_DBG(" 2xx code\n");
@ -904,30 +882,31 @@ int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
goto error;
}
}
}
buffer= xmlBufferCreate();
if(buffer== NULL)
{
LM_ERR("while adding creating new buffer\n");
goto error;
}
xmpp_msg.len= xmlNodeDump(buffer, doc, root_node, 1,1);
if(xmpp_msg.len== -1)
{
LM_ERR("while dumping node\n");
goto error;
}
xmpp_msg.s= (char*)xmlBufferContent( buffer);
if(xmpp_msg.s== NULL)
{
LM_ERR("while extracting buffer content\n");
goto error;
}
buffer= xmlBufferCreate();
if(buffer== NULL)
{
LM_ERR("while adding creating new buffer\n");
goto error;
}
xmpp_msg.len= xmlNodeDump(buffer, doc, root_node, 1,1);
if(xmpp_msg.len== -1)
{
LM_ERR("while dumping node\n");
goto error;
}
xmpp_msg.s= (char*)xmlBufferContent( buffer);
if(xmpp_msg.s== NULL)
{
LM_ERR("while extracting buffer content\n");
goto error;
}
LM_DBG("xmpp_msg: %.*s\n",xmpp_msg.len, xmpp_msg.s);
if(xmpp_packet(&from_uri, &to_uri, &xmpp_msg, &hentity->to_tag)< 0)
{
LM_ERR("while sending xmpp_reply_to_subscribe\n");
@ -936,7 +915,7 @@ int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg)
if(err_reason)
pkg_free(err_reason);
xmlFreeDoc(doc);
return 0;
error:

@ -133,8 +133,11 @@ char *find_sip_user(char *extern_user) {
if (result == NULL)
return NULL;
if (result->n <= 0)
if (result->n <= 0) {
pa_dbf.free_result(pa_db, result);
return NULL;
}
row = &result->rows[0];
row_vals = ROW_VALUES(row);
@ -208,6 +211,7 @@ extern_account_t *find_accounts(char* sip_user, int* count) {
return NULL;
}
if (result->n <= 0) {
pa_dbf.free_result(pa_db, result);
LM_ERR("result count = %d\n", result->n);
return NULL;
}
@ -290,8 +294,11 @@ extern_user_t *find_users(char *sip_user, int* count) {
if (result == NULL)
return NULL;
if (result->n <= 0)
if (result->n <= 0) {
pa_dbf.free_result(pa_db, result);
return NULL;
}
users = (extern_user_t*) pkg_malloc(sizeof(extern_user_t)*result->n);

@ -569,7 +569,7 @@ static int mod_init(void)
{
LM_ERR("failed to register RPC commands\n");
return -1;
}
}
pv_init_sbranch();
return 0;
@ -612,7 +612,10 @@ static int pv_unset(struct sip_msg* msg, char* pvid, char *foo)
pv_spec_t *sp;
sp = (pv_spec_t*)pvid;
pv_set_spec_value(msg, sp, 0, NULL);
if(pv_set_spec_value(msg, sp, 0, NULL)<0) {
LM_ERR("faile to unset variable\n");
return -1;
}
return 1;
}

@ -70,7 +70,7 @@ script_var_t* add_var(str *name, int vtype)
return 0;
}
it->name.len = name->len;
strncpy(it->name.s, name->s, name->len);
memcpy(it->name.s, name->s, name->len);
it->name.s[it->name.len] = '\0';
if(vtype==VAR_TYPE_NULL) {
@ -133,7 +133,7 @@ script_var_t* set_var_value(script_var_t* var, int_str *value, int flags)
}
var->v.flags |= VAR_VAL_STR;
}
strncpy(var->v.value.s.s, value->s.s, value->s.len);
memcpy(var->v.value.s.s, value->s.s, value->s.len);
var->v.value.s.len = value->s.len;
var->v.value.s.s[value->s.len] = '\0';
} else {

@ -13,8 +13,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

@ -14,8 +14,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
@ -33,8 +33,8 @@
#include "../../dprint.h"
#include "../../mem/mem.h"
#include "../../ut.h"
#include "../../trim.h"
#include "../../ut.h"
#include "../../trim.h"
#include "../../pvapi.h"
#include "../../dset.h"
#include "../../basex.h"
@ -198,7 +198,7 @@ static int pdu_7bit_encode(str sin) {
sin.s++;
i++;
nleft = 1;
}
}
sin.s++;
}
_tr_buffer[j] = '\0';
@ -230,11 +230,11 @@ static int pdu_7bit_decode(str sin) {
}
}
_tr_buffer[j] = '\0';
return j;
return j;
}
/* Get only the numeric part of string, e.g.
040/123-456 => 040123456 */
* 040/123-456 => 040123456 */
static int getNumericValue(str sin) {
int i, j = 0;
for(i = 0; i < sin.len; i ++) {
@ -285,7 +285,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
{
if(str2sint(&val->rs, &val->ri)!=0)
return -1;
} else {
} else {
if(!(val->flags&PV_VAL_STR))
val->rs.s = int2str(val->ri, &val->rs.len);
}
@ -676,7 +676,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
st.len = val->rs.len;
for (i=0; i<st.len; i++)
st.s[i]=(val->rs.s[i]>='A' && val->rs.s[i]<='Z')
?('a' + val->rs.s[i] -'A'):val->rs.s[i];
?('a' + val->rs.s[i] -'A'):val->rs.s[i];
memset(val, 0, sizeof(pv_value_t));
val->flags = PV_VAL_STR;
val->rs = st;
@ -695,7 +695,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
st.len = val->rs.len;
for (i=0; i<st.len; i++)
st.s[i]=(val->rs.s[i]>='a' && val->rs.s[i]<='z')
?('A' + val->rs.s[i] -'a'):val->rs.s[i];
?('A' + val->rs.s[i] -'a'):val->rs.s[i];
memset(val, 0, sizeof(pv_value_t));
val->flags = PV_VAL_STR;
val->rs = st;
@ -860,7 +860,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
}
st2 = w.rs;
}
val->flags = PV_VAL_STR;
val->ri = 0;
@ -915,7 +915,7 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
s[st.len] = '\0';
t = val->ri;
val->rs.len = strftime(_tr_buffer, TR_BUFFER_SIZE-1, s,
localtime(&t));
localtime(&t));
pkg_free(s);
val->flags = PV_VAL_STR;
val->rs.s = _tr_buffer;
@ -980,16 +980,16 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t *tp, int subtype,
switch(st.s[i+1]) {
case 'n':
p[j++] = '\n';
break;
break;
case 'r':
p[j++] = '\r';
break;
break;
case 't':
p[j++] = '\t';
break;
break;
case '\\':
p[j++] = '\\';
break;
break;
default:
p[j++] = st.s[i+1];
}
@ -1203,7 +1203,7 @@ int tr_eval_uri(struct sip_msg *msg, tr_param_t *tp, int subtype,
break;
case TR_URI_HEADERS:
val->rs = (_tr_parsed_uri.headers.s)?_tr_parsed_uri.headers:
_tr_empty;
_tr_empty;
break;
case TR_URI_TRANSPORT:
val->rs = (_tr_parsed_uri.transport_val.s)?
@ -1275,7 +1275,7 @@ int tr_eval_paramlist(struct sip_msg *msg, tr_param_t *tp, int subtype,
if(tp->type != TR_PARAM_STRING || tp->v.s.len != 1)
return -1;
separator = tp->v.s.s[0];
separator = tp->v.s.s[0];
}
else if (tp->next != NULL)
{
@ -1312,21 +1312,21 @@ int tr_eval_paramlist(struct sip_msg *msg, tr_param_t *tp, int subtype,
_tr_params_str.len = val->rs.len;
memcpy(_tr_params_str.s, val->rs.s, val->rs.len);
_tr_params_str.s[_tr_params_str.len] = '\0';
/* reset old values */
if(_tr_params_list != NULL)
{
free_params(_tr_params_list);
_tr_params_list = 0;
}
/* parse params */
sv = _tr_params_str;
if (parse_params2(&sv, CLASS_ANY, &phooks, &_tr_params_list,
_tr_params_separator)<0)
return -1;
}
if(_tr_params_list==NULL)
return -1;
@ -1354,7 +1354,7 @@ int tr_eval_paramlist(struct sip_msg *msg, tr_param_t *tp, int subtype,
}
sv = v.rs;
}
for (pit = _tr_params_list; pit; pit=pit->next)
{
if (pit->name.len==sv.len
@ -1400,7 +1400,7 @@ int tr_eval_paramlist(struct sip_msg *msg, tr_param_t *tp, int subtype,
n--;
}
} else {
/* ugly hack -- params are in reverse order
/* ugly hack -- params are in reverse order
* - first count then find */
i = 0;
for (pit = _tr_params_list; pit; pit=pit->next)
@ -1455,7 +1455,7 @@ int tr_eval_paramlist(struct sip_msg *msg, tr_param_t *tp, int subtype,
n--;
}
} else {
/* ugly hack -- params are in reverse order
/* ugly hack -- params are in reverse order
* - first count then find */
i = 0;
for (pit = _tr_params_list; pit; pit=pit->next)
@ -1535,10 +1535,10 @@ int tr_eval_nameaddr(struct sip_msg *msg, tr_param_t *tp, int subtype,
_tr_nameaddr_str.len = val->rs.len;
memcpy(_tr_nameaddr_str.s, val->rs.s, val->rs.len);
_tr_nameaddr_str.s[_tr_nameaddr_str.len] = '\0';
/* reset old values */
memset(&_tr_nameaddr, 0, sizeof(name_addr_t));
/* parse params */
sv = _tr_nameaddr_str;
ret = parse_nameaddr(&sv, &_tr_nameaddr);
@ -1550,7 +1550,7 @@ int tr_eval_nameaddr(struct sip_msg *msg, tr_param_t *tp, int subtype,
_tr_nameaddr.len = _tr_nameaddr_str.len;
}
}
memset(val, 0, sizeof(pv_value_t));
val->flags = PV_VAL_STR;
@ -1618,11 +1618,11 @@ int tr_eval_tobody(struct sip_msg *msg, tr_param_t *tp, int subtype,
_tr_tobody_str.s[_tr_tobody_str.len] = '\r';
_tr_tobody_str.s[_tr_tobody_str.len+1] = '\n';
_tr_tobody_str.s[_tr_tobody_str.len+2] = '\0';
/* reset old values */
free_to_params(&_tr_tobody);
memset(&_tr_tobody, 0, sizeof(struct to_body));
/* parse params */
sv = _tr_tobody_str;
parse_to(sv.s, sv.s + sv.len + 2, &_tr_tobody);
@ -1635,7 +1635,7 @@ int tr_eval_tobody(struct sip_msg *msg, tr_param_t *tp, int subtype,
return -1;
}
if (parse_uri(_tr_tobody.uri.s, _tr_tobody.uri.len,
&_tr_tobody.parsed_uri)<0)
&_tr_tobody.parsed_uri)<0)
{
free_to_params(&_tr_tobody);
memset(&_tr_tobody, 0, sizeof(struct to_body));
@ -1644,7 +1644,7 @@ int tr_eval_tobody(struct sip_msg *msg, tr_param_t *tp, int subtype,
return -1;
}
}
memset(val, 0, sizeof(pv_value_t));
val->flags = PV_VAL_STR;
@ -1661,18 +1661,18 @@ int tr_eval_tobody(struct sip_msg *msg, tr_param_t *tp, int subtype,
break;
case TR_TOBODY_URI_USER:
val->rs = (_tr_tobody.parsed_uri.user.s)
?_tr_tobody.parsed_uri.user:_tr_empty;
?_tr_tobody.parsed_uri.user:_tr_empty;
break;
case TR_TOBODY_URI_HOST:
val->rs = (_tr_tobody.parsed_uri.host.s)
?_tr_tobody.parsed_uri.host:_tr_empty;
?_tr_tobody.parsed_uri.host:_tr_empty;
break;
case TR_TOBODY_PARAMS:
if(_tr_tobody.param_lst!=NULL)
{
val->rs.s = _tr_tobody.param_lst->name.s;
val->rs.len = _tr_tobody_str.s + _tr_tobody_str.len
- val->rs.s;
- val->rs.s;
} else val->rs = _tr_empty;
break;
@ -1895,7 +1895,7 @@ done:
if(_p0==NULL) \
{ \
LM_ERR("invalid spec in substr transformation: %.*s!\n", \
_in->len, _in->s); \
_in->len, _in->s); \
goto error; \
} \
_p = _p0; \
@ -1918,7 +1918,7 @@ done:
} else if(*_p=='+') _p++; \
_n = 0; \
while(is_in_str(_p, _in) && (*_p==' ' || *_p=='\t' || *_p=='\n')) \
_p++; \
_p++; \
while(is_in_str(_p, _in) && *_p>='0' && *_p<='9') \
{ \
_n = _n*10 + *_p - '0'; \
@ -1935,7 +1935,7 @@ done:
_tp->v.n = sign*n; \
} else { \
LM_ERR("tinvalid param in transformation: %.*s!!\n", \
_in->len, _in->s); \
_in->len, _in->s); \
goto error; \
} \
}
@ -1955,7 +1955,7 @@ done:
if(_p0==NULL) \
{ \
LM_ERR("invalid spec in substr transformation: %.*s!\n", \
_in->len, _in->s); \
_in->len, _in->s); \
goto error; \
} \
_p = _p0; \
@ -1972,11 +1972,11 @@ done:
_ps = _p; \
while(is_in_str(_p, _in) && *_p!='\t' && *_p!='\n' \
&& *_p!=TR_PARAM_MARKER && *_p!=TR_RBRACKET) \
_p++; \
_p++; \
if(*_p=='\0') \
{ \
LM_ERR("invalid param in transformation: %.*s!!\n", \
_in->len, _in->s); \
_in->len, _in->s); \
goto error; \
} \
_tp = (tr_param_t*)pkg_malloc(sizeof(tr_param_t)); \
@ -2105,7 +2105,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_RBRACKET)
{
LM_ERR("invalid prefixes transformation: %.*s!!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
goto done;
@ -2121,7 +2121,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_RBRACKET)
{
LM_ERR("invalid prefixes transformation: %.*s!!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
goto done;
@ -2140,7 +2140,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_PARAM_MARKER)
{
LM_ERR("invalid substr transformation: %.*s!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
p++;
@ -2156,7 +2156,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_RBRACKET)
{
LM_ERR("invalid substr transformation: %.*s!!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
goto done;
@ -2196,7 +2196,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_RBRACKET)
{
LM_ERR("invalid select transformation: %.*s!!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
goto done;
@ -2216,7 +2216,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_RBRACKET)
{
LM_ERR("invalid strip transformation: %.*s!!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
goto done;
@ -2236,7 +2236,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_RBRACKET)
{
LM_ERR("invalid striptail transformation: %.*s!!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
goto done;
@ -2256,7 +2256,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_RBRACKET)
{
LM_ERR("invalid strip transformation: %.*s!!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
goto done;
@ -2276,7 +2276,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_RBRACKET)
{
LM_ERR("invalid ftime transformation: %.*s!!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
goto done;
@ -2295,7 +2295,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_PARAM_MARKER)
{
LM_ERR("invalid replace transformation: %.*s!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
p++;
@ -2306,7 +2306,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_RBRACKET)
{
LM_ERR("invalid replace transformation: %.*s!!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
goto done;
@ -2335,7 +2335,7 @@ char* tr_parse_string(str* in, trans_t *t)
if(*p!=TR_RBRACKET)
{
LM_ERR("invalid ftime transformation: %.*s!!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
goto done;
@ -2532,7 +2532,7 @@ char* tr_parse_paramlist(str* in, trans_t *t)
if (p - start_pos != 1)
{
LM_ERR("invalid separator in transformation: "
"%.*s\n", in->len, in->s);
"%.*s\n", in->len, in->s);
goto error;
}
while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
@ -2555,7 +2555,7 @@ char* tr_parse_paramlist(str* in, trans_t *t)
}
p++;
_tr_parse_nparam(p, p0, tp, spec, n, sign, in, s)
t->params = tp;
t->params = tp;
tp = 0;
while(is_in_str(p, in) && (*p==' ' || *p=='\t' || *p=='\n')) p++;
@ -2568,7 +2568,7 @@ char* tr_parse_paramlist(str* in, trans_t *t)
if (p - start_pos != 1)
{
LM_ERR("invalid separator in transformation: "
"%.*s\n", in->len, in->s);
"%.*s\n", in->len, in->s);
goto error;
}
while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
@ -2591,7 +2591,7 @@ char* tr_parse_paramlist(str* in, trans_t *t)
}
p++;
_tr_parse_nparam(p, p0, tp, spec, n, sign, in, s)
t->params = tp;
t->params = tp;
tp = 0;
while(is_in_str(p, in) && (*p==' ' || *p=='\t' || *p=='\n')) p++;
@ -2604,7 +2604,7 @@ char* tr_parse_paramlist(str* in, trans_t *t)
if (p - start_pos != 1)
{
LM_ERR("invalid separator in transformation: "
"%.*s\n", in->len, in->s);
"%.*s\n", in->len, in->s);
goto error;
}
while(*p && (*p==' ' || *p=='\t' || *p=='\n')) p++;
@ -2628,7 +2628,7 @@ char* tr_parse_paramlist(str* in, trans_t *t)
if (p - start_pos != 1)
{
LM_ERR("invalid separator in transformation: "
"%.*s\n", in->len, in->s);
"%.*s\n", in->len, in->s);
goto error;
}
@ -2636,7 +2636,7 @@ char* tr_parse_paramlist(str* in, trans_t *t)
if(*p!=TR_RBRACKET)
{
LM_ERR("invalid name transformation: %.*s!\n",
in->len, in->s);
in->len, in->s);
goto error;
}
}
@ -2821,7 +2821,7 @@ char* tr_parse_line(str* in, trans_t *t)
}
p++;
_tr_parse_nparam(p, p0, tp, spec, n, sign, in, s)
t->params = tp;
t->params = tp;
tp = 0;
while(is_in_str(p, in) && (*p==' ' || *p=='\t' || *p=='\n')) p++;
if(*p!=TR_RBRACKET)

@ -634,7 +634,7 @@ int pv_var_to_xavp(str *varname, str *xname)
if(varname->len==1 && varname->s[0] == '*') {
for(it=get_var_all(); it; it=it->next) {
memset(&xval, 0, sizeof(sr_xval_t));
if(it->v.flags&VAR_VAL_INT)
if(it->v.flags==VAR_VAL_INT)
{
xval.type = SR_XTYPE_INT;
xval.v.i = it->v.value.n;
@ -658,7 +658,7 @@ int pv_var_to_xavp(str *varname, str *xname)
return -1;
}
memset(&xval, 0, sizeof(sr_xval_t));
if(it->v.flags&VAR_VAL_INT)
if(it->v.flags==VAR_VAL_INT)
{
xval.type = SR_XTYPE_INT;
xval.v.i = it->v.value.n;

@ -338,6 +338,7 @@ static int get_cpuload(double * load)
if (fscanf(f, "cpu %lld%lld%lld%lld%lld%lld%lld%lld",
&n_user, &n_nice, &n_sys, &n_idle, &n_iow, &n_irq, &n_sirq, &n_stl) < 0) {
LM_ERR("could not parse load information\n");
fclose(f);
return -1;
}
fclose(f);

@ -125,7 +125,7 @@ static inline int find_first_route(struct sip_msg* _m)
static inline int is_myself(sip_uri_t *_puri)
{
int ret;
ret = check_self(&_puri->host,
_puri->port_no?_puri->port_no:SIP_PORT, 0);/* match all protos*/
if (ret < 0) return 0;
@ -138,7 +138,7 @@ static inline int is_myself(sip_uri_t *_puri)
return 0;
}
#endif
if(ret==1) {
/* match on host:port, but if gruu, then fail */
if(_puri->gr.s!=NULL)
@ -827,12 +827,19 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
}
if (!use_ob) {
si = grep_sock_info( &puri.host, puri.port_no, puri.proto);
if (si) {
if ((si = grep_sock_info( &puri.host, puri.port_no?puri.port_no:proto_default_port(puri.proto), puri.proto)) != 0) {
set_force_socket(_m, si);
} else if ((si = grep_sock_info( &puri.host, puri.port_no, puri.proto)) != 0) {
set_force_socket(_m, si);
} else {
if (enable_socket_mismatch_warning)
LM_WARN("no socket found for match second RR\n");
if (enable_socket_mismatch_warning) {
LM_WARN("no socket found to match second RR (%.*s)\n",
rt->nameaddr.uri.len, ZSW(rt->nameaddr.uri.s));
if(!is_myself(&puri)) {
LM_WARN("second RR uri is not myself (%.*s)\n",
rt->nameaddr.uri.len, ZSW(rt->nameaddr.uri.s));
}
}
}
}

@ -686,7 +686,6 @@ static inline int build_advertised_rr(struct lump* _l, struct lump* _l2, str *_d
}
memcpy(p, _data->s, _data->len);
p += _data->len;
p = suffix;
if (tag && tag->len) {

@ -371,8 +371,8 @@ int rtjson_init_serial(sip_msg_t *msg, srjson_doc_t *jdoc, sr_xavp_t *iavp)
}
rj = srjson_GetObjectItem(jdoc, nj, "branch_flags");
if(rj!=NULL && rj->type==srjson_Number && rj->valueint!=0) {
bflags = rj->valueint;
if(rj!=NULL && rj->type==srjson_Number && SRJSON_GET_UINT(rj)!=0) {
bflags = SRJSON_GET_UINT(rj);
old_bflags = 0;
getbflagsval(0, &old_bflags);
@ -406,12 +406,12 @@ int rtjson_prepare_branch(sip_msg_t *msg, srjson_doc_t *jdoc, srjson_t *nj)
if(tmb.set_fr!=NULL) {
rj = srjson_GetObjectItem(jdoc, nj, "fr_timer");
if(rj!=NULL && rj->type==srjson_Number && rj->valueint!=0) {
fr = rj->valueint;
if(rj!=NULL && rj->type==srjson_Number && SRJSON_GET_UINT(rj)!=0) {
fr = SRJSON_GET_UINT(rj);
}
rj = srjson_GetObjectItem(jdoc, nj, "fr_inv_timer");
if(rj!=NULL && rj->type==srjson_Number && rj->valueint!=0) {
fr_inv = rj->valueint;
if(rj!=NULL && rj->type==srjson_Number && SRJSON_GET_UINT(rj)!=0) {
fr_inv = SRJSON_GET_UINT(rj);
}
if(fr || fr_inv) tmb.set_fr(msg, fr_inv, fr);
}

@ -465,6 +465,7 @@ static int get_ip_type(char *str_addr)
LM_DBG("%s is an ipv6 addinfos\n", str_addr);
} else {
LM_DBG("%s is an unknown addinfos format AF=%d\n",str_addr, info->ai_family);
freeaddrinfo(info);
return -1;
}
@ -592,8 +593,7 @@ static inline int str_eq(const str *p, const char *q) {
}
static inline str str_prefix(const str *p, const char *q) {
str ret;
ret.s = NULL;
str ret = STR_NULL;
int l = strlen(q);
if (p->len < l)
return ret;

@ -129,7 +129,7 @@ modparam("sanity", "default_checks", 1)
'parse uri' will be executed.
Default value is 7. This resolves to the following list of parsed URIs:
Request RUI (1), From URI (2) and To URI (4).
Request URI (1), From URI (2) and To URI (4).
Example 1.2. Set uri_checks parameter
...

@ -160,7 +160,7 @@ modparam("sanity", "default_checks", 1)
</para>
<para>
Default value is 7. This resolves to the following list of
parsed URIs: Request RUI (1), From URI (2) and To URI (4).
parsed URIs: Request URI (1), From URI (2) and To URI (4).
</para>
<example>
<title>Set <varname>uri_checks</varname> parameter</title>

@ -19,7 +19,7 @@ static StatsConnection statsd_connection = {
bool statsd_connect(void){
struct addrinfo *serverAddr;
struct addrinfo *serverAddr = NULL;
int rc;
if (statsd_connection.sock > 0){
@ -34,12 +34,14 @@ bool statsd_connect(void){
LM_ERR(
"Statsd: could not initiate server information (%s)\n",
gai_strerror(rc));
if(serverAddr) freeaddrinfo(serverAddr);
return false;
}
statsd_connection.sock = socket(serverAddr->ai_family, SOCK_DGRAM, IPPROTO_UDP);
if (statsd_connection.sock < 0 ){
LM_ERR("Statsd: could not create a socket for statsd connection\n");
if(serverAddr) freeaddrinfo(serverAddr);
return false;
}

@ -107,7 +107,7 @@ static int func_set(struct sip_msg* msg, char* key, char* val)
static int func_time_start(struct sip_msg *msg, char *key)
{
int_str avp_key, avp_val;
char unix_time[20];
char unix_time[24];
get_milliseconds(unix_time);
avp_key.s.s = key;
avp_key.s.len = strlen(avp_key.s.s);
@ -125,7 +125,7 @@ static int func_time_start(struct sip_msg *msg, char *key)
static int func_time_end(struct sip_msg *msg, char *key)
{
char unix_time[20];
char unix_time[24];
char *endptr;
long int start_time;
int result;

@ -13,8 +13,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*
@ -1012,10 +1012,13 @@ int remove_hf_f(struct sip_msg* msg, char* str_hf, char* foo)
cnt=0;
/* we need to be sure we have seen all HFs */
parse_headers(msg, HDR_EOH_F, 0);
if(parse_headers(msg, HDR_EOH_F, 0)<0) {
LM_ERR("error while parsing message headers\n");
return -1;
}
for (hf=msg->headers; hf; hf=hf->next) {
/* for well known header names str_hf->s will be set to NULL
during parsing of kamailio.cfg and str_hf->len contains
/* for well known header names str_hf->s will be set to NULL
during parsing of kamailio.cfg and str_hf->len contains
the header type */
if(gp->type==GPARAM_TYPE_INT)
{
@ -1050,7 +1053,10 @@ static int remove_hf_re_f(struct sip_msg* msg, char* key, char* foo)
cnt=0;
/* we need to be sure we have seen all HFs */
parse_headers(msg, HDR_EOH_F, 0);
if(parse_headers(msg, HDR_EOH_F, 0)<0) {
LM_ERR("error while parsing message headers\n");
return -1;
}
for (hf=msg->headers; hf; hf=hf->next)
{
c = hf->name.s[hf->name.len];
@ -1081,7 +1087,10 @@ static int is_present_hf_f(struct sip_msg* msg, char* str_hf, char* foo)
gp = (gparam_p)str_hf;
/* we need to be sure we have seen all HFs */
parse_headers(msg, HDR_EOH_F, 0);
if(parse_headers(msg, HDR_EOH_F, 0)<0) {
LM_ERR("error while parsing message headers\n");
return -1;
}
for (hf=msg->headers; hf; hf=hf->next) {
if(gp->type==GPARAM_TYPE_INT)
{
@ -1108,7 +1117,10 @@ static int is_present_hf_re_f(struct sip_msg* msg, char* key, char* foo)
re = (regex_t*)key;
/* we need to be sure we have seen all HFs */
parse_headers(msg, HDR_EOH_F, 0);
if(parse_headers(msg, HDR_EOH_F, 0)<0) {
LM_ERR("error while parsing message headers\n");
return -1;
}
for (hf=msg->headers; hf; hf=hf->next)
{
c = hf->name.s[hf->name.len];
@ -2214,7 +2226,7 @@ int add_hf_helper(struct sip_msg* msg, str *str1, str *str2,
LM_ERR("error while parsing message\n");
return -1;
}
hf = 0;
if(hfanc!=NULL) {
for (hf=msg->headers; hf; hf=hf->next) {
@ -2265,7 +2277,7 @@ int add_hf_helper(struct sip_msg* msg, str *str1, str *str2,
s0.s = 0;
}
}
len=s0.len;
if (str2) len+= str2->len + REQ_LINE(msg).uri.len;
@ -2899,7 +2911,10 @@ static int search_hf_f(struct sip_msg* msg, char* str_hf, char* re, char *flags)
gp = (gparam_t*)str_hf;
/* we need to be sure we have seen all HFs */
parse_headers(msg, HDR_EOH_F, 0);
if(parse_headers(msg, HDR_EOH_F, 0)<0) {
LM_ERR("error while parsing message headers\n");
return -1;
}
for (hf=msg->headers; hf; hf=hf->next) {
if(gp->type==GPARAM_TYPE_INT)
{
@ -2980,7 +2995,10 @@ static int subst_hf_f(struct sip_msg *msg, char *str_hf, char *subst, char *flag
se=(struct subst_expr*)subst;
/* we need to be sure we have seen all HFs */
parse_headers(msg, HDR_EOH_F, 0);
if(parse_headers(msg, HDR_EOH_F, 0)<0) {
LM_ERR("error while parsing message headers\n");
return -1;
}
for (hf=msg->headers; hf; hf=hf->next) {
if(gp->type==GPARAM_TYPE_INT)
{
@ -3020,7 +3038,7 @@ static int subst_hf_f(struct sip_msg *msg, char *str_hf, char *subst, char *flag
ret=-1;
goto error;
}
/* hack to avoid re-copying rpl, possible because both
/* hack to avoid re-copying rpl, possible because both
* replace_lst & lumps use pkg_malloc */
if (insert_new_lump_after(l, rpl->rpl.s, rpl->rpl.len, 0)==0)
{

@ -1,4 +1,4 @@
/*
/*
* Kamailio TLS module
*
* Copyright (C) 2010 iptelorg GmbH
@ -63,6 +63,7 @@ static int tls_bio_mbuf_puts(BIO* b, const char* s);
static long tls_bio_mbuf_ctrl(BIO* b, int cmd, long arg1, void* arg2);
#if OPENSSL_VERSION_NUMBER < 0x010100000L
static BIO_METHOD tls_mbuf_method = {
BIO_TYPE_TLS_MBUF, /* type */
"sr_tls_mbuf", /* name */
@ -75,12 +76,35 @@ static BIO_METHOD tls_mbuf_method = {
tls_bio_mbuf_free, /* destroy(free) function */
0 /* ctrl callback */
};
#else
static BIO_METHOD *tls_mbuf_method = NULL;
#endif
/** returns a custom tls_mbuf BIO. */
BIO_METHOD* tls_BIO_mbuf(void)
{
#if OPENSSL_VERSION_NUMBER < 0x010100000L
return &tls_mbuf_method;
#else
if(tls_mbuf_method != NULL) {
return tls_mbuf_method;
}
tls_mbuf_method = BIO_meth_new(BIO_TYPE_TLS_MBUF, "sr_tls_mbuf");
if(tls_mbuf_method==NULL) {
LM_ERR("cannot get a new bio method structure\n");
return NULL;
}
BIO_meth_set_write(tls_mbuf_method, tls_bio_mbuf_write);
BIO_meth_set_read(tls_mbuf_method, tls_bio_mbuf_read);
BIO_meth_set_puts(tls_mbuf_method, tls_bio_mbuf_puts);
BIO_meth_set_gets(tls_mbuf_method, NULL);
BIO_meth_set_ctrl(tls_mbuf_method, tls_bio_mbuf_ctrl);
BIO_meth_set_create(tls_mbuf_method, tls_bio_mbuf_new);
BIO_meth_set_destroy(tls_mbuf_method, tls_bio_mbuf_free);
BIO_meth_set_callback_ctrl(tls_mbuf_method, NULL);
return tls_mbuf_method;
#endif
}
@ -91,7 +115,7 @@ BIO_METHOD* tls_BIO_mbuf(void)
BIO* tls_BIO_new_mbuf(struct tls_mbuf* rd, struct tls_mbuf* wr)
{
BIO* ret;
TLS_BIO_DBG("tls_BIO_new_mbuf called (%p, %p)\n", rd, wr);
ret = BIO_new(tls_BIO_mbuf());
if (unlikely(ret == 0))
@ -111,16 +135,24 @@ BIO* tls_BIO_new_mbuf(struct tls_mbuf* rd, struct tls_mbuf* wr)
int tls_BIO_mbuf_set(BIO* b, struct tls_mbuf* rd, struct tls_mbuf* wr)
{
struct tls_bio_mbuf_data* d;
TLS_BIO_DBG("tls_BIO_mbuf_set called (%p => %p, %p)\n", b, rd, wr);
if (unlikely(b->ptr == 0)){
BUG("null BIO ptr\n");
#if OPENSSL_VERSION_NUMBER < 0x010100000L
d = b->ptr;
#else
d = BIO_get_data(b);
#endif
if (unlikely(d == 0)){
BUG("null BIO ptr data\n");
return 0;
}
d = b->ptr;
d->rd = rd;
d->wr = wr;
#if OPENSSL_VERSION_NUMBER < 0x010100000L
b->init = 1;
#else
BIO_set_init(b, 1);
#endif
return 1;
}
@ -133,8 +165,9 @@ int tls_BIO_mbuf_set(BIO* b, struct tls_mbuf* rd, struct tls_mbuf* wr)
static int tls_bio_mbuf_new(BIO* b)
{
struct tls_bio_mbuf_data* d;
TLS_BIO_DBG("tls_bio_mbuf_new called (%p)\n", b);
#if OPENSSL_VERSION_NUMBER < 0x010100000L
b->init = 0; /* not initialized yet */
b->num = 0;
b->ptr = 0;
@ -145,6 +178,14 @@ static int tls_bio_mbuf_new(BIO* b)
d->rd = 0;
d->wr = 0;
b->ptr = d;
#else
BIO_set_init(b, 0);
BIO_set_data(b, NULL);
d = OPENSSL_zalloc(sizeof(*d));
if (unlikely(d == 0))
return 0;
BIO_set_data(b, d);
#endif
return 1;
}
@ -159,11 +200,23 @@ static int tls_bio_mbuf_free(BIO* b)
TLS_BIO_DBG("tls_bio_mbuf_free called (%p)\n", b);
if (unlikely( b == 0))
return 0;
#if OPENSSL_VERSION_NUMBER < 0x010100000L
if (likely(b->ptr)){
OPENSSL_free(b->ptr);
b->ptr = 0;
b->init = 0;
}
#else
do {
struct tls_bio_mbuf_data* d;
d = BIO_get_data(b);
if (likely(d)) {
OPENSSL_free(d);
BIO_set_data(b, NULL);
BIO_set_init(b, 0);
}
} while(0);
#endif
return 1;
}
@ -179,10 +232,14 @@ static int tls_bio_mbuf_read(BIO* b, char* dst, int dst_len)
struct tls_bio_mbuf_data* d;
struct tls_mbuf* rd;
int ret;
ret = 0;
if (likely(dst)) {
d= b->ptr;
#if OPENSSL_VERSION_NUMBER < 0x010100000L
d = b->ptr;
#else
d = BIO_get_data(b);
#endif
BIO_clear_retry_flags(b);
if (unlikely(d == 0 || d->rd->buf == 0)) {
if (d == 0)
@ -232,9 +289,13 @@ static int tls_bio_mbuf_write(BIO* b, const char* src, int src_len)
struct tls_bio_mbuf_data* d;
struct tls_mbuf* wr;
int ret;
ret = 0;
d= b->ptr;
#if OPENSSL_VERSION_NUMBER < 0x010100000L
d = b->ptr;
#else
d = BIO_get_data(b);
#endif
BIO_clear_retry_flags(b);
if (unlikely(d == 0 || d->wr->buf == 0)) {
if (d == 0)
@ -306,12 +367,10 @@ static long tls_bio_mbuf_ctrl(BIO* b, int cmd, long arg1, void* arg2)
static int tls_bio_mbuf_puts(BIO* b, const char* s)
{
int len;
TLS_BIO_DBG("puts called (%p, %s)\n", b, s);
len=strlen(s);
return tls_bio_mbuf_write(b, s, len);
}
/* vi: set ts=4 sw=4 tw=79:ai:cindent: */

@ -107,19 +107,31 @@ static unsigned char dh3072_g[] = { 0x02 };
static void setup_dh(SSL_CTX *ctx)
{
DH *dh;
DH *dh;
BIGNUM *p;
BIGNUM *g;
dh = DH_new();
if (dh == NULL) {
return;
}
dh = DH_new();
if (dh == NULL) {
return;
}
p = BN_bin2bn(dh3072_p, sizeof(dh3072_p), NULL);
g = BN_bin2bn(dh3072_g, sizeof(dh3072_g), NULL);
if (p == NULL || g == NULL) {
DH_free(dh);
return;
}
#if (OPENSSL_VERSION_NUMBER >= 0x1010000fL)
/* libssl >= v1.1.0 */
DH_set0_pqg(dh, p, NULL, g);
#else
dh->p = p;
dh->g = g;
#endif
dh->p = BN_bin2bn(dh3072_p, sizeof(dh3072_p), NULL);
dh->g = BN_bin2bn(dh3072_g, sizeof(dh3072_g), NULL);
if (dh->p == NULL || dh->g == NULL) {
DH_free(dh);
return;
}
SSL_CTX_set_options(ctx, SSL_OP_SINGLE_DH_USE);
SSL_CTX_set_tmp_dh(ctx, dh);
@ -713,11 +725,13 @@ static void sr_ssl_ctx_info_callback(const SSL *ssl, int event, int ret)
if(data==0)
data = (struct tls_extra_data*)SSL_get_app_data(ssl);
LOG(tls_dbg, "SSL handshake done\n");
#if OPENSSL_VERSION_NUMBER < 0x010100000L
/* CVE-2009-3555 - disable renegotiation */
if (ssl->s3) {
LOG(tls_dbg, "SSL disable renegotiation\n");
ssl->s3->flags |= SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS;
}
#endif
data->flags |= F_TLS_CON_HANDSHAKED;
}
}
@ -835,6 +849,7 @@ static int tls_ssl_ctx_mode(SSL_CTX* ctx, long mode, void* clear)
*/
static int tls_ssl_ctx_set_freelist(SSL_CTX* ctx, long val, void* unused)
{
#if OPENSSL_VERSION_NUMBER < 0x010100000L
if (val >= 0)
#if OPENSSL_VERSION_NUMBER >= 0x01000000L
#ifndef OPENSSL_NO_BUF_FREELISTS
@ -843,6 +858,7 @@ static int tls_ssl_ctx_set_freelist(SSL_CTX* ctx, long val, void* unused)
#endif
#if defined (OPENSSL_NO_BUF_FREELISTS) || OPENSSL_VERSION_NUMBER < 0x01000000L
return -1;
#endif
#endif
return 0;
}
@ -927,7 +943,7 @@ static int tls_server_name_cb(SSL *ssl, int *ad, void *private)
/* SSL_set_SSL_CTX only sets the correct certificate parameters, but does
set the proper verify options. Thus this will be done manually! */
SSL_set_options(ssl, SSL_CTX_get_options(ssl->ctx));
SSL_set_options(ssl, SSL_CTX_get_options(SSL_get_SSL_CTX(ssl)));
if ((SSL_get_verify_mode(ssl) == SSL_VERIFY_NONE) ||
(SSL_num_renegotiations(ssl) == 0)) {
/*
@ -937,8 +953,8 @@ static int tls_server_name_cb(SSL *ssl, int *ad, void *private)
* Otherwise, we would possibly reset a per-directory
* configuration which was put into effect by ssl_hook_access.
*/
SSL_set_verify(ssl, SSL_CTX_get_verify_mode(ssl->ctx),
SSL_CTX_get_verify_callback(ssl->ctx));
SSL_set_verify(ssl, SSL_CTX_get_verify_mode(SSL_get_SSL_CTX(ssl)),
SSL_CTX_get_verify_callback(SSL_get_SSL_CTX(ssl)));
}
return SSL_TLSEXT_ERR_OK;

@ -269,6 +269,7 @@ static void* ser_realloc(void *ptr, size_t size, const char* file, int line)
#else /*TLS_MALLOC_DBG */
#if OPENSSL_VERSION_NUMBER < 0x010100000L
static void* ser_malloc(size_t size)
{
return shm_malloc(size);
@ -279,9 +280,22 @@ static void* ser_realloc(void *ptr, size_t size)
{
return shm_realloc(ptr, size);
}
#else
static void* ser_malloc(size_t size, const char *fname, int fline)
{
return shm_malloc(size);
}
static void* ser_realloc(void *ptr, size_t size, const char *fname, int fline)
{
return shm_realloc(ptr, size);
}
#endif
#endif
#if OPENSSL_VERSION_NUMBER < 0x010100000L
static void ser_free(void *ptr)
{
/* The memory functions provided to openssl needs to behave like standard
@ -294,6 +308,14 @@ static void ser_free(void *ptr)
shm_free(ptr);
}
}
#else
static void ser_free(void *ptr, const char *fname, int fline)
{
if (ptr) {
shm_free(ptr);
}
}
#endif
/*
@ -338,11 +360,13 @@ static void init_ssl_methods(void)
ssl_methods[TLS_USE_SSLv23 - 1] = SSLv23_method();
/* only specific SSL or TLS version */
#if OPENSSL_VERSION_NUMBER < 0x010100000L
#ifndef OPENSSL_NO_SSL2
ssl_methods[TLS_USE_SSLv2_cli - 1] = SSLv2_client_method();
ssl_methods[TLS_USE_SSLv2_srv - 1] = SSLv2_server_method();
ssl_methods[TLS_USE_SSLv2 - 1] = SSLv2_method();
#endif
#endif
#ifndef OPENSSL_NO_SSL3_METHOD
ssl_methods[TLS_USE_SSLv3_cli - 1] = SSLv3_client_method();
@ -384,6 +408,7 @@ static void init_ssl_methods(void)
*/
static int init_tls_compression(void)
{
#if OPENSSL_VERSION_NUMBER < 0x010100000L
#if OPENSSL_VERSION_NUMBER >= 0x00908000L
int n, r;
STACK_OF(SSL_COMP)* comp_methods;
@ -468,6 +493,7 @@ static int init_tls_compression(void)
}
end:
#endif /* OPENSSL_VERSION_NUMBER >= 0.9.8 */
#endif /* OPENSSL_VERSION_NUMBER < 1.1.0 */
return 0;
}
@ -478,9 +504,16 @@ end:
*/
int tls_pre_init(void)
{
#if OPENSSL_VERSION_NUMBER < 0x010100000L
void *(*mf)(size_t) = NULL;
void *(*rf)(void *, size_t) = NULL;
void (*ff)(void *) = NULL;
#else
void *(*mf)(size_t, const char *, int) = NULL;
void *(*rf)(void *, size_t, const char *, int) = NULL;
void (*ff)(void *, const char *, int) = NULL;
#endif
/*
* this has to be called before any function calling CRYPTO_malloc,
* CRYPTO_malloc will set allow_customize in openssl to 0

@ -258,12 +258,14 @@ static int tls_complete_init(struct tcp_connection* c)
}
#endif
#if OPENSSL_VERSION_NUMBER < 0x010100000L
#ifdef TLS_KSSL_WORKARROUND
/* if needed apply workaround for openssl bug #1467 */
if (data->ssl->kssl_ctx && openssl_kssl_malloc_bug){
kssl_ctx_free(data->ssl->kssl_ctx);
data->ssl->kssl_ctx=0;
}
#endif
#endif
SSL_set_bio(data->ssl, data->rwbio, data->rwbio);
c->extra_data = data;

@ -30,7 +30,7 @@
/* FIXME: remove this and use the value in domains instead */
#define VERIFY_DEPTH_S 3
/* This callback is called during each verification process,
/* This callback is called during each verification process,
at each step during the chain of certificates (this function
is not the certificate_verification one!). */
int verify_callback(int pre_verify_ok, X509_STORE_CTX *ctx) {
@ -44,49 +44,54 @@ int verify_callback(int pre_verify_ok, X509_STORE_CTX *ctx) {
LOG(L_NOTICE, "tls_init: verify_callback: cert chain too long ( depth > VERIFY_DEPTH_S)\n");
pre_verify_ok=0;
}
if( pre_verify_ok ) {
LOG(L_NOTICE, "tls_init: verify_callback: preverify is good: verify return: %d\n", pre_verify_ok);
return pre_verify_ok;
}
err_cert = X509_STORE_CTX_get_current_cert(ctx);
err = X509_STORE_CTX_get_error(ctx);
err = X509_STORE_CTX_get_error(ctx);
X509_NAME_oneline(X509_get_subject_name(err_cert),buf,sizeof buf);
LOG(L_NOTICE, "tls_init: verify_callback: subject = %s\n", buf);
LOG(L_NOTICE, "tls_init: verify_callback: verify error:num=%d:%s\n", err, X509_verify_cert_error_string(err));
LOG(L_NOTICE, "tls_init: verify_callback: error code is %d\n", ctx->error);
switch (ctx->error) {
LOG(L_NOTICE, "tls_init: verify_callback: verify error - num=%d:%s\n", err,
X509_verify_cert_error_string(err));
LOG(L_NOTICE, "tls_init: verify_callback: error code is %d (depth: %d)\n",
err, depth);
switch (err) {
case X509_V_OK:
LOG(L_NOTICE, "tls_init: verify_callback: all ok\n");
break;
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,sizeof buf);
X509_NAME_oneline(X509_get_issuer_name(err_cert),buf,sizeof buf);
LOG(L_NOTICE, "tls_init: verify_callback: issuer= %s\n",buf);
break;
case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
case X509_V_ERR_CERT_NOT_YET_VALID:
LOG(L_NOTICE, "tls_init: verify_callback: notBefore\n");
break;
case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
case X509_V_ERR_CERT_HAS_EXPIRED:
LOG(L_NOTICE, "tls_init: verify_callback: notAfter\n");
break;
case X509_V_ERR_CERT_SIGNATURE_FAILURE:
case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
LOG(L_NOTICE, "tls_init: verify_callback: unable to decrypt cert signature\n");
break;
case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
LOG(L_NOTICE, "tls_init: verify_callback: unable to decode issuer public key\n");
break;
case X509_V_ERR_OUT_OF_MEM:
ERR("tls_init: verify_callback: Out of memory \n");
break;
case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
LOG(L_NOTICE, "tls_init: verify_callback: Self signed certificate issue\n");
@ -110,12 +115,14 @@ int verify_callback(int pre_verify_ok, X509_STORE_CTX *ctx) {
case X509_V_ERR_CERT_REJECTED:
LOG(L_NOTICE, "tls_init: verify_callback: certificate rejected\n");
break;
default:
LOG(L_NOTICE, "tls_init: verify_callback: something wrong with the cert ... error code is %d (check x509_vfy.h)\n", ctx->error);
LOG(L_NOTICE, "tls_init: verify_callback: something wrong with the"
" cert ... error code is %d (check x509_vfy.h)\n",
err);
break;
}
LOG(L_NOTICE, "tls_init: verify_callback: verify return:%d\n", pre_verify_ok);
return(pre_verify_ok);
}

@ -999,7 +999,7 @@ int add_uac_dns_fallback(struct cell *t, struct sip_msg* msg,
"branches exceeded\n");
if (lock_replies)
UNLOCK_REPLIES(t);
ret=ser_error=E_TOO_MANY_BRANCHES;
ret=ser_error=E_TOO_MANY_BRANCHES;
return ret;
}
/* copy the dns handle into the new uac */

@ -2058,7 +2058,7 @@ enum rps local_reply( struct cell *t, struct sip_msg *p_msg, int branch,
}
}
UNLOCK_REPLIES(t);
if (local_winner >= 0
&& cfg_get(tm, tm_cfg, pass_provisional_replies)
&& winning_code < 200) {
@ -2069,7 +2069,7 @@ enum rps local_reply( struct cell *t, struct sip_msg *p_msg, int branch,
winning_msg, winning_code);
}
}
if (local_winner>=0 && winning_code>=200 ) {
DBG("DEBUG: local transaction completed %d/%d (totag retr: %d/%d)\n",
winning_code, local_winner, totag_retr, t->tmcb_hl.reg_types);
@ -2174,7 +2174,7 @@ int reply_received( struct sip_msg *p_msg )
DBG("DEBUG: reply to local CANCEL processed\n");
goto done;
}
onreply_route=uac->on_reply;
if ( msg_status >= 200 ){
#ifdef TM_ONREPLY_FINAL_DROP_OK
@ -2187,7 +2187,7 @@ int reply_received( struct sip_msg *p_msg )
#endif /* TM_ONREPLY_FINAL_DROP_OK */
/* stop final response timer & retr. if I got a
final response */
stop_rb_timers(&uac->request);
stop_rb_timers(&uac->request);
/* acknowledge negative INVITE replies (do it before detailed
* on_reply processing, which may take very long, like if it
* is attempted to establish a TCP connection to a fail-over dst */
@ -2195,23 +2195,24 @@ int reply_received( struct sip_msg *p_msg )
if (msg_status >= 300) {
ack = build_ack(p_msg, t, branch, &ack_len);
if (ack) {
if (SEND_PR_BUFFER(&uac->request, ack, ack_len)>=0)
if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))){
INIT_TMCB_ONSEND_PARAMS(onsend_params,
t->uas.request, p_msg, &uac->request,
&uac->request.dst, ack, ack_len,
TMCB_LOCAL_F, branch, TYPE_LOCAL_ACK);
run_trans_callbacks_off_params(TMCB_REQUEST_SENT, t,
&onsend_params);
}
if (unlikely(has_tran_tmcbs(t, TMCB_ACK_NEG_IN))){
if (SEND_PR_BUFFER(&uac->request, ack, ack_len)>=0) {
if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))){
INIT_TMCB_ONSEND_PARAMS(onsend_params,
t->uas.request, p_msg, &uac->request,
&uac->request.dst, ack, ack_len,
TMCB_LOCAL_F, branch, TYPE_LOCAL_ACK);
run_trans_callbacks_off_params(TMCB_ACK_NEG_IN, t,
run_trans_callbacks_off_params(TMCB_REQUEST_SENT, t,
&onsend_params);
}
}
if (unlikely(has_tran_tmcbs(t, TMCB_ACK_NEG_IN))){
INIT_TMCB_ONSEND_PARAMS(onsend_params,
t->uas.request, p_msg, &uac->request,
&uac->request.dst, ack, ack_len,
TMCB_LOCAL_F, branch, TYPE_LOCAL_ACK);
run_trans_callbacks_off_params(TMCB_ACK_NEG_IN, t,
&onsend_params);
}
shm_free(ack);
}
} else if (is_local(t) /*&& 200 <= msg_status < 300*/) {
@ -2220,7 +2221,7 @@ int reply_received( struct sip_msg *p_msg )
if (msg_send(&lack_dst, ack, ack_len)<0)
LOG(L_ERR, "Error while sending local ACK\n");
else if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_SENT))){
INIT_TMCB_ONSEND_PARAMS(onsend_params,
INIT_TMCB_ONSEND_PARAMS(onsend_params,
t->uas.request, p_msg, &uac->request,
&lack_dst, ack, ack_len, TMCB_LOCAL_F,
branch, TYPE_LOCAL_ACK);
@ -2252,7 +2253,7 @@ int reply_received( struct sip_msg *p_msg )
}else if (atomic_cmpxchg_long((void*)&uac->local_cancel.buffer, 0,
(long)BUSY_BUFFER)==0){
/* try to rebuild it if empty (not set or marked as BUSY).
* if BUSY or set just exit, a cancel will be (or was) sent
* if BUSY or set just exit, a cancel will be (or was) sent
* shortly on this branch */
DBG("tm: reply_received: branch CANCEL created\n");
#ifdef CANCEL_REASON_SUPPORT
@ -2394,13 +2395,13 @@ int reply_received( struct sip_msg *p_msg )
p_msg->rcv.proto, &p_msg->rcv.src_su)
){
blst_503_timeout=cfg_get(tm, tm_cfg, tm_blst_503_default);
if ((parse_headers(p_msg, HDR_RETRY_AFTER_F, 0)==0) &&
if ((parse_headers(p_msg, HDR_RETRY_AFTER_F, 0)==0) &&
(p_msg->parsed_flag & HDR_RETRY_AFTER_F)){
for (hf=p_msg->headers; hf; hf=hf->next)
if (hf->type==HDR_RETRY_AFTER_T){
/* found */
blst_503_timeout=(unsigned)(unsigned long)hf->parsed;
blst_503_timeout=MAX_unsigned(blst_503_timeout,
blst_503_timeout=MAX_unsigned(blst_503_timeout,
cfg_get(tm, tm_cfg, tm_blst_503_min));
blst_503_timeout=MIN_unsigned(blst_503_timeout,
cfg_get(tm, tm_cfg, tm_blst_503_max));
@ -2435,7 +2436,7 @@ int reply_received( struct sip_msg *p_msg )
}
}
#endif
if (unlikely(p_msg->msg_flags&FL_RPL_SUSPENDED)) {
goto skip_send_reply;
/* suspend the reply (async), no error */
@ -2472,7 +2473,7 @@ int reply_received( struct sip_msg *p_msg )
cleanup_uac_timers( t );
/* 2xx is a special case: we can have a COMPLETED request
* with branches still open => we have to cancel them */
if (is_invite(t) && cancel_data.cancel_bitmap)
if (is_invite(t) && cancel_data.cancel_bitmap)
cancel_uacs( t, &cancel_data, F_CANCEL_B_KILL);
/* FR for negative INVITES, WAIT anything else */
/* Call to set_final_timer is embedded in relay_reply to avoid
@ -2498,7 +2499,7 @@ int reply_received( struct sip_msg *p_msg )
restart_rb_fr(& uac->request, t->fr_inv_timeout);
uac->request.flags|=F_RB_FR_INV; /* mark fr_inv */
} /* provisional replies */
skip_send_reply:
if (likely(replies_locked)){

@ -548,7 +548,9 @@ int t_next_contacts(struct sip_msg* msg, char* key, char* value)
}
/* Rewrite Request-URI */
rewrite_uri(msg, &uri);
if(rewrite_uri(msg, &uri)<0) {
LM_WARN("failed to rewrite r-uri\n");
}
if (dst_uri.len) {
set_dst_uri(msg, &dst_uri);
@ -557,7 +559,9 @@ int t_next_contacts(struct sip_msg* msg, char* key, char* value)
}
if (path.len) {
set_path_vector(msg, &path);
if(set_path_vector(msg, &path)<0) {
LM_WARN("failed to set path vector\n");
}
} else {
reset_path_vector(msg);
}

@ -641,6 +641,7 @@ struct mi_root* mi_tm_cancel(struct mi_root* cmd_tree, void* param)
init_cancel_info(&cancel_data);
cancel_data.cancel_bitmap = ~0; /*all branches*/
_tmx_tmb.prepare_to_cancel(trans, &cancel_data.cancel_bitmap, 0);
_tmx_tmb.cancel_uacs(trans, &cancel_data, 0);
_tmx_tmb.unref_cell(trans);

@ -32,10 +32,10 @@
#include "t_var.h"
struct _pv_tmx_data {
struct cell *T;
unsigned int index;
unsigned int label;
struct sip_msg msg;
struct sip_msg *tmsgp;
unsigned int id;
char *buf;
int buf_size;
};
@ -99,8 +99,7 @@ int pv_t_update_req(struct sip_msg *msg)
if(t->uas.request==NULL)
return 1;
if(_pv_treq.T==t && t->uas.request==_pv_treq.tmsgp
&& t->uas.request->id==_pv_treq.id)
if (_pv_treq.label == t->label && _pv_treq.index == t->hash_index)
return 0;
/* make a copy */
@ -111,8 +110,8 @@ int pv_t_update_req(struct sip_msg *msg)
if(_pv_treq.tmsgp)
free_sip_msg(&_pv_treq.msg);
_pv_treq.tmsgp = NULL;
_pv_treq.id = 0;
_pv_treq.T = NULL;
_pv_treq.index = 0;
_pv_treq.label = 0;
_pv_treq.buf_size = t->uas.request->len+1;
_pv_treq.buf = (char*)pkg_malloc(_pv_treq.buf_size*sizeof(char));
if(_pv_treq.buf==NULL)
@ -130,8 +129,8 @@ int pv_t_update_req(struct sip_msg *msg)
_pv_treq.msg.len = t->uas.request->len;
_pv_treq.msg.buf = _pv_treq.buf;
_pv_treq.tmsgp = t->uas.request;
_pv_treq.id = t->uas.request->id;
_pv_treq.T = t;
_pv_treq.index = t->hash_index;
_pv_treq.label = t->label;
if(pv_t_copy_msg(t->uas.request, &_pv_treq.msg)!=0)
@ -140,7 +139,8 @@ int pv_t_update_req(struct sip_msg *msg)
_pv_treq.buf_size = 0;
_pv_treq.buf = NULL;
_pv_treq.tmsgp = NULL;
_pv_treq.T = NULL;
_pv_treq.index = 0;
_pv_treq.label = 0;
return -1;
}
@ -175,8 +175,7 @@ int pv_t_update_rpl(struct sip_msg *msg)
if(t->uac[branch].reply==NULL || t->uac[branch].reply==FAKED_REPLY)
return 1;
if(_pv_trpl.T==t && t->uac[branch].reply==_pv_trpl.tmsgp
&& t->uac[branch].reply->id==_pv_trpl.id)
if (_pv_trpl.label == t->label && _pv_trpl.index == t->hash_index)
return 0;
/* make a copy */
@ -187,8 +186,8 @@ int pv_t_update_rpl(struct sip_msg *msg)
if(_pv_trpl.tmsgp)
free_sip_msg(&_pv_trpl.msg);
_pv_trpl.tmsgp = NULL;
_pv_trpl.id = 0;
_pv_trpl.T = NULL;
_pv_trpl.index = 0;
_pv_trpl.label = 0;
_pv_trpl.buf_size = t->uac[branch].reply->len+1;
_pv_trpl.buf = (char*)pkg_malloc(_pv_trpl.buf_size*sizeof(char));
if(_pv_trpl.buf==NULL)
@ -206,8 +205,8 @@ int pv_t_update_rpl(struct sip_msg *msg)
_pv_trpl.msg.len = t->uac[branch].reply->len;
_pv_trpl.msg.buf = _pv_trpl.buf;
_pv_trpl.tmsgp = t->uac[branch].reply;
_pv_trpl.id = t->uac[branch].reply->id;
_pv_trpl.T = t;
_pv_trpl.index = t->hash_index;
_pv_trpl.label = t->label;
if(pv_t_copy_msg(t->uac[branch].reply, &_pv_trpl.msg)!=0)
{
@ -215,7 +214,8 @@ int pv_t_update_rpl(struct sip_msg *msg)
_pv_trpl.buf_size = 0;
_pv_trpl.buf = NULL;
_pv_trpl.tmsgp = NULL;
_pv_trpl.T = NULL;
_pv_trpl.index = 0;
_pv_trpl.label = 0;
return -1;
}
@ -241,8 +241,7 @@ int pv_t_update_inv(struct sip_msg *msg)
return 1;
}
if(_pv_tinv.T==t && t->uas.request==_pv_tinv.tmsgp
&& t->uas.request->id==_pv_tinv.id)
if (_pv_tinv.label == t->label && _pv_tinv.index == t->hash_index)
goto done;
/* make a copy */
@ -253,8 +252,8 @@ int pv_t_update_inv(struct sip_msg *msg)
if(_pv_tinv.tmsgp)
free_sip_msg(&_pv_tinv.msg);
_pv_tinv.tmsgp = NULL;
_pv_tinv.id = 0;
_pv_tinv.T = NULL;
_pv_tinv.index = 0;
_pv_tinv.label = 0;
_pv_tinv.buf_size = t->uas.request->len+1;
_pv_tinv.buf = (char*)pkg_malloc(_pv_tinv.buf_size*sizeof(char));
if(_pv_tinv.buf==NULL)
@ -272,8 +271,8 @@ int pv_t_update_inv(struct sip_msg *msg)
_pv_tinv.msg.len = t->uas.request->len;
_pv_tinv.msg.buf = _pv_tinv.buf;
_pv_tinv.tmsgp = t->uas.request;
_pv_tinv.id = t->uas.request->id;
_pv_tinv.T = t;
_pv_tinv.index = t->hash_index;
_pv_tinv.label = t->label;
if(pv_t_copy_msg(t->uas.request, &_pv_tinv.msg)!=0)
@ -282,7 +281,8 @@ int pv_t_update_inv(struct sip_msg *msg)
_pv_tinv.buf_size = 0;
_pv_tinv.buf = NULL;
_pv_tinv.tmsgp = NULL;
_pv_tinv.T = NULL;
_pv_tinv.index = 0;
_pv_tinv.label = 0;
goto error;
}

@ -284,13 +284,16 @@ int replace_uri( struct sip_msg *msg, str *display, str *uri,
avp_value.s.len = p - body->body.s + ((p[i]=='>') ? (i+1) : 0) ;
avp_value.s.s=body->body.s;
LM_DBG("value to store is is '%.*s' and len is '%d'\n",avp_value.s.len, avp_value.s.s,avp_value.s.len);
LM_DBG("value to store is is '%.*s' and len is '%d'\n",
avp_value.s.len, avp_value.s.s,avp_value.s.len);
if(check_from) {
LM_DBG("Storing in FROM-AVP (for use in reply): '%.*s' with len '%d'\n",avp_value.s.len, avp_value.s.s,avp_value.s.len);
LM_DBG("Storing in FROM-AVP (for use in reply): '%.*s' with len '%d'\n",
avp_value.s.len, avp_value.s.s,avp_value.s.len);
add_avp(restore_from_avp_type, restore_from_avp_name, avp_value);
} else {
LM_DBG("Storing in TO-AVP (for use in reply): '%.*s' with len '%d'\n",avp_value.s.len, avp_value.s.s,avp_value.s.len);
LM_DBG("Storing in TO-AVP (for use in reply): '%.*s' with len '%d'\n",
avp_value.s.len, avp_value.s.s,avp_value.s.len);
add_avp(restore_to_avp_type, restore_to_avp_name, avp_value);
}
}
@ -303,9 +306,10 @@ int replace_uri( struct sip_msg *msg, str *display, str *uri,
/* first remove the existing display */
if ( body->display.len)
{
LM_DBG("removing display [%.*s]\n", body->display.len,body->display.s);
LM_DBG("removing display [%.*s]\n",
body->display.len, body->display.s);
/* build del lump */
l = del_lump( msg, body->display.s-msg->buf, body->display.len, 0);
l = del_lump(msg, body->display.s-msg->buf, body->display.len, 0);
if (l==0)
{
LM_ERR("display del lump failed\n");
@ -398,10 +402,13 @@ int replace_uri( struct sip_msg *msg, str *display, str *uri,
goto error;
}
LM_DBG("Stored <%.*s> var in dialog with value %.*s\n",
dlgvar_names[0].len, dlgvar_names[0].s, body->uri.len, body->uri.s);
dlgvar_names[0].len, dlgvar_names[0].s,
body->uri.len, body->uri.s);
if (dlg_api.register_dlgcb(dlg, DLGCB_REQ_WITHIN|DLGCB_CONFIRMED|DLGCB_TERMINATED,
(void*)(unsigned long)replace_callback, (void*)(unsigned long)uac_flag, 0) != 0) {
if (dlg_api.register_dlgcb(dlg,
DLGCB_REQ_WITHIN|DLGCB_CONFIRMED|DLGCB_TERMINATED,
(void*)(unsigned long)replace_callback,
(void*)(unsigned long)uac_flag, 0) != 0) {
LM_ERR("cannot register callback\n");
dlg_api.release_dlg(dlg);
goto error;
@ -507,14 +514,15 @@ error:
* return 0 - restored
* -1 - not restored or error
*/
int restore_uri( struct sip_msg *msg, str *rr_param, str* restore_avp, int check_from)
int restore_uri( struct sip_msg *msg, str *rr_param, str* restore_avp,
int check_from)
{
struct lump* l;
str param_val;
str add_to_rr = {0, 0};
struct to_body* old_body;
str old_uri;
str new_uri;
str old_uri = {0, 0};
str new_uri = {0, 0};
char *p;
int i;
int_str avp_value;
@ -546,7 +554,8 @@ int restore_uri( struct sip_msg *msg, str *rr_param, str* restore_avp, int check
LM_ERR("no more pkg mem\n");
goto failed;
}
add_to_rr.len = sprintf(add_to_rr.s, ";%.*s=%.*s", rr_param->len,rr_param->s,param_val.len,param_val.s);
add_to_rr.len = sprintf(add_to_rr.s, ";%.*s=%.*s",
rr_param->len, rr_param->s, param_val.len, param_val.s);
if ( uac_rrb.add_rr_param(msg, &add_to_rr)!=0 ) {
LM_ERR("add rr param failed\n");
@ -555,16 +564,16 @@ int restore_uri( struct sip_msg *msg, str *rr_param, str* restore_avp, int check
pkg_free(add_to_rr.s);
add_to_rr.s = NULL;
/* dencrypt parameter ;) */
if (uac_passwd.len)
/* decrypt parameter */
if (uac_passwd.len) {
for( i=0 ; i<new_uri.len ; i++)
new_uri.s[i] ^= uac_passwd.s[i%uac_passwd.len];
}
/* check the request direction */
if (
(check_from && uac_rrb.is_direction( msg, RR_FLOW_UPSTREAM)==0) ||
(!check_from && uac_rrb.is_direction( msg,RR_FLOW_DOWNSTREAM)==0)
) {
if ( (check_from && uac_rrb.is_direction(msg, RR_FLOW_UPSTREAM)==0)
|| (!check_from && uac_rrb.is_direction(msg, RR_FLOW_DOWNSTREAM)==0)
) {
/* replace the TO URI */
if ( msg->to==0 && (parse_headers(msg,HDR_TO_F,0)!=0 || msg->to==0) ) {
LM_ERR("failed to parse TO hdr\n");
@ -592,10 +601,12 @@ int restore_uri( struct sip_msg *msg, str *rr_param, str* restore_avp, int check
avp_value.s.s=old_body->body.s;
if(flag==FL_USE_UAC_FROM) {
LM_DBG("Storing in FROM-AVP (for use in reply): '%.*s' with len '%d'\n",avp_value.s.len, avp_value.s.s,avp_value.s.len);
LM_DBG("Storing in FROM-AVP (for use in reply): '%.*s' with len '%d'\n",
avp_value.s.len, avp_value.s.s,avp_value.s.len);
add_avp(restore_from_avp_type, restore_from_avp_name, avp_value);
} else {
LM_DBG("Storing in TO-AVP (for use in reply): '%.*s' with len '%d'\n",avp_value.s.len, avp_value.s.s,avp_value.s.len);
LM_DBG("Storing in TO-AVP (for use in reply): '%.*s' with len '%d'\n",
avp_value.s.len, avp_value.s.s,avp_value.s.len);
add_avp(restore_to_avp_type, restore_to_avp_name, avp_value);
}
}
@ -620,6 +631,16 @@ int restore_uri( struct sip_msg *msg, str *rr_param, str* restore_avp, int check
goto failed;
}
/* check if new uri has valid characters */
for(i=0; i<new_uri.len; i++) {
if(!isprint(new_uri.s[i])) {
LM_WARN("invalid char found in the new uri at pos %d (%c) [%.*s]\n",
i, new_uri.s[i], new_uri.len, new_uri.s);
LM_WARN("this can happen when URI values are altered by end points"
" - skipping the update\n");
goto failed;
}
}
LM_DBG("decoded uris are: new=[%.*s] old=[%.*s]\n",
new_uri.len, new_uri.s, old_uri.len, old_uri.s);
@ -764,7 +785,8 @@ void restore_uris_reply(struct cell* t, int type, struct tmcb_params *p)
avp_value.s.len=0;
if(restore_from_avp.s) {
search_first_avp(restore_from_avp_type, restore_from_avp_name, &avp_value,0);
search_first_avp(restore_from_avp_type, restore_from_avp_name,
&avp_value,0);
}
if (restore_uri_reply( rpl, rpl->from, req->from, &avp_value.s)) {
@ -783,7 +805,8 @@ void restore_uris_reply(struct cell* t, int type, struct tmcb_params *p)
avp_value.s.len=0;
if(restore_to_avp.s) {
search_first_avp(restore_to_avp_type, restore_to_avp_name, &avp_value,0);
search_first_avp(restore_to_avp_type, restore_to_avp_name,
&avp_value, 0);
}
if (restore_uri_reply( rpl, rpl->to, req->to, &avp_value.s)) {
@ -819,8 +842,9 @@ static void replace_callback(struct dlg_cell *dlg, int type,
dlgvar_names = (uac_flag==FL_USE_UAC_FROM)?from_dlgvar:to_dlgvar;
/* check the request direction */
if ( ((uac_flag == FL_USE_UAC_TO) && _params->direction == DLG_DIR_DOWNSTREAM) ||
((uac_flag != FL_USE_UAC_TO) && _params->direction == DLG_DIR_UPSTREAM) ) {
if ( ((uac_flag == FL_USE_UAC_TO) && _params->direction == DLG_DIR_DOWNSTREAM)
|| ((uac_flag != FL_USE_UAC_TO)
&& _params->direction == DLG_DIR_UPSTREAM) ) {
/* replace the TO URI */
if ( msg->to==0 && (parse_headers(msg,HDR_TO_F,0)!=0 || msg->to==0) ) {
LM_ERR("failed to parse TO hdr\n");
@ -874,7 +898,8 @@ static void replace_callback(struct dlg_cell *dlg, int type,
goto free;
}
/* register tm callback to change replies but only if not registered earlier */
/* register tm callback to change replies,
* but only if not registered earlier */
if (!(msg->msg_flags & (FL_USE_UAC_FROM|FL_USE_UAC_TO)) &&
uac_tmb.register_tmcb( msg, 0, TMCB_RESPONSE_IN,
restore_uris_reply, 0, 0) != 1 ) {

@ -366,7 +366,10 @@ static int mod_init(void)
}
if(db_mode==WRITE_THROUGH || db_mode==WRITE_BACK) {
if(ul_db_timer_clean!=0) {
sr_wtimer_add(ul_db_clean_timer, 0, timer_interval);
if(sr_wtimer_add(ul_db_clean_timer, 0, timer_interval)<0) {
LM_ERR("failed to add db clean timer routine\n");
return -1;
}
}
}

@ -17,15 +17,15 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/*!
* \file
* \brief Kamailio utils ::
* \brief Kamailio utils ::
* \ingroup utils
* Module: \ref utils
*/
@ -49,484 +49,485 @@
xmlNodePtr get_rule_node(subs_t* subs, xmlDocPtr xcap_tree)
{
str w_uri = {0, 0};
char* id = NULL, *domain = NULL, *time_cont= NULL;
int apply_rule = -1;
xmlNodePtr ruleset_node = NULL, node1= NULL, node2= NULL;
xmlNodePtr cond_node = NULL, except_node = NULL;
xmlNodePtr identity_node = NULL;
xmlNodePtr iden_child;
xmlNodePtr validity_node, time_node;
time_t t_init, t_fin, t;
int valid= 0;
uandd_to_uri(subs->from_user, subs->from_domain, &w_uri);
if (w_uri.s == NULL) {
LM_ERR("while creating uri\n");
return NULL;
}
ruleset_node = xmlDocGetNodeByName(xcap_tree, "ruleset", NULL);
if (ruleset_node == NULL) {
LM_DBG("ruleset_node NULL\n");
goto error;
}
for (node1 = ruleset_node->children; node1; node1 = node1->next) {
if (xmlStrcasecmp(node1->name, (unsigned char*)"text") == 0)
continue;
/* process conditions */
LM_DBG("node1->name= %s\n", node1->name);
cond_node = xmlNodeGetChildByName(node1, "conditions");
if(cond_node == NULL) {
LM_DBG("cond node NULL\n");
goto error;
str w_uri = {0, 0};
char* id = NULL, *domain = NULL, *time_cont= NULL;
int apply_rule = -1;
xmlNodePtr ruleset_node = NULL, node1= NULL, node2= NULL;
xmlNodePtr cond_node = NULL, except_node = NULL;
xmlNodePtr identity_node = NULL;
xmlNodePtr iden_child;
xmlNodePtr validity_node, time_node;
time_t t_init, t_fin, t;
int valid= 0;
uandd_to_uri(subs->from_user, subs->from_domain, &w_uri);
if (w_uri.s == NULL) {
LM_ERR("while creating uri\n");
return NULL;
}
LM_DBG("cond_node->name= %s\n", cond_node->name);
validity_node = xmlNodeGetChildByName(cond_node, "validity");
if (validity_node != NULL) {
LM_DBG("found validity tag\n");
t= time(NULL);
/* search all from-until pair */
for (time_node = validity_node->children; time_node;
time_node = time_node->next) {
if (xmlStrcasecmp(time_node->name, (unsigned char*)"from")!= 0)
continue;
time_cont= (char*)xmlNodeGetContent(time_node);
t_init= xml_parse_dateTime(time_cont);
xmlFree(time_cont);
if (t_init< 0) {
LM_ERR("failed to parse xml dateTime\n");
goto error;
}
ruleset_node = xmlDocGetNodeByName(xcap_tree, "ruleset", NULL);
if (ruleset_node == NULL) {
LM_DBG("ruleset_node NULL\n");
goto error;
}
for (node1 = ruleset_node->children; node1; node1 = node1->next) {
if (xmlStrcasecmp(node1->name, (unsigned char*)"text") == 0)
continue;
if (t< t_init) {
LM_DBG("the lower time limit is not respected\n");
continue;
}
time_node= time_node->next;
while (1) {
if (time_node == NULL) {
LM_ERR("bad formatted xml doc:until child not found in"
" validity pair\n");
/* process conditions */
LM_DBG("node1->name= %s\n", node1->name);
cond_node = xmlNodeGetChildByName(node1, "conditions");
if(cond_node == NULL) {
LM_DBG("cond node NULL\n");
goto error;
}
if( xmlStrcasecmp(time_node->name,
(unsigned char*)"until")== 0)
break;
time_node= time_node->next;
}
time_cont = (char*)xmlNodeGetContent(time_node);
t_fin= xml_parse_dateTime(time_cont);
xmlFree(time_cont);
if (t_fin< 0) {
LM_ERR("failed to parse xml dateTime\n");
goto error;
}
if (t <= t_fin) {
LM_DBG("the rule is active at this time\n");
valid= 1;
}
}
if (!valid) {
LM_DBG("the rule is not active at this time\n");
continue;
}
}
identity_node = xmlNodeGetChildByName(cond_node, "identity");
if (identity_node == NULL) {
LM_ERR("didn't find identity tag\n");
goto error;
}
iden_child = xmlNodeGetChildByName(identity_node, "one");
if(iden_child) {
for (node2 = identity_node->children; node2; node2 = node2->next) {
if(xmlStrcasecmp(node2->name, (unsigned char*)"one")!= 0)
continue;
id = xmlNodeGetAttrContentByName(node2, "id");
if(id== NULL) {
LM_ERR("while extracting attribute\n");
goto error;
}
if ((strlen(id)== w_uri.len &&
(strncmp(id, w_uri.s, w_uri.len)==0))) {
apply_rule = 1;
xmlFree(id);
break;
LM_DBG("cond_node->name= %s\n", cond_node->name);
validity_node = xmlNodeGetChildByName(cond_node, "validity");
if (validity_node != NULL) {
LM_DBG("found validity tag\n");
t= time(NULL);
/* search all from-until pair */
for (time_node = validity_node->children; time_node;
time_node = time_node->next) {
if (xmlStrcasecmp(time_node->name, (unsigned char*)"from")!= 0)
continue;
time_cont= (char*)xmlNodeGetContent(time_node);
t_init= xml_parse_dateTime(time_cont);
xmlFree(time_cont);
if (t_init< 0) {
LM_ERR("failed to parse xml dateTime\n");
goto error;
}
if (t< t_init) {
LM_DBG("the lower time limit is not respected\n");
continue;
}
time_node= time_node->next;
while (1) {
if (time_node == NULL) {
LM_ERR("bad formatted xml doc:until child not found in"
" validity pair\n");
goto error;
}
if( xmlStrcasecmp(time_node->name,
(unsigned char*)"until")== 0)
break;
time_node= time_node->next;
}
time_cont = (char*)xmlNodeGetContent(time_node);
t_fin= xml_parse_dateTime(time_cont);
xmlFree(time_cont);
if (t_fin< 0) {
LM_ERR("failed to parse xml dateTime\n");
goto error;
}
if (t <= t_fin) {
LM_DBG("the rule is active at this time\n");
valid= 1;
}
}
if (!valid) {
LM_DBG("the rule is not active at this time\n");
continue;
}
}
xmlFree(id);
}
}
/* search for many node*/
iden_child = xmlNodeGetChildByName(identity_node, "many");
if (iden_child) {
domain = NULL;
for (node2 = identity_node->children; node2; node2 = node2->next) {
if (xmlStrcasecmp(node2->name, (unsigned char*)"many") != 0)
continue;
domain = xmlNodeGetAttrContentByName(node2, "domain");
if(domain == NULL) {
LM_DBG("No domain attribute to many\n");
} else {
LM_DBG("<many domain= %s>\n", domain);
if((strlen(domain)!= subs->from_domain.len &&
strncmp(domain, subs->from_domain.s,
subs->from_domain.len) )) {
xmlFree(domain);
continue;
}
identity_node = xmlNodeGetChildByName(cond_node, "identity");
if (identity_node == NULL) {
LM_ERR("didn't find identity tag\n");
goto error;
}
xmlFree(domain);
apply_rule = 1;
if (node2->children == NULL) /* there is no exception */
break;
for (except_node = node2->children; except_node;
except_node= except_node->next) {
if(xmlStrcasecmp(except_node->name,
(unsigned char*)"except"))
continue;
id = xmlNodeGetAttrContentByName(except_node, "id");
if (id != NULL) {
if((strlen(id)- 1== w_uri.len &&
(strncmp(id, w_uri.s, w_uri.len)==0))) {
xmlFree(id);
apply_rule = 0;
break;
iden_child = xmlNodeGetChildByName(identity_node, "one");
if(iden_child) {
for (node2 = identity_node->children; node2; node2 = node2->next) {
if(xmlStrcasecmp(node2->name, (unsigned char*)"one")!= 0)
continue;
id = xmlNodeGetAttrContentByName(node2, "id");
if(id== NULL) {
LM_ERR("while extracting attribute\n");
goto error;
}
if ((strlen(id)== w_uri.len &&
(strncmp(id, w_uri.s, w_uri.len)==0))) {
apply_rule = 1;
xmlFree(id);
break;
}
xmlFree(id);
}
xmlFree(id);
} else {
}
/* search for many node*/
iden_child = xmlNodeGetChildByName(identity_node, "many");
if (iden_child) {
domain = NULL;
domain = xmlNodeGetAttrContentByName(except_node,
"domain");
if(domain!=NULL) {
LM_DBG("Found except domain= %s\n- strlen(domain)= %d\n",
domain, (int)strlen(domain));
if (strlen(domain)==subs->from_domain.len &&
(strncmp(domain,subs->from_domain.s ,
subs->from_domain.len)==0)) {
LM_DBG("except domain match\n");
for (node2 = identity_node->children; node2; node2 = node2->next) {
if (xmlStrcasecmp(node2->name, (unsigned char*)"many") != 0)
continue;
domain = xmlNodeGetAttrContentByName(node2, "domain");
if(domain == NULL) {
LM_DBG("No domain attribute to many\n");
} else {
LM_DBG("<many domain= %s>\n", domain);
if((strlen(domain)!= subs->from_domain.len &&
strncmp(domain, subs->from_domain.s,
subs->from_domain.len) )) {
xmlFree(domain);
continue;
}
}
xmlFree(domain);
apply_rule = 0;
break;
}
xmlFree(domain);
}
}
apply_rule = 1;
if (node2->children == NULL) /* there is no exception */
break;
for (except_node = node2->children; except_node;
except_node= except_node->next) {
if(xmlStrcasecmp(except_node->name,
(unsigned char*)"except"))
continue;
id = xmlNodeGetAttrContentByName(except_node, "id");
if (id != NULL) {
if((strlen(id)- 1== w_uri.len &&
(strncmp(id, w_uri.s, w_uri.len)==0))) {
xmlFree(id);
apply_rule = 0;
break;
}
xmlFree(id);
} else {
domain = NULL;
domain = xmlNodeGetAttrContentByName(except_node,
"domain");
if(domain!=NULL) {
LM_DBG("Found except domain= %s\n- strlen(domain)= %d\n",
domain, (int)strlen(domain));
if (strlen(domain)==subs->from_domain.len &&
(strncmp(domain,subs->from_domain.s ,
subs->from_domain.len)==0)) {
LM_DBG("except domain match\n");
xmlFree(domain);
apply_rule = 0;
break;
}
xmlFree(domain);
}
}
}
if (apply_rule == 1) /* if a match was found no need to keep searching*/
break;
}
}
if (apply_rule == 1) /* if a match was found no need to keep searching*/
break;
}
if (apply_rule ==1)
break;
}
if (apply_rule ==1)
break;
}
LM_DBG("apply_rule= %d\n", apply_rule);
if(w_uri.s!=NULL)
pkg_free(w_uri.s);
LM_DBG("apply_rule= %d\n", apply_rule);
if(w_uri.s!=NULL)
pkg_free(w_uri.s);
if( !apply_rule || !node1)
return NULL;
return node1;
if( !apply_rule || !node1)
return NULL;
return node1;
error:
if(w_uri.s)
pkg_free(w_uri.s);
return NULL;
error:
if(w_uri.s)
pkg_free(w_uri.s);
return NULL;
}
int pres_watcher_allowed(subs_t* subs)
{
xmlDocPtr xcap_tree= NULL;
xmlNodePtr node= NULL, actions_node = NULL;
xmlNodePtr sub_handling_node = NULL;
char* sub_handling = NULL;
subs->status= PENDING_STATUS;
subs->reason.s= NULL;
subs->reason.len= 0;
if (subs->auth_rules_doc== NULL)
return 0;
xmlDocPtr xcap_tree= NULL;
xmlNodePtr node= NULL, actions_node = NULL;
xmlNodePtr sub_handling_node = NULL;
char* sub_handling = NULL;
subs->status= PENDING_STATUS;
subs->reason.s= NULL;
subs->reason.len= 0;
if (subs->auth_rules_doc== NULL)
return 0;
xcap_tree= xmlParseMemory(subs->auth_rules_doc->s,
subs->auth_rules_doc->len);
if (xcap_tree== NULL) {
LM_ERR("parsing xml memory\n");
return -1;
}
xcap_tree= xmlParseMemory(subs->auth_rules_doc->s,
subs->auth_rules_doc->len);
if (xcap_tree== NULL) {
LM_ERR("parsing xml memory\n");
return -1;
}
node= get_rule_node(subs, xcap_tree);
if (node== NULL) {
xmlFreeDoc(xcap_tree);
return 0;
}
node= get_rule_node(subs, xcap_tree);
if (node== NULL) {
xmlFreeDoc(xcap_tree);
return 0;
/* process actions */
actions_node = xmlNodeGetChildByName(node, "actions");
if (actions_node == NULL) {
LM_DBG("actions_node NULL\n");
xmlFreeDoc(xcap_tree);
return 0;
}
LM_DBG("actions_node->name= %s\n", actions_node->name);
/* process actions */
actions_node = xmlNodeGetChildByName(node, "actions");
if (actions_node == NULL) {
LM_DBG("actions_node NULL\n");
xmlFreeDoc(xcap_tree);
return 0;
}
LM_DBG("actions_node->name= %s\n", actions_node->name);
sub_handling_node = xmlNodeGetChildByName(actions_node, "sub-handling");
if (sub_handling_node== NULL) {
LM_DBG("sub_handling_node NULL\n");
xmlFreeDoc(xcap_tree);
return 0;
}
sub_handling = (char*)xmlNodeGetContent(sub_handling_node);
LM_DBG("sub_handling_node->name= %s\n", sub_handling_node->name);
LM_DBG("sub_handling_node->content= %s\n", sub_handling);
if (sub_handling == NULL) {
LM_ERR("Couldn't get sub-handling content\n");
xmlFreeDoc(xcap_tree);
return -1;
}
if (strncmp((char*)sub_handling, "block", 5) == 0) {
subs->status = TERMINATED_STATUS;;
subs->reason.s= "rejected";
subs->reason.len = 8;
} else
if (strncmp((char*)sub_handling, "confirm", 7) == 0) {
subs->status = PENDING_STATUS;
} else
if (strncmp((char*)sub_handling , "polite-block", 12) == 0) {
subs->status = ACTIVE_STATUS;
subs->reason.s= "polite-block";
subs->reason.len = 12;
}
else
if (strncmp((char*)sub_handling, "allow", 5) == 0) {
subs->status = ACTIVE_STATUS;
subs->reason.s = NULL;
}
else {
LM_ERR("unknown subscription handling action\n");
sub_handling_node = xmlNodeGetChildByName(actions_node, "sub-handling");
if (sub_handling_node== NULL) {
LM_DBG("sub_handling_node NULL\n");
xmlFreeDoc(xcap_tree);
return 0;
}
sub_handling = (char*)xmlNodeGetContent(sub_handling_node);
LM_DBG("sub_handling_node->name= %s\n", sub_handling_node->name);
LM_DBG("sub_handling_node->content= %s\n", sub_handling);
if (sub_handling == NULL) {
LM_ERR("Couldn't get sub-handling content\n");
xmlFreeDoc(xcap_tree);
xmlFree(sub_handling);
return -1;
}
}
if (strncmp((char*)sub_handling, "block", 5) == 0) {
subs->status = TERMINATED_STATUS;
subs->reason.s= "rejected";
subs->reason.len = 8;
} else {
if (strncmp((char*)sub_handling, "confirm", 7) == 0) {
subs->status = PENDING_STATUS;
} else {
if (strncmp((char*)sub_handling , "polite-block", 12) == 0) {
subs->status = ACTIVE_STATUS;
subs->reason.s= "polite-block";
subs->reason.len = 12;
} else {
if (strncmp((char*)sub_handling, "allow", 5) == 0) {
subs->status = ACTIVE_STATUS;
subs->reason.s = NULL;
} else {
LM_ERR("unknown subscription handling action\n");
xmlFreeDoc(xcap_tree);
xmlFree(sub_handling);
return -1;
}
}
}
}
xmlFreeDoc(xcap_tree);
xmlFree(sub_handling);
xmlFree(sub_handling);
return 0;
return 0;
}
int get_rules_doc(str* user, str* domain, int type, str** rules_doc)
{
db_key_t query_cols[5];
db_val_t query_vals[5];
db_key_t result_cols[3];
int n_query_cols = 0;
db1_res_t *result = 0;
db_row_t *row;
db_val_t *row_vals;
str body;
str* doc= NULL;
int n_result_cols= 0, xcap_doc_col;
static str tmp1 = str_init("username");
static str tmp2 = str_init("domain");
static str tmp3 = str_init("doc_type");
static str tmp4 = str_init("doc");
LM_DBG("[user]= %.*s\t[domain]= %.*s",
user->len, user->s, domain->len, domain->s);
query_cols[n_query_cols] = &tmp1;
query_vals[n_query_cols].type = DB1_STR;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.str_val = *user;
n_query_cols++;
query_cols[n_query_cols] = &tmp2;
query_vals[n_query_cols].type = DB1_STR;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.str_val = *domain;
n_query_cols++;
query_cols[n_query_cols] = &tmp3;
query_vals[n_query_cols].type = DB1_INT;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.int_val= type;
n_query_cols++;
result_cols[xcap_doc_col= n_result_cols++] = &tmp4;
if (pres_dbf.query(pres_dbh, query_cols, 0 , query_vals, result_cols,
n_query_cols, 1, 0, &result) < 0) {
LM_ERR("while querying table xcap for [user]=%.*s\t[domain]= %.*s\n",
user->len, user->s, domain->len, domain->s);
if (result)
pres_dbf.free_result(pres_dbh, result);
return -1;
}
db_key_t query_cols[5];
db_val_t query_vals[5];
db_key_t result_cols[3];
int n_query_cols = 0;
db1_res_t *result = 0;
db_row_t *row;
db_val_t *row_vals;
str body;
str* doc= NULL;
int n_result_cols= 0, xcap_doc_col;
static str tmp1 = str_init("username");
static str tmp2 = str_init("domain");
static str tmp3 = str_init("doc_type");
static str tmp4 = str_init("doc");
LM_DBG("[user]= %.*s\t[domain]= %.*s",
user->len, user->s, domain->len, domain->s);
query_cols[n_query_cols] = &tmp1;
query_vals[n_query_cols].type = DB1_STR;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.str_val = *user;
n_query_cols++;
query_cols[n_query_cols] = &tmp2;
query_vals[n_query_cols].type = DB1_STR;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.str_val = *domain;
n_query_cols++;
query_cols[n_query_cols] = &tmp3;
query_vals[n_query_cols].type = DB1_INT;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.int_val= type;
n_query_cols++;
result_cols[xcap_doc_col= n_result_cols++] = &tmp4;
if (pres_dbf.query(pres_dbh, query_cols, 0 , query_vals, result_cols,
n_query_cols, 1, 0, &result) < 0) {
LM_ERR("while querying table xcap for [user]=%.*s\t[domain]= %.*s\n",
user->len, user->s, domain->len, domain->s);
if (result)
pres_dbf.free_result(pres_dbh, result);
return -1;
}
if(result == NULL)
return -1;
if(result == NULL)
return -1;
if (result->n <= 0) {
LM_DBG("No document found in db table for [user]=%.*s"
"\t[domain]= %.*s\t[doc_type]= %d\n",user->len, user->s,
domain->len, domain->s, type);
pres_dbf.free_result(pres_dbh, result);
return 0;
}
row = &result->rows[xcap_doc_col];
row_vals = ROW_VALUES(row);
body.s = (char*)row_vals[0].val.string_val;
if (body.s== NULL) {
LM_ERR("Xcap doc NULL\n");
goto error;
}
body.len = strlen(body.s);
if (body.len== 0) {
LM_ERR("Xcap doc empty\n");
goto error;
}
LM_DBG("xcap document:\n%.*s", body.len,body.s);
doc= (str*)pkg_malloc(sizeof(str));
if (doc== NULL) {
ERR_MEM(PKG_MEM_STR);
}
doc->s= (char*)pkg_malloc(body.len* sizeof(char));
if (doc->s== NULL) {
pkg_free(doc);
ERR_MEM(PKG_MEM_STR);
}
memcpy(doc->s, body.s, body.len);
doc->len= body.len;
*rules_doc= doc;
if (result)
pres_dbf.free_result(pres_dbh, result);
if (result->n <= 0) {
LM_DBG("No document found in db table for [user]=%.*s"
"\t[domain]= %.*s\t[doc_type]= %d\n",user->len, user->s,
domain->len, domain->s, type);
pres_dbf.free_result(pres_dbh, result);
return 0;
}
row = &result->rows[xcap_doc_col];
row_vals = ROW_VALUES(row);
body.s = (char*)row_vals[0].val.string_val;
if (body.s== NULL) {
LM_ERR("Xcap doc NULL\n");
goto error;
}
body.len = strlen(body.s);
if (body.len== 0) {
LM_ERR("Xcap doc empty\n");
goto error;
}
LM_DBG("xcap document:\n%.*s", body.len,body.s);
doc= (str*)pkg_malloc(sizeof(str));
if (doc== NULL) {
ERR_MEM(PKG_MEM_STR);
}
doc->s= (char*)pkg_malloc(body.len* sizeof(char));
if (doc->s== NULL) {
pkg_free(doc);
ERR_MEM(PKG_MEM_STR);
}
memcpy(doc->s, body.s, body.len);
doc->len= body.len;
*rules_doc= doc;
if (result)
pres_dbf.free_result(pres_dbh, result);
return 0;
error:
if (result)
pres_dbf.free_result(pres_dbh, result);
if (result)
pres_dbf.free_result(pres_dbh, result);
return -1;
return -1;
}
/*
/*
* Checks from presence server xcap table if watcher is authorized
* to subscribe event 'presence' of presentity.
*/
int xcap_auth_status(struct sip_msg* _msg, char* _sp1, char* _sp2)
{
pv_spec_t *sp;
pv_value_t pv_val;
str watcher_uri, presentity_uri;
struct sip_uri uri;
str* rules_doc = NULL;
subs_t subs;
int res;
if (pres_dbh == 0) {
LM_ERR("function is disabled, to enable define pres_db_url\n");
return -1;
}
pv_spec_t *sp;
pv_value_t pv_val;
str watcher_uri, presentity_uri;
struct sip_uri uri;
str* rules_doc = NULL;
subs_t subs;
int res;
if (pres_dbh == 0) {
LM_ERR("function is disabled, to enable define pres_db_url\n");
return -1;
}
sp = (pv_spec_t *)_sp1;
sp = (pv_spec_t *)_sp1;
if (sp && (pv_get_spec_value(_msg, sp, &pv_val) == 0)) {
if (pv_val.flags & PV_VAL_STR) {
watcher_uri = pv_val.rs;
if (watcher_uri.len == 0 || watcher_uri.s == NULL) {
LM_ERR("missing watcher uri\n");
return -1;
}
if (sp && (pv_get_spec_value(_msg, sp, &pv_val) == 0)) {
if (pv_val.flags & PV_VAL_STR) {
watcher_uri = pv_val.rs;
if (watcher_uri.len == 0 || watcher_uri.s == NULL) {
LM_ERR("missing watcher uri\n");
return -1;
}
} else {
LM_ERR("watcher pseudo variable value is not string\n");
return -1;
}
} else {
LM_ERR("watcher pseudo variable value is not string\n");
return -1;
LM_ERR("cannot get watcher pseudo variable value\n");
return -1;
}
} else {
LM_ERR("cannot get watcher pseudo variable value\n");
return -1;
}
sp = (pv_spec_t *)_sp2;
sp = (pv_spec_t *)_sp2;
if (sp && (pv_get_spec_value(_msg, sp, &pv_val) == 0)) {
if (pv_val.flags & PV_VAL_STR) {
presentity_uri = pv_val.rs;
if (presentity_uri.len == 0 || presentity_uri.s == NULL) {
LM_DBG("missing presentity uri\n");
return -1;
}
if (sp && (pv_get_spec_value(_msg, sp, &pv_val) == 0)) {
if (pv_val.flags & PV_VAL_STR) {
presentity_uri = pv_val.rs;
if (presentity_uri.len == 0 || presentity_uri.s == NULL) {
LM_DBG("missing presentity uri\n");
return -1;
}
} else {
LM_ERR("presentity pseudo variable value is not string\n");
return -1;
}
} else {
LM_ERR("presentity pseudo variable value is not string\n");
return -1;
LM_ERR("cannot get presentity pseudo variable value\n");
return -1;
}
} else {
LM_ERR("cannot get presentity pseudo variable value\n");
return -1;
}
if (parse_uri(presentity_uri.s, presentity_uri.len, &uri) < 0) {
LM_ERR("failed to parse presentity uri\n");
if (parse_uri(presentity_uri.s, presentity_uri.len, &uri) < 0) {
LM_ERR("failed to parse presentity uri\n");
return -1;
}
res = get_rules_doc(&uri.user, &uri.host, PRES_RULES, &rules_doc);
if ((res < 0) || (rules_doc == NULL) || (rules_doc->s == NULL)) {
LM_DBG("no xcap rules doc found for presentity uri\n");
return PENDING_STATUS;
}
if (parse_uri(watcher_uri.s, watcher_uri.len, &uri) < 0) {
LM_ERR("failed to parse watcher uri\n");
goto err;
}
subs.from_user = uri.user;
subs.from_domain = uri.host;
subs.pres_uri = presentity_uri;
subs.auth_rules_doc = rules_doc;
if (pres_watcher_allowed(&subs) < 0) {
LM_ERR("getting status from rules document\n");
goto err;
}
LM_DBG("auth status of watcher <%.*s> on presentity <%.*s> is %d\n",
watcher_uri.len, watcher_uri.s, presentity_uri.len, presentity_uri.s,
subs.status);
pkg_free(rules_doc->s);
pkg_free(rules_doc);
return subs.status;
err:
pkg_free(rules_doc->s);
pkg_free(rules_doc);
return -1;
}
res = get_rules_doc(&uri.user, &uri.host, PRES_RULES, &rules_doc);
if ((res < 0) || (rules_doc == NULL) || (rules_doc->s == NULL)) {
LM_DBG("no xcap rules doc found for presentity uri\n");
return PENDING_STATUS;
}
if (parse_uri(watcher_uri.s, watcher_uri.len, &uri) < 0) {
LM_ERR("failed to parse watcher uri\n");
goto err;
}
subs.from_user = uri.user;
subs.from_domain = uri.host;
subs.pres_uri = presentity_uri;
subs.auth_rules_doc = rules_doc;
if (pres_watcher_allowed(&subs) < 0) {
LM_ERR("getting status from rules document\n");
goto err;
}
LM_DBG("auth status of watcher <%.*s> on presentity <%.*s> is %d\n",
watcher_uri.len, watcher_uri.s, presentity_uri.len, presentity_uri.s,
subs.status);
pkg_free(rules_doc->s);
pkg_free(rules_doc);
return subs.status;
err:
pkg_free(rules_doc->s);
pkg_free(rules_doc);
return -1;
}

@ -136,6 +136,8 @@ static str str_status_error_closing = str_init("Error closing connection");
static str str_status_error_sending = str_init("Error sending frame");
static str str_status_string_error = str_init("Error converting string to int");
static int ws_send_crlf(ws_connection_t *wsc, int opcode);
static int encode_and_send_ws_frame(ws_frame_t *frame, conn_close_t conn_close)
{
int pos = 0, extended_length;
@ -680,10 +682,19 @@ int ws_frame_receive(void *data)
case OPCODE_BINARY_FRAME:
if (likely(frame.wsc->sub_protocol == SUB_PROTOCOL_SIP))
{
LM_DBG("Rx SIP message:\n%.*s\n", frame.payload_len,
LM_DBG("Rx SIP (or text) message:\n%.*s\n", frame.payload_len,
frame.payload_data);
update_stat(ws_sip_received_frames, 1);
if((frame.payload_len==CRLF_LEN
&& strncmp(frame.payload_data, CRLF, CRLF_LEN)==0)
|| (frame.payload_len==CRLFCRLF_LEN
&& strncmp(frame.payload_data, CRLFCRLF, CRLFCRLF_LEN)==0))
{
ws_send_crlf(frame.wsc, opcode);
wsconn_put(frame.wsc);
return 0;
}
if (frame.fin)
{
@ -788,7 +799,7 @@ int ws_frame_transmit(void *data)
frame.payload_data);
if (encode_and_send_ws_frame(&frame, CONN_CLOSE_DONT) < 0)
{
{
LM_ERR("sending message\n");
wsconn_put(frame.wsc);
@ -813,7 +824,7 @@ static int ping_pong(ws_connection_t *wsc, int opcode)
frame.wsc = wsc;
if (encode_and_send_ws_frame(&frame, CONN_CLOSE_DONT) < 0)
{
{
LM_ERR("sending keepalive\n");
return -1;
}
@ -824,6 +835,25 @@ static int ping_pong(ws_connection_t *wsc, int opcode)
return 0;
}
static int ws_send_crlf(ws_connection_t *wsc, int opcode)
{
ws_frame_t frame;
memset(&frame, 0, sizeof(frame));
frame.fin = 1;
frame.opcode = opcode;
frame.payload_len = CRLF_LEN;
frame.payload_data = CRLF;
frame.wsc = wsc;
if (encode_and_send_ws_frame(&frame, CONN_CLOSE_DONT) < 0) {
LM_ERR("failed sending CRLF\n");
return -1;
}
return 0;
}
struct mi_root *ws_mi_close(struct mi_root *cmd, void *param)
{
unsigned int id;

@ -451,7 +451,7 @@ int xmpp_server_child_process(int data_pipe)
int listen_fd;
fd_set fdset;
struct xmpp_connection *conn;
snprintf(local_secret, sizeof(local_secret), "%s", random_secret());
while ((listen_fd = net_listen(xmpp_domain, xmpp_port)) < 0) {
@ -463,13 +463,17 @@ int xmpp_server_child_process(int data_pipe)
FD_ZERO(&fdset);
FD_SET(data_pipe, &fdset);
FD_SET(listen_fd, &fdset);
/* check for dead connections */
for (conn = conn_list; conn; ) {
struct xmpp_connection *next = conn->next;
if (conn->type == CONN_DEAD)
if (conn->type == CONN_DEAD) {
if(conn == conn_list) {
conn_list = next;
}
conn_free(conn);
}
conn = next;
}
@ -488,7 +492,7 @@ int xmpp_server_child_process(int data_pipe)
} else {
conn->type = CONN_DEAD;
}
}
}
if (conn->fd != -1)
FD_SET(conn->fd, &fdset);

@ -400,7 +400,7 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
char* clen_builder( struct sip_msg* msg, int *clen_len, int diff,
char* clen_builder( struct sip_msg* msg, int *clen_len, int diff,
int body_only)
{
char* buf;
@ -414,7 +414,8 @@ char* clen_builder( struct sip_msg* msg, int *clen_len, int diff,
body=get_body(msg);
if (body==0){
ser_error=E_BAD_REQ;
LM_ERR("no message body found (missing crlf?)");
LM_ERR("no message body found (missing crlf?) [[%.*s]]\n",
msg->len, msg->buf);
return 0;
}
value=msg->len-(int)(body-msg->buf)+diff;

@ -1094,3 +1094,50 @@ int get_src_uri(sip_msg_t *m, int tmode, str *uri)
return 0;
}
/*! \brief returns a pointer to the begining of the msg's body
*/
char* get_body(sip_msg_t* const msg)
{
int offset;
unsigned int len;
if ( parse_headers(msg, HDR_EOH_F, 0)==-1 ) {
LM_ERR("failed to parse to end of headers\n");
return 0;
}
if (msg->unparsed) {
len=(unsigned int)(msg->unparsed-msg->buf);
} else {
LM_ERR("unparsed hook for end of headers is not set\n");
return 0;
}
if ((len+2<=msg->len) && (strncmp(CRLF,msg->unparsed,CRLF_LEN)==0) ) {
offset = CRLF_LEN;
} else if ( (len+1<=msg->len) &&
(*(msg->unparsed)=='\n' || *(msg->unparsed)=='\r' ) ) {
offset = 1;
} else {
LM_ERR("failed to locate end of headers (%p %p - %d %d [%s])\n",
msg->buf, msg->unparsed, msg->len, len, msg->unparsed);
return 0;
}
return msg->unparsed + offset;
}
/*! \brief make sure all HFs needed for transaction identification have been
* parsed; return 0 if those HFs can't be found
*/
int check_transaction_quadruple(sip_msg_t* const msg)
{
if ( parse_headers(msg, HDR_FROM_F|HDR_TO_F|HDR_CALLID_F|HDR_CSEQ_F,0)!=-1
&& msg->from && msg->to && msg->callid && msg->cseq ) {
return 1;
} else {
ser_error=E_BAD_TUPEL;
return 0;
}
}

@ -19,7 +19,7 @@
*
*/
/*! \file
/*! \file
* \brief Parser :: ???
*
* \ingroup parser
@ -83,9 +83,9 @@ typedef enum request_method {
#define FL_SDP_PORT_AFS (1 << 3) /*!< SDP port rewritten */
#define FL_SHM_CLONE (1 << 4) /*!< msg cloned in SHM as a single chunk */
#define FL_TIMEOUT (1 << 5) /*!< message belongs to an "expired" branch
(for failure route use) */
(for failure route use) */
#define FL_REPLIED (1 << 6) /*!< message branch received at least one reply
(for failure route use) */
(for failure route use) */
#define FL_HASH_INDEX (1 << 7) /*!< msg->hash_index contains a valid value (tm use)*/
#define FL_MTU_TCP_FB (1 << 8)
@ -118,32 +118,32 @@ typedef enum request_method {
#define IFISMETHOD(methodname,firstchar) \
if ( (*tmp==(firstchar) || *tmp==((firstchar) | 32)) && \
strncasecmp( tmp+1, #methodname +1, methodname##_LEN-1)==0 && \
*(tmp+methodname##_LEN)==' ') { \
fl->type=SIP_REQUEST; \
fl->u.request.method.len=methodname##_LEN; \
fl->u.request.method_value=METHOD_##methodname; \
tmp=buffer+methodname##_LEN; \
strncasecmp( tmp+1, #methodname +1, methodname##_LEN-1)==0 && \
*(tmp+methodname##_LEN)==' ') { \
fl->type=SIP_REQUEST; \
fl->u.request.method.len=methodname##_LEN; \
fl->u.request.method_value=METHOD_##methodname; \
tmp=buffer+methodname##_LEN; \
}
#define IS_HTTP(req) \
((req)->first_line.u.request.version.len >= HTTP_VERSION_LEN && \
!strncasecmp((req)->first_line.u.request.version.s, \
((req)->first_line.u.request.version.len >= HTTP_VERSION_LEN && \
!strncasecmp((req)->first_line.u.request.version.s, \
HTTP_VERSION, HTTP_VERSION_LEN))
#define IS_SIP(req) \
((req)->first_line.u.request.version.len >= SIP_VERSION_LEN && \
!strncasecmp((req)->first_line.u.request.version.s, \
((req)->first_line.u.request.version.len >= SIP_VERSION_LEN && \
!strncasecmp((req)->first_line.u.request.version.s, \
SIP_VERSION, SIP_VERSION_LEN))
#define IS_HTTP_REPLY(rpl) \
((rpl)->first_line.u.reply.version.len >= HTTP_VERSION_LEN && \
!strncasecmp((rpl)->first_line.u.reply.version.s, \
((rpl)->first_line.u.reply.version.len >= HTTP_VERSION_LEN && \
!strncasecmp((rpl)->first_line.u.reply.version.s, \
HTTP_VERSION, HTTP_VERSION_LEN))
#define IS_SIP_REPLY(rpl) \
((rpl)->first_line.u.reply.version.len >= SIP_VERSION_LEN && \
!strncasecmp((rpl)->first_line.u.reply.version.s, \
((rpl)->first_line.u.reply.version.len >= SIP_VERSION_LEN && \
!strncasecmp((rpl)->first_line.u.reply.version.s, \
SIP_VERSION, SIP_VERSION_LEN))
/*! \brief
@ -184,10 +184,10 @@ struct sip_uri {
str port; /*!< Port number */
str params; /*!< Parameters */
str sip_params; /*!< Parameters of the sip: URI.
* (If a tel: URI is embedded in a sip: URI, then
* params points to the parameters of the tel: URI,
* and sip_params to the parameters of the sip: URI.
*/
* (If a tel: URI is embedded in a sip: URI, then
* params points to the parameters of the tel: URI,
* and sip_params to the parameters of the sip: URI.
*/
str headers;
unsigned short port_no;
unsigned short proto; /*!< from transport */
@ -228,10 +228,10 @@ typedef enum msg_body_type {
/*! \brief This structure represents a generic SIP message body, regardless of the
* body type.
*
*
* Body parsers are supposed to cast this structure to some other
* body-type specific structure, but the body type specific structure must
* retain msg_body_type variable and a pointer to the free function as the
* retain msg_body_type variable and a pointer to the free function as the
* first two variables within the structure.
*/
typedef struct msg_body {
@ -270,10 +270,10 @@ typedef struct sip_msg {
struct hdr_field* last_header; /*!< Pointer to the last parsed header*/
hdr_flags_t parsed_flag; /*!< Already parsed header field types */
/* Via, To, CSeq, Call-Id, From, end of header*/
/* pointers to the first occurrences of these headers;
* everything is also saved in 'headers'
* (WARNING: do not deallocate them twice!)*/
/* Via, To, CSeq, Call-Id, From, end of header*/
/* pointers to the first occurrences of these headers;
* everything is also saved in 'headers'
* (WARNING: do not deallocate them twice!)*/
struct hdr_field* h_via1;
struct hdr_field* h_via2;
@ -327,22 +327,22 @@ typedef struct sip_msg {
struct receive_info rcv; /*!< source & dest ip, ports, proto a.s.o*/
char* buf; /*!< scratch pad, holds a modified message,
* via, etc. point into it */
* via, etc. point into it */
unsigned int len; /*!< message len (orig) */
/* modifications */
/* modifications */
str new_uri; /*!< changed first line uri, when you change this
don't forget to set parsed_uri_ok to 0*/
don't forget to set parsed_uri_ok to 0*/
str dst_uri; /*!< Destination URI, must be forwarded to this URI if len != 0 */
/* current uri */
int parsed_uri_ok; /*!< 1 if parsed_uri is valid, 0 if not, set if to 0
if you modify the uri (e.g change new_uri)*/
if you modify the uri (e.g change new_uri)*/
struct sip_uri parsed_uri; /*!< speed-up > keep here the parsed uri*/
int parsed_orig_ruri_ok; /*!< 1 if parsed_orig_uri is valid, 0 if not, set if to 0
if you modify the uri (e.g change new_uri)*/
if you modify the uri (e.g change new_uri)*/
struct sip_uri parsed_orig_ruri; /*!< speed-up > keep here the parsed orig uri*/
struct lump* add_rm; /*!< used for all the forwarded requests/replies */
@ -350,11 +350,12 @@ typedef struct sip_msg {
struct lump_rpl *reply_lump; /*!< only for localy generated replies !!!*/
/*! \brief str add_to_branch;
whatever whoever want to append to Via branch comes here */
whatever whoever want to append to Via branch comes here */
char add_to_branch_s[MAX_BRANCH_PARAM_LEN];
int add_to_branch_len;
unsigned int hash_index; /*!< index to TM hash table; stored in core to avoid unnecessary calculations */
unsigned int hash_index; /*!< index to TM hash table; stored in core
to avoid unnecessary calculations */
unsigned int msg_flags; /*!< internal flags used by core */
flag_t flags; /*!< config flags */
str set_global_address;
@ -378,8 +379,8 @@ typedef struct sip_msg {
} sip_msg_t;
/*! \brief pointer to a fakes message which was never received ;
(when this message is "relayed", it is generated out
of the original request)
(when this message is "relayed", it is generated out
of the original request)
*/
#define FAKED_REPLY ((struct sip_msg *) -1)
@ -401,44 +402,13 @@ char* get_hdr_field(char* const buf, char* const end, struct hdr_field* const hd
void free_sip_msg(struct sip_msg* const msg);
/*! \brief make sure all HFs needed for transaction identification have been
parsed; return 0 if those HFs can't be found
parsed; return 0 if those HFs can't be found
*/
inline static int check_transaction_quadruple(struct sip_msg* const msg)
{
if ( parse_headers(msg, HDR_FROM_F|HDR_TO_F|HDR_CALLID_F|HDR_CSEQ_F,0)!=-1
&& msg->from && msg->to && msg->callid && msg->cseq ) {
return 1;
} else {
ser_error=E_BAD_TUPEL;
return 0;
}
}
int check_transaction_quadruple(sip_msg_t* const msg);
/*! \brief returns a pointer to the begining of the msg's body
*/
inline static char* get_body(struct sip_msg* const msg)
{
int offset;
unsigned int len;
if ( parse_headers(msg, HDR_EOH_F, 0)==-1 )
return 0;
if (msg->unparsed){
len=(unsigned int)(msg->unparsed-msg->buf);
}else return 0;
if ((len+2<=msg->len) && (strncmp(CRLF,msg->unparsed,CRLF_LEN)==0) )
offset = CRLF_LEN;
else if ( (len+1<=msg->len) &&
(*(msg->unparsed)=='\n' || *(msg->unparsed)=='\r' ) )
offset = 1;
else
return 0;
return msg->unparsed + offset;
}
char* get_body(sip_msg_t* const msg);
/*! \brief If the new_uri is set, then reset it */
void reset_new_uri(struct sip_msg* const msg);
@ -454,7 +424,8 @@ void reset_dst_uri(struct sip_msg* const msg);
hdr_field_t* get_hdr(const sip_msg_t* const msg, const enum _hdr_types_t ht);
hdr_field_t* next_sibling_hdr(const hdr_field_t* const hf);
/** not used yet */
hdr_field_t* get_hdr_by_name(const sip_msg_t* const msg, const char* const name, const int name_len);
hdr_field_t* get_hdr_by_name(const sip_msg_t* const msg, const char* const name,
const int name_len);
hdr_field_t* next_sibling_hdr_by_name(const hdr_field_t* const hf);
int set_path_vector(struct sip_msg* msg, str* path);
@ -501,7 +472,7 @@ typedef struct msg_ctx_id {
/**
* set msg context id
* - return: -1 on error; 0 - on set
* - return: -1 on error; 0 - on set
*/
int msg_ctx_id_set(const sip_msg_t* const msg, msg_ctx_id_t* const mid);

@ -13,8 +13,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
@ -140,8 +140,7 @@ static char* parse_to_param(char* const buffer, const char* const end,
status=saved_status;
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to_param : "
"unexpected char [%c] in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -177,8 +176,7 @@ static char* parse_to_param(char* const buffer, const char* const end,
status=saved_status;
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to_param : "
"unexpected char [%c] in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -206,8 +204,7 @@ static char* parse_to_param(char* const buffer, const char* const end,
goto endofheader;
break;
default:
LOG( L_ERR , "ERROR: parse_to_param : "
"unexpected char [%c] in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -225,8 +222,7 @@ static char* parse_to_param(char* const buffer, const char* const end,
tmp++;
}
default:
LOG( L_ERR , "ERROR: parse_to_param : "
"unexpected char [%c] in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -249,8 +245,7 @@ static char* parse_to_param(char* const buffer, const char* const end,
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to_param :"
"unexpected char [%c] in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status,(int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -280,8 +275,7 @@ semicolon_add_param:
param = (struct to_param*)
pkg_malloc(sizeof(struct to_param));
if (!param){
LOG( L_ERR , "ERROR: parse_to_param"
" - out of memory\n" );
LM_ERR("out of memory\n");
goto error;
}
memset(param,0,sizeof(struct to_param));
@ -296,8 +290,7 @@ semicolon_add_param:
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to_param :"
"unexpected char [%c] in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -329,8 +322,7 @@ semicolon_add_param:
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to_param :"
"unexpected char [%c] in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -364,8 +356,7 @@ semicolon_add_param:
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to_param : "
"unexpected char [%c] in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -399,8 +390,7 @@ semicolon_add_param:
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to_param : "
"unexpected char [%c] in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -427,8 +417,7 @@ semicolon_add_param:
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to_param : "
"unexpected char [%c] in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -470,8 +459,7 @@ semicolon_add_param:
status=saved_status;
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to_param : "
"unexpected char [%c] in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -483,8 +471,7 @@ semicolon_add_param:
* - some user agents use it */
break;
}
LOG( L_ERR, "ERROR parse_to_param : "
"invalid character ',' in status %d: <<%.*s>>\n",
LM_ERR("invalid character ',' in status %d: [%.*s]\n",
status, (int)(tmp-buffer), ZSW(buffer));
}
default:
@ -513,8 +500,7 @@ semicolon_add_param:
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG(L_ERR, "ERROR: parse_to_param: "
"spitting out [%c] in status %d\n",*tmp,status );
LM_ERR("spitting out [%c] in status %d\n",*tmp,status);
goto error;
}
}/*switch*/
@ -560,8 +546,7 @@ endofheader:
case E_PARA_VALUE:
break;
default:
LOG( L_ERR , "ERROR: parse_to_param : unexpected end of header,"
" status %d: <<%.*s>> .\n",
LM_ERR("unexpected end of header, status %d: [%.*s] .\n",
saved_status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -577,12 +562,13 @@ error:
char* parse_addr_spec(char* const buffer, const char* const end, struct to_body* const to_b, const int allow_comma_sep)
char* parse_addr_spec(char* const buffer, const char* const end,
struct to_body* const to_b, const int allow_comma_sep)
{
int status;
int saved_status;
char *tmp,*foo;
saved_status=START_TO; /* fixes gcc 4.x warning */
status=START_TO;
memset(to_b, 0, sizeof(struct to_body));
@ -643,8 +629,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, struct to_body*
status=saved_status;
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
"in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -673,8 +658,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, struct to_body*
status=saved_status;
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
"in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -689,8 +673,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, struct to_body*
saved_status = status = END;
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
"in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -702,8 +685,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, struct to_body*
tmp++; /* jump over next char */
break;
default:
LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
"in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -736,8 +718,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, struct to_body*
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
"in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -759,8 +740,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, struct to_body*
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
"in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), ZSW(buffer));
goto error;
}
@ -783,8 +763,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, struct to_body*
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
"in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), buffer);
goto error;
}
@ -809,8 +788,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, struct to_body*
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
"in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), buffer);
goto error;
}
@ -837,8 +815,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, struct to_body*
/*previous=crlf and now !=' '*/
goto endofheader;
default:
LOG( L_ERR , "ERROR: parse_to : unexpected char [%c] "
"in status %d: <<%.*s>> .\n",
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
*tmp,status, (int)(tmp-buffer), buffer);
goto error;
}
@ -871,7 +848,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, struct to_body*
/*previous=crlf and now !=' '*/
goto endofheader;
default:
DBG("DEBUG:parse_to: spitting out [%c] in status %d\n",
LM_DBG("spitting out [%c] in status %d\n",
*tmp,status );
goto error;
}
@ -891,7 +868,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, struct to_body*
endofheader:
if (to_b->display.len==0) to_b->display.s=0;
status=saved_status;
DBG("end of header reached, state=%d\n", status);
LM_DBG("end of header reached, state=%d\n", status);
/* check if error*/
switch(status){
case URI_OR_TOKEN:
@ -902,7 +879,7 @@ endofheader:
case E_PARA_VALUE:
break;
default:
LOG(L_ERR, "ERROR: parse_to: invalid To - unexpected "
LM_ERR("invalid To - unexpected "
"end of header in state %d\n", status);
goto error;
}

@ -13,20 +13,21 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* You should have received a copy of the GNU General Public License
*
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*! \file
* \brief Parser :: Diversion header
*
*
* \ingroup parser
*/
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include "../dprint.h"
#include "../ut.h"
#include "../mem/mem.h"
@ -40,41 +41,49 @@
* params: msg : sip msg
* returns 0 on success,
* -1 on failure.
*
* limitations: it parses only the first occurence
*/
int parse_diversion_header(struct sip_msg *msg)
{
struct to_body* diversion_b;
if (!msg->diversion && (parse_headers(msg, HDR_DIVERSION_F, 0) == -1 ||
!msg->diversion)) {
goto error;
}
/* maybe the header is already parsed! */
if (msg->diversion->parsed)
return 0;
/* bad luck! :-( - we have to parse it */
/* first, get some memory */
diversion_b = pkg_malloc(sizeof(struct to_body));
if (diversion_b == 0) {
LOG(L_ERR, "ERROR:parse_diversion_header: out of pkg_memory\n");
goto error;
}
/* now parse it!! */
memset(diversion_b, 0, sizeof(struct to_body));
parse_to(msg->diversion->body.s, msg->diversion->body.s + msg->diversion->body.len + 1, diversion_b);
if (diversion_b->error == PARSE_ERROR) {
LOG(L_ERR, "ERROR:parse_diversion_header: bad diversion header\n");
free_to(diversion_b);
goto error;
}
msg->diversion->parsed = diversion_b;
return 0;
error:
return -1;
struct to_body* diversion_b;
if (!msg->diversion && (parse_headers(msg, HDR_DIVERSION_F, 0) == -1)) {
goto error;
}
if (!msg->diversion) {
/* header not found */
return -1;
}
/* maybe the header is already parsed! */
if (msg->diversion->parsed)
return 0;
/* bad luck! :-( - we have to parse it */
/* first, get some memory */
diversion_b = pkg_malloc(sizeof(struct to_body));
if (diversion_b == 0) {
LM_ERR("out of pkg_memory\n");
goto error;
}
/* now parse it!! */
memset(diversion_b, 0, sizeof(struct to_body));
parse_addr_spec(msg->diversion->body.s,
msg->diversion->body.s + msg->diversion->body.len + 1,
diversion_b, 1);
if (diversion_b->error == PARSE_ERROR) {
LM_ERR("bad diversion header\n");
free_to(diversion_b);
goto error;
}
msg->diversion->parsed = diversion_b;
return 0;
error:
return -1;
}
@ -83,22 +92,22 @@ int parse_diversion_header(struct sip_msg *msg)
*/
str *get_diversion_param(struct sip_msg *msg, str* name)
{
struct to_param *params;
struct to_param *params;
if (parse_diversion_header(msg) < 0) {
ERR("could not get diversion parameter\n");
if (parse_diversion_header(msg) < 0) {
LM_ERR("could not get diversion parameter\n");
return 0;
}
}
params = ((struct to_body*)(msg->diversion->parsed))->param_lst;
params = ((struct to_body*)(msg->diversion->parsed))->param_lst;
while (params) {
while (params) {
if ((params->name.len == name->len) &&
(strncmp(params->name.s, name->s, name->len) == 0)) {
(strncmp(params->name.s, name->s, name->len) == 0)) {
return &params->value;
}
params = params->next;
}
return 0;
}
return 0;
}

@ -53,14 +53,15 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
status=II_URI_BEGIN;
mainstatus = II_M_URI_BEGIN;
ii_b->uri.s = p + 1;
} else
} else {
goto parseerror;
break;
}
break;
case 'h':
case 'H': /* "http://" or "https://" part */
switch (status) {
case II_URI_BEGIN:
if (end - p <= 8 || strncasecmp(p,"http",strlen("http")))
if (end - p <= 8 || strncasecmp(p, "http", 4))
goto parseerror;
p+=4;
if (*p == 's' || *p == 'S') p++;
@ -168,7 +169,7 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
p=eat_lws_end(p, end);
/*check if the header ends here*/
if (p>=end) {
LOG(L_ERR, "ERROR: parse_identityinfo: strange EoHF\n");
LM_ERR("strange EoHF\n");
goto parseerror;
}
ii_b->error=PARSE_OK;
@ -201,7 +202,8 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
if (mainstatus == II_M_SEMIC) {
mainstatus = II_M_TAG;
status = II_TAG;
if (end - p <= 3 || strncasecmp(p,"alg",strlen("alg")))
if (end - p <= 3
|| strncasecmp(p,"alg",strlen("alg")))
goto parseerror;
p+=2;
} else
@ -293,9 +295,9 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
case II_URI_IPV4:
case II_URI_IPV6:
if (isalnum(*p)
|| *p == '-'
|| *p == '.'
|| *p == ':' )
|| *p == '-'
|| *p == '.'
|| *p == ':' )
break;
case II_START:
goto parseerror;
@ -308,9 +310,8 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
return ;
parseerror:
LOG( L_ERR , "ERROR: parse_identityinfo: "
"unexpected char [%c] in status %d: <<%.*s>> .\n",
*p,status, (int)(p-buffer), ZSW(p));
LM_ERR("unexpected char [%c] in status %d: <<%.*s>> .\n",
*p,status, (int)(p-buffer), ZSW(p));
return ;
}
@ -320,9 +321,9 @@ int parse_identityinfo_header(struct sip_msg *msg)
if ( !msg->identity_info
&& (parse_headers(msg,HDR_IDENTITY_INFO_F,0)==-1
|| !msg->identity_info) ) {
LOG(L_ERR,"ERROR:parse_identityinfo_header: bad msg or missing IDENTITY-INFO header\n");
&& (parse_headers(msg,HDR_IDENTITY_INFO_F,0)==-1
|| !msg->identity_info) ) {
LM_ERR("bad msg or missing IDENTITY-INFO header\n");
goto error;
}
@ -338,8 +339,8 @@ int parse_identityinfo_header(struct sip_msg *msg)
memset(identityinfo_b, 0, sizeof(*identityinfo_b));
parse_identityinfo(msg->identity_info->body.s,
msg->identity_info->body.s + msg->identity_info->body.len+1,
identityinfo_b);
msg->identity_info->body.s + msg->identity_info->body.len+1,
identityinfo_b);
if (identityinfo_b->error==PARSE_ERROR){
free_identityinfo(identityinfo_b);
goto error;

@ -375,6 +375,7 @@ static int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_
* - shorcut useful for multi-part bodies and sdp operations
*/
_sdp->text = *sdp_body;
pf = AF_INET;
/*
* Parsing of SDP body.

@ -20,7 +20,7 @@
/*!
* \file
* \brief Kamailio core ::
* \brief Kamailio core ::
* \ingroup core
* Module: \ref core
*/
@ -46,17 +46,17 @@
/** receive all the data or returns error (handles EINTR etc.)
* params: socket
* data - buffer for the results
* data_len -
* data_len -
* flags - recv flags for the first recv (see recv(2)), only
* 0, MSG_WAITALL and MSG_DONTWAIT make sense
* if flags is set to MSG_DONWAIT (or to 0 and the socket fd is non-blocking),
* and if no data is queued on the fd, recv_all will not wait (it will
* and if no data is queued on the fd, recv_all will not wait (it will
* return error and set errno to EAGAIN/EWOULDBLOCK). However if even 1 byte
* is queued, the call will block until the whole data_len was read or an
* error or eof occured ("semi-nonblocking" behaviour, some tcp code
* counts on it).
* if flags is set to MSG_WAITALL it will block even if no byte is available.
*
*
* returns: bytes read or error (<0)
* can return < data_len if EOF */
int recv_all(int socket, void* data, int data_len, int flags)
@ -66,7 +66,7 @@ int recv_all(int socket, void* data, int data_len, int flags)
#ifdef NO_MSG_WAITALL
struct pollfd pfd;
#endif /* NO_MSG_WAITALL */
b_read=0;
again:
#ifdef NO_MSG_WAITALL
@ -104,7 +104,7 @@ poll_recv:
pfd.events=POLLIN;
poll_retry:
n=poll(&pfd, 1, -1);
if (n<0){
if (n<0){
if (errno==EINTR) goto poll_retry;
LM_CRIT("poll on %d failed: %s\n",
socket, strerror(errno));
@ -128,7 +128,7 @@ poll_retry:
int send_all(int socket, void* data, int data_len)
{
int n;
again:
n=send(socket, data, data_len, 0);
if (n<0){
@ -156,12 +156,13 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
struct cmsghdr cm;
char control[CMSG_SPACE(sizeof(fd))];
}control_un;
memset(&msg, 0, sizeof(struct msghdr));
msg.msg_control=control_un.control;
/* openbsd doesn't like "more space", msg_controllen must not
* include the end padding */
msg.msg_controllen=CMSG_LEN(sizeof(fd));
cmsg=CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
@ -173,15 +174,15 @@ int send_fd(int unix_socket, void* data, int data_len, int fd)
msg.msg_accrights=(caddr_t) &fd;
msg.msg_accrightslen=sizeof(fd);
#endif
msg.msg_name=0;
msg.msg_namelen=0;
iov[0].iov_base=data;
iov[0].iov_len=data_len;
msg.msg_iov=iov;
msg.msg_iovlen=1;
again:
ret=sendmsg(unix_socket, &msg, 0);
if (ret<0){
@ -190,14 +191,14 @@ again:
LM_CRIT("sendmsg failed sending %d on %d: %s (%d)\n",
fd, unix_socket, strerror(errno), errno);
}
return ret;
}
/** receives a fd and data_len data
* params: unix_socket
* params: unix_socket
* data
* data_len
* fd - will be set to the passed fd value or -1 if no fd
@ -222,22 +223,23 @@ int receive_fd(int unix_socket, void* data, int data_len, int* fd, int flags)
struct cmsghdr cm;
char control[CMSG_SPACE(sizeof(new_fd))];
}control_un;
memset(&msg, 0, sizeof(struct msghdr));
msg.msg_control=control_un.control;
msg.msg_controllen=sizeof(control_un.control);
#else
msg.msg_accrights=(caddr_t) &new_fd;
msg.msg_accrightslen=sizeof(int);
#endif
msg.msg_name=0;
msg.msg_namelen=0;
iov[0].iov_base=data;
iov[0].iov_len=data_len;
msg.msg_iov=iov;
msg.msg_iovlen=1;
#ifdef NO_MSG_WAITALL
f=flags & ~MSG_WAITALL;
#endif /* NO_MSG_WAITALL */
@ -286,7 +288,7 @@ poll_again:
goto error;
}
}
#ifdef HAVE_MSGHDR_MSG_CONTROL
cmsg=CMSG_FIRSTHDR(&msg);
if ((cmsg!=0) && (cmsg->cmsg_len==CMSG_LEN(sizeof(new_fd)))){
@ -317,7 +319,7 @@ poll_again:
*fd=-1;
}
#endif
error:
return ret;
}

@ -1,5 +1,5 @@
%define name kamailio
%define ver 4.4.3
%define ver 4.4.4
%define rel 0.0%{dist}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save