Kaynağa Gözat

uac: clang-format for coherent indentation and coding style

Victor Seva 2 yıl önce
ebeveyn
işleme
f2c5879383

+ 10 - 8
src/modules/uac/api.h

@@ -25,19 +25,21 @@ typedef int (*uac_replace_from_t)(sip_msg_t *, str *, str *);
 typedef int (*uac_replace_to_t)(sip_msg_t *, str *, str *);
 typedef int (*uac_req_send_t)(void);
 
-typedef struct uac_binds {
-	uac_replace_from_t	replace_from;
-	uac_replace_to_t	replace_to;
-	uac_req_send_t      req_send;
+typedef struct uac_binds
+{
+	uac_replace_from_t replace_from;
+	uac_replace_to_t replace_to;
+	uac_req_send_t req_send;
 } uac_api_t;
 
-typedef int (*bind_uac_f)(uac_api_t*);
+typedef int (*bind_uac_f)(uac_api_t *);
 
-int bind_uac(uac_api_t*);
+int bind_uac(uac_api_t *);
 
-inline static int load_uac_api(uac_api_t *uacb){
+inline static int load_uac_api(uac_api_t *uacb)
+{
 	bind_uac_f bind_uac_exports;
-	if(!(bind_uac_exports=(bind_uac_f)find_export("bind_uac",1,0))){
+	if(!(bind_uac_exports = (bind_uac_f)find_export("bind_uac", 1, 0))) {
 		LM_WARN("failed to import bind_uac\n");
 		return -1;
 	}

+ 140 - 154
src/modules/uac/auth.c

@@ -54,123 +54,131 @@ extern pv_spec_t auth_password_spec;
 static struct uac_credential *crd_list = 0;
 
 
-#define  duplicate_str(_strd, _strs, _error) \
-	do { \
-		_strd.s = (char*)pkg_malloc(_strs.len); \
-		if (_strd.s==0) \
-		{ \
-			PKG_MEM_ERROR;\
-			goto _error; \
-		} \
-		memcpy( _strd.s, _strs.s, _strs.len); \
-		_strd.len = _strs.len; \
-	}while(0)
-
-
-#define WWW_AUTH_CODE       401
-#define WWW_AUTH_HDR        "WWW-Authenticate"
-#define WWW_AUTH_HDR_LEN    (sizeof(WWW_AUTH_HDR)-1)
-#define PROXY_AUTH_CODE     407
-#define PROXY_AUTH_HDR      "Proxy-Authenticate"
-#define PROXY_AUTH_HDR_LEN  (sizeof(PROXY_AUTH_HDR)-1)
+#define duplicate_str(_strd, _strs, _error)      \
+	do {                                         \
+		_strd.s = (char *)pkg_malloc(_strs.len); \
+		if(_strd.s == 0) {                       \
+			PKG_MEM_ERROR;                       \
+			goto _error;                         \
+		}                                        \
+		memcpy(_strd.s, _strs.s, _strs.len);     \
+		_strd.len = _strs.len;                   \
+	} while(0)
+
+
+#define WWW_AUTH_CODE 401
+#define WWW_AUTH_HDR "WWW-Authenticate"
+#define WWW_AUTH_HDR_LEN (sizeof(WWW_AUTH_HDR) - 1)
+#define PROXY_AUTH_CODE 407
+#define PROXY_AUTH_HDR "Proxy-Authenticate"
+#define PROXY_AUTH_HDR_LEN (sizeof(PROXY_AUTH_HDR) - 1)
 
 static str nc = {"00000001", 8};
 static str cnonce = {"o", 1};
 
 int has_credentials(void)
 {
-	return (crd_list!=0)?1:0;
+	return (crd_list != 0) ? 1 : 0;
 }
 
 void free_credential(struct uac_credential *crd)
 {
-	if (crd)
-	{
-		if (crd->realm.s)
+	if(crd) {
+		if(crd->realm.s)
 			pkg_free(crd->realm.s);
-		if (crd->user.s)
+		if(crd->user.s)
 			pkg_free(crd->user.s);
-		if (crd->passwd.s)
+		if(crd->passwd.s)
 			pkg_free(crd->passwd.s);
 		pkg_free(crd);
 	}
 }
 
 
-int add_credential( unsigned int type, void *val)
+int add_credential(unsigned int type, void *val)
 {
 	struct uac_credential *crd;
 	char *p;
 	str foo;
 
-	p = (char*)val;
+	p = (char *)val;
 	crd = 0;
 
-	if (p==0 || *p==0)
+	if(p == 0 || *p == 0)
 		goto error;
 
-	crd = (struct uac_credential*)pkg_malloc(sizeof(struct uac_credential));
-	if (crd==0)
-	{
+	crd = (struct uac_credential *)pkg_malloc(sizeof(struct uac_credential));
+	if(crd == 0) {
 		PKG_MEM_ERROR;
 		goto error;
 	}
-	memset( crd, 0, sizeof(struct uac_credential));
+	memset(crd, 0, sizeof(struct uac_credential));
 
 	/*parse the user */
-	while (*p && isspace((int)*p)) p++;
+	while(*p && isspace((int)*p))
+		p++;
 	foo.s = p;
-	while (*p && *p!=':' && !isspace((int)*p)) p++;
-	if (foo.s==p || *p==0)
+	while(*p && *p != ':' && !isspace((int)*p))
+		p++;
+	if(foo.s == p || *p == 0)
 		/* missing or empty user */
 		goto parse_error;
 	foo.len = p - foo.s;
 	/* dulicate it */
-	duplicate_str( crd->user, foo, error);
+	duplicate_str(crd->user, foo, error);
 
 	/* parse the ':' separator */
-	while (*p && isspace((int)*p)) p++;
-	if (*p!=':')
+	while(*p && isspace((int)*p))
+		p++;
+	if(*p != ':')
 		goto parse_error;
 	p++;
-	while (*p && isspace((int)*p)) p++;
-	if (*p==0)
+	while(*p && isspace((int)*p))
+		p++;
+	if(*p == 0)
 		goto parse_error;
 
 	/*parse the realm */
-	while (*p && isspace((int)*p)) p++;
+	while(*p && isspace((int)*p))
+		p++;
 	foo.s = p;
-	while (*p && *p!=':' && !isspace((int)*p)) p++;
-	if (foo.s==p || *p==0)
+	while(*p && *p != ':' && !isspace((int)*p))
+		p++;
+	if(foo.s == p || *p == 0)
 		/* missing or empty realm */
 		goto parse_error;
 	foo.len = p - foo.s;
 	/* dulicate it */
-	duplicate_str( crd->realm, foo, error);
+	duplicate_str(crd->realm, foo, error);
 
 	/* parse the ':' separator */
-	while (*p && isspace((int)*p)) p++;
-	if (*p!=':')
+	while(*p && isspace((int)*p))
+		p++;
+	if(*p != ':')
 		goto parse_error;
 	p++;
-	while (*p && isspace((int)*p)) p++;
-	if (*p==0)
+	while(*p && isspace((int)*p))
+		p++;
+	if(*p == 0)
 		goto parse_error;
 
 	/*parse the passwd */
-	while (*p && isspace((int)*p)) p++;
+	while(*p && isspace((int)*p))
+		p++;
 	foo.s = p;
-	while (*p && !isspace((int)*p)) p++;
-	if (foo.s==p)
+	while(*p && !isspace((int)*p))
+		p++;
+	if(foo.s == p)
 		/* missing or empty passwd */
 		goto parse_error;
 	foo.len = p - foo.s;
 	/* dulicate it */
-	duplicate_str( crd->passwd, foo, error);
+	duplicate_str(crd->passwd, foo, error);
 
 	/* end of string */
-	while (*p && isspace((int)*p)) p++;
-	if (*p!=0)
+	while(*p && isspace((int)*p))
+		p++;
+	if(*p != 0)
 		goto parse_error;
 
 	/* link the new cred struct */
@@ -180,10 +188,11 @@ int add_credential( unsigned int type, void *val)
 	pkg_free(val);
 	return 0;
 parse_error:
-		LM_ERR("parse error in <%s> "
-		"around %ld\n", (char*)val, (long)(p-(char*)val));
+	LM_ERR("parse error in <%s> "
+		   "around %ld\n",
+			(char *)val, (long)(p - (char *)val));
 error:
-	if (crd)
+	if(crd)
 		free_credential(crd);
 	return -1;
 }
@@ -193,8 +202,7 @@ void destroy_credentials(void)
 {
 	struct uac_credential *foo;
 
-	while (crd_list)
-	{
+	while(crd_list) {
 		foo = crd_list;
 		crd_list = crd_list->next;
 		free_credential(foo);
@@ -209,83 +217,81 @@ struct hdr_field *get_autenticate_hdr(struct sip_msg *rpl, int rpl_code)
 	str hdr_name;
 
 	/* what hdr should we look for */
-	if (rpl_code==WWW_AUTH_CODE)
-	{
+	if(rpl_code == WWW_AUTH_CODE) {
 		hdr_name.s = WWW_AUTH_HDR;
 		hdr_name.len = WWW_AUTH_HDR_LEN;
-	} else if (rpl_code==PROXY_AUTH_CODE) {
+	} else if(rpl_code == PROXY_AUTH_CODE) {
 		hdr_name.s = PROXY_AUTH_HDR;
 		hdr_name.len = PROXY_AUTH_HDR_LEN;
 	} else {
 		LM_ERR("reply is not an "
-			"auth request\n");
+			   "auth request\n");
 		goto error;
 	}
 
-	LM_DBG("looking for header \"%.*s\"\n",
-		hdr_name.len, hdr_name.s);
+	LM_DBG("looking for header \"%.*s\"\n", hdr_name.len, hdr_name.s);
 
 	/* search the auth hdr, but first parse them all */
-	if (parse_headers( rpl, HDR_EOH_F, 0)<0)
-	{
+	if(parse_headers(rpl, HDR_EOH_F, 0) < 0) {
 		LM_ERR("failed to parse reply\n");
 		goto error;
 	}
-	for( hdr=rpl->headers ; hdr ; hdr=hdr->next )
-	{
-		if ( rpl_code==WWW_AUTH_CODE && hdr->type==HDR_WWW_AUTHENTICATE_T )
+	for(hdr = rpl->headers; hdr; hdr = hdr->next) {
+		if(rpl_code == WWW_AUTH_CODE && hdr->type == HDR_WWW_AUTHENTICATE_T)
 			return hdr;
-		if ( rpl_code==PROXY_AUTH_CODE && hdr->type==HDR_PROXY_AUTHENTICATE_T )
+		if(rpl_code == PROXY_AUTH_CODE && hdr->type == HDR_PROXY_AUTHENTICATE_T)
 			return hdr;
 	}
 
 	LM_ERR("reply has no "
-		"auth hdr (%.*s)\n", hdr_name.len, hdr_name.s);
+		   "auth hdr (%.*s)\n",
+			hdr_name.len, hdr_name.s);
 error:
 	return 0;
 }
 
 
-static inline struct uac_credential *lookup_realm( str *realm)
+static inline struct uac_credential *lookup_realm(str *realm)
 {
 	struct uac_credential *crd;
 
-	for( crd=crd_list ; crd ; crd=crd->next )
-		if (realm->len==crd->realm.len &&
-		strncmp( realm->s, crd->realm.s, realm->len)==0 )
+	for(crd = crd_list; crd; crd = crd->next)
+		if(realm->len == crd->realm.len
+				&& strncmp(realm->s, crd->realm.s, realm->len) == 0)
 			return crd;
 	return 0;
 }
 
 
-static inline struct uac_credential *get_avp_credential(struct sip_msg *msg, str *realm)
+static inline struct uac_credential *get_avp_credential(
+		struct sip_msg *msg, str *realm)
 {
 	static struct uac_credential crd;
 	pv_value_t pv_val;
 
-	if(pv_get_spec_value( msg, &auth_realm_spec, &pv_val)!=0)
+	if(pv_get_spec_value(msg, &auth_realm_spec, &pv_val) != 0)
 		return 0;
 
-	if (pv_val.flags&PV_VAL_NULL || pv_val.rs.len<=0) {
+	if(pv_val.flags & PV_VAL_NULL || pv_val.rs.len <= 0) {
 		/* if realm parameter is empty or NULL, match any realm asked for */
 		crd.realm = *realm;
 	} else {
 		crd.realm = pv_val.rs;
 		/* is it the domain we are looking for? */
-		if (realm->len!=crd.realm.len ||
-		  strncmp( realm->s, crd.realm.s, realm->len)!=0 ) {
+		if(realm->len != crd.realm.len
+				|| strncmp(realm->s, crd.realm.s, realm->len) != 0) {
 			return 0;
 		}
 	}
 
 	/* get username and password */
-	if(pv_get_spec_value( msg, &auth_username_spec, &pv_val)!=0
-	|| pv_val.flags&PV_VAL_NULL || pv_val.rs.len<=0)
+	if(pv_get_spec_value(msg, &auth_username_spec, &pv_val) != 0
+			|| pv_val.flags & PV_VAL_NULL || pv_val.rs.len <= 0)
 		return 0;
 	crd.user = pv_val.rs;
 
-	if(pv_get_spec_value( msg, &auth_password_spec, &pv_val)!=0
-	|| pv_val.flags&PV_VAL_NULL || pv_val.rs.len<=0)
+	if(pv_get_spec_value(msg, &auth_password_spec, &pv_val) != 0
+			|| pv_val.flags & PV_VAL_NULL || pv_val.rs.len <= 0)
 		return 0;
 	crd.passwd = pv_val.rs;
 
@@ -293,85 +299,74 @@ static inline struct uac_credential *get_avp_credential(struct sip_msg *msg, str
 }
 
 
-void do_uac_auth(str *method, str *uri,
-		struct uac_credential *crd,
-		struct authenticate_body *auth,
-		HASHHEX response)
+void do_uac_auth(str *method, str *uri, struct uac_credential *crd,
+		struct authenticate_body *auth, HASHHEX response)
 {
 	HASHHEX ha1;
 	HASHHEX ha2;
 
-	if((auth->flags&QOP_AUTH) || (auth->flags&QOP_AUTH_INT))
-	{
+	if((auth->flags & QOP_AUTH) || (auth->flags & QOP_AUTH_INT)) {
 		/* if qop generate nonce-count and cnonce */
-		cnonce.s = int2str(get_hash1_raw(auth->nonce.s, auth->nonce.len), 
-						   &cnonce.len);
+		cnonce.s = int2str(
+				get_hash1_raw(auth->nonce.s, auth->nonce.len), &cnonce.len);
 
 		/* do authentication */
-		uac_calc_HA1( crd, auth, &cnonce, ha1);
-		uac_calc_HA2( method, uri,
-			auth, 0/*hentity*/, ha2 );
+		uac_calc_HA1(crd, auth, &cnonce, ha1);
+		uac_calc_HA2(method, uri, auth, 0 /*hentity*/, ha2);
 
-		uac_calc_response( ha1, ha2, auth, &nc, &cnonce, response);
+		uac_calc_response(ha1, ha2, auth, &nc, &cnonce, response);
 		auth->nc = &nc;
 		auth->cnonce = &cnonce;
 	} else {
 		/* do authentication */
-		uac_calc_HA1( crd, auth, 0/*cnonce*/, ha1);
-		uac_calc_HA2( method, uri,
-			auth, 0/*hentity*/, ha2 );
+		uac_calc_HA1(crd, auth, 0 /*cnonce*/, ha1);
+		uac_calc_HA2(method, uri, auth, 0 /*hentity*/, ha2);
 
-		uac_calc_response( ha1, ha2, auth, 0/*nc*/, 0/*cnonce*/, response);
+		uac_calc_response(ha1, ha2, auth, 0 /*nc*/, 0 /*cnonce*/, response);
 	}
 }
 
 
-static inline int apply_urihdr_changes( struct sip_msg *req,
-													str *uri, str *hdr)
+static inline int apply_urihdr_changes(struct sip_msg *req, str *uri, str *hdr)
 {
-	struct lump* anchor;
+	struct lump *anchor;
 
 	/* add the uri - move it to branch directly FIXME (bogdan)*/
-	if (req->new_uri.s)
-	{
+	if(req->new_uri.s) {
 		pkg_free(req->new_uri.s);
-		req->new_uri.len=0;
+		req->new_uri.len = 0;
 	}
-	req->parsed_uri_ok=0;
-	req->new_uri.s = (char*)pkg_malloc(uri->len+1);
-	if (req->new_uri.s==0)
-	{
+	req->parsed_uri_ok = 0;
+	req->new_uri.s = (char *)pkg_malloc(uri->len + 1);
+	if(req->new_uri.s == 0) {
 		PKG_MEM_ERROR;
 		goto error;
 	}
-	memcpy( req->new_uri.s, uri->s, uri->len);
-	req->new_uri.s[uri->len]=0;
-	req->new_uri.len=uri->len;
+	memcpy(req->new_uri.s, uri->s, uri->len);
+	req->new_uri.s[uri->len] = 0;
+	req->new_uri.len = uri->len;
 	ruri_mark_new();
 
 	/* add the header */
-	if (parse_headers(req, HDR_EOH_F, 0) == -1)
-	{
+	if(parse_headers(req, HDR_EOH_F, 0) == -1) {
 		LM_ERR("failed to parse message\n");
 		goto error;
 	}
 
 	anchor = anchor_lump(req, req->unparsed - req->buf, 0, 0);
-	if (anchor==0)
-	{
+	if(anchor == 0) {
 		LM_ERR("failed to get anchor\n");
 		goto error;
 	}
 
-	if (insert_new_lump_before(anchor, hdr->s, hdr->len, 0) == 0)
-	{
+	if(insert_new_lump_before(anchor, hdr->s, hdr->len, 0) == 0) {
 		LM_ERR("faield to insert lump\n");
 		goto error;
 	}
 
 	return 0;
 error:
-	pkg_free( hdr->s );
+	pkg_free(hdr->s);
 	return -1;
 }
 
@@ -392,46 +387,40 @@ int uac_auth_mode(sip_msg_t *msg, int mode)
 
 	/* get transaction */
 	t = uac_tmb.t_gett();
-	if (t==T_UNDEFINED || t==T_NULL_CELL)
-	{
+	if(t == T_UNDEFINED || t == T_NULL_CELL) {
 		LM_CRIT("no current transaction found\n");
 		goto error;
 	}
 
 	/* get the selected branch */
 	branch = uac_tmb.t_get_picked_branch();
-	if (branch<0) {
-		LM_CRIT("no picked branch (%d)\n",branch);
+	if(branch < 0) {
+		LM_CRIT("no picked branch (%d)\n", branch);
 		goto error;
 	}
 
 	rpl = t->uac[branch].reply;
 	code = t->uac[branch].last_received;
-	LM_DBG("picked reply is %p, code %d\n",rpl,code);
+	LM_DBG("picked reply is %p, code %d\n", rpl, code);
 
-	if (rpl==0)
-	{
+	if(rpl == 0) {
 		LM_CRIT("empty reply on picked branch\n");
 		goto error;
 	}
-	if (rpl==FAKED_REPLY)
-	{
+	if(rpl == FAKED_REPLY) {
 		LM_ERR("cannot process a FAKED reply\n");
 		goto error;
 	}
 
-	hdr = get_autenticate_hdr( rpl, code);
-	if (hdr==0)
-	{
+	hdr = get_autenticate_hdr(rpl, code);
+	if(hdr == 0) {
 		LM_ERR("failed to extract authenticate hdr\n");
 		goto error;
 	}
 
-	LM_DBG("header found; body=<%.*s>\n",
-		hdr->body.len, hdr->body.s);
+	LM_DBG("header found; body=<%.*s>\n", hdr->body.len, hdr->body.s);
 
-	if (parse_authenticate_body( &hdr->body, &auth)<0)
-	{
+	if(parse_authenticate_body(&hdr->body, &auth) < 0) {
 		LM_ERR("failed to parse auth hdr body\n");
 		goto error;
 	}
@@ -439,16 +428,15 @@ int uac_auth_mode(sip_msg_t *msg, int mode)
 	/* can we authenticate this realm? */
 	crd = 0;
 	/* first look into AVP, if set */
-	if ( auth_realm_spec.type!=PVT_NONE )
-		crd = get_avp_credential( msg, &auth.realm );
+	if(auth_realm_spec.type != PVT_NONE)
+		crd = get_avp_credential(msg, &auth.realm);
 	/* if not found, look into predefined credentials */
-	if (crd==0)
-		crd = lookup_realm( &auth.realm );
+	if(crd == 0)
+		crd = lookup_realm(&auth.realm);
 	/* found? */
-	if (crd==0)
-	{
-		LM_INFO("no credential for realm \"%.*s\"\n",
-			auth.realm.len, auth.realm.s);
+	if(crd == 0) {
+		LM_INFO("no credential for realm \"%.*s\"\n", auth.realm.len,
+				auth.realm.s);
 		goto error;
 	}
 
@@ -457,21 +445,19 @@ int uac_auth_mode(sip_msg_t *msg, int mode)
 	}
 
 	/* do authentication */
-	do_uac_auth( &msg->first_line.u.request.method,
-			&t->uac[branch].uri, crd, &auth, response);
+	do_uac_auth(&msg->first_line.u.request.method, &t->uac[branch].uri, crd,
+			&auth, response);
 
 	/* build the authorization header */
-	new_hdr = build_authorization_hdr( code, &t->uac[branch].uri,
-		crd, &auth, response);
-	if (new_hdr==0)
-	{
+	new_hdr = build_authorization_hdr(
+			code, &t->uac[branch].uri, crd, &auth, response);
+	if(new_hdr == 0) {
 		LM_ERR("failed to build authorization hdr\n");
 		goto error;
 	}
 
 	/* so far, so good -> add the header and set the proper RURI */
-	if ( apply_urihdr_changes( msg, &t->uac[branch].uri, new_hdr)<0 )
-	{
+	if(apply_urihdr_changes(msg, &t->uac[branch].uri, new_hdr) < 0) {
 		LM_ERR("failed to apply changes\n");
 		goto error;
 	}
@@ -483,7 +469,7 @@ int uac_auth_mode(sip_msg_t *msg, int mode)
 		t->uas.request->msg_flags |= FL_UAC_AUTH;
 		cenv = sr_cfgenv_get();
 		if(cenv->cb_cseq_update != NULL) {
-			if(cenv->cb_cseq_update(msg)<0) {
+			if(cenv->cb_cseq_update(msg) < 0) {
 				goto error;
 			}
 		}

+ 15 - 15
src/modules/uac/auth.h

@@ -26,9 +26,10 @@
 
 #include "../../core/parser/msg_parser.h"
 
-#define UAC_FLCRED_HA1 (1<<0)
+#define UAC_FLCRED_HA1 (1 << 0)
 
-typedef struct uac_credential {
+typedef struct uac_credential
+{
 	str realm;
 	str user;
 	str passwd;
@@ -36,7 +37,8 @@ typedef struct uac_credential {
 	struct uac_credential *next;
 } uac_credential_t;
 
-typedef struct authenticate_body {
+typedef struct authenticate_body
+{
 	int flags;
 	str realm;
 	str domain;
@@ -47,23 +49,23 @@ typedef struct authenticate_body {
 	str *cnonce;
 } uac_authenticate_body_t;
 
-#define UACAUTH_MODE_HA1 (1<<0)
+#define UACAUTH_MODE_HA1 (1 << 0)
 
-#define AUTHENTICATE_MD5         (1<<0)
-#define AUTHENTICATE_MD5SESS     (1<<1)
-#define AUTHENTICATE_STALE       (1<<2)
-#define QOP_AUTH                 (1<<3)
-#define QOP_AUTH_INT             (1<<4)
+#define AUTHENTICATE_MD5 (1 << 0)
+#define AUTHENTICATE_MD5SESS (1 << 1)
+#define AUTHENTICATE_STALE (1 << 2)
+#define QOP_AUTH (1 << 3)
+#define QOP_AUTH_INT (1 << 4)
 
 #define HASHLEN 16
 typedef char HASH[HASHLEN];
 
 #define HASHHEXLEN 32
-typedef char HASHHEX[HASHHEXLEN+1];
+typedef char HASHHEX[HASHHEXLEN + 1];
 
 int has_credentials(void);
 
-int add_credential( unsigned int type, void *val);
+int add_credential(unsigned int type, void *val);
 
 void destroy_credentials(void);
 
@@ -72,9 +74,7 @@ struct hdr_field *get_autenticate_hdr(struct sip_msg *rpl, int rpl_code);
 int uac_auth(sip_msg_t *msg);
 int uac_auth_mode(sip_msg_t *msg, int mode);
 
-void do_uac_auth(str *method, str *uri,
-		struct uac_credential *crd,
-		struct authenticate_body *auth,
-		HASHHEX response);
+void do_uac_auth(str *method, str *uri, struct uac_credential *crd,
+		struct authenticate_body *auth, HASHHEX response);
 
 #endif

+ 29 - 41
src/modules/uac/auth_alg.c

@@ -37,11 +37,9 @@ static inline void cvt_hex(HASH bin, HASHHEX hex)
 	unsigned short i;
 	unsigned char j;
 
-	for (i = 0; i<HASHLEN; i++)
-	{
+	for(i = 0; i < HASHLEN; i++) {
 		j = (bin[i] >> 4) & 0xf;
-		if (j <= 9)
-		{
+		if(j <= 9) {
 			hex[i * 2] = (j + '0');
 		} else {
 			hex[i * 2] = (j + 'a' - 10);
@@ -49,8 +47,7 @@ static inline void cvt_hex(HASH bin, HASHHEX hex)
 
 		j = bin[i] & 0xf;
 
-		if (j <= 9)
-		{
+		if(j <= 9) {
 			hex[i * 2 + 1] = (j + '0');
 		} else {
 			hex[i * 2 + 1] = (j + 'a' - 10);
@@ -65,21 +62,22 @@ static inline void cvt_bin(HASHHEX hex, HASH bin)
 {
 	unsigned short i;
 	unsigned char j;
-	for (i = 0; i<HASHLEN; i++) {
-		if(hex[2*i]>='0' && hex[2*i]<='9')
-			j = (hex[2*i]-'0') << 4;
-		else if(hex[2*i]>='a'&&hex[2*i]<='f')
-			j = (hex[2*i]-'a'+10) << 4;
-		else if(hex[2*i]>='A'&&hex[2*i]<='F')
-			j = (hex[2*i]-'A'+10) << 4;
-		else j = 0;
-
-		if(hex[2*i+1]>='0'&&hex[2*i+1]<='9')
-			j += hex[2*i+1]-'0';
-		else if(hex[2*i+1]>='a'&&hex[2*i+1]<='f')
-			j += hex[2*i+1]-'a'+10;
-		else if(hex[2*i+1]>='A'&&hex[2*i+1]<='F')
-			j += hex[2*i+1]-'A'+10;
+	for(i = 0; i < HASHLEN; i++) {
+		if(hex[2 * i] >= '0' && hex[2 * i] <= '9')
+			j = (hex[2 * i] - '0') << 4;
+		else if(hex[2 * i] >= 'a' && hex[2 * i] <= 'f')
+			j = (hex[2 * i] - 'a' + 10) << 4;
+		else if(hex[2 * i] >= 'A' && hex[2 * i] <= 'F')
+			j = (hex[2 * i] - 'A' + 10) << 4;
+		else
+			j = 0;
+
+		if(hex[2 * i + 1] >= '0' && hex[2 * i + 1] <= '9')
+			j += hex[2 * i + 1] - '0';
+		else if(hex[2 * i + 1] >= 'a' && hex[2 * i + 1] <= 'f')
+			j += hex[2 * i + 1] - 'a' + 10;
+		else if(hex[2 * i + 1] >= 'A' && hex[2 * i + 1] <= 'F')
+			j += hex[2 * i + 1] - 'A' + 10;
 
 		bin[i] = j;
 	}
@@ -88,10 +86,8 @@ static inline void cvt_bin(HASHHEX hex, HASH bin)
 /*
  * calculate H(A1)
  */
-void uac_calc_HA1( struct uac_credential *crd,
-		struct authenticate_body *auth,
-		str* cnonce,
-		HASHHEX sess_key)
+void uac_calc_HA1(struct uac_credential *crd, struct authenticate_body *auth,
+		str *cnonce, HASHHEX sess_key)
 {
 	MD5_CTX Md5Ctx;
 	HASH HA1;
@@ -99,7 +95,7 @@ void uac_calc_HA1( struct uac_credential *crd,
 	if(crd->aflags & UAC_FLCRED_HA1) {
 		memcpy(sess_key, crd->passwd.s, HASHHEXLEN);
 		sess_key[HASHHEXLEN] = '\0';
-		if ( auth->flags& AUTHENTICATE_MD5SESS ) {
+		if(auth->flags & AUTHENTICATE_MD5SESS) {
 			cvt_bin(sess_key, HA1);
 		} else {
 			return;
@@ -114,7 +110,7 @@ void uac_calc_HA1( struct uac_credential *crd,
 		MD5Final(HA1, &Md5Ctx);
 	}
 
-	if ( auth->flags& AUTHENTICATE_MD5SESS ) {
+	if(auth->flags & AUTHENTICATE_MD5SESS) {
 		MD5Init(&Md5Ctx);
 		MD5Update(&Md5Ctx, HA1, HASHLEN);
 		MD5Update(&Md5Ctx, ":", 1);
@@ -128,14 +124,11 @@ void uac_calc_HA1( struct uac_credential *crd,
 }
 
 
-
 /* 
  * calculate H(A2)
  */
-void uac_calc_HA2( str *method, str *uri,
-		struct authenticate_body *auth,
-		HASHHEX hentity,
-		HASHHEX HA2Hex )
+void uac_calc_HA2(str *method, str *uri, struct authenticate_body *auth,
+		HASHHEX hentity, HASHHEX HA2Hex)
 {
 	MD5_CTX Md5Ctx;
 	HASH HA2;
@@ -145,8 +138,7 @@ void uac_calc_HA2( str *method, str *uri,
 	MD5Update(&Md5Ctx, ":", 1);
 	MD5Update(&Md5Ctx, uri->s, uri->len);
 
-	if ( auth->flags&QOP_AUTH_INT)
-	{
+	if(auth->flags & QOP_AUTH_INT) {
 		MD5Update(&Md5Ctx, ":", 1);
 		MD5Update(&Md5Ctx, hentity, HASHHEXLEN);
 	};
@@ -156,14 +148,11 @@ void uac_calc_HA2( str *method, str *uri,
 }
 
 
-
 /* 
  * calculate request-digest/response-digest as per HTTP Digest spec 
  */
-void uac_calc_response( HASHHEX ha1, HASHHEX ha2,
-		struct authenticate_body *auth,
-		str* nc, str* cnonce,
-		HASHHEX response)
+void uac_calc_response(HASHHEX ha1, HASHHEX ha2, struct authenticate_body *auth,
+		str *nc, str *cnonce, HASHHEX response)
 {
 	MD5_CTX Md5Ctx;
 	HASH RespHash;
@@ -175,8 +164,7 @@ void uac_calc_response( HASHHEX ha1, HASHHEX ha2,
 	MD5Update(&Md5Ctx, auth->nonce.s, auth->nonce.len);
 	MD5Update(&Md5Ctx, ":", 1);
 
-	if ( auth->qop.len)
-	{
+	if(auth->qop.len) {
 		MD5Update(&Md5Ctx, nc->s, nc->len);
 		MD5Update(&Md5Ctx, ":", 1);
 		MD5Update(&Md5Ctx, cnonce->s, cnonce->len);

+ 8 - 14
src/modules/uac/auth_alg.h

@@ -28,19 +28,13 @@
 #include "auth.h"
 
 
-void uac_calc_HA1( struct uac_credential *crd,
-		struct authenticate_body *auth,
-		str* cnonce,
-		HASHHEX sess_key);
-
-void uac_calc_HA2( str *method, str *uri,
-		struct authenticate_body *auth,
-		HASHHEX hentity,
-		HASHHEX HA2Hex );
-
-void uac_calc_response( HASHHEX ha1, HASHHEX ha2,
-		struct authenticate_body *auth,
-		str* nc, str* cnonce,
-		HASHHEX response);
+void uac_calc_HA1(struct uac_credential *crd, struct authenticate_body *auth,
+		str *cnonce, HASHHEX sess_key);
+
+void uac_calc_HA2(str *method, str *uri, struct authenticate_body *auth,
+		HASHHEX hentity, HASHHEX HA2Hex);
+
+void uac_calc_response(HASHHEX ha1, HASHHEX ha2, struct authenticate_body *auth,
+		str *nc, str *cnonce, HASHHEX response);
 
 #endif

+ 206 - 219
src/modules/uac/auth_hdr.c

@@ -37,184 +37,178 @@
 #include "auth.h"
 
 
-#define AUTHENTICATE_MD5         (1<<0)
-#define AUTHENTICATE_MD5SESS     (1<<1)
-#define AUTHENTICATE_STALE       (1<<2)
+#define AUTHENTICATE_MD5 (1 << 0)
+#define AUTHENTICATE_MD5SESS (1 << 1)
+#define AUTHENTICATE_STALE (1 << 2)
 
-#define AUTHENTICATE_DIGEST_S    "Digest"
-#define AUTHENTICATE_DIGEST_LEN  (sizeof(AUTHENTICATE_DIGEST_S)-1)
+#define AUTHENTICATE_DIGEST_S "Digest"
+#define AUTHENTICATE_DIGEST_LEN (sizeof(AUTHENTICATE_DIGEST_S) - 1)
 
-#define LOWER1B(_n) \
-	((_n)|0x20)
-#define LOWER4B(_n) \
-	((_n)|0x20202020)
+#define LOWER1B(_n) ((_n) | 0x20)
+#define LOWER4B(_n) ((_n) | 0x20202020)
 #define GET4B(_p) \
-	((*(_p)<<24) + (*(_p+1)<<16) + (*(_p+2)<<8) + *(_p+3))
-#define GET3B(_p) \
-	((*(_p)<<24) + (*(_p+1)<<16) + (*(_p+2)<<8) + 0xff)
-
-#define CASE_5B(_hex4,_c5, _new_state, _quoted) \
-	case _hex4: \
-		if (p+5<end && LOWER1B(*(p+4))==_c5 ) \
-		{ \
-			p+=5; \
-			state = _new_state; \
-			quoted_val = _quoted; \
-		} else { \
-			p+=4; \
-		} \
+	((*(_p) << 24) + (*(_p + 1) << 16) + (*(_p + 2) << 8) + *(_p + 3))
+#define GET3B(_p) ((*(_p) << 24) + (*(_p + 1) << 16) + (*(_p + 2) << 8) + 0xff)
+
+#define CASE_5B(_hex4, _c5, _new_state, _quoted)      \
+	case _hex4:                                       \
+		if(p + 5 < end && LOWER1B(*(p + 4)) == _c5) { \
+			p += 5;                                   \
+			state = _new_state;                       \
+			quoted_val = _quoted;                     \
+		} else {                                      \
+			p += 4;                                   \
+		}                                             \
 		break;
 
-#define CASE_6B(_hex4,_c5,_c6, _new_state, _quoted) \
-	case _hex4: \
-		if (p+6<end && LOWER1B(*(p+4))==_c5 && LOWER1B(*(p+5))==_c6) \
-		{ \
-			p+=6; \
-			state = _new_state; \
-			quoted_val = _quoted; \
-		} else { \
-			p+=4; \
-		} \
+#define CASE_6B(_hex4, _c5, _c6, _new_state, _quoted) \
+	case _hex4:                                       \
+		if(p + 6 < end && LOWER1B(*(p + 4)) == _c5    \
+				&& LOWER1B(*(p + 5)) == _c6) {        \
+			p += 6;                                   \
+			state = _new_state;                       \
+			quoted_val = _quoted;                     \
+		} else {                                      \
+			p += 4;                                   \
+		}                                             \
 		break;
 
-#define OTHER_STATE      0
-#define QOP_STATE        1
-#define REALM_STATE      2
-#define NONCE_STATE      3
-#define STALE_STATE      4
-#define DOMAIN_STATE     5
-#define OPAQUE_STATE     6
-#define ALGORITHM_STATE  7
+#define OTHER_STATE 0
+#define QOP_STATE 1
+#define REALM_STATE 2
+#define NONCE_STATE 3
+#define STALE_STATE 4
+#define DOMAIN_STATE 5
+#define OPAQUE_STATE 6
+#define ALGORITHM_STATE 7
 
 
-
-int parse_authenticate_body( str *body, struct authenticate_body *auth)
+int parse_authenticate_body(str *body, struct authenticate_body *auth)
 {
 	char *p;
 	char *end;
-	int  n;
+	int n;
 	int state;
 	str name;
 	str val;
 	int quoted_val;
 
-	if (body->s==0 || *body->s==0 )
-	{
+	if(body->s == 0 || *body->s == 0) {
 		LM_ERR("empty body\n");
 		goto error;
 	}
 
-	memset( auth, 0, sizeof(struct authenticate_body));
+	memset(auth, 0, sizeof(struct authenticate_body));
 	p = body->s;
 	end = body->s + body->len;
 
 	/* parse the "digest" */
-	while (p<end && isspace((int)*p)) p++;
-	if (p+AUTHENTICATE_DIGEST_LEN>=end )
+	while(p < end && isspace((int)*p))
+		p++;
+	if(p + AUTHENTICATE_DIGEST_LEN >= end)
 		goto parse_error;
-	if (strncasecmp(p,AUTHENTICATE_DIGEST_S,AUTHENTICATE_DIGEST_LEN)!=0)
+	if(strncasecmp(p, AUTHENTICATE_DIGEST_S, AUTHENTICATE_DIGEST_LEN) != 0)
 		goto parse_error;
 	p += AUTHENTICATE_DIGEST_LEN;
-	if (!isspace((int)*p))
+	if(!isspace((int)*p))
 		goto parse_error;
 	p++;
-	while (p<end && isspace((int)*p)) p++;
-	if (p==end)
+	while(p < end && isspace((int)*p))
+		p++;
+	if(p == end)
 		goto parse_error;
 
-	while (p<end)
-	{
+	while(p < end) {
 		state = OTHER_STATE;
 		quoted_val = 0;
 		/* get name */
 		name.s = p;
-		if (p+4<end)
-		{
-			n = LOWER4B( GET4B(p) );
-			switch(n)
-			{
-				CASE_5B( 0x7265616c, 'm', REALM_STATE, 1); /*realm*/
-				CASE_5B( 0x6e6f6e63, 'e', NONCE_STATE, 1); /*nonce*/
-				CASE_5B( 0x7374616c, 'e', STALE_STATE, 0); /*stale*/
-				CASE_6B( 0x646f6d62, 'i', 'n', DOMAIN_STATE, 1); /*domain*/
-				CASE_6B( 0x6f706171, 'u', 'e', OPAQUE_STATE, 1); /*opaque*/
-				case 0x616c676f: /*algo*/
-					if (p+9<end && LOWER4B(GET4B(p+4))==0x72697468
-						&& LOWER1B(*(p+8))=='m' )
-					{
-						p+=9;
+		if(p + 4 < end) {
+			n = LOWER4B(GET4B(p));
+			switch(n) {
+				CASE_5B(0x7265616c, 'm', REALM_STATE, 1);		/*realm*/
+				CASE_5B(0x6e6f6e63, 'e', NONCE_STATE, 1);		/*nonce*/
+				CASE_5B(0x7374616c, 'e', STALE_STATE, 0);		/*stale*/
+				CASE_6B(0x646f6d62, 'i', 'n', DOMAIN_STATE, 1); /*domain*/
+				CASE_6B(0x6f706171, 'u', 'e', OPAQUE_STATE, 1); /*opaque*/
+				case 0x616c676f:								/*algo*/
+					if(p + 9 < end && LOWER4B(GET4B(p + 4)) == 0x72697468
+							&& LOWER1B(*(p + 8)) == 'm') {
+						p += 9;
 						state = ALGORITHM_STATE;
 					} else {
-						p+=4;
+						p += 4;
 					}
 					break;
 				default:
-					if ((n|0xff)==0x716f70ff) /*qop*/
+					if((n | 0xff) == 0x716f70ff) /*qop*/
 					{
 						state = QOP_STATE;
-						p+=3;
+						p += 3;
 					}
 			}
-		} else if (p+3<end) {
-			n = LOWER4B( GET3B(p) );
-			if (n==0x716f70ff) /*qop*/
+		} else if(p + 3 < end) {
+			n = LOWER4B(GET3B(p));
+			if(n == 0x716f70ff) /*qop*/
 			{
-				p+=3;
+				p += 3;
 				state = QOP_STATE;
 			}
 		}
 
 		/* parse to the "=" */
-		for( n=0 ; p<end&&!isspace((int)*p)&&*p!='=' ; n++,p++  );
-		if (p==end)
+		for(n = 0; p < end && !isspace((int)*p) && *p != '='; n++, p++)
+			;
+		if(p == end)
 			goto parse_error;
-		if (n!=0)
+		if(n != 0)
 			state = OTHER_STATE;
-		name.len = p-name.s;
+		name.len = p - name.s;
 		/* get the '=' */
-		while (p<end && isspace((int)*p)) p++;
-		if (p==end || *p!='=')
+		while(p < end && isspace((int)*p))
+			p++;
+		if(p == end || *p != '=')
 			goto parse_error;
 		p++;
 		/* get the value (quoted or not) */
-		while (p<end && isspace((int)*p)) p++;
-		if (p+1>=end || (quoted_val && *p!='\"'))
+		while(p < end && isspace((int)*p))
+			p++;
+		if(p + 1 >= end || (quoted_val && *p != '\"'))
 			goto parse_error;
-		if (!quoted_val && *p=='\"')
+		if(!quoted_val && *p == '\"')
 			quoted_val = 1;
-		if (quoted_val)
-		{
+		if(quoted_val) {
 			val.s = ++p;
-			while (p<end && *p!='\"')
+			while(p < end && *p != '\"')
 				p++;
-			if (p==end)
+			if(p == end)
 				goto error;
 		} else {
 			val.s = p;
-			while (p<end && !isspace((int)*p) && *p!=',')
+			while(p < end && !isspace((int)*p) && *p != ',')
 				p++;
 		}
 		val.len = p - val.s;
-		if (val.len==0)
+		if(val.len == 0)
 			val.s = 0;
 		/* consume the closing '"' if quoted */
 		p += quoted_val;
-		while (p<end && isspace((int)*p)) p++;
-		if (p<end && *p==',')
-		{
+		while(p < end && isspace((int)*p))
+			p++;
+		if(p < end && *p == ',') {
 			p++;
-			while (p<end && isspace((int)*p)) p++;
+			while(p < end && isspace((int)*p))
+				p++;
 		}
 
-		LM_DBG("<%.*s>=\"%.*s\" state=%d\n",
-			name.len,name.s,val.len,val.s,state);
+		LM_DBG("<%.*s>=\"%.*s\" state=%d\n", name.len, name.s, val.len, val.s,
+				state);
 
 		/* process the AVP */
-		switch (state)
-		{
+		switch(state) {
 			case QOP_STATE:
 				auth->qop = val;
-				if(val.len>=4 && !strncmp(val.s, "auth", 4))
+				if(val.len >= 4 && !strncmp(val.s, "auth", 4))
 					auth->flags |= QOP_AUTH;
 				break;
 			case REALM_STATE:
@@ -230,23 +224,22 @@ int parse_authenticate_body( str *body, struct authenticate_body *auth)
 				auth->opaque = val;
 				break;
 			case ALGORITHM_STATE:
-				if (val.len==3)
-				{
-					if ( LOWER4B(GET3B(val.s))==0x6d6435ff) /*MD5*/
+				if(val.len == 3) {
+					if(LOWER4B(GET3B(val.s)) == 0x6d6435ff) /*MD5*/
 						auth->flags |= AUTHENTICATE_MD5;
 				} else {
-					LM_ERR("unsupported algorithm \"%.*s\"\n",val.len,val.s);
+					LM_ERR("unsupported algorithm \"%.*s\"\n", val.len, val.s);
 					goto error;
 				}
 				break;
 			case STALE_STATE:
-				if (val.len==4 && LOWER4B(GET4B(val.s))==0x74727565) /*true*/
-				{
-						auth->flags |= AUTHENTICATE_STALE;
-				} else if ( !(val.len==5 && LOWER1B(val.s[4])=='e' && 
-					LOWER4B(GET4B(val.s))==0x66616c73) )
+				if(val.len == 4 && LOWER4B(GET4B(val.s)) == 0x74727565) /*true*/
 				{
-					LM_ERR("unsupported stale value \"%.*s\"\n",val.len,val.s);
+					auth->flags |= AUTHENTICATE_STALE;
+				} else if(!(val.len == 5 && LOWER1B(val.s[4]) == 'e'
+								  && LOWER4B(GET4B(val.s)) == 0x66616c73)) {
+					LM_ERR("unsupported stale value \"%.*s\"\n", val.len,
+							val.s);
 					goto error;
 				}
 				break;
@@ -256,63 +249,62 @@ int parse_authenticate_body( str *body, struct authenticate_body *auth)
 	}
 
 	/* some checkings */
-	if (auth->nonce.s==0 || auth->realm.s==0)
-	{
+	if(auth->nonce.s == 0 || auth->realm.s == 0) {
 		LM_ERR("realm or nonce missing\n");
 		goto error;
 	}
 
 	return 0;
 parse_error:
-		LM_ERR("parse error in <%.*s> around %ld\n", body->len, body->s, (long)(p-body->s));
+	LM_ERR("parse error in <%.*s> around %ld\n", body->len, body->s,
+			(long)(p - body->s));
 error:
 	return -1;
 }
 
 
-#define AUTHORIZATION_HDR_START       "Authorization: Digest "
-#define AUTHORIZATION_HDR_START_LEN   (sizeof(AUTHORIZATION_HDR_START)-1)
-
-#define PROXY_AUTHORIZATION_HDR_START      "Proxy-Authorization: Digest "
-#define PROXY_AUTHORIZATION_HDR_START_LEN  \
-	(sizeof(PROXY_AUTHORIZATION_HDR_START)-1)
-
-#define USERNAME_FIELD_S         "username=\""
-#define USERNAME_FIELD_LEN       (sizeof(USERNAME_FIELD_S)-1)
-#define REALM_FIELD_S            "realm=\""
-#define REALM_FIELD_LEN          (sizeof(REALM_FIELD_S)-1)
-#define NONCE_FIELD_S            "nonce=\""
-#define NONCE_FIELD_LEN          (sizeof(NONCE_FIELD_S)-1)
-#define URI_FIELD_S              "uri=\""
-#define URI_FIELD_LEN            (sizeof(URI_FIELD_S)-1)
-#define OPAQUE_FIELD_S           "opaque=\""
-#define OPAQUE_FIELD_LEN         (sizeof(OPAQUE_FIELD_S)-1)
-#define RESPONSE_FIELD_S         "response=\""
-#define RESPONSE_FIELD_LEN       (sizeof(RESPONSE_FIELD_S)-1)
-#define ALGORITHM_FIELD_S        "algorithm=MD5"
-#define ALGORITHM_FIELD_LEN       (sizeof(ALGORITHM_FIELD_S)-1)
-#define FIELD_SEPARATOR_S        "\", "
-#define FIELD_SEPARATOR_LEN      (sizeof(FIELD_SEPARATOR_S)-1)
-#define FIELD_SEPARATOR_UQ_S     ", "
-#define FIELD_SEPARATOR_UQ_LEN   (sizeof(FIELD_SEPARATOR_UQ_S)-1)
-
-#define QOP_FIELD_S              "qop="
-#define QOP_FIELD_LEN            (sizeof(QOP_FIELD_S)-1)
-#define NC_FIELD_S               "nc="
-#define NC_FIELD_LEN             (sizeof(NC_FIELD_S)-1)
-#define CNONCE_FIELD_S           "cnonce=\""
-#define CNONCE_FIELD_LEN         (sizeof(CNONCE_FIELD_S)-1)
-
-#define add_string( _p, _s, _l) \
-	do {\
-		memcpy( _p, _s, _l);\
-		_p += _l; \
-	}while(0)
-
-
-str* build_authorization_hdr(int code, str *uri, 
-		struct uac_credential *crd, struct authenticate_body *auth,
-		char *response)
+#define AUTHORIZATION_HDR_START "Authorization: Digest "
+#define AUTHORIZATION_HDR_START_LEN (sizeof(AUTHORIZATION_HDR_START) - 1)
+
+#define PROXY_AUTHORIZATION_HDR_START "Proxy-Authorization: Digest "
+#define PROXY_AUTHORIZATION_HDR_START_LEN \
+	(sizeof(PROXY_AUTHORIZATION_HDR_START) - 1)
+
+#define USERNAME_FIELD_S "username=\""
+#define USERNAME_FIELD_LEN (sizeof(USERNAME_FIELD_S) - 1)
+#define REALM_FIELD_S "realm=\""
+#define REALM_FIELD_LEN (sizeof(REALM_FIELD_S) - 1)
+#define NONCE_FIELD_S "nonce=\""
+#define NONCE_FIELD_LEN (sizeof(NONCE_FIELD_S) - 1)
+#define URI_FIELD_S "uri=\""
+#define URI_FIELD_LEN (sizeof(URI_FIELD_S) - 1)
+#define OPAQUE_FIELD_S "opaque=\""
+#define OPAQUE_FIELD_LEN (sizeof(OPAQUE_FIELD_S) - 1)
+#define RESPONSE_FIELD_S "response=\""
+#define RESPONSE_FIELD_LEN (sizeof(RESPONSE_FIELD_S) - 1)
+#define ALGORITHM_FIELD_S "algorithm=MD5"
+#define ALGORITHM_FIELD_LEN (sizeof(ALGORITHM_FIELD_S) - 1)
+#define FIELD_SEPARATOR_S "\", "
+#define FIELD_SEPARATOR_LEN (sizeof(FIELD_SEPARATOR_S) - 1)
+#define FIELD_SEPARATOR_UQ_S ", "
+#define FIELD_SEPARATOR_UQ_LEN (sizeof(FIELD_SEPARATOR_UQ_S) - 1)
+
+#define QOP_FIELD_S "qop="
+#define QOP_FIELD_LEN (sizeof(QOP_FIELD_S) - 1)
+#define NC_FIELD_S "nc="
+#define NC_FIELD_LEN (sizeof(NC_FIELD_S) - 1)
+#define CNONCE_FIELD_S "cnonce=\""
+#define CNONCE_FIELD_LEN (sizeof(CNONCE_FIELD_S) - 1)
+
+#define add_string(_p, _s, _l) \
+	do {                       \
+		memcpy(_p, _s, _l);    \
+		_p += _l;              \
+	} while(0)
+
+
+str *build_authorization_hdr(int code, str *uri, struct uac_credential *crd,
+		struct authenticate_body *auth, char *response)
 {
 	static str _uac_auth_hdr;
 	char *p;
@@ -322,94 +314,89 @@ str* build_authorization_hdr(int code, str *uri,
 	response_len = strlen(response);
 
 	/* compile then len */
-	len = (code==401?
-		AUTHORIZATION_HDR_START_LEN:PROXY_AUTHORIZATION_HDR_START_LEN) +
-		USERNAME_FIELD_LEN + crd->user.len + FIELD_SEPARATOR_LEN +
-		REALM_FIELD_LEN + crd->realm.len + FIELD_SEPARATOR_LEN +
-		NONCE_FIELD_LEN + auth->nonce.len + FIELD_SEPARATOR_LEN +
-		URI_FIELD_LEN + uri->len + FIELD_SEPARATOR_LEN +
-		(auth->opaque.len?
-			(OPAQUE_FIELD_LEN + auth->opaque.len + FIELD_SEPARATOR_LEN):0) +
-		RESPONSE_FIELD_LEN + response_len + FIELD_SEPARATOR_LEN +
-		ALGORITHM_FIELD_LEN + CRLF_LEN;
-	if((auth->flags&QOP_AUTH) || (auth->flags&QOP_AUTH_INT))
-		len += QOP_FIELD_LEN + 4 /*auth*/ + FIELD_SEPARATOR_UQ_LEN +
-				NC_FIELD_LEN + auth->nc->len + FIELD_SEPARATOR_UQ_LEN +
-				CNONCE_FIELD_LEN + auth->cnonce->len + FIELD_SEPARATOR_LEN;
-
-	_uac_auth_hdr.s = (char*)pkg_malloc( len + 1);
-	if (_uac_auth_hdr.s==0)
-	{
+	len = (code == 401 ? AUTHORIZATION_HDR_START_LEN
+					   : PROXY_AUTHORIZATION_HDR_START_LEN)
+		  + USERNAME_FIELD_LEN + crd->user.len + FIELD_SEPARATOR_LEN
+		  + REALM_FIELD_LEN + crd->realm.len + FIELD_SEPARATOR_LEN
+		  + NONCE_FIELD_LEN + auth->nonce.len + FIELD_SEPARATOR_LEN
+		  + URI_FIELD_LEN + uri->len + FIELD_SEPARATOR_LEN
+		  + (auth->opaque.len ? (
+					 OPAQUE_FIELD_LEN + auth->opaque.len + FIELD_SEPARATOR_LEN)
+							  : 0)
+		  + RESPONSE_FIELD_LEN + response_len + FIELD_SEPARATOR_LEN
+		  + ALGORITHM_FIELD_LEN + CRLF_LEN;
+	if((auth->flags & QOP_AUTH) || (auth->flags & QOP_AUTH_INT))
+		len += QOP_FIELD_LEN + 4 /*auth*/ + FIELD_SEPARATOR_UQ_LEN
+			   + NC_FIELD_LEN + auth->nc->len + FIELD_SEPARATOR_UQ_LEN
+			   + CNONCE_FIELD_LEN + auth->cnonce->len + FIELD_SEPARATOR_LEN;
+
+	_uac_auth_hdr.s = (char *)pkg_malloc(len + 1);
+	if(_uac_auth_hdr.s == 0) {
 		PKG_MEM_ERROR;
 		goto error;
 	}
 
 	p = _uac_auth_hdr.s;
 	/* header start */
-	if (code==401)
-	{
-		add_string( p, AUTHORIZATION_HDR_START USERNAME_FIELD_S,
-			AUTHORIZATION_HDR_START_LEN+USERNAME_FIELD_LEN);
+	if(code == 401) {
+		add_string(p, AUTHORIZATION_HDR_START USERNAME_FIELD_S,
+				AUTHORIZATION_HDR_START_LEN + USERNAME_FIELD_LEN);
 	} else {
-		add_string( p, PROXY_AUTHORIZATION_HDR_START USERNAME_FIELD_S,
-			PROXY_AUTHORIZATION_HDR_START_LEN+USERNAME_FIELD_LEN);
+		add_string(p, PROXY_AUTHORIZATION_HDR_START USERNAME_FIELD_S,
+				PROXY_AUTHORIZATION_HDR_START_LEN + USERNAME_FIELD_LEN);
 	}
 	/* username */
-	add_string( p, crd->user.s, crd->user.len);
+	add_string(p, crd->user.s, crd->user.len);
 	/* REALM */
-	add_string( p, FIELD_SEPARATOR_S REALM_FIELD_S,
-		FIELD_SEPARATOR_LEN+REALM_FIELD_LEN);
-	add_string( p, crd->realm.s, crd->realm.len);
+	add_string(p, FIELD_SEPARATOR_S REALM_FIELD_S,
+			FIELD_SEPARATOR_LEN + REALM_FIELD_LEN);
+	add_string(p, crd->realm.s, crd->realm.len);
 	/* NONCE */
-	add_string( p, FIELD_SEPARATOR_S NONCE_FIELD_S, 
-		FIELD_SEPARATOR_LEN+NONCE_FIELD_LEN);
-	add_string( p, auth->nonce.s, auth->nonce.len);
+	add_string(p, FIELD_SEPARATOR_S NONCE_FIELD_S,
+			FIELD_SEPARATOR_LEN + NONCE_FIELD_LEN);
+	add_string(p, auth->nonce.s, auth->nonce.len);
 	/* URI */
-	add_string( p, FIELD_SEPARATOR_S URI_FIELD_S,
-		FIELD_SEPARATOR_LEN+URI_FIELD_LEN);
-	add_string( p, uri->s, uri->len);
+	add_string(p, FIELD_SEPARATOR_S URI_FIELD_S,
+			FIELD_SEPARATOR_LEN + URI_FIELD_LEN);
+	add_string(p, uri->s, uri->len);
 	/* OPAQUE */
-	if (auth->opaque.len )
-	{
-		add_string( p, FIELD_SEPARATOR_S OPAQUE_FIELD_S, 
-			FIELD_SEPARATOR_LEN+OPAQUE_FIELD_LEN);
-		add_string( p, auth->opaque.s, auth->opaque.len);
+	if(auth->opaque.len) {
+		add_string(p, FIELD_SEPARATOR_S OPAQUE_FIELD_S,
+				FIELD_SEPARATOR_LEN + OPAQUE_FIELD_LEN);
+		add_string(p, auth->opaque.s, auth->opaque.len);
 	}
-	if((auth->flags&QOP_AUTH) || (auth->flags&QOP_AUTH_INT))
-	{
-		add_string( p, FIELD_SEPARATOR_S QOP_FIELD_S, 
-			FIELD_SEPARATOR_LEN+QOP_FIELD_LEN);
-		add_string( p, "auth", 4);
-		add_string( p, FIELD_SEPARATOR_UQ_S NC_FIELD_S, 
-			FIELD_SEPARATOR_UQ_LEN+NC_FIELD_LEN);
-		add_string( p, auth->nc->s, auth->nc->len);
-		add_string( p, FIELD_SEPARATOR_UQ_S CNONCE_FIELD_S, 
-			FIELD_SEPARATOR_UQ_LEN+CNONCE_FIELD_LEN);
-		add_string( p, auth->cnonce->s, auth->cnonce->len);
+	if((auth->flags & QOP_AUTH) || (auth->flags & QOP_AUTH_INT)) {
+		add_string(p, FIELD_SEPARATOR_S QOP_FIELD_S,
+				FIELD_SEPARATOR_LEN + QOP_FIELD_LEN);
+		add_string(p, "auth", 4);
+		add_string(p, FIELD_SEPARATOR_UQ_S NC_FIELD_S,
+				FIELD_SEPARATOR_UQ_LEN + NC_FIELD_LEN);
+		add_string(p, auth->nc->s, auth->nc->len);
+		add_string(p, FIELD_SEPARATOR_UQ_S CNONCE_FIELD_S,
+				FIELD_SEPARATOR_UQ_LEN + CNONCE_FIELD_LEN);
+		add_string(p, auth->cnonce->s, auth->cnonce->len);
 	}
 	/* RESPONSE */
-	add_string( p, FIELD_SEPARATOR_S RESPONSE_FIELD_S,
-		FIELD_SEPARATOR_LEN+RESPONSE_FIELD_LEN);
-	add_string( p, response, response_len);
+	add_string(p, FIELD_SEPARATOR_S RESPONSE_FIELD_S,
+			FIELD_SEPARATOR_LEN + RESPONSE_FIELD_LEN);
+	add_string(p, response, response_len);
 	/* ALGORITHM */
-	add_string( p, FIELD_SEPARATOR_S ALGORITHM_FIELD_S CRLF,
-		FIELD_SEPARATOR_LEN+ALGORITHM_FIELD_LEN+CRLF_LEN);
+	add_string(p, FIELD_SEPARATOR_S ALGORITHM_FIELD_S CRLF,
+			FIELD_SEPARATOR_LEN + ALGORITHM_FIELD_LEN + CRLF_LEN);
 
 	_uac_auth_hdr.len = p - _uac_auth_hdr.s;
 
-	if (_uac_auth_hdr.len!=len)
-	{
+	if(_uac_auth_hdr.len != len) {
 		LM_CRIT("BUG: bad buffer computation "
-			"(%d<>%d)\n",len,_uac_auth_hdr.len);
-		pkg_free( _uac_auth_hdr.s );
+				"(%d<>%d)\n",
+				len, _uac_auth_hdr.len);
+		pkg_free(_uac_auth_hdr.s);
 		goto error;
 	}
 
-	LM_DBG("hdr is <%.*s>\n",
-		_uac_auth_hdr.len,_uac_auth_hdr.s);
+	LM_DBG("hdr is <%.*s>\n", _uac_auth_hdr.len, _uac_auth_hdr.s);
 
 	return &_uac_auth_hdr;
 error:
 	return 0;
 }
-

+ 3 - 4
src/modules/uac/auth_hdr.h

@@ -27,10 +27,9 @@
 
 #include "auth.h"
 
-int parse_authenticate_body( str *body, struct authenticate_body *auth);
+int parse_authenticate_body(str *body, struct authenticate_body *auth);
 
-str* build_authorization_hdr(int code, str *uri,
-		struct uac_credential *crd, struct authenticate_body *auth,
-		char *response);
+str *build_authorization_hdr(int code, str *uri, struct uac_credential *crd,
+		struct authenticate_body *auth, char *response);
 
 #endif

Dosya farkı çok büyük olduğundan ihmal edildi
+ 261 - 268
src/modules/uac/replace.c


+ 7 - 6
src/modules/uac/replace.h

@@ -27,16 +27,17 @@
 #include "../../core/str.h"
 #include "../../modules/tm/t_hooks.h"
 
-#define UAC_NO_RESTORE      (0)
-#define UAC_AUTO_RESTORE    (1)
-#define UAC_MANUAL_RESTORE  (2)
+#define UAC_NO_RESTORE (0)
+#define UAC_AUTO_RESTORE (1)
+#define UAC_MANUAL_RESTORE (2)
 
 void init_from_replacer(void);
 
-int replace_uri( struct sip_msg *msg, str *display, str *uri,
-					struct hdr_field *hdr, str *rr_param, str* restore_avp, int check_from);
+int replace_uri(struct sip_msg *msg, str *display, str *uri,
+		struct hdr_field *hdr, 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);
+int restore_uri(
+		struct sip_msg *msg, str *rr_param, str *restore_avp, int check_from);
 
 /* RR callback functions */
 void rr_checker(struct sip_msg *msg, str *r_param, void *cb_param);

+ 242 - 233
src/modules/uac/uac.c

@@ -67,10 +67,10 @@ MODULE_VERSION
 
 
 /* local variable used for init */
-static char* restore_mode_str = NULL;
-static char* auth_username_avp = NULL;
-static char* auth_realm_avp = NULL;
-static char* auth_password_avp = NULL;
+static char *restore_mode_str = NULL;
+static char *auth_username_avp = NULL;
+static char *auth_realm_avp = NULL;
+static char *auth_password_avp = NULL;
 unsigned short restore_from_avp_type;
 int_str restore_from_avp_name;
 unsigned short restore_to_avp_type;
@@ -91,23 +91,23 @@ pv_spec_t auth_username_spec;
 pv_spec_t auth_realm_spec;
 pv_spec_t auth_password_spec;
 str uac_default_socket = STR_NULL;
-struct socket_info * uac_default_sockinfo = NULL;
+struct socket_info *uac_default_sockinfo = NULL;
 
 str uac_event_callback = STR_NULL;
 
-static int w_replace_from(struct sip_msg* msg, char* p1, char* p2);
-static int w_restore_from(struct sip_msg* msg, char* p1, char* p2);
-static int w_replace_to(struct sip_msg* msg, char* p1, char* p2);
-static int w_restore_to(struct sip_msg* msg, char* p1, char* p2);
-static int w_uac_auth(struct sip_msg* msg, char* str, char* str2);
-static int w_uac_auth_mode(struct sip_msg* msg, char* pmode, char* str2);
-static int w_uac_reg_lookup(struct sip_msg* msg, char* src, char* dst);
-static int w_uac_reg_lookup_uri(struct sip_msg* msg, char* src, char* dst);
-static int w_uac_reg_status(struct sip_msg* msg, char* src, char* dst);
-static int w_uac_reg_request_to(struct sip_msg* msg, char* src, char* mode_s);
-static int w_uac_reg_enable(struct sip_msg* msg, char* pfilter, char* pval);
-static int w_uac_reg_disable(struct sip_msg* msg, char* pfilter, char* pval);
-static int w_uac_reg_refresh(struct sip_msg* msg, char* pluuid, char* p2);
+static int w_replace_from(struct sip_msg *msg, char *p1, char *p2);
+static int w_restore_from(struct sip_msg *msg, char *p1, char *p2);
+static int w_replace_to(struct sip_msg *msg, char *p1, char *p2);
+static int w_restore_to(struct sip_msg *msg, char *p1, char *p2);
+static int w_uac_auth(struct sip_msg *msg, char *str, char *str2);
+static int w_uac_auth_mode(struct sip_msg *msg, char *pmode, char *str2);
+static int w_uac_reg_lookup(struct sip_msg *msg, char *src, char *dst);
+static int w_uac_reg_lookup_uri(struct sip_msg *msg, char *src, char *dst);
+static int w_uac_reg_status(struct sip_msg *msg, char *src, char *dst);
+static int w_uac_reg_request_to(struct sip_msg *msg, char *src, char *mode_s);
+static int w_uac_reg_enable(struct sip_msg *msg, char *pfilter, char *pval);
+static int w_uac_reg_disable(struct sip_msg *msg, char *pfilter, char *pval);
+static int w_uac_reg_refresh(struct sip_msg *msg, char *pluuid, char *p2);
 static int mod_init(void);
 static void mod_destroy(void);
 static int child_init(int rank);
@@ -117,106 +117,98 @@ extern int _uac_reg_gc_interval;
 extern int _uac_reg_use_domain;
 
 static pv_export_t mod_pvs[] = {
-	{ {"uac_req", sizeof("uac_req")-1}, PVT_OTHER, pv_get_uac_req, pv_set_uac_req,
-		pv_parse_uac_req_name, 0, 0, 0 },
-	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
-};
+		{{"uac_req", sizeof("uac_req") - 1}, PVT_OTHER, pv_get_uac_req,
+				pv_set_uac_req, pv_parse_uac_req_name, 0, 0, 0},
+		{{0, 0}, 0, 0, 0, 0, 0, 0, 0}};
 
 
 /* Exported functions */
-static cmd_export_t cmds[]={
-	{"uac_replace_from",  (cmd_function)w_replace_from,  2, fixup_spve_spve, 0,
-		REQUEST_ROUTE | BRANCH_ROUTE },
-	{"uac_replace_from",  (cmd_function)w_replace_from,  1, fixup_spve_spve, 0,
-		REQUEST_ROUTE | BRANCH_ROUTE },
-	{"uac_restore_from",  (cmd_function)w_restore_from,  0,		  0, 0,
-		REQUEST_ROUTE },
-	{"uac_replace_to",  (cmd_function)w_replace_to,  2, fixup_spve_spve, 0,
-		REQUEST_ROUTE | BRANCH_ROUTE },
-	{"uac_replace_to",  (cmd_function)w_replace_to,  1, fixup_spve_spve, 0,
-		REQUEST_ROUTE | BRANCH_ROUTE },
-	{"uac_restore_to",  (cmd_function)w_restore_to,  0, 0, 0, REQUEST_ROUTE },
-	{"uac_auth",	  (cmd_function)w_uac_auth,       0, 0, 0, 
-		FAILURE_ROUTE | BRANCH_FAILURE_ROUTE |  EVENT_ROUTE },
-	{"uac_auth",      (cmd_function)w_uac_auth_mode,  1,
-			fixup_igp_null, fixup_free_igp_null, 
-		FAILURE_ROUTE | BRANCH_FAILURE_ROUTE |  EVENT_ROUTE },
-	{"uac_auth_mode", (cmd_function)w_uac_auth_mode,  1,
-			fixup_igp_null, fixup_free_igp_null,
-		FAILURE_ROUTE | BRANCH_FAILURE_ROUTE |  EVENT_ROUTE },
-	{"uac_req_send",  (cmd_function)w_uac_req_send,   0, 0, 0, ANY_ROUTE},
-	{"uac_reg_lookup",  (cmd_function)w_uac_reg_lookup,  2, fixup_spve_pvar,
-		fixup_free_spve_pvar, ANY_ROUTE },
-	{"uac_reg_lookup_uri", (cmd_function)w_uac_reg_lookup_uri, 2, fixup_spve_pvar,
-		fixup_free_spve_pvar, ANY_ROUTE },
-	{"uac_reg_status",  (cmd_function)w_uac_reg_status,  1, fixup_spve_null, 0,
-		ANY_ROUTE },
-	{"uac_reg_request_to",  (cmd_function)w_uac_reg_request_to,  2,
-		fixup_spve_igp, fixup_free_spve_igp,
-		REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE },
-	{"uac_reg_enable",   (cmd_function)w_uac_reg_enable,   2, fixup_spve_spve,
-		fixup_free_spve_spve, ANY_ROUTE },
-	{"uac_reg_disable",  (cmd_function)w_uac_reg_disable,  2, fixup_spve_spve,
-		fixup_free_spve_spve, ANY_ROUTE },
-	{"uac_reg_refresh",  (cmd_function)w_uac_reg_refresh,  1, fixup_spve_null,
-		fixup_free_spve_null, ANY_ROUTE },
-	{"bind_uac", (cmd_function)bind_uac,		  1,  0, 0, 0},
-	{0,0,0,0,0,0}
-};
-
+static cmd_export_t cmds[] = {
+		{"uac_replace_from", (cmd_function)w_replace_from, 2, fixup_spve_spve,
+				0, REQUEST_ROUTE | BRANCH_ROUTE},
+		{"uac_replace_from", (cmd_function)w_replace_from, 1, fixup_spve_spve,
+				0, REQUEST_ROUTE | BRANCH_ROUTE},
+		{"uac_restore_from", (cmd_function)w_restore_from, 0, 0, 0,
+				REQUEST_ROUTE},
+		{"uac_replace_to", (cmd_function)w_replace_to, 2, fixup_spve_spve, 0,
+				REQUEST_ROUTE | BRANCH_ROUTE},
+		{"uac_replace_to", (cmd_function)w_replace_to, 1, fixup_spve_spve, 0,
+				REQUEST_ROUTE | BRANCH_ROUTE},
+		{"uac_restore_to", (cmd_function)w_restore_to, 0, 0, 0, REQUEST_ROUTE},
+		{"uac_auth", (cmd_function)w_uac_auth, 0, 0, 0,
+				FAILURE_ROUTE | BRANCH_FAILURE_ROUTE | EVENT_ROUTE},
+		{"uac_auth", (cmd_function)w_uac_auth_mode, 1, fixup_igp_null,
+				fixup_free_igp_null,
+				FAILURE_ROUTE | BRANCH_FAILURE_ROUTE | EVENT_ROUTE},
+		{"uac_auth_mode", (cmd_function)w_uac_auth_mode, 1, fixup_igp_null,
+				fixup_free_igp_null,
+				FAILURE_ROUTE | BRANCH_FAILURE_ROUTE | EVENT_ROUTE},
+		{"uac_req_send", (cmd_function)w_uac_req_send, 0, 0, 0, ANY_ROUTE},
+		{"uac_reg_lookup", (cmd_function)w_uac_reg_lookup, 2, fixup_spve_pvar,
+				fixup_free_spve_pvar, ANY_ROUTE},
+		{"uac_reg_lookup_uri", (cmd_function)w_uac_reg_lookup_uri, 2,
+				fixup_spve_pvar, fixup_free_spve_pvar, ANY_ROUTE},
+		{"uac_reg_status", (cmd_function)w_uac_reg_status, 1, fixup_spve_null,
+				0, ANY_ROUTE},
+		{"uac_reg_request_to", (cmd_function)w_uac_reg_request_to, 2,
+				fixup_spve_igp, fixup_free_spve_igp,
+				REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE},
+		{"uac_reg_enable", (cmd_function)w_uac_reg_enable, 2, fixup_spve_spve,
+				fixup_free_spve_spve, ANY_ROUTE},
+		{"uac_reg_disable", (cmd_function)w_uac_reg_disable, 2, fixup_spve_spve,
+				fixup_free_spve_spve, ANY_ROUTE},
+		{"uac_reg_refresh", (cmd_function)w_uac_reg_refresh, 1, fixup_spve_null,
+				fixup_free_spve_null, ANY_ROUTE},
+		{"bind_uac", (cmd_function)bind_uac, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0}};
 
 
 /* Exported parameters */
 static param_export_t params[] = {
-	{"rr_from_store_param", PARAM_STR,			&rr_from_param       },
-	{"rr_to_store_param",   PARAM_STR,			&rr_to_param       },
-	{"restore_mode",	PARAM_STRING,			&restore_mode_str      },
-	{"restore_dlg",	 	INT_PARAM,			&uac_restore_dlg       },
-	{"restore_passwd",      PARAM_STR,			&uac_passwd	  },
-	{"restore_from_avp",	PARAM_STR,			&restore_from_avp },
-	{"restore_to_avp",	PARAM_STR,			&restore_to_avp },
-	{"credential",		PARAM_STRING|USE_FUNC_PARAM,	(void*)&add_credential },
-	{"auth_username_avp",	PARAM_STRING,			&auth_username_avp     },
-	{"auth_realm_avp",	PARAM_STRING,			&auth_realm_avp	},
-	{"auth_password_avp",	PARAM_STRING,			&auth_password_avp     },
-	{"reg_db_url",		PARAM_STR,			&reg_db_url	  },
-	{"reg_db_table",	PARAM_STR,			&reg_db_table	},
-	{"reg_contact_addr",	PARAM_STR,			&reg_contact_addr    },
-	{"reg_timer_interval",	INT_PARAM,			&reg_timer_interval	},
-	{"reg_retry_interval",	INT_PARAM,	  		&reg_retry_interval    },
-	{"reg_keep_callid",	INT_PARAM,			&reg_keep_callid       },
-	{"reg_random_delay",	INT_PARAM,			&reg_random_delay      },
-	{"reg_active",	INT_PARAM,			&reg_active_param      },
-	{"reg_gc_interval",		INT_PARAM,	&_uac_reg_gc_interval	},
-	{"reg_hash_size",	INT_PARAM,		&reg_htable_size      },
-	{"reg_use_domain",	PARAM_INT,		&_uac_reg_use_domain  },
-	{"default_socket",	PARAM_STR, &uac_default_socket},
-	{"event_callback",	PARAM_STR,	&uac_event_callback},
-	{0, 0, 0}
-};
-
-
-
-struct module_exports exports= {
-	"uac",           /* module name */
-	DEFAULT_DLFLAGS, /* dlopen flags */
-	cmds,            /* cmd exports */
-	params,          /* param exports */
-	0,               /* RPC method exports */
-	mod_pvs,         /* pseudo-variables exports */
-	0,               /* response handling function */
-	mod_init,        /* module initialization function */
-	child_init,      /* per-child init function */
-	mod_destroy
-};
-
-
-inline static int parse_auth_avp( char *avp_spec, pv_spec_t *avp, char *txt)
+		{"rr_from_store_param", PARAM_STR, &rr_from_param},
+		{"rr_to_store_param", PARAM_STR, &rr_to_param},
+		{"restore_mode", PARAM_STRING, &restore_mode_str},
+		{"restore_dlg", INT_PARAM, &uac_restore_dlg},
+		{"restore_passwd", PARAM_STR, &uac_passwd},
+		{"restore_from_avp", PARAM_STR, &restore_from_avp},
+		{"restore_to_avp", PARAM_STR, &restore_to_avp},
+		{"credential", PARAM_STRING | USE_FUNC_PARAM, (void *)&add_credential},
+		{"auth_username_avp", PARAM_STRING, &auth_username_avp},
+		{"auth_realm_avp", PARAM_STRING, &auth_realm_avp},
+		{"auth_password_avp", PARAM_STRING, &auth_password_avp},
+		{"reg_db_url", PARAM_STR, &reg_db_url},
+		{"reg_db_table", PARAM_STR, &reg_db_table},
+		{"reg_contact_addr", PARAM_STR, &reg_contact_addr},
+		{"reg_timer_interval", INT_PARAM, &reg_timer_interval},
+		{"reg_retry_interval", INT_PARAM, &reg_retry_interval},
+		{"reg_keep_callid", INT_PARAM, &reg_keep_callid},
+		{"reg_random_delay", INT_PARAM, &reg_random_delay},
+		{"reg_active", INT_PARAM, &reg_active_param},
+		{"reg_gc_interval", INT_PARAM, &_uac_reg_gc_interval},
+		{"reg_hash_size", INT_PARAM, &reg_htable_size},
+		{"reg_use_domain", PARAM_INT, &_uac_reg_use_domain},
+		{"default_socket", PARAM_STR, &uac_default_socket},
+		{"event_callback", PARAM_STR, &uac_event_callback}, {0, 0, 0}};
+
+
+struct module_exports exports = {"uac", /* module name */
+		DEFAULT_DLFLAGS,				/* dlopen flags */
+		cmds,							/* cmd exports */
+		params,							/* param exports */
+		0,								/* RPC method exports */
+		mod_pvs,						/* pseudo-variables exports */
+		0,								/* response handling function */
+		mod_init,						/* module initialization function */
+		child_init,						/* per-child init function */
+		mod_destroy};
+
+
+inline static int parse_auth_avp(char *avp_spec, pv_spec_t *avp, char *txt)
 {
 	str s;
-	s.s = avp_spec; s.len = strlen(s.s);
-	if (pv_parse_spec(&s, avp)==NULL) {
-		LM_ERR("malformed or non AVP %s AVP definition\n",txt);
+	s.s = avp_spec;
+	s.len = strlen(s.s);
+	if(pv_parse_spec(&s, avp) == NULL) {
+		LM_ERR("malformed or non AVP %s AVP definition\n", txt);
 		return -1;
 	}
 	return 0;
@@ -229,53 +221,57 @@ static int mod_init(void)
 	str host;
 	int port, proto;
 
-	if (restore_mode_str && *restore_mode_str) {
-		if (strcasecmp(restore_mode_str,"none")==0) {
+	if(restore_mode_str && *restore_mode_str) {
+		if(strcasecmp(restore_mode_str, "none") == 0) {
 			restore_mode = UAC_NO_RESTORE;
-		} else if (strcasecmp(restore_mode_str,"manual")==0) {
+		} else if(strcasecmp(restore_mode_str, "manual") == 0) {
 			restore_mode = UAC_MANUAL_RESTORE;
-		} else if (strcasecmp(restore_mode_str,"auto")==0) {
+		} else if(strcasecmp(restore_mode_str, "auto") == 0) {
 			restore_mode = UAC_AUTO_RESTORE;
 		} else {
-			LM_ERR("unsupported value '%s' for restore_mode\n",  restore_mode_str);
+			LM_ERR("unsupported value '%s' for restore_mode\n",
+					restore_mode_str);
 			goto error;
 		}
 	}
 
-	if ( (rr_from_param.len==0 || rr_to_param.len==0) && restore_mode!=UAC_NO_RESTORE)
-	{
+	if((rr_from_param.len == 0 || rr_to_param.len == 0)
+			&& restore_mode != UAC_NO_RESTORE) {
 		LM_ERR("rr_store_param cannot be empty if FROM is restoreable\n");
 		goto error;
 	}
 
 	/* parse the auth AVP spesc, if any */
-	if ( auth_username_avp || auth_password_avp || auth_realm_avp) {
-		if (!auth_username_avp || !auth_password_avp || !auth_realm_avp) {
+	if(auth_username_avp || auth_password_avp || auth_realm_avp) {
+		if(!auth_username_avp || !auth_password_avp || !auth_realm_avp) {
 			LM_ERR("partial definition of auth AVP!");
 			goto error;
 		}
-		if ( parse_auth_avp(auth_realm_avp, &auth_realm_spec, "realm")<0
-				|| parse_auth_avp(auth_username_avp, &auth_username_spec, "username")<0
-				|| parse_auth_avp(auth_password_avp, &auth_password_spec, "password")<0
-		   ) {
+		if(parse_auth_avp(auth_realm_avp, &auth_realm_spec, "realm") < 0
+				|| parse_auth_avp(
+						   auth_username_avp, &auth_username_spec, "username")
+						   < 0
+				|| parse_auth_avp(
+						   auth_password_avp, &auth_password_spec, "password")
+						   < 0) {
 			goto error;
 		}
 	} else {
-		memset( &auth_realm_spec, 0, sizeof(pv_spec_t));
-		memset( &auth_password_spec, 0, sizeof(pv_spec_t));
-		memset( &auth_username_spec, 0, sizeof(pv_spec_t));
+		memset(&auth_realm_spec, 0, sizeof(pv_spec_t));
+		memset(&auth_password_spec, 0, sizeof(pv_spec_t));
+		memset(&auth_username_spec, 0, sizeof(pv_spec_t));
 	}
 
 	/* load the TM API - FIXME it should be loaded only
 	 * if NO_RESTORE and AUTH */
-	if (load_tm_api(&uac_tmb)!=0) {
+	if(load_tm_api(&uac_tmb) != 0) {
 		LM_ERR("can't load TM API\n");
 		goto error;
 	}
 
-	if (restore_mode!=UAC_NO_RESTORE) {
+	if(restore_mode != UAC_NO_RESTORE) {
 		/* load the RR API */
-		if (load_rr_api(&uac_rrb)!=0) {
+		if(load_rr_api(&uac_rrb) != 0) {
 			LM_ERR("can't load RR API\n");
 			goto error;
 		}
@@ -283,85 +279,90 @@ static int mod_init(void)
 
 		if(restore_from_avp.s) {
 
-			if (pv_parse_spec(&restore_from_avp, &avp_spec)==0	|| avp_spec.type!=PVT_AVP) {
-				LM_ERR("malformed or non AVP %.*s AVP definition\n", restore_from_avp.len, restore_from_avp.s);
+			if(pv_parse_spec(&restore_from_avp, &avp_spec) == 0
+					|| avp_spec.type != PVT_AVP) {
+				LM_ERR("malformed or non AVP %.*s AVP definition\n",
+						restore_from_avp.len, restore_from_avp.s);
 				return -1;
 			}
 
-			if(pv_get_avp_name(0, &avp_spec.pvp, &restore_from_avp_name, &restore_from_avp_type)!=0) {
-				LM_ERR("[%.*s]- invalid AVP definition\n", restore_from_avp.len, restore_from_avp.s);
+			if(pv_get_avp_name(0, &avp_spec.pvp, &restore_from_avp_name,
+					   &restore_from_avp_type)
+					!= 0) {
+				LM_ERR("[%.*s]- invalid AVP definition\n", restore_from_avp.len,
+						restore_from_avp.s);
 				return -1;
 			}
 
 			restore_from_avp_type |= AVP_VAL_STR;
-
 		}
 
 		if(restore_to_avp.s) {
 
-			if (pv_parse_spec(&restore_to_avp, &avp_spec)==0	|| avp_spec.type!=PVT_AVP) {
-				LM_ERR("malformed or non AVP %.*s AVP definition\n", restore_to_avp.len, restore_to_avp.s);
+			if(pv_parse_spec(&restore_to_avp, &avp_spec) == 0
+					|| avp_spec.type != PVT_AVP) {
+				LM_ERR("malformed or non AVP %.*s AVP definition\n",
+						restore_to_avp.len, restore_to_avp.s);
 				return -1;
 			}
 
-			if(pv_get_avp_name(0, &avp_spec.pvp, &restore_to_avp_name, &restore_to_avp_type)!=0) {
-				LM_ERR("[%.*s]- invalid AVP definition\n", restore_to_avp.len, restore_to_avp.s);
+			if(pv_get_avp_name(0, &avp_spec.pvp, &restore_to_avp_name,
+					   &restore_to_avp_type)
+					!= 0) {
+				LM_ERR("[%.*s]- invalid AVP definition\n", restore_to_avp.len,
+						restore_to_avp.s);
 				return -1;
 			}
 
 			restore_to_avp_type |= AVP_VAL_STR;
-
 		}
 
 
-		if (restore_mode==UAC_AUTO_RESTORE) {
+		if(restore_mode == UAC_AUTO_RESTORE) {
 			/* we need the append_fromtag on in RR */
 
-			if (uac_restore_dlg==0) {
-				if (!uac_rrb.append_fromtag) {
+			if(uac_restore_dlg == 0) {
+				if(!uac_rrb.append_fromtag) {
 					LM_ERR("'append_fromtag' RR param is not enabled!"
-							" - required by AUTO restore mode\n");
+						   " - required by AUTO restore mode\n");
 					goto error;
 				}
 			} else {
-				if (uac_init_dlg()!=0) {
-					LM_ERR("failed to find dialog API - is dialog module loaded?\n");
+				if(uac_init_dlg() != 0) {
+					LM_ERR("failed to find dialog API - is dialog module "
+						   "loaded?\n");
 					goto error;
 				}
 			}
 
 			/* get all requests doing loose route */
-			if (uac_rrb.register_rrcb( rr_checker, 0)!=0) {
+			if(uac_rrb.register_rrcb(rr_checker, 0) != 0) {
 				LM_ERR("failed to install RR callback\n");
 				goto error;
 			}
 		}
 	}
 
-	if(reg_db_url.s && reg_db_url.len>=0)
-	{
-		if(!reg_contact_addr.s || reg_contact_addr.len<=0)
-		{
+	if(reg_db_url.s && reg_db_url.len >= 0) {
+		if(!reg_contact_addr.s || reg_contact_addr.len <= 0) {
 			LM_ERR("contact address parameter not set\n");
 			goto error;
 		}
-		if(reg_active_init(reg_active_param)<0) {
+		if(reg_active_init(reg_active_param) < 0) {
 			LM_ERR("failed to init reg active mode\n");
 			goto error;
 		}
-		if(reg_htable_size>14)
+		if(reg_htable_size > 14)
 			reg_htable_size = 14;
-		if(reg_htable_size<2)
+		if(reg_htable_size < 2)
 			reg_htable_size = 2;
 
-		reg_htable_size = 1<<reg_htable_size;
-		if(uac_reg_init_rpc()!=0)
-		{
+		reg_htable_size = 1 << reg_htable_size;
+		if(uac_reg_init_rpc() != 0) {
 			LM_ERR("failed to register RPC commands\n");
 			goto error;
 		}
-		if(uac_reg_init_ht(reg_htable_size)<0)
-		{
+		if(uac_reg_init_ht(reg_htable_size) < 0) {
 			LM_ERR("failed to init reg htable\n");
 			goto error;
 		}
@@ -386,8 +387,8 @@ static int mod_init(void)
 					uac_default_socket.s);
 			return -1;
 		}
-		LM_INFO("default uac socket set to <%.*s>\n",
-				uac_default_socket.len, uac_default_socket.s);
+		LM_INFO("default uac socket set to <%.*s>\n", uac_default_socket.len,
+				uac_default_socket.s);
 	}
 	init_from_replacer();
 
@@ -402,28 +403,27 @@ static int child_init(int rank)
 {
 	int pid;
 
-	if (rank!=PROC_MAIN)
+	if(rank != PROC_MAIN)
 		return 0;
 
-	if(!reg_db_url.s || reg_db_url.len<=0)
+	if(!reg_db_url.s || reg_db_url.len <= 0)
 		return 0;
 
-	pid=fork_process(PROC_TIMER, "TIMER UAC REG", 1);
-	if (pid<0)
-	{
+	pid = fork_process(PROC_TIMER, "TIMER UAC REG", 1);
+	if(pid < 0) {
 		LM_ERR("failed to register timer routine as process\n");
 		return -1;
 	}
-	if (pid==0){
+	if(pid == 0) {
 		/* child */
 		/* initialize the config framework */
-		if (cfg_child_init())
+		if(cfg_child_init())
 			return -1;
 
 		uac_reg_load_db();
 		LM_DBG("run initial uac registration routine\n");
 		uac_reg_timer(0);
-		for(;;){
+		for(;;) {
 			/* update the local config framework structures */
 			cfg_update();
 
@@ -446,12 +446,13 @@ static void mod_destroy(void)
 static int ki_restore_from(struct sip_msg *msg)
 {
 	/* safety checks - must be a request */
-	if (msg->first_line.type!=SIP_REQUEST) {
+	if(msg->first_line.type != SIP_REQUEST) {
 		LM_ERR("called for something not request\n");
 		return -1;
 	}
 
-	return (restore_uri(msg,&rr_from_param,&restore_from_avp,1)==0)?1:-1;
+	return (restore_uri(msg, &rr_from_param, &restore_from_avp, 1) == 0) ? 1
+																		 : -1;
 }
 
 static int w_restore_from(struct sip_msg *msg, char *p1, char *p2)
@@ -476,21 +477,24 @@ int ki_replace_from(sip_msg_t *msg, str *pdsp, str *puri)
 			uri ? uri->len : 0);
 
 	return (replace_uri(msg, dsp, uri, msg->from, &rr_from_param,
-					&restore_from_avp, 1)==0)? 1 : -1;
+					&restore_from_avp, 1)
+				   == 0)
+				   ? 1
+				   : -1;
 }
 
-static int ki_replace_from_uri(sip_msg_t* msg, str* puri)
+static int ki_replace_from_uri(sip_msg_t *msg, str *puri)
 {
 	return ki_replace_from(msg, NULL, puri);
 }
 
-int w_replace_from(struct sip_msg* msg, char* p1, char* p2)
+int w_replace_from(struct sip_msg *msg, char *p1, char *p2)
 {
 	str uri_s;
 	str dsp_s;
 	str *dsp = NULL;
 
-	if (p2==NULL) {
+	if(p2 == NULL) {
 		p2 = p1;
 		p1 = NULL;
 		dsp = NULL;
@@ -513,33 +517,34 @@ int w_replace_from(struct sip_msg* msg, char* p1, char* p2)
 	return ki_replace_from(msg, dsp, &uri_s);
 }
 
-int replace_from_api(sip_msg_t *msg, str* pd, str* pu)
+int replace_from_api(sip_msg_t *msg, str *pd, str *pu)
 {
 	str *uri;
 	str *dsp;
-	if (parse_from_header(msg)<0 ) {
+	if(parse_from_header(msg) < 0) {
 		LM_ERR("failed to find/parse FROM hdr\n");
 		return -1;
 	}
 
-	uri = (pu!=NULL && pu->len>0)?pu:NULL;
-	dsp = (pd!=NULL && pd->len>0)?pd:NULL;
+	uri = (pu != NULL && pu->len > 0) ? pu : NULL;
+	dsp = (pd != NULL && pd->len > 0) ? pd : NULL;
 
-	LM_DBG("dsp=%p (len=%d) , uri=%p (len=%d)\n", dsp, dsp?dsp->len:0,
-			uri, uri?uri->len:0);
+	LM_DBG("dsp=%p (len=%d) , uri=%p (len=%d)\n", dsp, dsp ? dsp->len : 0, uri,
+			uri ? uri->len : 0);
 
-	return replace_uri(msg, dsp, uri, msg->from, &rr_from_param, &restore_from_avp, 1);
+	return replace_uri(
+			msg, dsp, uri, msg->from, &rr_from_param, &restore_from_avp, 1);
 }
 
 static int ki_restore_to(struct sip_msg *msg)
 {
 	/* safety checks - must be a request */
-	if (msg->first_line.type!=SIP_REQUEST) {
+	if(msg->first_line.type != SIP_REQUEST) {
 		LM_ERR("called for something not request\n");
 		return -1;
 	}
 
-	return (restore_uri(msg,&rr_to_param,&restore_to_avp,0)==0)?1:-1;
+	return (restore_uri(msg, &rr_to_param, &restore_to_avp, 0) == 0) ? 1 : -1;
 }
 
 static int w_restore_to(struct sip_msg *msg, char *p1, char *p2)
@@ -547,7 +552,7 @@ static int w_restore_to(struct sip_msg *msg, char *p1, char *p2)
 	return ki_restore_to(msg);
 }
 
-static int ki_replace_to(sip_msg_t* msg, str* pdsp, str* puri)
+static int ki_replace_to(sip_msg_t *msg, str *pdsp, str *puri)
 {
 	str *uri = NULL;
 	str *dsp = NULL;
@@ -556,30 +561,33 @@ static int ki_replace_to(sip_msg_t* msg, str* pdsp, str* puri)
 	uri = (puri && puri->len) ? puri : NULL;
 
 	/* parse TO hdr */
-	if ( msg->to==0 && (parse_headers(msg,HDR_TO_F,0)!=0 || msg->to==0) ) {
+	if(msg->to == 0 && (parse_headers(msg, HDR_TO_F, 0) != 0 || msg->to == 0)) {
 		LM_ERR("failed to parse TO hdr\n");
 		return -1;
 	}
 
-	LM_DBG("dsp=%p (len=%d) , uri=%p (len=%d)\n",
-			dsp, dsp?dsp->len:0, uri, uri?uri->len:0);
+	LM_DBG("dsp=%p (len=%d) , uri=%p (len=%d)\n", dsp, dsp ? dsp->len : 0, uri,
+			uri ? uri->len : 0);
 
-	return (replace_uri(msg, dsp, uri, msg->to, &rr_to_param,
-				&restore_to_avp, 0)==0)?1:-1;
+	return (replace_uri(
+					msg, dsp, uri, msg->to, &rr_to_param, &restore_to_avp, 0)
+				   == 0)
+				   ? 1
+				   : -1;
 }
 
-static int ki_replace_to_uri(sip_msg_t* msg, str* puri)
+static int ki_replace_to_uri(sip_msg_t *msg, str *puri)
 {
 	return ki_replace_to(msg, NULL, puri);
 }
 
-static int w_replace_to(struct sip_msg* msg, char* p1, char* p2)
+static int w_replace_to(struct sip_msg *msg, char *p1, char *p2)
 {
 	str uri_s;
 	str dsp_s;
 	str *dsp = NULL;
 
-	if (p2==NULL) {
+	if(p2 == NULL) {
 		p2 = p1;
 		p1 = NULL;
 		dsp = NULL;
@@ -603,108 +611,109 @@ static int w_replace_to(struct sip_msg* msg, char* p1, char* p2)
 }
 
 
-int replace_to_api(sip_msg_t *msg, str* pd, str* pu)
+int replace_to_api(sip_msg_t *msg, str *pd, str *pu)
 {
 	str *uri;
 	str *dsp;
-	if ( msg->to==0 && (parse_headers(msg,HDR_TO_F,0)!=0 || msg->to==0) ) {
+	if(msg->to == 0 && (parse_headers(msg, HDR_TO_F, 0) != 0 || msg->to == 0)) {
 		LM_ERR("failed to find/parse TO hdr\n");
 		return -1;
 	}
 
-	uri = (pu!=NULL && pu->len>0)?pu:NULL;
-	dsp = (pd!=NULL && pd->len>0)?pd:NULL;
+	uri = (pu != NULL && pu->len > 0) ? pu : NULL;
+	dsp = (pd != NULL && pd->len > 0) ? pd : NULL;
 
-	LM_DBG("dsp=%p (len=%d) , uri=%p (len=%d)\n", dsp, dsp?dsp->len:0,
-			uri, uri?uri->len:0);
+	LM_DBG("dsp=%p (len=%d) , uri=%p (len=%d)\n", dsp, dsp ? dsp->len : 0, uri,
+			uri ? uri->len : 0);
 
-	return replace_uri(msg, dsp, uri, msg->to, &rr_to_param, &restore_to_avp, 0);
+	return replace_uri(
+			msg, dsp, uri, msg->to, &rr_to_param, &restore_to_avp, 0);
 }
 
 
-static int w_uac_auth(struct sip_msg* msg, char* str, char* str2)
+static int w_uac_auth(struct sip_msg *msg, char *str, char *str2)
 {
-	return (uac_auth(msg)==0)?1:-1;
+	return (uac_auth(msg) == 0) ? 1 : -1;
 }
 
-static int ki_uac_auth(struct sip_msg* msg)
+static int ki_uac_auth(struct sip_msg *msg)
 {
-	return (uac_auth(msg)==0)?1:-1;
+	return (uac_auth(msg) == 0) ? 1 : -1;
 }
 
-static int w_uac_auth_mode(struct sip_msg* msg, char* pmode, char* str2)
+static int w_uac_auth_mode(struct sip_msg *msg, char *pmode, char *str2)
 {
 	int imode = 0;
 
-	if(fixup_get_ivalue(msg, (gparam_t*)pmode, &imode)<0) {
+	if(fixup_get_ivalue(msg, (gparam_t *)pmode, &imode) < 0) {
 		LM_ERR("failed to get the mode parameter\n");
 		return -1;
 	}
-	return (uac_auth_mode(msg, imode)==0)?1:-1;
+	return (uac_auth_mode(msg, imode) == 0) ? 1 : -1;
 }
 
-static int ki_uac_auth_mode(sip_msg_t* msg, int mode)
+static int ki_uac_auth_mode(sip_msg_t *msg, int mode)
 {
-	return (uac_auth_mode(msg, mode)==0)?1:-1;
+	return (uac_auth_mode(msg, mode) == 0) ? 1 : -1;
 }
 
-static int w_uac_reg_lookup(struct sip_msg* msg, char* src, char* dst)
+static int w_uac_reg_lookup(struct sip_msg *msg, char *src, char *dst)
 {
 	pv_spec_t *dpv;
 	str sval;
 
-	if(fixup_get_svalue(msg, (gparam_t*)src, &sval)<0) {
+	if(fixup_get_svalue(msg, (gparam_t *)src, &sval) < 0) {
 		LM_ERR("cannot get the uuid parameter\n");
 		return -1;
 	}
 
-	dpv = (pv_spec_t*)dst;
+	dpv = (pv_spec_t *)dst;
 
 	return uac_reg_lookup(msg, &sval, dpv, 0);
 }
 
-static int ki_uac_reg_lookup(sip_msg_t* msg, str* userid, str* sdst)
+static int ki_uac_reg_lookup(sip_msg_t *msg, str *userid, str *sdst)
 {
 	pv_spec_t *dpv = NULL;
 	dpv = pv_cache_get(sdst);
-	if(dpv==NULL) {
+	if(dpv == NULL) {
 		LM_ERR("cannot get pv spec for [%.*s]\n", sdst->len, sdst->s);
 		return -1;
 	}
 	return uac_reg_lookup(msg, userid, dpv, 0);
 }
 
-static int w_uac_reg_lookup_uri(struct sip_msg* msg, char* src, char* dst)
+static int w_uac_reg_lookup_uri(struct sip_msg *msg, char *src, char *dst)
 {
 	pv_spec_t *dpv;
 	str sval;
 
-	if(fixup_get_svalue(msg, (gparam_t*)src, &sval)<0) {
+	if(fixup_get_svalue(msg, (gparam_t *)src, &sval) < 0) {
 		LM_ERR("cannot get the uuid parameter\n");
 		return -1;
 	}
 
-	dpv = (pv_spec_t*)dst;
+	dpv = (pv_spec_t *)dst;
 
 	return uac_reg_lookup(msg, &sval, dpv, 1);
 }
 
-static int ki_uac_reg_lookup_uri(sip_msg_t* msg, str* suri, str* sdst)
+static int ki_uac_reg_lookup_uri(sip_msg_t *msg, str *suri, str *sdst)
 {
 	pv_spec_t *dpv = NULL;
 	dpv = pv_cache_get(sdst);
-	if(dpv==NULL) {
+	if(dpv == NULL) {
 		LM_ERR("cannot get pv spec for [%.*s]\n", sdst->len, sdst->s);
 		return -1;
 	}
 	return uac_reg_lookup(msg, suri, dpv, 1);
 }
 
-static int w_uac_reg_status(struct sip_msg* msg, char* src, char* p2)
+static int w_uac_reg_status(struct sip_msg *msg, char *src, char *p2)
 {
 	str sval;
 
-	if(fixup_get_svalue(msg, (gparam_t*)src, &sval)<0) {
+	if(fixup_get_svalue(msg, (gparam_t *)src, &sval) < 0) {
 		LM_ERR("cannot get the uuid parameter\n");
 		return -1;
 	}
@@ -717,64 +726,64 @@ static int ki_uac_reg_status(sip_msg_t *msg, str *sruuid)
 	return uac_reg_status(msg, sruuid, 0);
 }
 
-static int w_uac_reg_enable(struct sip_msg* msg, char* pfilter, char* pval)
+static int w_uac_reg_enable(struct sip_msg *msg, char *pfilter, char *pval)
 {
 	str sfilter;
 	str sval;
 
-	if(fixup_get_svalue(msg, (gparam_t*)pfilter, &sfilter)<0) {
+	if(fixup_get_svalue(msg, (gparam_t *)pfilter, &sfilter) < 0) {
 		LM_ERR("cannot get the filter parameter\n");
 		return -1;
 	}
-	if(fixup_get_svalue(msg, (gparam_t*)pval, &sval)<0) {
+	if(fixup_get_svalue(msg, (gparam_t *)pval, &sval) < 0) {
 		LM_ERR("cannot get the value parameter\n");
 		return -1;
 	}
 	return uac_reg_enable(msg, &sfilter, &sval);
 }
 
-static int w_uac_reg_disable(struct sip_msg* msg, char* pfilter, char* pval)
+static int w_uac_reg_disable(struct sip_msg *msg, char *pfilter, char *pval)
 {
 	str sfilter;
 	str sval;
 
-	if(fixup_get_svalue(msg, (gparam_t*)pfilter, &sfilter)<0) {
+	if(fixup_get_svalue(msg, (gparam_t *)pfilter, &sfilter) < 0) {
 		LM_ERR("cannot get the filter parameter\n");
 		return -1;
 	}
-	if(fixup_get_svalue(msg, (gparam_t*)pval, &sval)<0) {
+	if(fixup_get_svalue(msg, (gparam_t *)pval, &sval) < 0) {
 		LM_ERR("cannot get the value parameter\n");
 		return -1;
 	}
 	return uac_reg_disable(msg, &sfilter, &sval);
 }
 
-static int w_uac_reg_refresh(struct sip_msg* msg, char* pluuid, char* p2)
+static int w_uac_reg_refresh(struct sip_msg *msg, char *pluuid, char *p2)
 {
 	str sluuid;
 
-	if(fixup_get_svalue(msg, (gparam_t*)pluuid, &sluuid)<0) {
+	if(fixup_get_svalue(msg, (gparam_t *)pluuid, &sluuid) < 0) {
 		LM_ERR("cannot get the local uuid parameter\n");
 		return -1;
 	}
 	return uac_reg_refresh(msg, &sluuid);
 }
 
-static int w_uac_reg_request_to(struct sip_msg* msg, char* src, char* pmode)
+static int w_uac_reg_request_to(struct sip_msg *msg, char *src, char *pmode)
 {
 	str sval;
 	int imode;
 
-	if(fixup_get_svalue(msg, (gparam_t*)src, &sval)<0) {
+	if(fixup_get_svalue(msg, (gparam_t *)src, &sval) < 0) {
 		LM_ERR("cannot get the uuid parameter\n");
 		return -1;
 	}
-	if(fixup_get_ivalue(msg, (gparam_t*)pmode, &imode)<0) {
+	if(fixup_get_ivalue(msg, (gparam_t *)pmode, &imode) < 0) {
 		LM_ERR("cannot get the mode parameter\n");
 		return -1;
 	}
 
-	if (imode > (UACREG_REQTO_MASK_USER|UACREG_REQTO_MASK_AUTH)) {
+	if(imode > (UACREG_REQTO_MASK_USER | UACREG_REQTO_MASK_AUTH)) {
 		LM_ERR("invalid mode\n");
 		return -1;
 	}
@@ -784,7 +793,7 @@ static int w_uac_reg_request_to(struct sip_msg* msg, char* src, char* pmode)
 
 static int ki_uac_reg_request_to(sip_msg_t *msg, str *userid, int imode)
 {
-	if (imode > 1) {
+	if(imode > 1) {
 		LM_ERR("invalid mode\n");
 		return -1;
 	}
@@ -794,7 +803,7 @@ static int ki_uac_reg_request_to(sip_msg_t *msg, str *userid, int imode)
 
 int bind_uac(uac_api_t *uacb)
 {
-	if (uacb == NULL) {
+	if(uacb == NULL) {
 		LM_WARN("bind_uac: Cannot load uac API into a NULL pointer\n");
 		return -1;
 	}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 256 - 312
src/modules/uac/uac_reg.c


+ 5 - 5
src/modules/uac/uac_reg.h

@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
-		       
+
 #ifndef _UAC_REG_H_
 #define _UAC_REG_H_
 
@@ -39,7 +39,7 @@ extern str reg_db_url;
 extern str reg_db_table;
 extern str uac_default_socket;
 /* just to check for non-local sockets for now */
-extern struct socket_info * uac_default_sockinfo;
+extern struct socket_info *uac_default_sockinfo;
 
 extern str l_uuid_column;
 extern str l_username_column;
@@ -60,9 +60,9 @@ int uac_reg_free_ht(void);
 void uac_reg_timer(unsigned int ticks);
 int uac_reg_init_rpc(void);
 
-int  uac_reg_lookup(struct sip_msg *msg, str *src, pv_spec_t *dst, int mode);
-int  uac_reg_status(struct sip_msg *msg, str *src, int mode);
-int  uac_reg_request_to(struct sip_msg *msg, str *src, unsigned int mode);
+int uac_reg_lookup(struct sip_msg *msg, str *src, pv_spec_t *dst, int mode);
+int uac_reg_status(struct sip_msg *msg, str *src, int mode);
+int uac_reg_request_to(struct sip_msg *msg, str *src, unsigned int mode);
 
 int uac_reg_enable(sip_msg_t *msg, str *attr, str *val);
 int uac_reg_disable(sip_msg_t *msg, str *attr, str *val);

+ 220 - 276
src/modules/uac/uac_send.c

@@ -43,7 +43,7 @@
 #include "uac_send.h"
 #include "uac_reg.h"
 
-#define UAC_SEND_FL_HA1 (1<<0)
+#define UAC_SEND_FL_HA1 (1 << 0)
 
 #define MAX_UACH_SIZE 2048
 #define MAX_UACB_SIZE 32768
@@ -52,32 +52,33 @@
 /** TM bind */
 struct tm_binds tmb;
 
-typedef struct _uac_send_info {
+typedef struct _uac_send_info
+{
 	unsigned int flags;
-	char  b_method[32];
-	str   s_method;
-	char  b_ruri[MAX_URI_SIZE];
-	str   s_ruri;
-	char  b_turi[MAX_URI_SIZE];
-	str   s_turi;
-	char  b_furi[MAX_URI_SIZE];
-	str   s_furi;
-	char  b_callid[128];
-	str   s_callid;
-	char  b_hdrs[MAX_UACH_SIZE];
-	str   s_hdrs;
-	char  b_body[MAX_UACB_SIZE];
-	str   s_body;
-	char  b_ouri[MAX_URI_SIZE];
-	str   s_ouri;
-	char  b_sock[MAX_URI_SIZE];
-	str   s_sock;
-	char  b_auser[128];
-	str   s_auser;
-	char  b_apasswd[64];
-	str   s_apasswd;
-	char  b_evparam[MAX_UACD_SIZE];
-	str   s_evparam;
+	char b_method[32];
+	str s_method;
+	char b_ruri[MAX_URI_SIZE];
+	str s_ruri;
+	char b_turi[MAX_URI_SIZE];
+	str s_turi;
+	char b_furi[MAX_URI_SIZE];
+	str s_furi;
+	char b_callid[128];
+	str s_callid;
+	char b_hdrs[MAX_UACH_SIZE];
+	str s_hdrs;
+	char b_body[MAX_UACB_SIZE];
+	str s_body;
+	char b_ouri[MAX_URI_SIZE];
+	str s_ouri;
+	char b_sock[MAX_URI_SIZE];
+	str s_sock;
+	char b_auser[128];
+	str s_auser;
+	char b_apasswd[64];
+	str s_apasswd;
+	char b_evparam[MAX_UACD_SIZE];
+	str s_evparam;
 	unsigned int evroute;
 	unsigned int evcode;
 	unsigned int evtype;
@@ -90,26 +91,25 @@ extern str uac_event_callback;
 void uac_send_info_copy(uac_send_info_t *src, uac_send_info_t *dst)
 {
 	memcpy(dst, src, sizeof(uac_send_info_t));
-	dst->s_method.s  = dst->b_method;
-	dst->s_ruri.s    = dst->b_ruri;
-	dst->s_turi.s    = dst->b_turi;
-	dst->s_furi.s    = dst->b_furi;
-	dst->s_hdrs.s    = dst->b_hdrs;
-	dst->s_body.s    = dst->b_body;
-	dst->s_ouri.s    = dst->b_ouri;
-	dst->s_auser.s   = dst->b_auser;
+	dst->s_method.s = dst->b_method;
+	dst->s_ruri.s = dst->b_ruri;
+	dst->s_turi.s = dst->b_turi;
+	dst->s_furi.s = dst->b_furi;
+	dst->s_hdrs.s = dst->b_hdrs;
+	dst->s_body.s = dst->b_body;
+	dst->s_ouri.s = dst->b_ouri;
+	dst->s_auser.s = dst->b_auser;
 	dst->s_apasswd.s = dst->b_apasswd;
-	dst->s_callid.s  = dst->b_callid;
-	dst->s_sock.s    = dst->b_sock;
+	dst->s_callid.s = dst->b_callid;
+	dst->s_sock.s = dst->b_sock;
 	dst->s_evparam.s = dst->b_evparam;
 }
 
 uac_send_info_t *uac_send_info_clone(uac_send_info_t *ur)
 {
 	uac_send_info_t *tp = NULL;
-	tp = (uac_send_info_t*)shm_malloc(sizeof(uac_send_info_t));
-	if(tp==NULL)
-	{
+	tp = (uac_send_info_t *)shm_malloc(sizeof(uac_send_info_t));
+	if(tp == NULL) {
 		SHM_MEM_ERROR;
 		return NULL;
 	}
@@ -118,64 +118,62 @@ uac_send_info_t *uac_send_info_clone(uac_send_info_t *ur)
 	return tp;
 }
 
-int pv_get_uac_req(struct sip_msg *msg, pv_param_t *param,
-		pv_value_t *res)
+int pv_get_uac_req(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 {
-	if(param==NULL || tmb.t_request==NULL)
+	if(param == NULL || tmb.t_request == NULL)
 		return -1;
 
-	switch(param->pvn.u.isname.name.n)
-	{
+	switch(param->pvn.u.isname.name.n) {
 		case 0:
 			return pv_get_uintval(msg, param, res, _uac_req.flags);
 		case 1:
-			if(_uac_req.s_ruri.len<=0)
+			if(_uac_req.s_ruri.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_ruri);
 		case 2:
-			if(_uac_req.s_turi.len<=0)
+			if(_uac_req.s_turi.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_turi);
 		case 3:
-			if(_uac_req.s_furi.len<=0)
+			if(_uac_req.s_furi.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_furi);
 		case 4:
-			if(_uac_req.s_hdrs.len<=0)
+			if(_uac_req.s_hdrs.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_hdrs);
 		case 5:
-			if(_uac_req.s_body.len<=0)
+			if(_uac_req.s_body.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_body);
 		case 6:
-			if(_uac_req.s_ouri.len<=0)
+			if(_uac_req.s_ouri.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_ouri);
 		case 7:
-			if(_uac_req.s_method.len<=0)
+			if(_uac_req.s_method.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_method);
 		case 8:
 			return pv_get_uintval(msg, param, res, _uac_req.evroute);
 		case 9:
-			if(_uac_req.s_auser.len<=0)
+			if(_uac_req.s_auser.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_auser);
 		case 10:
-			if(_uac_req.s_apasswd.len<=0)
+			if(_uac_req.s_apasswd.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_apasswd);
 		case 11:
-			if(_uac_req.s_callid.len<=0)
+			if(_uac_req.s_callid.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_callid);
 		case 12:
-			if(_uac_req.s_sock.len<=0)
+			if(_uac_req.s_sock.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_sock);
 		case 14:
-			if(_uac_req.s_evparam.len<=0)
+			if(_uac_req.s_evparam.len <= 0)
 				return pv_get_null(msg, param, res);
 			return pv_get_strval(msg, param, res, &_uac_req.s_evparam);
 		case 15:
@@ -188,23 +186,21 @@ int pv_get_uac_req(struct sip_msg *msg, pv_param_t *param,
 	return 0;
 }
 
-int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
-		int op, pv_value_t *val)
+int pv_set_uac_req(
+		struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val)
 {
 	pv_value_t *tval;
 
-	if(param==NULL || tmb.t_request==NULL)
+	if(param == NULL || tmb.t_request == NULL)
 		return -1;
 
 	tval = val;
-	if((tval!=NULL) && (tval->flags&PV_VAL_NULL)) {
+	if((tval != NULL) && (tval->flags & PV_VAL_NULL)) {
 		tval = NULL;
 	}
-	switch(param->pvn.u.isname.name.n)
-	{
+	switch(param->pvn.u.isname.name.n) {
 		case 0:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.flags = 0;
 				_uac_req.s_ruri.len = 0;
 				_uac_req.s_furi.len = 0;
@@ -221,18 +217,15 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			}
 			break;
 		case 1:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_ruri.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
-			if(tval->rs.len>=MAX_URI_SIZE)
-			{
+			if(tval->rs.len >= MAX_URI_SIZE) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -241,18 +234,15 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_ruri.len = tval->rs.len;
 			break;
 		case 2:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_turi.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
-			if(tval->rs.len>=MAX_URI_SIZE)
-			{
+			if(tval->rs.len >= MAX_URI_SIZE) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -261,18 +251,15 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_turi.len = tval->rs.len;
 			break;
 		case 3:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_furi.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
-			if(tval->rs.len>=MAX_URI_SIZE)
-			{
+			if(tval->rs.len >= MAX_URI_SIZE) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -281,18 +268,15 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_furi.len = tval->rs.len;
 			break;
 		case 4:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_hdrs.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
-			if(tval->rs.len>=MAX_UACH_SIZE)
-			{
+			if(tval->rs.len >= MAX_UACH_SIZE) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -301,18 +285,15 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_hdrs.len = tval->rs.len;
 			break;
 		case 5:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_body.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
-			if(tval->rs.len>=MAX_UACB_SIZE)
-			{
+			if(tval->rs.len >= MAX_UACB_SIZE) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -321,18 +302,15 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_body.len = tval->rs.len;
 			break;
 		case 6:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_ouri.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
-			if(tval->rs.len>=MAX_URI_SIZE)
-			{
+			if(tval->rs.len >= MAX_URI_SIZE) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -341,18 +319,15 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_ouri.len = tval->rs.len;
 			break;
 		case 7:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_method.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
-			if(tval->rs.len>=32)
-			{
+			if(tval->rs.len >= 32) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -361,31 +336,26 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_method.len = tval->rs.len;
 			break;
 		case 8:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.evroute = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_INT))
-			{
+			if(!(tval->flags & PV_VAL_INT)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
 			_uac_req.evroute = tval->ri;
 			break;
 		case 9:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_auser.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid auth user type\n");
 				return -1;
 			}
-			if(tval->rs.len>=128)
-			{
+			if(tval->rs.len >= 128) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -394,18 +364,15 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_auser.len = tval->rs.len;
 			break;
 		case 10:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_apasswd.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid auth password type\n");
 				return -1;
 			}
-			if(tval->rs.len>=64)
-			{
+			if(tval->rs.len >= 64) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -414,18 +381,15 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_apasswd.len = tval->rs.len;
 			break;
 		case 11:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_callid.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
-			if(tval->rs.len>=128)
-			{
+			if(tval->rs.len >= 128) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -434,18 +398,15 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_callid.len = tval->rs.len;
 			break;
 		case 12:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_apasswd.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid socket pv type\n");
 				return -1;
 			}
-			if(tval->rs.len>=MAX_URI_SIZE)
-			{
+			if(tval->rs.len >= MAX_URI_SIZE) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -454,18 +415,15 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_sock.len = tval->rs.len;
 			break;
 		case 14:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.s_evparam.len = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_STR))
-			{
+			if(!(tval->flags & PV_VAL_STR)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
-			if(tval->rs.len>=MAX_UACD_SIZE)
-			{
+			if(tval->rs.len >= MAX_UACD_SIZE) {
 				LM_ERR("Value size too big\n");
 				return -1;
 			}
@@ -474,39 +432,33 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 			_uac_req.s_evparam.len = tval->rs.len;
 			break;
 		case 15:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.evcode = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_INT))
-			{
+			if(!(tval->flags & PV_VAL_INT)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
 			_uac_req.evcode = tval->ri;
 			break;
 		case 16:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.evtype = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_INT))
-			{
+			if(!(tval->flags & PV_VAL_INT)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
 			_uac_req.evtype = tval->ri;
 			break;
 		case 17:
-			if(tval==NULL)
-			{
+			if(tval == NULL) {
 				_uac_req.flags = 0;
 				return 0;
 			}
-			if(!(tval->flags&PV_VAL_INT))
-			{
+			if(!(tval->flags & PV_VAL_INT)) {
 				LM_ERR("Invalid value type\n");
 				return -1;
 			}
@@ -518,60 +470,64 @@ int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
 
 int pv_parse_uac_req_name(pv_spec_p sp, str *in)
 {
-	if(sp==NULL || in==NULL || in->len<=0)
+	if(sp == NULL || in == NULL || in->len <= 0)
 		return -1;
 
-	switch(in->len)
-	{
+	switch(in->len) {
 		case 3:
-			if(strncmp(in->s, "all", 3)==0)
+			if(strncmp(in->s, "all", 3) == 0)
 				sp->pvp.pvn.u.isname.name.n = 0;
-			else goto error;
-		break;
+			else
+				goto error;
+			break;
 		case 4:
-			if(strncmp(in->s, "ruri", 4)==0)
+			if(strncmp(in->s, "ruri", 4) == 0)
 				sp->pvp.pvn.u.isname.name.n = 1;
-			else if(strncmp(in->s, "turi", 4)==0)
+			else if(strncmp(in->s, "turi", 4) == 0)
 				sp->pvp.pvn.u.isname.name.n = 2;
-			else if(strncmp(in->s, "furi", 4)==0)
+			else if(strncmp(in->s, "furi", 4) == 0)
 				sp->pvp.pvn.u.isname.name.n = 3;
-			else if(strncmp(in->s, "hdrs", 4)==0)
+			else if(strncmp(in->s, "hdrs", 4) == 0)
 				sp->pvp.pvn.u.isname.name.n = 4;
-			else if(strncmp(in->s, "body", 4)==0)
+			else if(strncmp(in->s, "body", 4) == 0)
 				sp->pvp.pvn.u.isname.name.n = 5;
-			else if(strncmp(in->s, "ouri", 4)==0)
+			else if(strncmp(in->s, "ouri", 4) == 0)
 				sp->pvp.pvn.u.isname.name.n = 6;
-			else if(strncmp(in->s, "sock", 4)==0)
+			else if(strncmp(in->s, "sock", 4) == 0)
 				sp->pvp.pvn.u.isname.name.n = 12;
-			else goto error;
-		break;
+			else
+				goto error;
+			break;
 		case 5:
-			if(strncmp(in->s, "auser", 5)==0)
+			if(strncmp(in->s, "auser", 5) == 0)
 				sp->pvp.pvn.u.isname.name.n = 9;
-			else if(strncmp(in->s, "flags", 5)==0)
+			else if(strncmp(in->s, "flags", 5) == 0)
 				sp->pvp.pvn.u.isname.name.n = 17;
-			else goto error;
-		break;
+			else
+				goto error;
+			break;
 		case 6:
-			if(strncmp(in->s, "method", 6)==0)
+			if(strncmp(in->s, "method", 6) == 0)
 				sp->pvp.pvn.u.isname.name.n = 7;
-			else if(strncmp(in->s, "callid", 6)==0)
+			else if(strncmp(in->s, "callid", 6) == 0)
 				sp->pvp.pvn.u.isname.name.n = 11;
-			else if(strncmp(in->s, "evcode", 6)==0)
+			else if(strncmp(in->s, "evcode", 6) == 0)
 				sp->pvp.pvn.u.isname.name.n = 15;
-			else if(strncmp(in->s, "evtype", 6)==0)
+			else if(strncmp(in->s, "evtype", 6) == 0)
 				sp->pvp.pvn.u.isname.name.n = 16;
-			else goto error;
-		break;
+			else
+				goto error;
+			break;
 		case 7:
-			if(strncmp(in->s, "evroute", 7)==0)
+			if(strncmp(in->s, "evroute", 7) == 0)
 				sp->pvp.pvn.u.isname.name.n = 8;
-			else if(strncmp(in->s, "apasswd", 7)==0)
+			else if(strncmp(in->s, "apasswd", 7) == 0)
 				sp->pvp.pvn.u.isname.name.n = 10;
-			else if(strncmp(in->s, "evparam", 7)==0)
+			else if(strncmp(in->s, "evparam", 7) == 0)
 				sp->pvp.pvn.u.isname.name.n = 14;
-			else goto error;
-		break;
+			else
+				goto error;
+			break;
 		default:
 			goto error;
 	}
@@ -588,7 +544,7 @@ error:
 void uac_req_init(void)
 {
 	/* load the TM API */
-	if (load_tm_api(&tmb)!=0) {
+	if(load_tm_api(&tmb) != 0) {
 		LM_DBG("can't load TM API - disable it\n");
 		memset(&tmb, 0, sizeof(struct tm_binds));
 		return;
@@ -601,24 +557,24 @@ void uac_req_init(void)
 	_uac_req.s_hdrs.s = _uac_req.b_hdrs;
 	_uac_req.s_body.s = _uac_req.b_body;
 	_uac_req.s_method.s = _uac_req.b_method;
-	_uac_req.s_auser.s  = _uac_req.b_auser;
-	_uac_req.s_apasswd.s  = _uac_req.b_apasswd;
-	_uac_req.s_callid.s   = _uac_req.b_callid;
-	_uac_req.s_sock.s     = _uac_req.b_sock;
-	_uac_req.s_evparam.s  = _uac_req.b_evparam;
+	_uac_req.s_auser.s = _uac_req.b_auser;
+	_uac_req.s_apasswd.s = _uac_req.b_apasswd;
+	_uac_req.s_callid.s = _uac_req.b_callid;
+	_uac_req.s_sock.s = _uac_req.b_sock;
+	_uac_req.s_evparam.s = _uac_req.b_evparam;
 	return;
 }
 
 int uac_send_tmdlg(dlg_t *tmdlg, sip_msg_t *rpl)
 {
-	if(tmdlg==NULL || rpl==NULL)
+	if(tmdlg == NULL || rpl == NULL)
 		return -1;
 
-	if (parse_headers(rpl, HDR_EOH_F, 0) < 0) {
+	if(parse_headers(rpl, HDR_EOH_F, 0) < 0) {
 		LM_ERR("error while parsing all headers in the reply\n");
 		return -1;
 	}
-	if(parse_to_header(rpl)<0 || parse_from_header(rpl)<0) {
+	if(parse_to_header(rpl) < 0 || parse_from_header(rpl) < 0) {
 		LM_ERR("error while parsing From/To headers in the reply\n");
 		return -1;
 	}
@@ -630,7 +586,7 @@ int uac_send_tmdlg(dlg_t *tmdlg, sip_msg_t *rpl)
 	tmdlg->id.call_id = rpl->callid->body;
 	trim(&tmdlg->id.call_id);
 
-	if (get_from(rpl)->tag_value.len) {
+	if(get_from(rpl)->tag_value.len) {
 		tmdlg->id.loc_tag = get_from(rpl)->tag_value;
 	}
 #if 0
@@ -640,7 +596,7 @@ int uac_send_tmdlg(dlg_t *tmdlg, sip_msg_t *rpl)
 #endif
 	tmdlg->loc_uri = get_from(rpl)->uri;
 	tmdlg->rem_uri = get_to(rpl)->uri;
-	tmdlg->state= DLG_CONFIRMED;
+	tmdlg->state = DLG_CONFIRMED;
 	return 0;
 }
 
@@ -658,9 +614,9 @@ void uac_req_run_event_route(sip_msg_t *msg, uac_send_info_t *tp, int rcode)
 	sr_kemi_eng_t *keng = NULL;
 	int kemi_evroute = 0;
 
-	if(uac_event_callback.s!=NULL && uac_event_callback.len>0) {
+	if(uac_event_callback.s != NULL && uac_event_callback.len > 0) {
 		keng = sr_kemi_eng_get();
-		if(keng==NULL) {
+		if(keng == NULL) {
 			LM_DBG("event callback (%s) set, but no cfg engine\n",
 					uac_event_callback.s);
 			return;
@@ -669,10 +625,9 @@ void uac_req_run_event_route(sip_msg_t *msg, uac_send_info_t *tp, int rcode)
 		}
 	}
 
-	if (kemi_evroute==0) {
+	if(kemi_evroute == 0) {
 		rt = route_get(&event_rt, evrtname);
-		if (rt < 0 || event_rt.rlist[rt] == NULL)
-		{
+		if(rt < 0 || event_rt.rlist[rt] == NULL) {
 			LM_DBG("event_route[uac:reply] does not exist\n");
 			return;
 		}
@@ -680,8 +635,7 @@ void uac_req_run_event_route(sip_msg_t *msg, uac_send_info_t *tp, int rcode)
 
 	uac_send_info_copy(tp, &_uac_req);
 	_uac_req.evcode = rcode;
-	if(msg==NULL)
-	{
+	if(msg == NULL) {
 		_uac_req.evtype = 2;
 		fmsg = faked_msg_get_next();
 	} else {
@@ -693,11 +647,12 @@ void uac_req_run_event_route(sip_msg_t *msg, uac_send_info_t *tp, int rcode)
 	set_route_type(REQUEST_ROUTE);
 	init_run_actions_ctx(&ctx);
 
-	if (kemi_evroute==1) {
+	if(kemi_evroute == 1) {
 		str evrtname = str_init("uac:reply");
 
-		if(sr_kemi_route(keng, fmsg, EVENT_ROUTE,
-					&uac_event_callback, &evrtname)<0) {
+		if(sr_kemi_route(
+				   keng, fmsg, EVENT_ROUTE, &uac_event_callback, &evrtname)
+				< 0) {
 			LM_ERR("error running event route kemi callback\n");
 		}
 	} else {
@@ -715,25 +670,23 @@ void uac_resend_tm_callback(struct cell *t, int type, struct tmcb_params *ps)
 
 	LM_DBG("tm callback with status %d\n", ps->code);
 
-	if(ps->param==NULL || *ps->param==0)
-	{
+	if(ps->param == NULL || *ps->param == 0) {
 		LM_DBG("callback param with message id not received\n");
 		goto done;
 	}
-	tp = (uac_send_info_t*)(*ps->param);
+	tp = (uac_send_info_t *)(*ps->param);
 
-	if(tp->evroute!=0 && ps->code > 0) {
-		uac_req_run_event_route((ps->rpl==FAKED_REPLY)?NULL:ps->rpl,
-				tp, ps->code);
+	if(tp->evroute != 0 && ps->code > 0) {
+		uac_req_run_event_route(
+				(ps->rpl == FAKED_REPLY) ? NULL : ps->rpl, tp, ps->code);
 	}
 
 done:
-	if(tp!=NULL){
+	if(tp != NULL) {
 		shm_free(tp);
 		*ps->param = NULL;
 	}
 	return;
-
 }
 
 /**
@@ -747,28 +700,26 @@ void uac_send_tm_callback(struct cell *t, int type, struct tmcb_params *ps)
 	str *new_auth_hdr = NULL;
 	static uac_authenticate_body_t auth;
 	uac_credential_t cred;
-	char  b_hdrs[MAX_UACH_SIZE];
-	str   s_hdrs;
+	char b_hdrs[MAX_UACH_SIZE];
+	str s_hdrs;
 	uac_req_t uac_r;
 	dlg_t tmdlg;
 	uac_send_info_t *tp = NULL;
 
 	LM_DBG("tm callback with status %d\n", ps->code);
 
-	if(ps->param==NULL || *ps->param==0)
-	{
+	if(ps->param == NULL || *ps->param == 0) {
 		LM_DBG("callback param with message id not received\n");
 		goto done;
 	}
-	tp = (uac_send_info_t*)(*ps->param);
+	tp = (uac_send_info_t *)(*ps->param);
 
-	if(tp->evroute!=0 && ps->code > 0) {
-		uac_req_run_event_route((ps->rpl==FAKED_REPLY)?NULL:ps->rpl,
-				tp, ps->code);
+	if(tp->evroute != 0 && ps->code > 0) {
+		uac_req_run_event_route(
+				(ps->rpl == FAKED_REPLY) ? NULL : ps->rpl, tp, ps->code);
 	}
 
-	if((ps->code != 401 && ps->code != 407) || tp->s_apasswd.len<=0)
-	{
+	if((ps->code != 401 && ps->code != 407) || tp->s_apasswd.len <= 0) {
 		LM_DBG("completed with status %d\n", ps->code);
 		goto done;
 	}
@@ -776,87 +727,80 @@ void uac_send_tm_callback(struct cell *t, int type, struct tmcb_params *ps)
 	LM_DBG("completed with status %d\n", ps->code);
 
 	hdr = get_autenticate_hdr(ps->rpl, ps->code);
-	if (hdr==0)
-	{
+	if(hdr == 0) {
 		LM_ERR("failed to extract authenticate hdr\n");
 		goto error;
 	}
 
-	LM_DBG("auth header body [%.*s]\n",
-		hdr->body.len, hdr->body.s);
+	LM_DBG("auth header body [%.*s]\n", hdr->body.len, hdr->body.s);
 
-	if (parse_authenticate_body(&hdr->body, &auth)<0)
-	{
+	if(parse_authenticate_body(&hdr->body, &auth) < 0) {
 		LM_ERR("failed to parse auth hdr body\n");
 		goto error;
 	}
 
 	memset(&cred, 0, sizeof(struct uac_credential));
-	cred.realm  = auth.realm;
-	cred.user   = tp->s_auser;
+	cred.realm = auth.realm;
+	cred.user = tp->s_auser;
 	cred.passwd = tp->s_apasswd;
 	if(tp->flags & UAC_SEND_FL_HA1) {
 		cred.aflags = UAC_FLCRED_HA1;
 	}
 
 	do_uac_auth(&tp->s_method, &tp->s_ruri, &cred, &auth, response);
-	new_auth_hdr=build_authorization_hdr(ps->code, &tp->s_ruri, &cred,
-						&auth, response);
-	if (new_auth_hdr==0)
-	{
+	new_auth_hdr = build_authorization_hdr(
+			ps->code, &tp->s_ruri, &cred, &auth, response);
+	if(new_auth_hdr == 0) {
 		LM_ERR("failed to build authorization hdr\n");
 		goto error;
 	}
 
 	if(tp->s_hdrs.len <= 0) {
-		snprintf(b_hdrs, MAX_UACH_SIZE,
-				"%.*s",
-				new_auth_hdr->len, new_auth_hdr->s);
+		snprintf(b_hdrs, MAX_UACH_SIZE, "%.*s", new_auth_hdr->len,
+				new_auth_hdr->s);
 	} else {
-		snprintf(b_hdrs, MAX_UACH_SIZE,
-				"%.*s%.*s",
-				tp->s_hdrs.len, tp->s_hdrs.s,
-				new_auth_hdr->len, new_auth_hdr->s);
+		snprintf(b_hdrs, MAX_UACH_SIZE, "%.*s%.*s", tp->s_hdrs.len,
+				tp->s_hdrs.s, new_auth_hdr->len, new_auth_hdr->s);
 	}
 
-	s_hdrs.s = b_hdrs; s_hdrs.len = strlen(s_hdrs.s);
+	s_hdrs.s = b_hdrs;
+	s_hdrs.len = strlen(s_hdrs.s);
 	pkg_free(new_auth_hdr->s);
 
 	memset(&uac_r, 0, sizeof(uac_r));
-	if(uac_send_tmdlg(&tmdlg, ps->rpl)<0)
-	{
+	if(uac_send_tmdlg(&tmdlg, ps->rpl) < 0) {
 		LM_ERR("failed to build tm dialog\n");
 		goto error;
 	}
 	tmdlg.rem_target = tp->s_ruri;
-	if(tp->s_ouri.len>0)
+	if(tp->s_ouri.len > 0)
 		tmdlg.dst_uri = tp->s_ouri;
 	uac_r.method = &tp->s_method;
 	uac_r.headers = &s_hdrs;
 	uac_r.body = (tp->s_body.len <= 0) ? NULL : &tp->s_body;
 	uac_r.ssock = (tp->s_sock.len <= 0) ? NULL : &tp->s_sock;
 	uac_r.dialog = &tmdlg;
-	uac_r.cb_flags = TMCB_LOCAL_COMPLETED|TMCB_DESTROY;
-	if(tp->evroute!=0) {
+	uac_r.cb_flags = TMCB_LOCAL_COMPLETED | TMCB_DESTROY;
+	if(tp->evroute != 0) {
 		/* Callback function */
-		uac_r.cb  = uac_resend_tm_callback;
+		uac_r.cb = uac_resend_tm_callback;
 		/* Callback parameter */
-		uac_r.cbp = (void*)tp;
+		uac_r.cbp = (void *)tp;
 	}
 	ret = tmb.t_request_within(&uac_r);
 
-	if(ret<0) {
+	if(ret < 0) {
 		LM_ERR("failed to send request with authentication\n");
 		goto error;
 	}
 
-	if(tp->evroute!=0) {
+	if(tp->evroute != 0) {
 		return;
 	}
 
 done:
 error:
-	if(tp!=NULL){
+	if(tp != NULL) {
 		shm_free(tp);
 		*ps->param = NULL;
 	}
@@ -870,8 +814,8 @@ int uac_req_send(void)
 	uac_req_t uac_r;
 	uac_send_info_t *tp = NULL;
 
-	if(_uac_req.s_ruri.len<=0 || _uac_req.s_method.len == 0
-			|| tmb.t_request==NULL)
+	if(_uac_req.s_ruri.len <= 0 || _uac_req.s_method.len == 0
+			|| tmb.t_request == NULL)
 		return -1;
 
 	memset(&uac_r, '\0', sizeof(uac_r));
@@ -879,50 +823,50 @@ int uac_req_send(void)
 	uac_r.headers = (_uac_req.s_hdrs.len <= 0) ? NULL : &_uac_req.s_hdrs;
 	uac_r.body = (_uac_req.s_body.len <= 0) ? NULL : &_uac_req.s_body;
 
-	if (_uac_req.s_sock.s != NULL && _uac_req.s_sock.len > 0) {
+	if(_uac_req.s_sock.s != NULL && _uac_req.s_sock.len > 0) {
 		uac_r.ssock = &_uac_req.s_sock;
 	} else if(uac_default_socket.s != NULL && uac_default_socket.len > 0) {
 		uac_r.ssock = &uac_default_socket;
 	}
 
-	if((_uac_req.s_auser.len > 0 && _uac_req.s_apasswd.len>0)
-			|| (_uac_req.evroute > 0))
-	{
+	if((_uac_req.s_auser.len > 0 && _uac_req.s_apasswd.len > 0)
+			|| (_uac_req.evroute > 0)) {
 		tp = uac_send_info_clone(&_uac_req);
-		if(tp==NULL)
-		{
+		if(tp == NULL) {
 			LM_ERR("cannot clone the uac structure\n");
 			return -1;
 		}
 
-		switch (_uac_req.evroute)
-		{
+		switch(_uac_req.evroute) {
 
-			case 2: 
-				uac_r.cb_flags = TMCB_ON_FAILURE|TMCB_DESTROY;
+			case 2:
+				uac_r.cb_flags = TMCB_ON_FAILURE | TMCB_DESTROY;
 				/* Callback function */
-				uac_r.cb  = uac_resend_tm_callback;
+				uac_r.cb = uac_resend_tm_callback;
 				break;
 			case 1:
 			default:
-				uac_r.cb_flags = TMCB_LOCAL_COMPLETED|TMCB_DESTROY;
+				uac_r.cb_flags = TMCB_LOCAL_COMPLETED | TMCB_DESTROY;
 				/* Callback function */
-				uac_r.cb  = uac_send_tm_callback;
+				uac_r.cb = uac_send_tm_callback;
 				break;
 		}
 		/* Callback parameter */
-		uac_r.cbp = (void*)tp;
+		uac_r.cbp = (void *)tp;
 	}
 	uac_r.callid = (_uac_req.s_callid.len <= 0) ? NULL : &_uac_req.s_callid;
-	ret = tmb.t_request(&uac_r,  /* UAC Req */
-			&_uac_req.s_ruri,        /* Request-URI */
-			(_uac_req.s_turi.len<=0)?&_uac_req.s_ruri:&_uac_req.s_turi, /* To */
-			(_uac_req.s_furi.len<=0)?&_uac_req.s_ruri:&_uac_req.s_furi, /* From */
-			(_uac_req.s_ouri.len<=0)?NULL:&_uac_req.s_ouri /* outbound uri */
-		);
-
-	if(ret<0) {
-		if(tp!=NULL)
+	ret = tmb.t_request(&uac_r, /* UAC Req */
+			&_uac_req.s_ruri,	/* Request-URI */
+			(_uac_req.s_turi.len <= 0) ? &_uac_req.s_ruri
+									   : &_uac_req.s_turi, /* To */
+			(_uac_req.s_furi.len <= 0) ? &_uac_req.s_ruri
+									   : &_uac_req.s_furi, /* From */
+			(_uac_req.s_ouri.len <= 0) ? NULL
+									   : &_uac_req.s_ouri /* outbound uri */
+	);
+
+	if(ret < 0) {
+		if(tp != NULL)
 			shm_free(tp);
 		return -1;
 	}

+ 4 - 5
src/modules/uac/uac_send.h

@@ -17,16 +17,15 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
-		       
+
 #ifndef _UAC_SEND_H_
 #define _UAC_SEND_H_
 
 #include "../../core/pvar.h"
 
-int pv_get_uac_req(struct sip_msg *msg, pv_param_t *param,
-		pv_value_t *res);
-int pv_set_uac_req(struct sip_msg* msg, pv_param_t *param,
-		int op, pv_value_t *val);
+int pv_get_uac_req(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+int pv_set_uac_req(
+		struct sip_msg *msg, pv_param_t *param, int op, pv_value_t *val);
 int pv_parse_uac_req_name(pv_spec_p sp, str *in);
 void uac_req_init(void);
 int uac_req_send(void);

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor