Ver Fonte

core: Consolidate append_str macro usage

The definition of append_str macro was scattered across the source tree,
there were multiple definition of the macro, some of them with different
parameters.

This patch brings the definition of append_str macro into ut.h header
file and removes all other definitions from core and modules.

We chose the version with three parameters where the pointer and the
length of the source string are passed separately to the macro. This is
more flexible than passing both of them within one parameter as str
structure.

All references to append_mem_block have been removed because the same
operation can now be achieved with append_str. In addition to that we
updated parameters passed to append_str where needed, converting one
str parameter to <pointer,len> pair of parameters.

Some modules had yet another version of append_str defined, there we
renamed the macro to some other name to make sure that the local
definition does not conflict with the definition on ut.h
Jan Janak há 16 anos atrás
pai
commit
47945782e1

+ 0 - 11
lib/kcore/km_ut.h

@@ -41,17 +41,6 @@
 #endif
 
 
-#define append_str(_dest,_src,_len)				\
-	do{											\
-		memcpy( (_dest) , (_src) , (_len) );	\
-		(_dest) += (_len) ;						\
-	}while(0);									\
-	
-/*! append _c char to _dest string */
-#define append_chr(_dest,_c) \
-	*((_dest)++) = _c;
-
-
 /* INTeger-TO-Buffer-STRing : convers an unsigned long to a string 
  * IMPORTANT: the provided buffer must be at least INT2STR_MAX_LEN size !! */
 static inline char* int2bstr(unsigned long l, char *s, int* len)

+ 4 - 4
modules/tm/t_fifo.c

@@ -105,7 +105,7 @@
 			append_chr(s,','); len++;\
 		}\
 		append_chr(s,'<');len++;\
-		append_mem_block(s,rs,rlen);\
+		append_str(s,rs,rlen);\
 		len += rlen; \
 		append_chr(s,'>');len++;\
 	} while(0)
@@ -824,7 +824,7 @@ static int assemble_msg(struct sip_msg* msg, struct tw_info *twi)
 		    "while copying optional header\n");
 		goto error;
 	}
-	append_mem_block(s,"P-MsgFlags: ",12);
+	append_str(s,"P-MsgFlags: ",12);
 	l = APPEND_BUFFER_MAX - (12+1); /* include trailing `\n'*/
 
 	if (int2reverse_hex(&s, &l, (int)msg->msg_flags) == -1) {
@@ -848,8 +848,8 @@ static int assemble_msg(struct sip_msg* msg, struct tw_info *twi)
 		    "copying command name\n");
 		goto error;
 	}
-	append_mem_block(s,"sip_request.",12);
-	append_str(s,twi->action);
+	append_str(s,"sip_request.",12);
+	append_str(s,twi->action.s, twi->action.len);
 	eol_line_len(1) = s - (char*)eol_line_s(1);
 
 	eol_line(2,REQ_LINE(msg).method);     /* method type */

+ 0 - 16
modules/tm/t_funcs.h

@@ -86,22 +86,6 @@ extern int_str contacts_avp;
 #define FR_INV_TIMER_AVP  "callee_fr_inv_timer"
 
 
-#define append_str(_dest,_str) \
-	do{ \
-		memcpy( (_dest) , (_str).s , (_str).len );\
-		(_dest) += (_str).len ;\
-	}while(0);
-
-#define  append_mem_block(_d,_s,_len) \
-		do{\
-			memcpy((_d),(_s),(_len));\
-			(_d) += (_len);\
-		}while(0);
-
-#define append_chr(_dest,_c) \
-	*((_dest)++) = _c;
-
-
 /* send a private buffer: utilize a retransmission structure
    but take a separate buffer not referred by it; healthy
    for reducing time spend in REPLIES locks

+ 48 - 48
modules/tm/t_msgbuilder.c

@@ -167,37 +167,37 @@ char *build_local(struct cell *Trans,unsigned int branch,
 	}
 	p = cancel_buf;
 
-	append_mem_block( p, method, method_len );
-	append_mem_block( p, " ", 1 );
-	append_str( p, Trans->uac[branch].uri);
-	append_mem_block( p, " " SIP_VERSION CRLF, 1+SIP_VERSION_LEN+CRLF_LEN );
+	append_str( p, method, method_len );
+	append_str( p, " ", 1 );
+	append_str( p, Trans->uac[branch].uri.s, Trans->uac[branch].uri.len);
+	append_str( p, " " SIP_VERSION CRLF, 1+SIP_VERSION_LEN+CRLF_LEN );
 
 	/* insert our via */
-	append_mem_block(p,via,via_len);
+	append_str(p,via,via_len);
 
 	/*other headers*/
-	append_str( p, Trans->from );
-	append_str( p, Trans->callid );
-	append_str( p, *to );
+	append_str( p, Trans->from.s, Trans->from.len );
+	append_str( p, Trans->callid.s, Trans->callid.len );
+	append_str( p, to->s, to->len );
 
-	append_str( p, Trans->cseq_n );
-	append_mem_block( p, " ", 1 );
-	append_mem_block( p, method, method_len );
-	append_mem_block( p, CRLF, CRLF_LEN );
+	append_str( p, Trans->cseq_n.s, Trans->cseq_n.len );
+	append_str( p, " ", 1 );
+	append_str( p, method, method_len );
+	append_str( p, CRLF, CRLF_LEN );
 
 	if (!is_local(Trans))  {
 		for ( hdr=Trans->uas.request->headers ; hdr ; hdr=hdr->next )
 			if(hdr->type==HDR_ROUTE_T) {
-				append_mem_block(p, hdr->name.s, hdr->len );
+				append_str(p, hdr->name.s, hdr->len );
 			}
 	}
 
 	/* User Agent header */
 	if (server_signature) {
-		append_mem_block(p,USER_AGENT CRLF, USER_AGENT_LEN+CRLF_LEN );
+		append_str(p,USER_AGENT CRLF, USER_AGENT_LEN+CRLF_LEN );
 	}
 	/* Content Length, EoM */
-	append_mem_block(p, CONTENT_LENGTH "0" CRLF CRLF ,
+	append_str(p, CONTENT_LENGTH "0" CRLF CRLF ,
 		CONTENT_LENGTH_LEN+1 + CRLF_LEN + CRLF_LEN);
 	*p=0;
 
@@ -253,14 +253,14 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
 	d = cancel_buf;
 
 	/* method name + space */
-	append_mem_block(d, method, method_len);
+	append_str(d, method, method_len);
 	*d = ' ';
 	d++;
 	/* skip "INVITE " and copy the rest of the line including CRLF */
 	s += 7;
 	s1 = s;
 	s = eat_line(s, invite_buf_end - s);
-	append_mem_block(d, s1, s - s1);
+	append_str(d, s1, s - s1);
 
 	/* check every header field name,
 	we must exclude and modify some of the headers */
@@ -282,9 +282,9 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
 				while ((s < invite_buf_end)
 					&& ((*s == ':') || (*s == ' ') || (*s == '\t') || ((*s >= '0') && (*s <= '9')))
 					) s++;
-				append_mem_block(d, s1, s - s1);
-				append_mem_block(d, method, method_len);
-				append_mem_block(d, CRLF, CRLF_LEN);
+				append_str(d, s1, s - s1);
+				append_str(d, method, method_len);
+				append_str(d, CRLF, CRLF_LEN);
 				s = lw_next_line(s, invite_buf_end);
 				break;
 
@@ -292,7 +292,7 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
 				s = lw_next_line(s, invite_buf_end);
 				if (first_via) {
 					/* copy hf */
-					append_mem_block(d, s1, s - s1);
+					append_str(d, s1, s - s1);
 					first_via = 0;
 				} /* else skip this line, we need olny the first via */
 				break;
@@ -301,10 +301,10 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
 				if (to_len == 0) {
 					/* there is no To tag required, just copy paste the header */
 					s = lw_next_line(s, invite_buf_end);
-					append_mem_block(d, s1, s - s1);
+					append_str(d, s1, s - s1);
 				} else {
 					/* use the given To HF instead of the original one */
-					append_mem_block(d, to->s, to->len);
+					append_str(d, to->s, to->len);
 					/* move the pointer to the next line */
 					s = lw_next_line(s, invite_buf_end);
 				}
@@ -316,7 +316,7 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
 			case HDR_MAXFORWARDS_T:
 				/* copy hf */
 				s = lw_next_line(s, invite_buf_end);
-				append_mem_block(d, s1, s - s1);
+				append_str(d, s1, s - s1);
 				break;
 
 			case HDR_REQUIRE_T:
@@ -327,15 +327,15 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
 
 			case HDR_CONTENTLENGTH_T:
 				/* copy hf name with 0 value */
-				append_mem_block(d, s1, s - s1);
-				append_mem_block(d, ": 0" CRLF, 3 + CRLF_LEN);
+				append_str(d, s1, s - s1);
+				append_str(d, ": 0" CRLF, 3 + CRLF_LEN);
 				/* move the pointer to the next line */
 				s = lw_next_line(s, invite_buf_end);
 				break;
 
 			case HDR_EOH_T:
 				/* end of SIP message found */
-				append_mem_block(d, CRLF, CRLF_LEN);
+				append_str(d, CRLF, CRLF_LEN);
 				*len = d - cancel_buf;
 				/* LOG(L_DBG, "DBG: build_local: %.*s\n", *len, cancel_buf); */
 				return cancel_buf;
@@ -349,7 +349,7 @@ char *build_local_reparse(struct cell *Trans,unsigned int branch,
 						cfg_get(tm, tm_cfg, ac_extra_hdrs).s,
 						cfg_get(tm, tm_cfg, ac_extra_hdrs).len) == 0)
 				) {
-					append_mem_block(d, s1, s - s1);
+					append_str(d, s1, s - s1);
 				} /* else skip this line */
 				break;
 		}
@@ -444,7 +444,7 @@ static inline char* print_rs(char* p, struct rte* list, str* contact)
 	if (contact) {
 		if (list) memapp(p, ROUTE_SEPARATOR, ROUTE_SEPARATOR_LEN);
 		*p++ = '<';
-		append_str(p, *contact);
+		append_str(p, contact->s, contact->len);
 		*p++ = '>';
 	}
 	
@@ -1054,45 +1054,45 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans,
 	}
 	p = req_buf;
 	
-	append_mem_block( p, ACK, ACK_LEN );
-	append_mem_block( p, " ", 1 );
-	append_str(p, ruri);
-	append_mem_block( p, " " SIP_VERSION CRLF, 1 + SIP_VERSION_LEN + CRLF_LEN);
+	append_str( p, ACK, ACK_LEN );
+	append_str( p, " ", 1 );
+	append_str(p, ruri.s, ruri.len);
+	append_str( p, " " SIP_VERSION CRLF, 1 + SIP_VERSION_LEN + CRLF_LEN);
   	 
 	     /* insert our via */
-	append_mem_block(p, via, via_len);
+	append_str(p, via, via_len);
 	
 	     /*other headers*/
-	append_str(p, Trans->from);
-	append_str(p, Trans->callid);
-	append_str(p, *to);
+	append_str(p, Trans->from.s, Trans->from.len);
+	append_str(p, Trans->callid.s, Trans->callid.len);
+	append_str(p, to->s, to->len);
 	
-	append_str(p, Trans->cseq_n);
-	append_mem_block( p, " ", 1 );
-	append_mem_block( p, ACK, ACK_LEN);
-	append_mem_block(p, CRLF, CRLF_LEN);
+	append_str(p, Trans->cseq_n.s, Trans->cseq_n.len);
+	append_str( p, " ", 1 );
+	append_str( p, ACK, ACK_LEN);
+	append_str(p, CRLF, CRLF_LEN);
 	
 	     /* Routeset */
 	p = print_rs(p, list, cont);
 	
 	     /* User Agent header */
 	if (server_signature) {
-		append_mem_block(p, USER_AGENT CRLF, USER_AGENT_LEN + CRLF_LEN);
+		append_str(p, USER_AGENT CRLF, USER_AGENT_LEN + CRLF_LEN);
 	}
 	
 	/* extra headers */
 	if (hdrs)
-		append_mem_block(p, hdrs->s, hdrs->len);
+		append_str(p, hdrs->s, hdrs->len);
 	
 	     /* Content Length, EoH, (body) */
 	if (body) {
-		append_mem_block(p, CONTENT_LENGTH, CONTENT_LENGTH_LEN);
-		append_mem_block(p, body_len.s, body_len.len);
-		append_mem_block(p, /*end crr. header*/CRLF /*EoH*/CRLF, CRLF_LEN + 
+		append_str(p, CONTENT_LENGTH, CONTENT_LENGTH_LEN);
+		append_str(p, body_len.s, body_len.len);
+		append_str(p, /*end crr. header*/CRLF /*EoH*/CRLF, CRLF_LEN + 
 				CRLF_LEN);
-		append_mem_block(p, body->s, body->len);
+		append_str(p, body->s, body->len);
 	} else {
-		append_mem_block(p, CONTENT_LENGTH "0" CRLF CRLF, 
+		append_str(p, CONTENT_LENGTH "0" CRLF CRLF, 
 				CONTENT_LENGTH_LEN + 1 + CRLF_LEN + CRLF_LEN);
 	}
 

+ 4 - 4
modules/tm/t_serial.c

@@ -83,11 +83,11 @@ static inline int encode_branch_info(str *info, struct contact *con)
 		return 0;
     }
     at = info->s;
-    append_str(at, con->uri);
+    append_str(at, con->uri.s, con->uri.len);
     append_chr(at, '\n');
-    append_str(at, con->dst_uri);
+    append_str(at, con->dst_uri.s, con->dst_uri.len);
     append_chr(at, '\n');
-    append_str(at, con->path);
+    append_str(at, con->path.s, con->path.len);
     append_chr(at, '\n');
     if (con->sock) {
 		len = MAX_SOCKET_STR;
@@ -101,7 +101,7 @@ static inline int encode_branch_info(str *info, struct contact *con)
     at = at + len;
     append_chr(at, '\n');
     s = int2str(con->flags, &len);
-    append_mem_block(at, s, len);
+    append_str(at, s, len);
     append_chr(at, '\n');
     info->len = at - info->s + 1;
 

+ 4 - 4
modules_s/acc_syslog/acc_syslog.c

@@ -250,7 +250,7 @@ static inline int skip_cancel(struct sip_msg *msg)
     } while(0);
 
 
-#define append_str(buf, str)                  \
+#define str_append_str(buf, str)			  \
     do {                                      \
         memcpy((buf).s, (str).s, (str).len);  \
         (buf).s += (str).len;                 \
@@ -659,9 +659,9 @@ static int log_request(struct sip_msg* rq, str* ouri, struct hdr_field* to, str*
 
 	for (i = 0; i < attr_cnt; i++) {
 		append(buf, A_SEPARATOR);
-		append_str(buf, atr_arr[i]);
+		str_append_str(buf, atr_arr[i]);
 		append(buf, A_EQ);
-		append_str(buf, *(val_arr[i]))
+		str_append_str(buf, *(val_arr[i]))
 	}
 
 	     /* terminating text */
@@ -671,7 +671,7 @@ static int log_request(struct sip_msg* rq, str* ouri, struct hdr_field* to, str*
 	buf.s = log_msg;
 	buf.len = len;
 	append(buf, ACC);
-	append_str(buf, *txt);
+	str_append_str(buf, *txt);
 
 	LOG(log_level, "%s", log_msg);
 	pkg_free(log_msg);

+ 0 - 4
modules_s/sms/sms_funcs.c

@@ -98,10 +98,6 @@ struct tm_binds tmb;
 #define CONTENT_TYPE_HDR     "Content-Type: text/plain"
 #define CONTENT_TYPE_HDR_LEN (sizeof(CONTENT_TYPE_HDR)-1)
 
-#define append_str(_p,_s,_l) \
-	{memcpy((_p),(_s),(_l));\
-	(_p) += (_l);}
-
 #define is_in_sip_addr(_p) \
 	((_p)!=' ' && (_p)!='\t' && (_p)!='(' && (_p)!='[' && (_p)!='<' \
 	&& (_p)!='>' && (_p)!=']' && (_p)!=')' && (_p)!='?' && (_p)!='!' \

+ 0 - 6
msg_translator.c

@@ -143,12 +143,6 @@
 #include "forward.h"
 
 
-#define append_str(_dest,_src,_len) \
-	do{\
-		memcpy( (_dest) , (_src) , (_len) );\
-		(_dest) += (_len) ;\
-	}while(0);
-
 #define append_str_trans(_dest,_src,_len,_msg) \
 	append_str( (_dest), (_src), (_len) );
 

+ 12 - 0
ut.h

@@ -149,6 +149,18 @@
 #endif
 
 
+#define append_str(_dest,_src,_len)				\
+	do{											\
+		memcpy( (_dest) , (_src) , (_len) );	\
+		(_dest) += (_len) ;						\
+	}while(0);									\
+
+	
+/*! append _c char to _dest string */
+#define append_chr(_dest,_c) \
+	*((_dest)++) = _c;
+
+
 /* links a value to a msgid */
 struct msgid_var{
 	union{