Browse Source

siptrace: siptrace_copy_proto() converted to macro

Daniel-Constantin Mierla 7 years ago
parent
commit
aaf3b2e35b
2 changed files with 36 additions and 24 deletions
  1. 0 23
      src/modules/siptrace/siptrace_send.c
  2. 36 1
      src/modules/siptrace/siptrace_send.h

+ 0 - 23
src/modules/siptrace/siptrace_send.c

@@ -41,29 +41,6 @@ extern int *xheaders_read_flag;
 extern str dup_uri_str;
 extern sip_uri_t *dup_uri;
 
-/**
- *
- */
-int siptrace_copy_proto(int proto, char *buf)
-{
-	if(buf == 0)
-		return -1;
-	if(proto == PROTO_TCP) {
-		strcpy(buf, "tcp:");
-	} else if(proto == PROTO_TLS) {
-		strcpy(buf, "tls:");
-	} else if(proto == PROTO_SCTP) {
-		strcpy(buf, "sctp:");
-	} else if(proto == PROTO_WS) {
-		strcpy(buf, "ws:");
-	} else if(proto == PROTO_WSS) {
-		strcpy(buf, "wss:");
-	} else {
-		strcpy(buf, "udp:");
-	}
-	return 0;
-}
-
 /**
  *
  */

+ 36 - 1
src/modules/siptrace/siptrace_send.h

@@ -28,11 +28,46 @@
 #include "../../core/ip_addr.h"
 #include "siptrace_data.h"
 
-int siptrace_copy_proto(int proto, char *buf);
 int sip_trace_prepare(sip_msg_t *msg);
 int sip_trace_xheaders_write(struct _siptrace_data *sto);
 int sip_trace_xheaders_read(struct _siptrace_data *sto);
 int sip_trace_xheaders_free(struct _siptrace_data *sto);
 int trace_send_duplicate(char *buf, int len, struct dest_info *dst2);
 
+/**
+ *
+ */
+#define siptrace_copy_proto_olen(vproto, vbuf, vlen) do { \
+		switch(vproto) { \
+			case PROTO_TCP: \
+				strcpy(vbuf, "tcp:"); \
+				vlen = 4; \
+			break; \
+			case PROTO_TLS: \
+				strcpy(vbuf, "tls:"); \
+				vlen = 4; \
+			break; \
+			case PROTO_SCTP: \
+				strcpy(vbuf, "sctp:"); \
+				vlen = 5; \
+			break; \
+			case PROTO_WS: \
+				strcpy(vbuf, "ws:"); \
+				vlen = 3; \
+			break; \
+			case PROTO_WSS: \
+				strcpy(vbuf, "wss:"); \
+				vlen = 4; \
+			break; \
+			default: \
+				strcpy(vbuf, "udp:"); \
+				vlen = 4; \
+		} \
+	} while(0)
+
+#define siptrace_copy_proto(vproto, vbuf) do { \
+		int __olen; \
+		siptrace_copy_proto_olen(vproto, vbuf, __olen); \
+	} while(0)
+
 #endif