From aaf3b2e35bf58ad19b2b375f26909b102b7d512f Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Tue, 9 Jan 2018 10:00:31 +0100 Subject: [PATCH] siptrace: siptrace_copy_proto() converted to macro --- src/modules/siptrace/siptrace_send.c | 23 ----------------- src/modules/siptrace/siptrace_send.h | 37 +++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/modules/siptrace/siptrace_send.c b/src/modules/siptrace/siptrace_send.c index 0a57d3b1f7f..eeb91c20c70 100644 --- a/src/modules/siptrace/siptrace_send.c +++ b/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; -} - /** * */ diff --git a/src/modules/siptrace/siptrace_send.h b/src/modules/siptrace/siptrace_send.h index 288566b75a7..a83eebad222 100644 --- a/src/modules/siptrace/siptrace_send.h +++ b/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