浏览代码

core: parser - updated old log messages

Daniel-Constantin Mierla 8 年之前
父节点
当前提交
08327019aa
共有 5 个文件被更改,包括 711 次插入676 次删除
  1. 235 243
      src/core/parser/parse_addr_spec.c
  2. 42 44
      src/core/parser/parse_cseq.c
  3. 24 25
      src/core/parser/parse_from.c
  4. 394 347
      src/core/parser/parse_param.c
  5. 16 17
      src/core/parser/parse_to.c

+ 235 - 243
src/core/parser/parse_addr_spec.c

@@ -34,68 +34,84 @@
 #include "../mem/mem.h"
 
 
-enum {
-	START_TO, DISPLAY_QUOTED, E_DISPLAY_QUOTED, DISPLAY_TOKEN,
-	DISPLAY_TOKEN_SP, S_URI_ENCLOSED, URI_ENCLOSED, E_URI_ENCLOSED,
-	URI_OR_TOKEN, MAYBE_URI_END, END, F_CR, F_LF, F_CRLF
+enum
+{
+	START_TO,
+	DISPLAY_QUOTED,
+	E_DISPLAY_QUOTED,
+	DISPLAY_TOKEN,
+	DISPLAY_TOKEN_SP,
+	S_URI_ENCLOSED,
+	URI_ENCLOSED,
+	E_URI_ENCLOSED,
+	URI_OR_TOKEN,
+	MAYBE_URI_END,
+	END,
+	F_CR,
+	F_LF,
+	F_CRLF
 };
 
 
-enum {
-	S_PARA_NAME=20, PARA_NAME, S_EQUAL, S_PARA_VALUE, TAG1, TAG2,
-	TAG3, PARA_VALUE_TOKEN , PARA_VALUE_QUOTED, E_PARA_VALUE
+enum
+{
+	S_PARA_NAME = 20,
+	PARA_NAME,
+	S_EQUAL,
+	S_PARA_VALUE,
+	TAG1,
+	TAG2,
+	TAG3,
+	PARA_VALUE_TOKEN,
+	PARA_VALUE_QUOTED,
+	E_PARA_VALUE
 };
 
 
-
-#define add_param( _param , _body , _newparam ) \
-	do{\
-		DBG("DEBUG: add_param: %.*s=%.*s\n",param->name.len,ZSW(param->name.s),\
-			param->value.len,ZSW(param->value.s));\
-		if (!(_body)->param_lst)  (_body)->param_lst=(_param);\
-		else (_body)->last_param->next=(_param);\
-		(_body)->last_param =(_param);\
-		if ((_param)->type==TAG_PARAM)\
-			memcpy(&((_body)->tag_value),&((_param)->value),sizeof(str));\
-		_newparam = 0;\
-	}while(0);
-
-
-
-
-
-static char* parse_to_param(char* const buffer, const char* const end,
-					struct to_body* const to_b, const int allow_comma_sep,
-					int* const returned_status)
+#define add_param(_param, _body, _newparam)                                   \
+	do {                                                                      \
+		LM_DBG("add param: %.*s=%.*s\n", param->name.len, ZSW(param->name.s), \
+				param->value.len, ZSW(param->value.s));                       \
+		if(!(_body)->param_lst)                                               \
+			(_body)->param_lst = (_param);                                    \
+		else                                                                  \
+			(_body)->last_param->next = (_param);                             \
+		(_body)->last_param = (_param);                                       \
+		if((_param)->type == TAG_PARAM)                                       \
+			memcpy(&((_body)->tag_value), &((_param)->value), sizeof(str));   \
+		_newparam = 0;                                                        \
+	} while(0);
+
+
+static char *parse_to_param(char *const buffer, const char *const end,
+		struct to_body *const to_b, const int allow_comma_sep,
+		int *const returned_status)
 {
 	struct to_param *param;
 	struct to_param *newparam;
 	int status;
 	int saved_status;
-	char  *tmp;
-
-	param=0;
-	newparam=0;
-	status=E_PARA_VALUE;
-	saved_status=E_PARA_VALUE;
-	for( tmp=buffer; tmp<end; tmp++)
-	{
-		switch(*tmp)
-		{
+	char *tmp;
+
+	param = 0;
+	newparam = 0;
+	status = E_PARA_VALUE;
+	saved_status = E_PARA_VALUE;
+	for(tmp = buffer; tmp < end; tmp++) {
+		switch(*tmp) {
 			case ' ':
 			case '\t':
-				switch (status)
-				{
+				switch(status) {
 					case TAG3:
-						param->type=TAG_PARAM;
+						param->type = TAG_PARAM;
 					case PARA_NAME:
 					case TAG1:
 					case TAG2:
-						param->name.len = tmp-param->name.s;
+						param->name.len = tmp - param->name.s;
 						status = S_EQUAL;
 						break;
 					case PARA_VALUE_TOKEN:
-						param->value.len = tmp-param->value.s;
+						param->value.len = tmp - param->value.s;
 						status = E_PARA_VALUE;
 						add_param(param, to_b, newparam);
 						break;
@@ -103,69 +119,67 @@ static char* parse_to_param(char* const buffer, const char* const end,
 					case F_LF:
 					case F_CR:
 						/*previous=crlf and now =' '*/
-						status=saved_status;
+						status = saved_status;
 						break;
 				}
 				break;
 			case '\n':
-				switch (status)
-				{
+				switch(status) {
 					case S_PARA_NAME:
 					case S_EQUAL:
 					case S_PARA_VALUE:
 					case E_PARA_VALUE:
-						saved_status=status;
-						status=F_LF;
+						saved_status = status;
+						status = F_LF;
 						break;
 					case TAG3:
-						param->type=TAG_PARAM;
+						param->type = TAG_PARAM;
 					case PARA_NAME:
 					case TAG1:
 					case TAG2:
-						param->name.len = tmp-param->name.s;
+						param->name.len = tmp - param->name.s;
 						saved_status = S_EQUAL;
 						status = F_LF;
 						break;
 					case PARA_VALUE_TOKEN:
-						param->value.len = tmp-param->value.s;
+						param->value.len = tmp - param->value.s;
 						saved_status = E_PARA_VALUE;
 						status = F_LF;
 						add_param(param, to_b, newparam);
 						break;
 					case F_CR:
-						status=F_CRLF;
+						status = F_CRLF;
 						break;
 					case F_CRLF:
 					case F_LF:
-						status=saved_status;
+						status = saved_status;
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case '\r':
-				switch (status)
-				{
+				switch(status) {
 					case S_PARA_NAME:
 					case S_EQUAL:
 					case S_PARA_VALUE:
 					case E_PARA_VALUE:
-						saved_status=status;
-						status=F_CR;
+						saved_status = status;
+						status = F_CR;
 						break;
 					case TAG3:
-						param->type=TAG_PARAM;
+						param->type = TAG_PARAM;
 					case PARA_NAME:
 					case TAG1:
 					case TAG2:
-						param->name.len = tmp-param->name.s;
+						param->name.len = tmp - param->name.s;
 						saved_status = S_EQUAL;
 						status = F_CR;
 						break;
 					case PARA_VALUE_TOKEN:
-						param->value.len = tmp-param->value.s;
+						param->value.len = tmp - param->value.s;
 						saved_status = E_PARA_VALUE;
 						status = F_CR;
 						add_param(param, to_b, newparam);
@@ -173,48 +187,45 @@ static char* parse_to_param(char* const buffer, const char* const end,
 					case F_CRLF:
 					case F_CR:
 					case F_LF:
-						status=saved_status;
+						status = saved_status;
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case 0:
-				switch (status)
-				{
+				switch(status) {
 					case TAG3:
 						param->type = TAG_PARAM;
 					case PARA_NAME:
 					case TAG1:
 					case TAG2:
-						param->name.len = tmp-param->name.s;
+						param->name.len = tmp - param->name.s;
 						status = S_EQUAL;
 					case S_EQUAL:
 					case S_PARA_VALUE:
-						saved_status=status;
+						saved_status = status;
 						goto endofheader;
 					case PARA_VALUE_TOKEN:
 						status = E_PARA_VALUE;
-						param->value.len = tmp-param->value.s;
-						add_param(param , to_b, newparam);
+						param->value.len = tmp - param->value.s;
+						add_param(param, to_b, newparam);
 					case E_PARA_VALUE:
 						saved_status = status;
 						goto endofheader;
 						break;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case '\\':
-				switch (status)
-				{
+				switch(status) {
 					case PARA_VALUE_QUOTED:
-						switch (*(tmp+1))
-						{
+						switch(*(tmp + 1)) {
 							case '\r':
 							case '\n':
 								break;
@@ -223,19 +234,18 @@ static char* parse_to_param(char* const buffer, const char* const end,
 						}
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case '"':
-				switch (status)
-				{
+				switch(status) {
 					case S_PARA_VALUE:
-						param->value.s = tmp+1;
+						param->value.s = tmp + 1;
 						status = PARA_VALUE_QUOTED;
 						break;
 					case PARA_VALUE_QUOTED:
-						param->value.len=tmp-param->value.s;
+						param->value.len = tmp - param->value.s;
 						add_param(param, to_b, newparam);
 						status = E_PARA_VALUE;
 						break;
@@ -246,13 +256,12 @@ static char* parse_to_param(char* const buffer, const char* const end,
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status,(int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
-			case ';' :
-				switch (status)
-				{
+			case ';':
+				switch(status) {
 					case PARA_VALUE_QUOTED:
 						break;
 					case TAG3:
@@ -260,7 +269,7 @@ static char* parse_to_param(char* const buffer, const char* const end,
 					case PARA_NAME:
 					case TAG1:
 					case TAG2:
-						param->name.len = tmp-param->name.s;
+						param->name.len = tmp - param->name.s;
 					case S_EQUAL:
 						param->value.s = 0;
 						param->value.len = 0;
@@ -268,18 +277,18 @@ static char* parse_to_param(char* const buffer, const char* const end,
 					case S_PARA_VALUE:
 						param->value.s = tmp;
 					case PARA_VALUE_TOKEN:
-						param->value.len=tmp-param->value.s;
-semicolon_add_param:
+						param->value.len = tmp - param->value.s;
+					semicolon_add_param:
 						add_param(param, to_b, newparam);
 					case E_PARA_VALUE:
-						param = (struct to_param*)
-							pkg_malloc(sizeof(struct to_param));
-						if (!param){
+						param = (struct to_param *)pkg_malloc(
+								sizeof(struct to_param));
+						if(!param) {
 							LM_ERR("out of memory\n");
 							goto error;
 						}
-						memset(param,0,sizeof(struct to_param));
-						param->type=GENERAL_PARAM;
+						memset(param, 0, sizeof(struct to_param));
+						param->type = GENERAL_PARAM;
 						status = S_PARA_NAME;
 						/* link to free mem if not added in to_body list */
 						newparam = param;
@@ -291,14 +300,13 @@ semicolon_add_param:
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case 'T':
-			case 't' :
-				switch (status)
-				{
+			case 't':
+				switch(status) {
 					case PARA_VALUE_QUOTED:
 					case PARA_VALUE_TOKEN:
 					case PARA_NAME:
@@ -323,14 +331,13 @@ semicolon_add_param:
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case 'A':
-			case 'a' :
-				switch (status)
-				{
+			case 'a':
+				switch(status) {
 					case PARA_VALUE_QUOTED:
 					case PARA_VALUE_TOKEN:
 					case PARA_NAME:
@@ -357,14 +364,13 @@ semicolon_add_param:
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case 'G':
-			case 'g' :
-				switch (status)
-				{
+			case 'g':
+				switch(status) {
 					case PARA_VALUE_QUOTED:
 					case PARA_VALUE_TOKEN:
 					case PARA_NAME:
@@ -391,21 +397,20 @@ semicolon_add_param:
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case '=':
-				switch (status)
-				{
+				switch(status) {
 					case PARA_VALUE_QUOTED:
 						break;
 					case TAG3:
-						param->type=TAG_PARAM;
+						param->type = TAG_PARAM;
 					case PARA_NAME:
 					case TAG1:
 					case TAG2:
-						param->name.len = tmp-param->name.s;
+						param->name.len = tmp - param->name.s;
 						status = S_PARA_VALUE;
 						break;
 					case S_EQUAL:
@@ -418,37 +423,35 @@ semicolon_add_param:
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case ',':
-				if(status==PARA_VALUE_QUOTED) {
+				if(status == PARA_VALUE_QUOTED) {
 					/* comma is allowed inside quoted values */
 					break;
 				}
-				if (allow_comma_sep)
-				{
-					switch (status)
-					{
+				if(allow_comma_sep) {
+					switch(status) {
 						case S_PARA_NAME:
 						case S_EQUAL:
 						case S_PARA_VALUE:
 						case E_PARA_VALUE:
-							saved_status=status;
-							status=E_PARA_VALUE;
+							saved_status = status;
+							status = E_PARA_VALUE;
 							goto endofheader;
 						case TAG3:
-							param->type=TAG_PARAM;
+							param->type = TAG_PARAM;
 						case PARA_NAME:
 						case TAG1:
 						case TAG2:
-							param->name.len = tmp-param->name.s;
+							param->name.len = tmp - param->name.s;
 							saved_status = S_EQUAL;
 							status = E_PARA_VALUE;
 							goto endofheader;
 						case PARA_VALUE_TOKEN:
-							param->value.len = tmp-param->value.s;
+							param->value.len = tmp - param->value.s;
 							saved_status = E_PARA_VALUE;
 							status = E_PARA_VALUE;
 							add_param(param, to_b, newparam);
@@ -456,27 +459,28 @@ semicolon_add_param:
 						case F_CRLF:
 						case F_CR:
 						case F_LF:
-							status=saved_status;
+							status = saved_status;
 							goto endofheader;
 						default:
-							LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-								*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+							LM_ERR("unexpected char [%c] in status %d: [%.*s] "
+									".\n",
+									*tmp, status, (int)(tmp - buffer),
+									ZSW(buffer));
 							goto error;
 					}
 					break;
 				} else {
-					if((status==S_PARA_VALUE || status==PARA_VALUE_TOKEN)
-							&& param->type==TAG_PARAM) {
+					if((status == S_PARA_VALUE || status == PARA_VALUE_TOKEN)
+							&& param->type == TAG_PARAM) {
 						/* if comma is not separator, allow it as part of value
 						 * - some user agents use it */
 						break;
 					}
 					LM_ERR("invalid character ',' in status %d: [%.*s]\n",
-							status, (int)(tmp-buffer), ZSW(buffer));
+							status, (int)(tmp - buffer), ZSW(buffer));
 				}
 			default:
-				switch (status)
-				{
+				switch(status) {
 					case TAG1:
 					case TAG2:
 					case TAG3:
@@ -500,94 +504,92 @@ semicolon_add_param:
 						/*previous=crlf and now !=' '*/
 						goto endofheader;
 					default:
-						LM_ERR("spitting out [%c] in status %d\n",*tmp,status);
+						LM_ERR("spitting out [%c] in status %d\n", *tmp,
+								status);
 						goto error;
 				}
-		}/*switch*/
-	}/*for*/
-	if (!(status==F_CR || status==F_LF || status==F_CRLF))
-		saved_status=status;
+		} /*switch*/
+	}	 /*for*/
+	if(!(status == F_CR || status == F_LF || status == F_CRLF))
+		saved_status = status;
 
 
 endofheader:
-	switch(saved_status){
+	switch(saved_status) {
 		case TAG3:
-			param->type = TAG_PARAM; /* tag at the end */
-			/* no break */
+			param->type = TAG_PARAM;	/* tag at the end */
+										/* no break */
 		case PARA_NAME:
 		case TAG1:
 		case TAG2:
-			param->name.len = tmp-param->name.s;
-			/* no break */
+			param->name.len = tmp - param->name.s;
+		/* no break */
 		case S_EQUAL:
 			/* parameter without '=', e.g. foo */
-			param->value.s=0;
-			param->value.len=0;
+			param->value.s = 0;
+			param->value.len = 0;
 			add_param(param, to_b, newparam);
-			saved_status=E_PARA_VALUE;
+			saved_status = E_PARA_VALUE;
 			break;
 		case S_PARA_VALUE:
 			/* parameter with null value, e.g. foo= */
-			if ( status==F_CRLF )
-				param->value.s=tmp-2;
-			else if ( status==F_CR || status==F_LF )
-				param->value.s=tmp-1;
+			if(status == F_CRLF)
+				param->value.s = tmp - 2;
+			else if(status == F_CR || status == F_LF)
+				param->value.s = tmp - 1;
 			else
-				param->value.s=tmp;
-			param->value.len=0;
+				param->value.s = tmp;
+			param->value.len = 0;
 			add_param(param, to_b, newparam);
-			saved_status=E_PARA_VALUE;
+			saved_status = E_PARA_VALUE;
 			break;
 		case PARA_VALUE_TOKEN:
-			param->value.len=tmp-param->value.s;
+			param->value.len = tmp - param->value.s;
 			add_param(param, to_b, newparam);
-			saved_status=E_PARA_VALUE;
+			saved_status = E_PARA_VALUE;
 			break;
 		case E_PARA_VALUE:
 			break;
 		default:
 			LM_ERR("unexpected end of header, status %d: [%.*s] .\n",
-						saved_status, (int)(tmp-buffer), ZSW(buffer));
+					saved_status, (int)(tmp - buffer), ZSW(buffer));
 			goto error;
 	}
-	*returned_status=saved_status;
+	*returned_status = saved_status;
 	return tmp;
 
 error:
-	if (newparam) pkg_free(newparam);
-	to_b->error=PARSE_ERROR;
+	if(newparam)
+		pkg_free(newparam);
+	to_b->error = PARSE_ERROR;
 	*returned_status = status;
 	return tmp;
 }
 
 
-
-char* parse_addr_spec(char* const buffer, const char* const end,
-		struct to_body* const to_b, const int allow_comma_sep)
+char *parse_addr_spec(char *const buffer, const char *const end,
+		struct to_body *const to_b, const int allow_comma_sep)
 {
 	int status;
 	int saved_status;
-	char  *tmp,*foo;
+	char *tmp, *foo;
 
-	saved_status=START_TO; /* fixes gcc 4.x warning */
-	status=START_TO;
+	saved_status = START_TO; /* fixes gcc 4.x warning */
+	status = START_TO;
 	memset(to_b, 0, sizeof(struct to_body));
-	to_b->error=PARSE_OK;
-	foo=0;
+	to_b->error = PARSE_OK;
+	foo = 0;
 
-	for( tmp=buffer; tmp<end; tmp++)
-	{
-		switch(*tmp)
-		{
+	for(tmp = buffer; tmp < end; tmp++) {
+		switch(*tmp) {
 			case ' ':
 			case '\t':
-				switch (status)
-				{
+				switch(status) {
 					case F_CRLF:
 					case F_LF:
 					case F_CR:
 						/*previous=crlf and now =' '*/
-						status=saved_status;
+						status = saved_status;
 						break;
 					case URI_ENCLOSED:
 						to_b->uri.len = tmp - to_b->uri.s;
@@ -604,8 +606,7 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 				}
 				break;
 			case '\n':
-				switch (status)
-				{
+				switch(status) {
 					case URI_OR_TOKEN:
 						foo = tmp;
 						status = MAYBE_URI_END;
@@ -613,30 +614,29 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 					case DISPLAY_TOKEN_SP:
 					case E_DISPLAY_QUOTED:
 					case END:
-						saved_status=status;
-						status=F_LF;
+						saved_status = status;
+						status = F_LF;
 						break;
 					case DISPLAY_TOKEN:
-						foo=tmp;
-						saved_status=DISPLAY_TOKEN_SP;
-						status=F_LF;
+						foo = tmp;
+						saved_status = DISPLAY_TOKEN_SP;
+						status = F_LF;
 						break;
 					case F_CR:
-						status=F_CRLF;
+						status = F_CRLF;
 						break;
 					case F_CRLF:
 					case F_LF:
-						status=saved_status;
+						status = saved_status;
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case '\r':
-				switch (status)
-				{
+				switch(status) {
 					case URI_OR_TOKEN:
 						foo = tmp;
 						status = MAYBE_URI_END;
@@ -644,28 +644,27 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 					case DISPLAY_TOKEN_SP:
 					case E_DISPLAY_QUOTED:
 					case END:
-						saved_status=status;
-						status=F_CR;
+						saved_status = status;
+						status = F_CR;
 						break;
 					case DISPLAY_TOKEN:
-						foo=tmp;
-						saved_status=DISPLAY_TOKEN_SP;
-						status=F_CR;
+						foo = tmp;
+						saved_status = DISPLAY_TOKEN_SP;
+						status = F_CR;
 						break;
 					case F_CRLF:
 					case F_CR:
 					case F_LF:
-						status=saved_status;
+						status = saved_status;
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case 0:
-				switch (status)
-				{
+				switch(status) {
 					case URI_OR_TOKEN:
 					case MAYBE_URI_END:
 						to_b->uri.len = tmp - to_b->uri.s;
@@ -674,27 +673,25 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case '\\':
-				switch (status)
-				{
+				switch(status) {
 					case DISPLAY_QUOTED:
 						tmp++; /* jump over next char */
 						break;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case '<':
-				switch (status)
-				{
+				switch(status) {
 					case START_TO:
-						to_b->body.s=tmp;
+						to_b->body.s = tmp;
 						status = S_URI_ENCLOSED;
 						break;
 					case DISPLAY_QUOTED:
@@ -704,12 +701,12 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 						break;
 					case URI_OR_TOKEN:
 					case DISPLAY_TOKEN:
-						to_b->display.len=tmp-to_b->display.s;
+						to_b->display.len = tmp - to_b->display.s;
 						status = S_URI_ENCLOSED;
 						break;
 					case DISPLAY_TOKEN_SP:
 					case MAYBE_URI_END:
-						to_b->display.len=foo-to_b->display.s;
+						to_b->display.len = foo - to_b->display.s;
 						status = S_URI_ENCLOSED;
 						break;
 					case F_CRLF:
@@ -719,13 +716,12 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case '>':
-				switch (status)
-				{
+				switch(status) {
 					case DISPLAY_QUOTED:
 						break;
 					case URI_ENCLOSED:
@@ -741,13 +737,12 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), ZSW(buffer));
+								*tmp, status, (int)(tmp - buffer), ZSW(buffer));
 						goto error;
 				}
 				break;
 			case '"':
-				switch (status)
-				{
+				switch(status) {
 					case START_TO:
 						to_b->body.s = tmp;
 						to_b->display.s = tmp;
@@ -755,7 +750,7 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 						break;
 					case DISPLAY_QUOTED:
 						status = E_DISPLAY_QUOTED;
-						to_b->display.len = tmp-to_b->display.s+1;
+						to_b->display.len = tmp - to_b->display.s + 1;
 						break;
 					case F_CRLF:
 					case F_LF:
@@ -764,13 +759,12 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), buffer);
+								*tmp, status, (int)(tmp - buffer), buffer);
 						goto error;
 				}
 				break;
-			case ';' :
-				switch (status)
-				{
+			case ';':
+				switch(status) {
 					case DISPLAY_QUOTED:
 					case URI_ENCLOSED:
 						break;
@@ -779,8 +773,9 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 					case MAYBE_URI_END:
 						to_b->uri.len = foo - to_b->uri.s;
 					case END:
-						to_b->body.len = tmp-to_b->body.s;
-						tmp = parse_to_param(tmp,end,to_b,allow_comma_sep,&saved_status);
+						to_b->body.len = tmp - to_b->body.s;
+						tmp = parse_to_param(
+								tmp, end, to_b, allow_comma_sep, &saved_status);
 						goto endofheader;
 					case F_CRLF:
 					case F_LF:
@@ -789,15 +784,13 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 						goto endofheader;
 					default:
 						LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-							*tmp,status, (int)(tmp-buffer), buffer);
+								*tmp, status, (int)(tmp - buffer), buffer);
 						goto error;
 				}
 				break;
-			case ',' :
-				if (allow_comma_sep)
-				{
-					switch (status)
-					{
+			case ',':
+				if(allow_comma_sep) {
+					switch(status) {
 						case DISPLAY_QUOTED:
 						case URI_ENCLOSED:
 							break;
@@ -806,7 +799,7 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 						case MAYBE_URI_END:
 							to_b->uri.len = foo - to_b->uri.s;
 						case END:
-							to_b->body.len = tmp-to_b->body.s;
+							to_b->body.len = tmp - to_b->body.s;
 							saved_status = END;
 							goto endofheader;
 						case F_CRLF:
@@ -815,24 +808,24 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 							/*previous=crlf and now !=' '*/
 							goto endofheader;
 						default:
-							LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n",
-								*tmp,status, (int)(tmp-buffer), buffer);
+							LM_ERR("unexpected char [%c] in status %d: [%.*s] "
+									".\n",
+									*tmp, status, (int)(tmp - buffer), buffer);
 							goto error;
 					}
 					break;
 				}
-				/* If commas not allowed treat as a default character */
+			/* If commas not allowed treat as a default character */
 			default:
-				switch (status)
-				{
+				switch(status) {
 					case START_TO:
 						to_b->uri.s = to_b->body.s = tmp;
 						status = URI_OR_TOKEN;
-						to_b->display.s=tmp;
+						to_b->display.s = tmp;
 						break;
 					case S_URI_ENCLOSED:
-						to_b->uri.s=tmp;
-						status=URI_ENCLOSED;
+						to_b->uri.s = tmp;
+						status = URI_ENCLOSED;
 						break;
 					case MAYBE_URI_END:
 					case DISPLAY_TOKEN_SP:
@@ -848,16 +841,15 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 						/*previous=crlf and now !=' '*/
 						goto endofheader;
 					default:
-						LM_DBG("spitting out [%c] in status %d\n",
-						*tmp,status );
+						LM_DBG("spitting out [%c] in status %d\n", *tmp,
+								status);
 						goto error;
 				}
-		}/*char switch*/
-	}/*for*/
+		} /*char switch*/
+	}	 /*for*/
 
 	/* Reached end of buffer */
-	switch (status)
-	{
+	switch(status) {
 		case URI_OR_TOKEN:
 		case MAYBE_URI_END:
 		case END:
@@ -866,11 +858,12 @@ char* parse_addr_spec(char* const buffer, const char* const end,
 	}
 
 endofheader:
-	if (to_b->display.len==0) to_b->display.s=0;
-	status=saved_status;
+	if(to_b->display.len == 0)
+		to_b->display.s = 0;
+	status = saved_status;
 	LM_DBG("end of header reached, state=%d\n", status);
 	/* check if error*/
-	switch(status){
+	switch(status) {
 		case URI_OR_TOKEN:
 		case MAYBE_URI_END:
 			to_b->uri.len = foo - to_b->uri.s;
@@ -880,35 +873,34 @@ endofheader:
 			break;
 		default:
 			LM_ERR("invalid To -  unexpected "
-					"end of header in state %d\n", status);
+					"end of header in state %d\n",
+					status);
 			goto error;
 	}
 	return tmp;
 
 error:
 	free_to_params(to_b);
-	to_b->error=PARSE_ERROR;
+	to_b->error = PARSE_ERROR;
 	return tmp;
-
 }
 
 
-void free_to_params(struct to_body* const tb)
+void free_to_params(struct to_body *const tb)
 {
-	struct to_param *tp=tb->param_lst;
+	struct to_param *tp = tb->param_lst;
 	struct to_param *foo;
-	while (tp){
+	while(tp) {
 		foo = tp->next;
 		pkg_free(tp);
-		tp=foo;
+		tp = foo;
 	}
 	tb->param_lst = NULL;
 }
 
 
-void free_to(struct to_body* const tb)
+void free_to(struct to_body *const tb)
 {
 	free_to_params(tb);
 	pkg_free(tb);
 }
-

+ 42 - 44
src/core/parser/parse_cseq.c

@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2001-2003 FhG Fokus
  *
  * This file is part of Kamailio, a free SIP server.
@@ -13,10 +13,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 /*! \file
@@ -26,77 +26,75 @@
  */
 
 
-
 #include "../comp_defs.h"
 #include "parse_cseq.h"
-#include "parser_f.h"  /* eat_space_end and so on */
+#include "parser_f.h" /* eat_space_end and so on */
 #include "../dprint.h"
 #include "parse_def.h"
 #include "parse_methods.h"
 #include "../mem/mem.h"
 
-/*BUGGY*/
-char* parse_cseq(char* const buf, const char* const end, struct cseq_body* const cb)
+/* parse cseq header */
+char *parse_cseq(char *const buf, const char *const end,
+		struct cseq_body *const cb)
 {
 	char *t, *m, *m_end;
-	
-	cb->error=PARSE_ERROR;
-	t=buf;
-	
-	cb->number.s=t;
-	t=eat_token_end(t, end);
-	if (t>=end) goto error;
-	cb->number.len=t-cb->number.s;
 
-	m=eat_space_end(t, end);
-	m_end=eat_token_end(m, end);
+	cb->error = PARSE_ERROR;
+	t = buf;
+
+	cb->number.s = t;
+	t = eat_token_end(t, end);
+	if(t >= end)
+		goto error;
+	cb->number.len = t - cb->number.s;
+
+	m = eat_space_end(t, end);
+	m_end = eat_token_end(m, end);
 
-	if (m_end>=end) {
-			LOG(L_ERR, "ERROR: parse_cseq: "
-						"method terminated unexpectedly\n");
-			goto error;
+	if(m_end >= end) {
+		LM_ERR("method terminated unexpectedly\n");
+		goto error;
 	}
-	if (m_end==m){
+	if(m_end == m) {
 		/* null method*/
-		LOG(L_ERR,  "ERROR:parse_cseq: no method found\n");
+		LM_ERR("no method found\n");
 		goto error;
 	}
-	cb->method.s=m;
-	t=m_end;
-	cb->method.len=t-cb->method.s;
+	cb->method.s = m;
+	t = m_end;
+	cb->method.len = t - cb->method.s;
 
 	/* Cache method id */
-	if (parse_method_name(&cb->method, &cb->method_id)!=0){
-		LOG(L_ERR, "Cannot parse method string\n");
+	if(parse_method_name(&cb->method, &cb->method_id) != 0) {
+		LM_ERR("Cannot parse method string\n");
 		goto error;
 	}
 
-	/* there may be trailing LWS 
-	 * (it was not my idea to put it in SIP; -jiri )
-	 */
-	t=eat_lws_end(t, end);
+	/* there may be trailing LWS */
+	t = eat_lws_end(t, end);
 	/*check if the header ends here*/
-	if (t>=end) {
-		LOG(L_ERR, "ERROR: parse_cseq: strange EoHF\n");
+	if(t >= end) {
+		LM_ERR("strange EoHF\n");
 		goto error;
 	}
-	if (*t=='\r' && t+1<end && *(t+1)=='\n') {
-			cb->error=PARSE_OK;
-			return t+2;
+	if(*t == '\r' && t + 1 < end && *(t + 1) == '\n') {
+		cb->error = PARSE_OK;
+		return t + 2;
 	}
-	if (*t=='\n') {
-			cb->error=PARSE_OK;
-			return t+1;
+	if(*t == '\n') {
+		cb->error = PARSE_OK;
+		return t + 1;
 	}
-	LOG(L_ERR, "ERROR: CSeq EoL expected\n");
+	LM_ERR("CSeq EoL expected\n");
 
 error:
-	LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n");
+	LM_ERR("bad cseq\n");
 	return t;
 }
 
 
-void free_cseq(struct cseq_body* const cb)
+void free_cseq(struct cseq_body *const cb)
 {
 	pkg_free(cb);
 }

+ 24 - 25
src/core/parser/parse_from.c

@@ -13,8 +13,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -38,40 +38,41 @@
  * This method is used to parse the from header.
  *
  * \note It was decided not to parse
- * anything in core that is not *needed* so this method gets called by 
+ * anything in core that is not *needed* so this method gets called by
  * rad_acc module and any other modules that needs the FROM header.
  *
  * params: msg : sip msg
  * returns 0 on success,
  *        -1 on failure.
  */
-int parse_from_header( struct sip_msg *msg)
+int parse_from_header(struct sip_msg *msg)
 {
-	struct to_body* from_b;
+	struct to_body *from_b;
 
-	if ( !msg->from && ( parse_headers(msg,HDR_FROM_F,0)==-1 || !msg->from)) {
-		LOG(L_ERR,"ERROR:parse_from_header: bad msg or missing FROM header\n");
+	if(!msg->from && (parse_headers(msg, HDR_FROM_F, 0) == -1 || !msg->from)) {
+		LM_ERR("bad msg or missing FROM header\n");
 		goto error;
 	}
 
 	/* maybe the header is already parsed! */
-	if (msg->from->parsed)
+	if(msg->from->parsed)
 		return 0;
 
 	/* bad luck! :-( - we have to parse it */
 	/* first, get some memory */
 	from_b = pkg_malloc(sizeof(struct to_body));
-	if (from_b == 0) {
-		LOG(L_ERR, "ERROR:parse_from_header: out of pkg_memory\n");
+	if(from_b == 0) {
+		LM_ERR("out of pkg_memory\n");
 		goto error;
 	}
 
 	/* now parse it!! */
 	memset(from_b, 0, sizeof(struct to_body));
-	parse_to(msg->from->body.s,msg->from->body.s+msg->from->body.len+1,from_b);
-	if (from_b->error == PARSE_ERROR) {
-		LOG(L_ERR, "ERROR:parse_from_header: bad from header [%.*s]\n",
-				msg->from->body.len, msg->from->body.s);
+	parse_to(msg->from->body.s, msg->from->body.s + msg->from->body.len + 1,
+			from_b);
+	if(from_b->error == PARSE_ERROR) {
+		LM_ERR("bad From header [%.*s]\n", msg->from->body.len,
+				msg->from->body.s);
 		free_to(from_b);
 		goto error;
 	}
@@ -85,26 +86,24 @@ error:
 sip_uri_t *parse_from_uri(sip_msg_t *msg)
 {
 	to_body_t *tb = NULL;
-        
-	if(msg==NULL)
+
+	if(msg == NULL)
 		return NULL;
 
-	if(parse_from_header(msg)<0)
-	{
+	if(parse_from_header(msg) < 0) {
 		LM_ERR("cannot parse FROM header\n");
 		return NULL;
 	}
-	
-	if(msg->from==NULL || get_from(msg)==NULL)
+
+	if(msg->from == NULL || get_from(msg) == NULL)
 		return NULL;
 
 	tb = get_from(msg);
-	
-	if(tb->parsed_uri.user.s!=NULL || tb->parsed_uri.host.s!=NULL)
+
+	if(tb->parsed_uri.user.s != NULL || tb->parsed_uri.host.s != NULL)
 		return &tb->parsed_uri;
-	
-	if (parse_uri(tb->uri.s, tb->uri.len , &tb->parsed_uri)<0)
-	{
+
+	if(parse_uri(tb->uri.s, tb->uri.len, &tb->parsed_uri) < 0) {
 		LM_ERR("failed to parse From uri\n");
 		memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
 		return NULL;

文件差异内容过多而无法显示
+ 394 - 347
src/core/parser/parse_param.c


+ 16 - 17
src/core/parser/parse_to.c

@@ -13,8 +13,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -35,50 +35,49 @@
 #include "../mem/mem.h"
 
 
-char* parse_to(char* const buffer, const char* const end, struct to_body* const to_b)
+char *parse_to(char *const buffer, const char *const end,
+		struct to_body *const to_b)
 {
 	return parse_addr_spec(buffer, end, to_b, 0);
 }
 
 
-int parse_to_header(struct sip_msg* const msg)
+int parse_to_header(struct sip_msg *const msg)
 {
-	if ( !msg->to && ( parse_headers(msg,HDR_TO_F,0)==-1 || !msg->to)) {
-		ERR("bad msg or missing TO header\n");
+	if(!msg->to && (parse_headers(msg, HDR_TO_F, 0) == -1 || !msg->to)) {
+		LM_ERR("bad msg or missing TO header\n");
 		return -1;
 	}
 
 	// HDR_TO_T is automatically parsed (get_hdr_field in parser/msg_parser.c)
 	// so check only ptr validity
-	if (msg->to->parsed)
+	if(msg->to->parsed)
 		return 0;
 	else
 		return -1;
 }
 
-sip_uri_t *parse_to_uri(sip_msg_t* const msg)
+sip_uri_t *parse_to_uri(sip_msg_t *const msg)
 {
 	to_body_t *tb = NULL;
-	
-	if(msg==NULL)
+
+	if(msg == NULL)
 		return NULL;
 
-	if(parse_to_header(msg)<0)
-	{
+	if(parse_to_header(msg) < 0) {
 		LM_ERR("cannot parse TO header\n");
 		return NULL;
 	}
 
-	if(msg->to==NULL || get_to(msg)==NULL)
+	if(msg->to == NULL || get_to(msg) == NULL)
 		return NULL;
 
 	tb = get_to(msg);
-	
-	if(tb->parsed_uri.user.s!=NULL || tb->parsed_uri.host.s!=NULL)
+
+	if(tb->parsed_uri.user.s != NULL || tb->parsed_uri.host.s != NULL)
 		return &tb->parsed_uri;
 
-	if (parse_uri(tb->uri.s, tb->uri.len , &tb->parsed_uri)<0)
-	{
+	if(parse_uri(tb->uri.s, tb->uri.len, &tb->parsed_uri) < 0) {
 		LM_ERR("failed to parse To uri\n");
 		memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
 		return NULL;

部分文件因为文件数量过多而无法显示