Browse code

siptrace: siptrace_copy_proto() converted to macro

Daniel-Constantin Mierla authored on 09/01/2018 09:00:31
Showing 2 changed files
... ...
@@ -41,29 +41,6 @@ extern int *xheaders_read_flag;
41 41
 extern str dup_uri_str;
42 42
 extern sip_uri_t *dup_uri;
43 43
 
44
-/**
45
- *
46
- */
47
-int siptrace_copy_proto(int proto, char *buf)
48
-{
49
-	if(buf == 0)
50
-		return -1;
51
-	if(proto == PROTO_TCP) {
52
-		strcpy(buf, "tcp:");
53
-	} else if(proto == PROTO_TLS) {
54
-		strcpy(buf, "tls:");
55
-	} else if(proto == PROTO_SCTP) {
56
-		strcpy(buf, "sctp:");
57
-	} else if(proto == PROTO_WS) {
58
-		strcpy(buf, "ws:");
59
-	} else if(proto == PROTO_WSS) {
60
-		strcpy(buf, "wss:");
61
-	} else {
62
-		strcpy(buf, "udp:");
63
-	}
64
-	return 0;
65
-}
66
-
67 44
 /**
68 45
  *
69 46
  */
... ...
@@ -28,11 +28,46 @@
28 28
 #include "../../core/ip_addr.h"
29 29
 #include "siptrace_data.h"
30 30
 
31
-int siptrace_copy_proto(int proto, char *buf);
32 31
 int sip_trace_prepare(sip_msg_t *msg);
33 32
 int sip_trace_xheaders_write(struct _siptrace_data *sto);
34 33
 int sip_trace_xheaders_read(struct _siptrace_data *sto);
35 34
 int sip_trace_xheaders_free(struct _siptrace_data *sto);
36 35
 int trace_send_duplicate(char *buf, int len, struct dest_info *dst2);
37 36
 
37
+/**
38
+ *
39
+ */
40
+#define siptrace_copy_proto_olen(vproto, vbuf, vlen) do { \
41
+		switch(vproto) { \
42
+			case PROTO_TCP: \
43
+				strcpy(vbuf, "tcp:"); \
44
+				vlen = 4; \
45
+			break; \
46
+			case PROTO_TLS: \
47
+				strcpy(vbuf, "tls:"); \
48
+				vlen = 4; \
49
+			break; \
50
+			case PROTO_SCTP: \
51
+				strcpy(vbuf, "sctp:"); \
52
+				vlen = 5; \
53
+			break; \
54
+			case PROTO_WS: \
55
+				strcpy(vbuf, "ws:"); \
56
+				vlen = 3; \
57
+			break; \
58
+			case PROTO_WSS: \
59
+				strcpy(vbuf, "wss:"); \
60
+				vlen = 4; \
61
+			break; \
62
+			default: \
63
+				strcpy(vbuf, "udp:"); \
64
+				vlen = 4; \
65
+		} \
66
+	} while(0)
67
+
68
+#define siptrace_copy_proto(vproto, vbuf) do { \
69
+		int __olen; \
70
+		siptrace_copy_proto_olen(vproto, vbuf, __olen); \
71
+	} while(0)
72
+
38 73
 #endif