From 06d61cd3dd0d0cb736bb2ddf7bcc304cc1f83107 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 12 Feb 2019 16:29:52 -0500 Subject: [PATCH] TT#52651 move socket.[ch] into lib/ includes necessary re-shuffling of additional code pieces Change-Id: I74b314ab5936ac8a0eeaff94e084617b59b28d79 --- daemon/.gitignore | 1 + daemon/Makefile | 4 ++-- daemon/aux.c | 33 --------------------------------- daemon/log.h | 7 +++++++ include/aux.h | 20 -------------------- include/call.h | 6 ------ include/tcp_listener.h | 1 + lib/auxlib.c | 36 ++++++++++++++++++++++++++++++++++++ lib/auxlib.h | 29 +++++++++++++++++++++++++++++ {daemon => lib}/socket.c | 3 +-- {include => lib}/socket.h | 4 +++- t/Makefile | 4 ++-- t/log.h | 1 + 13 files changed, 83 insertions(+), 66 deletions(-) rename {daemon => lib}/socket.c (99%) rename {include => lib}/socket.h (99%) diff --git a/daemon/.gitignore b/daemon/.gitignore index 21bdd047b..c648704e7 100644 --- a/daemon/.gitignore +++ b/daemon/.gitignore @@ -11,3 +11,4 @@ codeclib.c resample.c str.c fix_frame_channel_layout.h +socket.c diff --git a/daemon/Makefile b/daemon/Makefile index d706f893b..151947e0a 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -121,10 +121,10 @@ endif SRCS= main.c kernel.c poller.c aux.c control_tcp.c streambuf.c call.c control_udp.c redis.c \ bencode.c cookie_cache.c udp_listener.c control_ng.strhash.c sdp.strhash.c stun.c rtcp.c \ - crypto.c rtp.c call_interfaces.strhash.c dtls.c log.c cli.c graphite.c ice.c socket.c \ + crypto.c rtp.c call_interfaces.strhash.c dtls.c log.c cli.c graphite.c ice.c \ media_socket.c homer.c recording.c statistics.c cdr.c ssrc.c iptables.c tcp_listener.c \ codec.c load.c dtmf.c -LIBSRCS= loglib.c auxlib.c rtplib.c str.c +LIBSRCS= loglib.c auxlib.c rtplib.c str.c socket.c ifeq ($(with_transcoding),yes) LIBSRCS+= codeclib.c resample.c endif diff --git a/daemon/aux.c b/daemon/aux.c index b81e1cf39..f651d5576 100644 --- a/daemon/aux.c +++ b/daemon/aux.c @@ -27,9 +27,6 @@ struct detach_thread { const char *scheduler; int priority; }; -struct thread_buf { - char buf[THREAD_BUF_SIZE]; -}; struct scheduler { const char *name; int num; @@ -42,9 +39,6 @@ static GList *threads_to_join; static GList *threads_running; static cond_t threads_cond = COND_STATIC_INIT; -static struct thread_buf __thread t_bufs[NUM_THREAD_BUFS]; -static int __thread t_buf_idx; - __thread struct timeval rtpe_now; volatile int rtpe_shutdown; @@ -249,25 +243,6 @@ void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler abort(); } -unsigned int in6_addr_hash(const void *p) { - const struct in6_addr *a = p; - return a->s6_addr32[0] ^ a->s6_addr32[3]; -} - -int in6_addr_eq(const void *a, const void *b) { - const struct in6_addr *A = a, *B = b; - return !memcmp(A, B, sizeof(*A)); -} - -char *get_thread_buf(void) { - char *ret; - ret = t_bufs[t_buf_idx].buf; - t_buf_idx++; - if (t_buf_idx >= G_N_ELEMENTS(t_bufs)) - t_buf_idx = 0; - return ret; -} - int g_tree_find_first_cmp(void *k, void *v, void *d) { void **p = d; GEqualFunc f = p[1]; @@ -285,14 +260,6 @@ int g_tree_find_all_cmp(void *k, void *v, void *d) { g_queue_push_tail(q, v); return FALSE; } -unsigned int uint32_hash(const void *p) { - const u_int32_t *a = p; - return *a; -} -int uint32_eq(const void *a, const void *b) { - const u_int32_t *A = a, *B = b; - return (*A == *B) ? TRUE : FALSE; -} void free_buf(char **p) { if (*p) diff --git a/daemon/log.h b/daemon/log.h index e8864ca07..a5f6ff46a 100644 --- a/daemon/log.h +++ b/daemon/log.h @@ -48,5 +48,12 @@ void dtmflog(GString *s); void log_format(enum log_format); void __ilog(int prio, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); +// call debug +#ifdef __DEBUG +#define __C_DBG(x...) ilog(LOG_DEBUG, x) +#else +#define __C_DBG(x...) ((void)0) +#endif + #endif diff --git a/include/aux.h b/include/aux.h index a9b7e426f..4319fc677 100644 --- a/include/aux.h +++ b/include/aux.h @@ -49,21 +49,6 @@ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \ -/*** HELPER MACROS ***/ - -#define ZERO(x) memset(&(x), 0, sizeof(x)) - -#define UINT64F "%" G_GUINT64_FORMAT - -#define THREAD_BUF_SIZE 64 -#define NUM_THREAD_BUFS 8 - -#define AUTO_CLEANUP(decl, func) decl __attribute__ ((__cleanup__(func))) -#define AUTO_CLEANUP_INIT(decl, func, val) AUTO_CLEANUP(decl, func) = val -#define AUTO_CLEANUP_NULL(decl, func) AUTO_CLEANUP_INIT(decl, func, 0) -#define AUTO_CLEANUP_BUF(var) AUTO_CLEANUP_NULL(char *var, free_buf) - - /*** GLOBALS ***/ extern __thread struct timeval rtpe_now; @@ -79,11 +64,6 @@ typedef int (*parse_func)(char **, void **, void *); int pcre_multi_match(pcre *, pcre_extra *, const char *, unsigned int, parse_func, void *, GQueue *); INLINE void strmove(char **, char **); INLINE void strdupfree(char **, const char *); -char *get_thread_buf(void); -unsigned int in6_addr_hash(const void *p); -int in6_addr_eq(const void *a, const void *b); -unsigned int uint32_hash(const void *p); -int uint32_eq(const void *a, const void *b); diff --git a/include/call.h b/include/call.h index a665d1e69..83ab0e6ab 100644 --- a/include/call.h +++ b/include/call.h @@ -90,12 +90,6 @@ enum call_type { #define RTP_LOOP_MAX_COUNT 30 /* number of consecutively detected dupes to trigger protection */ #endif -#ifdef __DEBUG -#define __C_DBG(x...) ilog(LOG_DEBUG, x) -#else -#define __C_DBG(x...) ((void)0) -#endif - #define IS_FOREIGN_CALL(c) (c->foreign_call) #define IS_OWN_CALL(c) !IS_FOREIGN_CALL(c) diff --git a/include/tcp_listener.h b/include/tcp_listener.h index 0bb297a79..327e108a7 100644 --- a/include/tcp_listener.h +++ b/include/tcp_listener.h @@ -3,6 +3,7 @@ #include "socket.h" #include "obj.h" +#include "aux.h" struct poller; diff --git a/lib/auxlib.c b/lib/auxlib.c index ceedad0b7..7884662a6 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -10,13 +10,21 @@ #ifdef HAVE_LIBSYSTEMD #include #endif +#include +#include #include "log.h" #include "loglib.h" +struct thread_buf { + char buf[THREAD_BUF_SIZE]; +}; static int version; struct rtpengine_common_config *rtpe_common_config_ptr; +static struct thread_buf __thread t_bufs[NUM_THREAD_BUFS]; +static int __thread t_buf_idx; + void daemonize(void) { if (rtpe_common_config_ptr->foreground) @@ -200,3 +208,31 @@ out: err: die("Bad command line: %s", er->message); } + +char *get_thread_buf(void) { + char *ret; + ret = t_bufs[t_buf_idx].buf; + t_buf_idx++; + if (t_buf_idx >= G_N_ELEMENTS(t_bufs)) + t_buf_idx = 0; + return ret; +} + +unsigned int in6_addr_hash(const void *p) { + const struct in6_addr *a = p; + return a->s6_addr32[0] ^ a->s6_addr32[3]; +} + +int in6_addr_eq(const void *a, const void *b) { + const struct in6_addr *A = a, *B = b; + return !memcmp(A, B, sizeof(*A)); +} + +unsigned int uint32_hash(const void *p) { + const u_int32_t *a = p; + return *a; +} +int uint32_eq(const void *a, const void *b) { + const u_int32_t *A = a, *B = b; + return (*A == *B) ? TRUE : FALSE; +} diff --git a/lib/auxlib.h b/lib/auxlib.h index 395fee1be..982dcd479 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -6,6 +6,11 @@ #include "compat.h" #include + +#define THREAD_BUF_SIZE 64 +#define NUM_THREAD_BUFS 8 + + struct rtpengine_common_config { char *config_file; char *config_section; @@ -18,6 +23,8 @@ struct rtpengine_common_config { extern struct rtpengine_common_config *rtpe_common_config_ptr; +/*** PROTOTYPES ***/ + void daemonize(void); void wpidfile(void); void service_notify(const char *message); @@ -25,6 +32,28 @@ void config_load(int *argc, char ***argv, GOptionEntry *entries, const char *des char *default_config, char *default_section, struct rtpengine_common_config *); +char *get_thread_buf(void); + +unsigned int in6_addr_hash(const void *p); +int in6_addr_eq(const void *a, const void *b); +unsigned int uint32_hash(const void *p); +int uint32_eq(const void *a, const void *b); + + +/*** HELPER MACROS ***/ + +#define ZERO(x) memset(&(x), 0, sizeof(x)) + +#define UINT64F "%" G_GUINT64_FORMAT + +#define AUTO_CLEANUP(decl, func) decl __attribute__ ((__cleanup__(func))) +#define AUTO_CLEANUP_INIT(decl, func, val) AUTO_CLEANUP(decl, func) = val +#define AUTO_CLEANUP_NULL(decl, func) AUTO_CLEANUP_INIT(decl, func, 0) +#define AUTO_CLEANUP_BUF(var) AUTO_CLEANUP_NULL(char *var, free_buf) + + +/*** STRING HELPERS ***/ + INLINE void random_string(unsigned char *buf, int len) { int ret = RAND_bytes(buf, len); assert(ret == 1); diff --git a/daemon/socket.c b/lib/socket.c similarity index 99% rename from daemon/socket.c rename to lib/socket.c index b1fe71f94..e71c84e52 100644 --- a/daemon/socket.c +++ b/lib/socket.c @@ -8,9 +8,8 @@ #include #include #include "str.h" -#include "media_socket.h" #include "xt_RTPENGINE.h" -#include "call.h" +#include "log.h" static int __ip4_addr_parse(sockaddr_t *dst, const char *src); static int __ip6_addr_parse(sockaddr_t *dst, const char *src); diff --git a/include/socket.h b/lib/socket.h similarity index 99% rename from include/socket.h rename to lib/socket.h index 7a010d849..e33e238b9 100644 --- a/include/socket.h +++ b/lib/socket.h @@ -4,6 +4,8 @@ #include #include +#include +#include @@ -103,7 +105,7 @@ extern socktype_t *socktype_udp; -#include "aux.h" +#include "auxlib.h" INLINE int sockaddr_print(const sockaddr_t *a, char *buf, size_t len) { diff --git a/t/Makefile b/t/Makefile index 7a52d85cf..549cfc058 100644 --- a/t/Makefile +++ b/t/Makefile @@ -62,8 +62,8 @@ SRCS+= transcode-test.c ifeq ($(with_amr_tests),yes) SRCS+= amr-decode-test.c amr-encode-test.c endif -LIBSRCS+= codeclib.c resample.c -DAEMONSRCS+= codec.c call.c ice.c kernel.c media_socket.c stun.c bencode.c socket.c poller.c \ +LIBSRCS+= codeclib.c resample.c socket.c +DAEMONSRCS+= codec.c call.c ice.c kernel.c media_socket.c stun.c bencode.c poller.c \ dtls.c recording.c statistics.c rtcp.c redis.c iptables.c graphite.c \ streambuf.c cookie_cache.c udp_listener.c homer.c load.c cdr.c dtmf.c HASHSRCS+= call_interfaces.c control_ng.c sdp.c diff --git a/t/log.h b/t/log.h index 2ebaa381b..3bfc3bb5e 100644 --- a/t/log.h +++ b/t/log.h @@ -3,6 +3,7 @@ #include "loglib.h" #define __ilog(prio, fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__) +#define __C_DBG(x...) ilog(LOG_DEBUG, x) INLINE void rtcplog(const char *x) { }