C99 inlining rules

pull/6/head
Richard Fuchs 11 years ago
parent 5faf5e6d7d
commit 05e429c610

@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "compat.h"
@ -57,8 +58,8 @@ typedef int (*parse_func)(char **, void **, void *);
GList *g_list_link(GList *, GList *);
int pcre_multi_match(pcre *, pcre_extra *, const char *, unsigned int, parse_func, void *, GQueue *);
static inline void strmove(char **, char **);
static inline void strdupfree(char **, const char *);
INLINE void strmove(char **, char **);
INLINE void strdupfree(char **, const char *);
#if !GLIB_CHECK_VERSION(2,14,0)
@ -68,64 +69,64 @@ void g_queue_clear(GQueue *);
#endif
#if !GLIB_CHECK_VERSION(2,32,0)
static inline int g_hash_table_contains(GHashTable *h, const void *k) {
INLINE int g_hash_table_contains(GHashTable *h, const void *k) {
return g_hash_table_lookup(h, k) ? 1 : 0;
}
#endif
static inline void g_queue_move(GQueue *dst, GQueue *src) {
INLINE void g_queue_move(GQueue *dst, GQueue *src) {
GList *l;
while ((l = g_queue_pop_head_link(src)))
g_queue_push_tail_link(dst, l);
}
static inline void g_queue_truncate(GQueue *q, unsigned int len) {
INLINE void g_queue_truncate(GQueue *q, unsigned int len) {
while (q->length > len)
g_queue_pop_tail(q);
}
static inline void strmove(char **d, char **s) {
INLINE void strmove(char **d, char **s) {
if (*d)
free(*d);
*d = *s;
*s = strdup("");
}
static inline void strdupfree(char **d, const char *s) {
INLINE void strdupfree(char **d, const char *s) {
if (*d)
free(*d);
*d = strdup(s);
}
static inline void nonblock(int fd) {
INLINE void nonblock(int fd) {
fcntl(fd, F_SETFL, O_NONBLOCK);
}
static inline void reuseaddr(int fd) {
INLINE void reuseaddr(int fd) {
int one = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
}
static inline void ipv6only(int fd, int yn) {
INLINE void ipv6only(int fd, int yn) {
setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yn, sizeof(yn));
}
static inline int bit_array_isset(unsigned long *name, unsigned int bit) {
INLINE int bit_array_isset(unsigned long *name, unsigned int bit) {
return name[(bit) / (sizeof(long) * 8)] & (1UL << ((bit) % (sizeof(long) * 8)));
}
static inline void bit_array_set(unsigned long *name, unsigned int bit) {
INLINE void bit_array_set(unsigned long *name, unsigned int bit) {
name[(bit) / (sizeof(long) * 8)] |= 1UL << ((bit) % (sizeof(long) * 8));
}
static inline void bit_array_clear(unsigned long *name, unsigned int bit) {
INLINE void bit_array_clear(unsigned long *name, unsigned int bit) {
name[(bit) / (sizeof(long) * 8)] &= ~(1UL << ((bit) % (sizeof(long) * 8)));
}
static inline char chrtoupper(char x) {
INLINE char chrtoupper(char x) {
return x & 0xdf;
}
static inline void swap_ptrs(void *a, void *b) {
INLINE void swap_ptrs(void *a, void *b) {
void *t, **aa, **bb;
aa = a;
bb = b;
@ -134,14 +135,14 @@ static inline void swap_ptrs(void *a, void *b) {
*bb = t;
}
static inline void in4_to_6(struct in6_addr *o, u_int32_t ip) {
INLINE void in4_to_6(struct in6_addr *o, u_int32_t ip) {
o->s6_addr32[0] = 0;
o->s6_addr32[1] = 0;
o->s6_addr32[2] = htonl(0xffff);
o->s6_addr32[3] = ip;
}
static inline void smart_ntop(char *o, struct in6_addr *a, size_t len) {
INLINE void smart_ntop(char *o, struct in6_addr *a, size_t len) {
const char *r;
if (IN6_IS_ADDR_V4MAPPED(a))
@ -153,7 +154,7 @@ static inline void smart_ntop(char *o, struct in6_addr *a, size_t len) {
*o = '\0';
}
static inline char *smart_ntop_p(char *o, struct in6_addr *a, size_t len) {
INLINE char *smart_ntop_p(char *o, struct in6_addr *a, size_t len) {
int l;
if (IN6_IS_ADDR_V4MAPPED(a)) {
@ -175,7 +176,7 @@ static inline char *smart_ntop_p(char *o, struct in6_addr *a, size_t len) {
}
}
static inline void smart_ntop_port(char *o, struct sockaddr_in6 *a, size_t len) {
INLINE void smart_ntop_port(char *o, struct sockaddr_in6 *a, size_t len) {
char *e;
e = smart_ntop_p(o, &a->sin6_addr, len);
@ -186,7 +187,7 @@ static inline void smart_ntop_port(char *o, struct sockaddr_in6 *a, size_t len)
sprintf(e, ":%hu", ntohs(a->sin6_port));
}
static inline int smart_pton(int af, char *src, void *dst) {
INLINE int smart_pton(int af, char *src, void *dst) {
char *p;
int ret;
@ -201,7 +202,7 @@ static inline int smart_pton(int af, char *src, void *dst) {
return inet_pton(af, src, dst);
}
static inline int strmemcmp(const void *mem, int len, const char *str) {
INLINE int strmemcmp(const void *mem, int len, const char *str) {
int l = strlen(str);
if (l < len)
return -1;
@ -211,7 +212,7 @@ static inline int strmemcmp(const void *mem, int len, const char *str) {
}
/* XXX replace with better source of randomness */
static inline void random_string(unsigned char *buf, int len) {
INLINE void random_string(unsigned char *buf, int len) {
while (len--)
*buf++ = random() % 0x100;
}
@ -269,60 +270,60 @@ typedef pthread_cond_t cond_t;
static inline int __debug_mutex_init(mutex_t *m, const char *file, unsigned int line) {
INLINE int __debug_mutex_init(mutex_t *m, const char *file, unsigned int line) {
mylog(LOG_DEBUG, "mutex_init(%p) at %s:%u", m, file, line);
return pthread_mutex_init(m, NULL);
}
static inline int __debug_mutex_destroy(mutex_t *m, const char *file, unsigned int line) {
INLINE int __debug_mutex_destroy(mutex_t *m, const char *file, unsigned int line) {
mylog(LOG_DEBUG, "mutex_destroy(%p) at %s:%u", m, file, line);
return pthread_mutex_destroy(m);
}
static inline int __debug_mutex_lock(mutex_t *m, const char *file, unsigned int line) {
INLINE int __debug_mutex_lock(mutex_t *m, const char *file, unsigned int line) {
int ret;
mylog(LOG_DEBUG, "mutex_lock(%p) at %s:%u ...", m, file, line);
ret = pthread_mutex_lock(m);
mylog(LOG_DEBUG, "mutex_lock(%p) at %s:%u returning %i", m, file, line, ret);
return ret;
}
static inline int __debug_mutex_trylock(mutex_t *m, const char *file, unsigned int line) {
INLINE int __debug_mutex_trylock(mutex_t *m, const char *file, unsigned int line) {
int ret;
mylog(LOG_DEBUG, "mutex_trylock(%p) at %s:%u ...", m, file, line);
ret = pthread_mutex_trylock(m);
mylog(LOG_DEBUG, "mutex_trylock(%p) at %s:%u returning %i", m, file, line, ret);
return ret;
}
static inline int __debug_mutex_unlock(mutex_t *m, const char *file, unsigned int line) {
INLINE int __debug_mutex_unlock(mutex_t *m, const char *file, unsigned int line) {
mylog(LOG_DEBUG, "mutex_unlock(%p) at %s:%u", m, file, line);
return pthread_mutex_unlock(m);
}
static inline int __debug_rwlock_init(rwlock_t *m, const char *file, unsigned int line) {
INLINE int __debug_rwlock_init(rwlock_t *m, const char *file, unsigned int line) {
mylog(LOG_DEBUG, "rwlock_init(%p) at %s:%u", m, file, line);
return pthread_rwlock_init(m, NULL);
}
static inline int __debug_rwlock_destroy(rwlock_t *m, const char *file, unsigned int line) {
INLINE int __debug_rwlock_destroy(rwlock_t *m, const char *file, unsigned int line) {
mylog(LOG_DEBUG, "rwlock_destroy(%p) at %s:%u", m, file, line);
return pthread_rwlock_destroy(m);
}
static inline int __debug_rwlock_lock_r(rwlock_t *m, const char *file, unsigned int line) {
INLINE int __debug_rwlock_lock_r(rwlock_t *m, const char *file, unsigned int line) {
int ret;
mylog(LOG_DEBUG, "rwlock_lock_r(%p) at %s:%u ...", m, file, line);
ret = pthread_rwlock_rdlock(m);
mylog(LOG_DEBUG, "rwlock_lock_r(%p) at %s:%u returning %i", m, file, line, ret);
return ret;
}
static inline int __debug_rwlock_lock_w(rwlock_t *m, const char *file, unsigned int line) {
INLINE int __debug_rwlock_lock_w(rwlock_t *m, const char *file, unsigned int line) {
int ret;
mylog(LOG_DEBUG, "rwlock_lock_w(%p) at %s:%u ...", m, file, line);
ret = pthread_rwlock_wrlock(m);
mylog(LOG_DEBUG, "rwlock_lock_w(%p) at %s:%u returning %i", m, file, line, ret);
return ret;
}
static inline int __debug_rwlock_unlock_r(rwlock_t *m, const char *file, unsigned int line) {
INLINE int __debug_rwlock_unlock_r(rwlock_t *m, const char *file, unsigned int line) {
mylog(LOG_DEBUG, "rwlock_unlock_r(%p) at %s:%u", m, file, line);
return pthread_rwlock_unlock(m);
}
static inline int __debug_rwlock_unlock_w(rwlock_t *m, const char *file, unsigned int line) {
INLINE int __debug_rwlock_unlock_w(rwlock_t *m, const char *file, unsigned int line) {
mylog(LOG_DEBUG, "rwlock_unlock_w(%p) at %s:%u", m, file, line);
return pthread_rwlock_unlock(m);
}
@ -341,7 +342,7 @@ void thread_create_detach(void (*)(void *), void *);
static inline int rlim(int res, rlim_t val) {
INLINE int rlim(int res, rlim_t val) {
struct rlimit rlim;
ZERO(rlim);
@ -349,7 +350,7 @@ static inline int rlim(int res, rlim_t val) {
return setrlimit(res, &rlim);
}
static inline int is_addr_unspecified(const struct in6_addr *a) {
INLINE int is_addr_unspecified(const struct in6_addr *a) {
if (a->s6_addr32[0])
return 0;
if (a->s6_addr32[1])
@ -362,23 +363,23 @@ static inline int is_addr_unspecified(const struct in6_addr *a) {
}
/* checks if at least one of the flags is set */
static inline int bf_isset(const unsigned int *u, unsigned int f) {
INLINE int bf_isset(const unsigned int *u, unsigned int f) {
if ((*u & f))
return -1;
return 0;
}
static inline void bf_set(unsigned int *u, unsigned int f) {
INLINE void bf_set(unsigned int *u, unsigned int f) {
*u |= f;
}
static inline void bf_clear(unsigned int *u, unsigned int f) {
INLINE void bf_clear(unsigned int *u, unsigned int f) {
*u &= ~f;
}
static inline void bf_xset(unsigned int *u, unsigned int f, int cond) {
INLINE void bf_xset(unsigned int *u, unsigned int f, int cond) {
bf_clear(u, f);
bf_set(u, cond ? f : 0);
}
/* works only for single flags */
static inline void bf_copy(unsigned int *u, unsigned int f, const unsigned int *s, unsigned int g) {
INLINE void bf_copy(unsigned int *u, unsigned int f, const unsigned int *s, unsigned int g) {
/* a good compiler will optimize out the calls to log2() */
*u &= ~f;
if (f >= g)
@ -387,7 +388,7 @@ static inline void bf_copy(unsigned int *u, unsigned int f, const unsigned int *
*u |= (*s & g) >> (int) (log2(g) - log2(f));
}
/* works for multiple flags */
static inline void bf_copy_same(unsigned int *u, const unsigned int *s, unsigned int g) {
INLINE void bf_copy_same(unsigned int *u, const unsigned int *s, unsigned int g) {
bf_copy(u, g, s, g);
}

@ -12,8 +12,10 @@
# define BENCODE_MALLOC pkg_malloc
# define BENCODE_FREE pkg_free
# endif
# define INLINE static inline
#else
/* rtpengine */
# include "compat.h"
# include "str.h"
# ifndef BENCODE_MALLOC
# define BENCODE_MALLOC malloc
@ -92,7 +94,7 @@ bencode_item_t *bencode_list(bencode_buffer_t *buf);
void bencode_buffer_destroy_add(bencode_buffer_t *buf, free_func_t, void *);
/* Returns the buffer associated with an item, or NULL if pointer given is NULL */
static inline bencode_buffer_t *bencode_item_buffer(bencode_item_t *);
INLINE bencode_buffer_t *bencode_item_buffer(bencode_item_t *);
@ -107,29 +109,29 @@ static inline bencode_buffer_t *bencode_item_buffer(bencode_item_t *);
* Also, the function does not reorder keys into lexicographical order; keys will be encoded in
* the same order as they've been added. The key must a null-terminated string.
* The value to be added must not have been previously linked into any other dictionary or list. */
static inline bencode_item_t *bencode_dictionary_add(bencode_item_t *dict, const char *key, bencode_item_t *val);
INLINE bencode_item_t *bencode_dictionary_add(bencode_item_t *dict, const char *key, bencode_item_t *val);
/* Identical to bencode_dictionary_add() but doesn't require the key string to be null-terminated */
bencode_item_t *bencode_dictionary_add_len(bencode_item_t *dict, const char *key, int keylen, bencode_item_t *val);
/* Convenience function to add a string value to a dictionary, possibly duplicated into the
* bencode_buffer_t object. */
static inline bencode_item_t *bencode_dictionary_add_string(bencode_item_t *dict, const char *key, const char *val);
static inline bencode_item_t *bencode_dictionary_add_string_dup(bencode_item_t *dict, const char *key, const char *val);
INLINE bencode_item_t *bencode_dictionary_add_string(bencode_item_t *dict, const char *key, const char *val);
INLINE bencode_item_t *bencode_dictionary_add_string_dup(bencode_item_t *dict, const char *key, const char *val);
/* Ditto, but for a "str" object */
static inline bencode_item_t *bencode_dictionary_add_str(bencode_item_t *dict, const char *key, const str *val);
static inline bencode_item_t *bencode_dictionary_add_str_dup(bencode_item_t *dict, const char *key, const str *val);
INLINE bencode_item_t *bencode_dictionary_add_str(bencode_item_t *dict, const char *key, const str *val);
INLINE bencode_item_t *bencode_dictionary_add_str_dup(bencode_item_t *dict, const char *key, const str *val);
/* Ditto, but adds a string created through an iovec array to the dictionary. See
* bencode_string_iovec(). */
static inline bencode_item_t *bencode_dictionary_add_iovec(bencode_item_t *dict, const char *key,
INLINE bencode_item_t *bencode_dictionary_add_iovec(bencode_item_t *dict, const char *key,
const struct iovec *iov, int iov_cnt, int str_len);
/* Convenience functions to add the respective (newly created) objects to a dictionary */
static inline bencode_item_t *bencode_dictionary_add_integer(bencode_item_t *dict, const char *key, long long int val);
static inline bencode_item_t *bencode_dictionary_add_dictionary(bencode_item_t *dict, const char *key);
static inline bencode_item_t *bencode_dictionary_add_list(bencode_item_t *dict, const char *key);
INLINE bencode_item_t *bencode_dictionary_add_integer(bencode_item_t *dict, const char *key, long long int val);
INLINE bencode_item_t *bencode_dictionary_add_dictionary(bencode_item_t *dict, const char *key);
INLINE bencode_item_t *bencode_dictionary_add_list(bencode_item_t *dict, const char *key);
@ -142,9 +144,9 @@ static inline bencode_item_t *bencode_dictionary_add_list(bencode_item_t *dict,
bencode_item_t *bencode_list_add(bencode_item_t *list, bencode_item_t *item);
/* Convenience function to add the respective (newly created) objects to a list */
static inline bencode_item_t *bencode_list_add_string(bencode_item_t *list, const char *s);
static inline bencode_item_t *bencode_list_add_list(bencode_item_t *list);
static inline bencode_item_t *bencode_list_add_dictionary(bencode_item_t *list);
INLINE bencode_item_t *bencode_list_add_string(bencode_item_t *list, const char *s);
INLINE bencode_item_t *bencode_list_add_list(bencode_item_t *list);
INLINE bencode_item_t *bencode_list_add_dictionary(bencode_item_t *list);
@ -161,17 +163,17 @@ bencode_item_t *bencode_string_len(bencode_buffer_t *buf, const char *s, int len
/* Creates a new byte-string object. The given string must be null-terminated. Otherwise identical
* to bencode_string_len(). */
static inline bencode_item_t *bencode_string(bencode_buffer_t *buf, const char *s);
INLINE bencode_item_t *bencode_string(bencode_buffer_t *buf, const char *s);
/* Creates a new byte-string object from a "str" object. The string does not have to be null-
* terminated. */
static inline bencode_item_t *bencode_str(bencode_buffer_t *buf, const str *s);
INLINE bencode_item_t *bencode_str(bencode_buffer_t *buf, const str *s);
/* Identical to the above three functions, but copies the string into the bencode_buffer_t object.
* Thus, the given string doesn't have to remain valid and accessible afterwards. */
bencode_item_t *bencode_string_len_dup(bencode_buffer_t *buf, const char *s, int len);
static inline bencode_item_t *bencode_string_dup(bencode_buffer_t *buf, const char *s);
static inline bencode_item_t *bencode_str_dup(bencode_buffer_t *buf, const str *s);
INLINE bencode_item_t *bencode_string_dup(bencode_buffer_t *buf, const char *s);
INLINE bencode_item_t *bencode_str_dup(bencode_buffer_t *buf, const str *s);
/* Creates a new byte-string object from an iovec array. The created object has different internal
* semantics (not a BENCODE_STRING, but a BENCODE_IOVEC) and must not be treated like other string
@ -183,11 +185,11 @@ bencode_item_t *bencode_string_iovec(bencode_buffer_t *buf, const struct iovec *
/* Convenience function to compare a string object to a regular C string. Returns 2 if object
* isn't a string object, otherwise returns according to strcmp(). */
static inline int bencode_strcmp(bencode_item_t *a, const char *b);
INLINE int bencode_strcmp(bencode_item_t *a, const char *b);
/* Converts the string object "in" into a str object "out". Returns "out" on success, or NULL on
* error ("in" was NULL or not a string object). */
static inline str *bencode_get_str(bencode_item_t *in, str *out);
INLINE str *bencode_get_str(bencode_item_t *in, str *out);
@ -295,10 +297,10 @@ bencode_item_t *bencode_decode(bencode_buffer_t *buf, const char *s, int len);
/* Identical to bencode_decode(), but returns successfully only if the type of the decoded object match
* "expect". */
static inline bencode_item_t *bencode_decode_expect(bencode_buffer_t *buf, const char *s, int len, bencode_type_t expect);
INLINE bencode_item_t *bencode_decode_expect(bencode_buffer_t *buf, const char *s, int len, bencode_type_t expect);
/* Identical to bencode_decode_expect() but takes a "str" argument. */
static inline bencode_item_t *bencode_decode_expect_str(bencode_buffer_t *buf, const str *s, bencode_type_t expect);
INLINE bencode_item_t *bencode_decode_expect_str(bencode_buffer_t *buf, const str *s, bencode_type_t expect);
@ -309,7 +311,7 @@ static inline bencode_item_t *bencode_decode_expect_str(bencode_buffer_t *buf, c
/* Searches the given dictionary object for the given key and returns the respective value. Returns
* NULL if the given object isn't a dictionary or if the key doesn't exist. The key must be a
* null-terminated string. */
static inline bencode_item_t *bencode_dictionary_get(bencode_item_t *dict, const char *key);
INLINE bencode_item_t *bencode_dictionary_get(bencode_item_t *dict, const char *key);
/* Identical to bencode_dictionary_get() but doesn't require the key to be null-terminated. */
bencode_item_t *bencode_dictionary_get_len(bencode_item_t *dict, const char *key, int key_len);
@ -318,31 +320,31 @@ bencode_item_t *bencode_dictionary_get_len(bencode_item_t *dict, const char *key
* returns it as a pointer to the string itself. Returns NULL if the value is of some other type. The
* returned string is NOT null-terminated. Length of the string is returned in *len, which must be a
* valid pointer. The returned string will be valid until dict's bencode_buffer_t object is destroyed. */
static inline char *bencode_dictionary_get_string(bencode_item_t *dict, const char *key, int *len);
INLINE char *bencode_dictionary_get_string(bencode_item_t *dict, const char *key, int *len);
/* Identical to bencode_dictionary_get_string() but fills in a "str" struct. Returns str->s, which
* may be NULL. */
static inline char *bencode_dictionary_get_str(bencode_item_t *dict, const char *key, str *str);
INLINE char *bencode_dictionary_get_str(bencode_item_t *dict, const char *key, str *str);
/* Looks up the given key in the dictionary and compares the corresponding value to the given
* null-terminated string. Returns 2 if the key isn't found or if the value isn't a string, otherwise
* returns according to strcmp(). */
static inline int bencode_dictionary_get_strcmp(bencode_item_t *dict, const char *key, const char *str);
INLINE int bencode_dictionary_get_strcmp(bencode_item_t *dict, const char *key, const char *str);
/* Identical to bencode_dictionary_get() but returns the string in a newly allocated buffer (using the
* BENCODE_MALLOC function), which remains valid even after bencode_buffer_t is destroyed. */
static inline char *bencode_dictionary_get_string_dup(bencode_item_t *dict, const char *key, int *len);
INLINE char *bencode_dictionary_get_string_dup(bencode_item_t *dict, const char *key, int *len);
/* Combines bencode_dictionary_get_str() and bencode_dictionary_get_string_dup(). Fills in a "str"
* struct, but copies the string into a newly allocated buffer. Returns str->s. */
static inline char *bencode_dictionary_get_str_dup(bencode_item_t *dict, const char *key, str *str);
INLINE char *bencode_dictionary_get_str_dup(bencode_item_t *dict, const char *key, str *str);
/* Identical to bencode_dictionary_get_string() but expects an integer object. The parameter "defval"
* specified which value should be returned if the key is not found or if the value is not an integer. */
static inline long long int bencode_dictionary_get_integer(bencode_item_t *dict, const char *key, long long int defval);
INLINE long long int bencode_dictionary_get_integer(bencode_item_t *dict, const char *key, long long int defval);
/* Identical to bencode_dictionary_get(), but returns the object only if its type matches "expect". */
static inline bencode_item_t *bencode_dictionary_get_expect(bencode_item_t *dict, const char *key, bencode_type_t expect);
INLINE bencode_item_t *bencode_dictionary_get_expect(bencode_item_t *dict, const char *key, bencode_type_t expect);
@ -350,89 +352,89 @@ static inline bencode_item_t *bencode_dictionary_get_expect(bencode_item_t *dict
/**************************/
static inline bencode_buffer_t *bencode_item_buffer(bencode_item_t *i) {
INLINE bencode_buffer_t *bencode_item_buffer(bencode_item_t *i) {
if (!i)
return NULL;
return i->buffer;
}
static inline bencode_item_t *bencode_string(bencode_buffer_t *buf, const char *s) {
INLINE bencode_item_t *bencode_string(bencode_buffer_t *buf, const char *s) {
return bencode_string_len(buf, s, strlen(s));
}
static inline bencode_item_t *bencode_string_dup(bencode_buffer_t *buf, const char *s) {
INLINE bencode_item_t *bencode_string_dup(bencode_buffer_t *buf, const char *s) {
return bencode_string_len_dup(buf, s, strlen(s));
}
static inline bencode_item_t *bencode_str(bencode_buffer_t *buf, const str *s) {
INLINE bencode_item_t *bencode_str(bencode_buffer_t *buf, const str *s) {
return bencode_string_len(buf, s->s, s->len);
}
static inline bencode_item_t *bencode_str_dup(bencode_buffer_t *buf, const str *s) {
INLINE bencode_item_t *bencode_str_dup(bencode_buffer_t *buf, const str *s) {
return bencode_string_len_dup(buf, s->s, s->len);
}
static inline bencode_item_t *bencode_dictionary_add(bencode_item_t *dict, const char *key, bencode_item_t *val) {
INLINE bencode_item_t *bencode_dictionary_add(bencode_item_t *dict, const char *key, bencode_item_t *val) {
if (!key)
return NULL;
return bencode_dictionary_add_len(dict, key, strlen(key), val);
}
static inline bencode_item_t *bencode_dictionary_add_string(bencode_item_t *dict, const char *key, const char *val) {
INLINE bencode_item_t *bencode_dictionary_add_string(bencode_item_t *dict, const char *key, const char *val) {
if (!val)
return NULL;
return bencode_dictionary_add(dict, key, bencode_string(bencode_item_buffer(dict), val));
}
static inline bencode_item_t *bencode_dictionary_add_string_dup(bencode_item_t *dict, const char *key, const char *val) {
INLINE bencode_item_t *bencode_dictionary_add_string_dup(bencode_item_t *dict, const char *key, const char *val) {
if (!val)
return NULL;
return bencode_dictionary_add(dict, key, bencode_string_dup(bencode_item_buffer(dict), val));
}
static inline bencode_item_t *bencode_dictionary_add_str(bencode_item_t *dict, const char *key, const str *val) {
INLINE bencode_item_t *bencode_dictionary_add_str(bencode_item_t *dict, const char *key, const str *val) {
if (!val)
return NULL;
return bencode_dictionary_add(dict, key, bencode_str(bencode_item_buffer(dict), val));
}
static inline bencode_item_t *bencode_dictionary_add_str_dup(bencode_item_t *dict, const char *key, const str *val) {
INLINE bencode_item_t *bencode_dictionary_add_str_dup(bencode_item_t *dict, const char *key, const str *val) {
if (!val)
return NULL;
return bencode_dictionary_add(dict, key, bencode_str_dup(bencode_item_buffer(dict), val));
}
static inline bencode_item_t *bencode_dictionary_add_integer(bencode_item_t *dict, const char *key, long long int val) {
INLINE bencode_item_t *bencode_dictionary_add_integer(bencode_item_t *dict, const char *key, long long int val) {
return bencode_dictionary_add(dict, key, bencode_integer(bencode_item_buffer(dict), val));
}
static inline bencode_item_t *bencode_dictionary_add_dictionary(bencode_item_t *dict, const char *key) {
INLINE bencode_item_t *bencode_dictionary_add_dictionary(bencode_item_t *dict, const char *key) {
return bencode_dictionary_add(dict, key, bencode_dictionary(bencode_item_buffer(dict)));
}
static inline bencode_item_t *bencode_dictionary_add_list(bencode_item_t *dict, const char *key) {
INLINE bencode_item_t *bencode_dictionary_add_list(bencode_item_t *dict, const char *key) {
return bencode_dictionary_add(dict, key, bencode_list(bencode_item_buffer(dict)));
}
static inline bencode_item_t *bencode_list_add_string(bencode_item_t *list, const char *s) {
INLINE bencode_item_t *bencode_list_add_string(bencode_item_t *list, const char *s) {
return bencode_list_add(list, bencode_string(bencode_item_buffer(list), s));
}
static inline bencode_item_t *bencode_list_add_list(bencode_item_t *list) {
INLINE bencode_item_t *bencode_list_add_list(bencode_item_t *list) {
return bencode_list_add(list, bencode_list(bencode_item_buffer(list)));
}
static inline bencode_item_t *bencode_list_add_dictionary(bencode_item_t *list) {
INLINE bencode_item_t *bencode_list_add_dictionary(bencode_item_t *list) {
return bencode_list_add(list, bencode_dictionary(bencode_item_buffer(list)));
}
static inline bencode_item_t *bencode_dictionary_get(bencode_item_t *dict, const char *key) {
INLINE bencode_item_t *bencode_dictionary_get(bencode_item_t *dict, const char *key) {
if (!key)
return NULL;
return bencode_dictionary_get_len(dict, key, strlen(key));
}
static inline char *bencode_dictionary_get_string(bencode_item_t *dict, const char *key, int *len) {
INLINE char *bencode_dictionary_get_string(bencode_item_t *dict, const char *key, int *len) {
bencode_item_t *val;
val = bencode_dictionary_get(dict, key);
if (!val || val->type != BENCODE_STRING)
@ -441,14 +443,14 @@ static inline char *bencode_dictionary_get_string(bencode_item_t *dict, const ch
return val->iov[1].iov_base;
}
static inline char *bencode_dictionary_get_str(bencode_item_t *dict, const char *key, str *str) {
INLINE char *bencode_dictionary_get_str(bencode_item_t *dict, const char *key, str *str) {
str->s = bencode_dictionary_get_string(dict, key, &str->len);
if (!str->s)
str->len = 0;
return str->s;
}
static inline char *bencode_dictionary_get_string_dup(bencode_item_t *dict, const char *key, int *len) {
INLINE char *bencode_dictionary_get_string_dup(bencode_item_t *dict, const char *key, int *len) {
const char *s;
char *ret;
s = bencode_dictionary_get_string(dict, key, len);
@ -461,12 +463,12 @@ static inline char *bencode_dictionary_get_string_dup(bencode_item_t *dict, cons
return ret;
}
static inline char *bencode_dictionary_get_str_dup(bencode_item_t *dict, const char *key, str *str) {
INLINE char *bencode_dictionary_get_str_dup(bencode_item_t *dict, const char *key, str *str) {
str->s = bencode_dictionary_get_string_dup(dict, key, &str->len);
return str->s;
}
static inline long long int bencode_dictionary_get_integer(bencode_item_t *dict, const char *key, long long int defval) {
INLINE long long int bencode_dictionary_get_integer(bencode_item_t *dict, const char *key, long long int defval) {
bencode_item_t *val;
val = bencode_dictionary_get(dict, key);
if (!val || val->type != BENCODE_INTEGER)
@ -474,7 +476,7 @@ static inline long long int bencode_dictionary_get_integer(bencode_item_t *dict,
return val->value;
}
static inline bencode_item_t *bencode_decode_expect(bencode_buffer_t *buf, const char *s, int len, bencode_type_t expect) {
INLINE bencode_item_t *bencode_decode_expect(bencode_buffer_t *buf, const char *s, int len, bencode_type_t expect) {
bencode_item_t *ret;
ret = bencode_decode(buf, s, len);
if (!ret || ret->type != expect)
@ -482,22 +484,22 @@ static inline bencode_item_t *bencode_decode_expect(bencode_buffer_t *buf, const
return ret;
}
static inline bencode_item_t *bencode_decode_expect_str(bencode_buffer_t *buf, const str *s, bencode_type_t expect) {
INLINE bencode_item_t *bencode_decode_expect_str(bencode_buffer_t *buf, const str *s, bencode_type_t expect) {
return bencode_decode_expect(buf, s->s, s->len, expect);
}
static inline bencode_item_t *bencode_dictionary_get_expect(bencode_item_t *dict, const char *key, bencode_type_t expect) {
INLINE bencode_item_t *bencode_dictionary_get_expect(bencode_item_t *dict, const char *key, bencode_type_t expect) {
bencode_item_t *ret;
ret = bencode_dictionary_get(dict, key);
if (!ret || ret->type != expect)
return NULL;
return ret;
}
static inline str *bencode_collapse_str(bencode_item_t *root, str *out) {
INLINE str *bencode_collapse_str(bencode_item_t *root, str *out) {
out->s = bencode_collapse(root, &out->len);
return out;
}
static inline int bencode_strcmp(bencode_item_t *a, const char *b) {
INLINE int bencode_strcmp(bencode_item_t *a, const char *b) {
int len;
if (a->type != BENCODE_STRING)
return 2;
@ -508,7 +510,7 @@ static inline int bencode_strcmp(bencode_item_t *a, const char *b) {
return 1;
return memcmp(a->iov[1].iov_base, b, len);
}
static inline int bencode_dictionary_get_strcmp(bencode_item_t *dict, const char *key, const char *str) {
INLINE int bencode_dictionary_get_strcmp(bencode_item_t *dict, const char *key, const char *str) {
bencode_item_t *i;
i = bencode_dictionary_get(dict, key);
if (!i)
@ -516,7 +518,7 @@ static inline int bencode_dictionary_get_strcmp(bencode_item_t *dict, const char
return bencode_strcmp(i, str);
}
static inline str *bencode_get_str(bencode_item_t *in, str *out) {
INLINE str *bencode_get_str(bencode_item_t *in, str *out) {
if (!in || in->type != BENCODE_STRING)
return NULL;
out->s = in->iov[1].iov_base;
@ -524,7 +526,7 @@ static inline str *bencode_get_str(bencode_item_t *in, str *out) {
return out;
}
static inline bencode_item_t *bencode_dictionary_add_iovec(bencode_item_t *dict, const char *key,
INLINE bencode_item_t *bencode_dictionary_add_iovec(bencode_item_t *dict, const char *key,
const struct iovec *iov, int iov_cnt, int str_len)
{
return bencode_dictionary_add(dict, key, bencode_string_iovec(bencode_item_buffer(dict), iov, iov_cnt, str_len));

@ -9,6 +9,7 @@
#include <time.h>
#include <pcre.h>
#include <openssl/x509.h>
#include "compat.h"
@ -369,7 +370,7 @@ const struct transport_protocol *transport_protocol(const str *s);
static inline void *call_malloc(struct call *c, size_t l) {
INLINE void *call_malloc(struct call *c, size_t l) {
void *ret;
mutex_lock(&c->buffer_lock);
ret = call_buffer_alloc(&c->buffer, l);
@ -377,7 +378,7 @@ static inline void *call_malloc(struct call *c, size_t l) {
return ret;
}
static inline char *call_strdup_len(struct call *c, const char *s, unsigned int len) {
INLINE char *call_strdup_len(struct call *c, const char *s, unsigned int len) {
char *r;
r = call_malloc(c, len + 1);
memcpy(r, s, len);
@ -385,12 +386,12 @@ static inline char *call_strdup_len(struct call *c, const char *s, unsigned int
return r;
}
static inline char *call_strdup(struct call *c, const char *s) {
INLINE char *call_strdup(struct call *c, const char *s) {
if (!s)
return NULL;
return call_strdup_len(c, s, strlen(s));
}
static inline str *call_str_cpy_len(struct call *c, str *out, const char *in, int len) {
INLINE str *call_str_cpy_len(struct call *c, str *out, const char *in, int len) {
if (!in) {
*out = STR_NULL;
return out;
@ -399,33 +400,33 @@ static inline str *call_str_cpy_len(struct call *c, str *out, const char *in, in
out->len = len;
return out;
}
static inline str *call_str_cpy(struct call *c, str *out, const str *in) {
INLINE str *call_str_cpy(struct call *c, str *out, const str *in) {
return call_str_cpy_len(c, out, in ? in->s : NULL, in ? in->len : 0);
}
static inline str *call_str_cpy_c(struct call *c, str *out, const char *in) {
INLINE str *call_str_cpy_c(struct call *c, str *out, const char *in) {
return call_str_cpy_len(c, out, in, in ? strlen(in) : 0);
}
static inline str *call_str_dup(struct call *c, const str *in) {
INLINE str *call_str_dup(struct call *c, const str *in) {
str *out;
out = call_malloc(c, sizeof(*out));
call_str_cpy_len(c, out, in->s, in->len);
return out;
}
static inline str *call_str_init_dup(struct call *c, char *s) {
INLINE str *call_str_init_dup(struct call *c, char *s) {
str t;
str_init(&t, s);
return call_str_dup(c, &t);
}
static inline int callmaster_has_ipv6(struct callmaster *m) {
INLINE int callmaster_has_ipv6(struct callmaster *m) {
return is_addr_unspecified(&m->conf.ipv6) ? 0 : 1;
}
static inline void callmaster_exclude_port(struct callmaster *m, u_int16_t p) {
INLINE void callmaster_exclude_port(struct callmaster *m, u_int16_t p) {
/* XXX atomic bit field? */
mutex_lock(&m->portlock);
bit_array_set(m->ports_used, p);
mutex_unlock(&m->portlock);
}
static inline struct packet_stream *packet_stream_sink(struct packet_stream *ps) {
INLINE struct packet_stream *packet_stream_sink(struct packet_stream *ps) {
struct packet_stream *ret;
ret = ps->rtp_sink;
if (!ret)

@ -0,0 +1,10 @@
#ifndef __COMPAT_H__
#define __COMPAT_H__
#if __DEBUG
# define INLINE static inline
#else
# define INLINE static inline __attribute__((always_inline))
#endif
#endif

@ -3,13 +3,14 @@
#include <time.h>
#include <glib.h>
#include "compat.h"
#include "aux.h"
#include "poller.h"
#include "str.h"
static const char *cookie_in_use = "MAGIC";
static inline void cookie_cache_state_init(struct cookie_cache_state *s) {
INLINE void cookie_cache_state_init(struct cookie_cache_state *s) {
s->cookies = g_hash_table_new(str_hash, str_equal);
s->chunks = g_string_chunk_new(4 * 1024);
}

@ -5,6 +5,7 @@
#include <sys/types.h>
#include <glib.h>
#include "compat.h"
#include "str.h"
@ -92,36 +93,36 @@ extern const int num_crypto_suites;
const struct crypto_suite *crypto_find_suite(const str *);
int crypto_gen_session_key(struct crypto_context *, str *, unsigned char, int);
static inline int crypto_encrypt_rtp(struct crypto_context *c, struct rtp_header *rtp,
INLINE int crypto_encrypt_rtp(struct crypto_context *c, struct rtp_header *rtp,
str *payload, u_int64_t index)
{
return c->params.crypto_suite->encrypt_rtp(c, rtp, payload, index);
}
static inline int crypto_decrypt_rtp(struct crypto_context *c, struct rtp_header *rtp,
INLINE int crypto_decrypt_rtp(struct crypto_context *c, struct rtp_header *rtp,
str *payload, u_int64_t index)
{
return c->params.crypto_suite->decrypt_rtp(c, rtp, payload, index);
}
static inline int crypto_encrypt_rtcp(struct crypto_context *c, struct rtcp_packet *rtcp,
INLINE int crypto_encrypt_rtcp(struct crypto_context *c, struct rtcp_packet *rtcp,
str *payload, u_int64_t index)
{
return c->params.crypto_suite->encrypt_rtcp(c, rtcp, payload, index);
}
static inline int crypto_decrypt_rtcp(struct crypto_context *c, struct rtcp_packet *rtcp,
INLINE int crypto_decrypt_rtcp(struct crypto_context *c, struct rtcp_packet *rtcp,
str *payload, u_int64_t index)
{
return c->params.crypto_suite->decrypt_rtcp(c, rtcp, payload, index);
}
static inline int crypto_init_session_key(struct crypto_context *c) {
INLINE int crypto_init_session_key(struct crypto_context *c) {
return c->params.crypto_suite->session_key_init(c);
}
static inline void crypto_params_cleanup(struct crypto_params *p) {
INLINE void crypto_params_cleanup(struct crypto_params *p) {
if (p->mki)
free(p->mki);
p->mki = NULL;
}
static inline void crypto_cleanup(struct crypto_context *c) {
INLINE void crypto_cleanup(struct crypto_context *c) {
if (!c->params.crypto_suite)
return;
if (c->params.crypto_suite->session_key_cleanup)
@ -129,11 +130,11 @@ static inline void crypto_cleanup(struct crypto_context *c) {
c->have_session_key = 0;
crypto_params_cleanup(&c->params);
}
static inline void crypto_reset(struct crypto_context *c) {
INLINE void crypto_reset(struct crypto_context *c) {
crypto_cleanup(c);
c->last_index = 0;
}
static inline void crypto_params_copy(struct crypto_params *o, const struct crypto_params *i) {
INLINE void crypto_params_copy(struct crypto_params *o, const struct crypto_params *i) {
crypto_params_cleanup(o);
*o = *i;
if (o->mki_len > 255)
@ -143,7 +144,7 @@ static inline void crypto_params_copy(struct crypto_params *o, const struct cryp
memcpy(o->mki, i->mki, i->mki_len);
}
}
static inline void crypto_init(struct crypto_context *c, const struct crypto_params *p) {
INLINE void crypto_init(struct crypto_context *c, const struct crypto_params *p) {
crypto_cleanup(c);
crypto_params_copy(&c->params, p);
}

@ -8,6 +8,7 @@
#include <openssl/ssl.h>
#include <openssl/bio.h>
#include "compat.h"
#include "str.h"
#include "obj.h"
@ -70,7 +71,7 @@ void dtls_connection_cleanup(struct dtls_connection *);
static inline void __dtls_hash(const struct dtls_hash_func *hash_func, X509 *cert, unsigned char *out,
INLINE void __dtls_hash(const struct dtls_hash_func *hash_func, X509 *cert, unsigned char *out,
unsigned int bufsize)
{
unsigned int n;
@ -81,11 +82,11 @@ static inline void __dtls_hash(const struct dtls_hash_func *hash_func, X509 *cer
}
#define dtls_hash(hash_func, cert, outbuf) __dtls_hash(hash_func, cert, outbuf, sizeof(outbuf))
static inline void dtls_fingerprint_hash(struct dtls_fingerprint *fp, X509 *cert) {
INLINE void dtls_fingerprint_hash(struct dtls_fingerprint *fp, X509 *cert) {
__dtls_hash(fp->hash_func, cert, fp->digest, sizeof(fp->digest));
}
static inline int is_dtls(const str *s) {
INLINE int is_dtls(const str *s) {
const unsigned char *b = (const void *) s->s;
if (s->len < 1)

@ -4,6 +4,7 @@
#include <syslog.h>
#include <glib.h>
#include "compat.h"
@ -38,7 +39,7 @@ void ilog(int prio, const char *fmt, ...)__attribute__ ((format (printf, 2, 3)))
static inline void log_info_clear() {
INLINE void log_info_clear() {
switch (log_info.e) {
case LOG_INFO_NONE:
return;
@ -51,14 +52,14 @@ static inline void log_info_clear() {
}
log_info.e = LOG_INFO_NONE;
}
static inline void log_info_call(struct call *c) {
INLINE void log_info_call(struct call *c) {
log_info_clear();
if (!c)
return;
log_info.e = LOG_INFO_CALL;
log_info.u.call = __obj_get((void *) c);
}
static inline void log_info_stream_fd(struct stream_fd *sfd) {
INLINE void log_info_stream_fd(struct stream_fd *sfd) {
log_info_clear();
if (!sfd)
return;

@ -8,6 +8,7 @@
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include "compat.h"
@ -51,17 +52,17 @@ struct obj {
#define obj_get_o(a) __obj_get(a,__FILE__,__LINE__)
#define obj_put_o(a) __obj_put(a,__FILE__,__LINE__)
static inline void __obj_init(struct obj *o, unsigned int size, void (*free_func)(void *),
INLINE void __obj_init(struct obj *o, unsigned int size, void (*free_func)(void *),
const char *type, const char *file, unsigned int line);
static inline void *__obj_alloc(unsigned int size, void (*free_func)(void *),
INLINE void *__obj_alloc(unsigned int size, void (*free_func)(void *),
const char *type, const char *file, unsigned int line);
static inline void *__obj_alloc0(unsigned int size, void (*free_func)(void *),
INLINE void *__obj_alloc0(unsigned int size, void (*free_func)(void *),
const char *type, const char *file, unsigned int line);
static inline struct obj *__obj_hold(struct obj *o,
INLINE struct obj *__obj_hold(struct obj *o,
const char *type, const char *file, unsigned int line);
static inline void *__obj_get(struct obj *o,
INLINE void *__obj_get(struct obj *o,
const char *type, const char *file, unsigned int line);
static inline void __obj_put(struct obj *o,,
INLINE void __obj_put(struct obj *o,,
const char *type, const char *file, unsigned int line);
#else
@ -75,12 +76,12 @@ static inline void __obj_put(struct obj *o,,
#define obj_get_o(a) __obj_get(a)
#define obj_put_o(a) __obj_put(a)
static inline void __obj_init(struct obj *o, unsigned int size, void (*free_func)(void *));
static inline void *__obj_alloc(unsigned int size, void (*free_func)(void *));
static inline void *__obj_alloc0(unsigned int size, void (*free_func)(void *));
static inline struct obj *__obj_hold(struct obj *o);
static inline void *__obj_get(struct obj *o);
static inline void __obj_put(struct obj *o);
INLINE void __obj_init(struct obj *o, unsigned int size, void (*free_func)(void *));
INLINE void *__obj_alloc(unsigned int size, void (*free_func)(void *));
INLINE void *__obj_alloc0(unsigned int size, void (*free_func)(void *));
INLINE struct obj *__obj_hold(struct obj *o);
INLINE void *__obj_get(struct obj *o);
INLINE void __obj_put(struct obj *o);
#endif
@ -90,7 +91,7 @@ static inline void __obj_put(struct obj *o);
static inline void __obj_init(struct obj *o, unsigned int size, void (*free_func)(void *)
INLINE void __obj_init(struct obj *o, unsigned int size, void (*free_func)(void *)
#if OBJ_DEBUG
, const char *type, const char *file, unsigned int line
#endif
@ -105,7 +106,7 @@ static inline void __obj_init(struct obj *o, unsigned int size, void (*free_func
o->size = size;
}
static inline void *__obj_alloc(unsigned int size, void (*free_func)(void *)
INLINE void *__obj_alloc(unsigned int size, void (*free_func)(void *)
#if OBJ_DEBUG
, const char *type, const char *file, unsigned int line
#endif
@ -121,7 +122,7 @@ static inline void *__obj_alloc(unsigned int size, void (*free_func)(void *)
return r;
}
static inline void *__obj_alloc0(unsigned int size, void (*free_func)(void *)
INLINE void *__obj_alloc0(unsigned int size, void (*free_func)(void *)
#if OBJ_DEBUG
, const char *type, const char *file, unsigned int line
#endif
@ -137,7 +138,7 @@ static inline void *__obj_alloc0(unsigned int size, void (*free_func)(void *)
return r;
}
static inline struct obj *__obj_hold(struct obj *o
INLINE struct obj *__obj_hold(struct obj *o
#if OBJ_DEBUG
, const char *file, unsigned int line
#endif
@ -155,7 +156,7 @@ static inline struct obj *__obj_hold(struct obj *o
return o;
}
static inline void *__obj_get(struct obj *o
INLINE void *__obj_get(struct obj *o
#if OBJ_DEBUG
, const char *file, unsigned int line
#endif
@ -167,7 +168,7 @@ static inline void *__obj_get(struct obj *o
);
}
static inline void __obj_put(struct obj *o
INLINE void __obj_put(struct obj *o
#if OBJ_DEBUG
, const char *file, unsigned int line
#endif

@ -5,6 +5,7 @@
#include <sys/types.h>
#include "compat.h"
@ -24,17 +25,17 @@ extern void (*redis_wipe_mod)(struct redis *);
static inline void redis_update(struct call *c, struct redis *r) {
INLINE void redis_update(struct call *c, struct redis *r) {
if (!redis_update_mod)
return;
redis_update_mod(c, r);
}
static inline void redis_delete(struct call *c, struct redis *r) {
INLINE void redis_delete(struct call *c, struct redis *r) {
if (!redis_delete_mod)
return;
redis_delete_mod(c, r);
}
static inline int redis_restore(struct callmaster *m, struct redis *r) {
INLINE int redis_restore(struct callmaster *m, struct redis *r) {
if (!redis_restore_mod)
return 0;
return redis_restore_mod(m, r);

@ -5,6 +5,7 @@
#include <sys/types.h>
#include <glib.h>
#include "compat.h"
#include "str.h"
#include "call.h"
#include "log.h"
@ -330,7 +331,7 @@ int rtcp_avpf2avp(str *s) {
}
static inline int check_session_keys(struct crypto_context *c) {
INLINE int check_session_keys(struct crypto_context *c) {
str s;
const char *err;

@ -4,6 +4,7 @@
#include <arpa/inet.h>
#include <glib.h>
#include "compat.h"
#include "str.h"
#include "crypto.h"
#include "log.h"
@ -19,7 +20,7 @@ struct rtp_extension {
static inline int check_session_keys(struct crypto_context *c) {
INLINE int check_session_keys(struct crypto_context *c) {
str s;
const char *err;

@ -6,6 +6,7 @@
#include <arpa/inet.h>
#include <math.h>
#include "compat.h"
#include "call.h"
#include "log.h"
#include "str.h"
@ -194,7 +195,7 @@ static str ice_foundation_str_alt;
static inline struct sdp_attribute *attr_get_by_id(struct sdp_attributes *a, int id) {
INLINE struct sdp_attribute *attr_get_by_id(struct sdp_attributes *a, int id) {
return g_hash_table_lookup(a->id_hash, &id);
}
@ -209,7 +210,7 @@ static struct sdp_attribute *attr_get_by_id_m_s(struct sdp_media *m, int id) {
/* hack hack */
static inline int inet_pton_str(int af, str *src, void *dst) {
INLINE int inet_pton_str(int af, str *src, void *dst) {
char *s = src->s;
char p;
int ret;
@ -278,7 +279,7 @@ static int parse_address(struct network_address *address) {
&address->address_type, &address->address);
}
static inline int extract_token(char **sp, char *end, str *out) {
INLINE int extract_token(char **sp, char *end, str *out) {
char *space;
out->s = *sp;
@ -1076,7 +1077,7 @@ struct sdp_chopper *sdp_chopper_new(str *input) {
return c;
}
static void chopper_append(struct sdp_chopper *c, const char *s, int len) {
INLINE void chopper_append(struct sdp_chopper *c, const char *s, int len) {
struct iovec *iov;
g_array_set_size(c->iov, ++c->iov_num);
@ -1085,10 +1086,10 @@ static void chopper_append(struct sdp_chopper *c, const char *s, int len) {
iov->iov_len = len;
c->str_len += len;
}
static inline void chopper_append_c(struct sdp_chopper *c, const char *s) {
INLINE void chopper_append_c(struct sdp_chopper *c, const char *s) {
chopper_append(c, s, strlen(s));
}
static inline void chopper_append_str(struct sdp_chopper *c, const str *s) {
INLINE void chopper_append_str(struct sdp_chopper *c, const str *s) {
chopper_append(c, s->s, s->len);
}

@ -1,5 +1,6 @@
#include "str.h"
#include <assert.h>
#include <stdarg.h>
guint str_hash(gconstpointer ss) {
const str *s = ss;
@ -30,3 +31,12 @@ guint str_hash(gconstpointer ss) {
gboolean str_equal(gconstpointer a, gconstpointer b) {
return str_cmp_str((str *) a, (str *) b) == 0;
}
str *__str_sprintf(const char *fmt, ...) {
str *ret;
va_list ap;
va_start(ap, fmt);
ret = __str_vsprintf(fmt, ap);
va_end(ap);
return ret;
}

@ -7,6 +7,7 @@
#include <stdarg.h>
#include <assert.h>
#include <stdio.h>
#include "compat.h"
@ -28,42 +29,42 @@ typedef struct _str str;
/* returns pointer to end of str (s->s + s->len) */
static inline char *str_end(const str *s);
INLINE char *str_end(const str *s);
/* returns pointer to first occurence of "c" in s */
static inline char *str_chr(const str *s, int c);
INLINE char *str_chr(const str *s, int c);
/* sets "out" to point to first occurence of c in s. adjusts len also */
static inline str *str_chr_str(str *out, const str *s, int c);
INLINE str *str_chr_str(str *out, const str *s, int c);
/* compares a str to a regular string */
static inline int str_cmp(const str *a, const char *b);
INLINE int str_cmp(const str *a, const char *b);
/* compares a str to a non-null-terminated string */
static inline int str_cmp_len(const str *a, const char *b, int len);
INLINE int str_cmp_len(const str *a, const char *b, int len);
/* compares two str objects */
static inline int str_cmp_str(const str *a, const str *b);
INLINE int str_cmp_str(const str *a, const str *b);
/* compares two str objects, allows either to be NULL */
static inline int str_cmp_str0(const str *a, const str *b);
INLINE int str_cmp_str0(const str *a, const str *b);
/* inits a str object from a regular string. returns out */
static inline str *str_init(str *out, char *s);
INLINE str *str_init(str *out, char *s);
/* inits a str object from any binary string. returns out */
static inline str *str_init_len(str *out, char *s, int len);
static inline str *str_init_len_assert_len(str *out, char *s, int buflen, int len);
INLINE str *str_init_len(str *out, char *s, int len);
INLINE str *str_init_len_assert_len(str *out, char *s, int buflen, int len);
#define str_init_len_assert(out, s, len) str_init_len_assert_len(out, s, sizeof(s), len)
/* returns new str object allocated with malloc, including buffer */
static inline str *str_dup(const str *s);
INLINE str *str_dup(const str *s);
/* returns new str object allocated from chunk, including buffer */
static inline str *str_chunk_insert(GStringChunk *c, const str *s);
INLINE str *str_chunk_insert(GStringChunk *c, const str *s);
/* shifts pointer by len chars and decrements len. returns -1 if buffer too short, 0 otherwise */
static inline int str_shift(str *s, int len);
INLINE int str_shift(str *s, int len);
/* binary compares str object with memory chunk of equal size */
static inline int str_memcmp(const str *s, void *m);
INLINE int str_memcmp(const str *s, void *m);
/* asprintf() analogs */
#define str_sprintf(fmt, a...) __str_sprintf(STR_MALLOC_PADDING fmt, a)
#define str_vsprintf(fmt, a) __str_vsprintf(STR_MALLOC_PADDING fmt, a)
/* creates a new empty GString that has mem allocated for a new str object */
static inline GString *g_string_new_str(void);
INLINE GString *g_string_new_str(void);
/* frees the GString object and returns the new str object */
static inline str *g_string_free_str(GString *gs);
INLINE str *g_string_free_str(GString *gs);
/* for GHashTables */
guint str_hash(gconstpointer s);
@ -73,31 +74,31 @@ gboolean str_equal(gconstpointer a, gconstpointer b);
static inline str *str_chunk_insert(GStringChunk *c, const str *s) {
INLINE str *str_chunk_insert(GStringChunk *c, const str *s) {
str *i;
i = (void *) g_string_chunk_insert_len(c, (void *) s, sizeof(*s));
i->s = g_string_chunk_insert_len(c, s->s, s->len);
return i;
}
static inline char *str_end(const str *s) {
INLINE char *str_end(const str *s) {
return s->s + s->len;
}
static inline int str_shift(str *s, int len) {
INLINE int str_shift(str *s, int len) {
if (s->len < len)
return -1;
s->s += len;
s->len -= len;
return 0;
}
static inline char *str_chr(const str *s, int c) {
INLINE char *str_chr(const str *s, int c) {
return memchr(s->s, c, s->len);
}
static inline str *str_chr_str(str *out, const str *s, int c) {
INLINE str *str_chr_str(str *out, const str *s, int c) {
out->s = str_chr(s, c);
out->len = out->s ? (s->len - (out->s - s->s)) : 0;
return out;
}
static inline int str_cmp_len(const str *a, const char *b, int l) {
INLINE int str_cmp_len(const str *a, const char *b, int l) {
if (a->len < l)
return -1;
if (a->len > l)
@ -106,10 +107,10 @@ static inline int str_cmp_len(const str *a, const char *b, int l) {
return 0;
return memcmp(a->s, b, l);
}
static inline int str_cmp(const str *a, const char *b) {
INLINE int str_cmp(const str *a, const char *b) {
return str_cmp_len(a, b, strlen(b));
}
static inline int str_cmp_str(const str *a, const str *b) {
INLINE int str_cmp_str(const str *a, const str *b) {
if (a->len < b->len)
return -1;
if (a->len > b->len)
@ -118,7 +119,7 @@ static inline int str_cmp_str(const str *a, const str *b) {
return 0;
return memcmp(a->s, b->s, a->len);
}
static inline int str_cmp_str0(const str *a, const str *b) {
INLINE int str_cmp_str0(const str *a, const str *b) {
if (!a) {
if (!b)
return 0;
@ -133,21 +134,21 @@ static inline int str_cmp_str0(const str *a, const str *b) {
}
return str_cmp_str(a, b);
}
static inline str *str_init(str *out, char *s) {
INLINE str *str_init(str *out, char *s) {
out->s = s;
out->len = s ? strlen(s) : 0;
return out;
}
static inline str *str_init_len(str *out, char *s, int len) {
INLINE str *str_init_len(str *out, char *s, int len) {
out->s = s;
out->len = len;
return out;
}
static inline str *str_init_len_assert_len(str *out, char *s, int buflen, int len) {
INLINE str *str_init_len_assert_len(str *out, char *s, int buflen, int len) {
assert(buflen >= len);
return str_init_len(out, s, len);
}
static inline str *str_dup(const str *s) {
INLINE str *str_dup(const str *s) {
str *r;
r = malloc(sizeof(*r) + s->len + 1);
r->s = ((char *) r) + sizeof(*r);
@ -158,7 +159,7 @@ static inline str *str_dup(const str *s) {
}
#define STR_MALLOC_PADDING "xxxxxxxxxxxxxxxx"
static inline str *__str_vsprintf(const char *fmt, va_list ap) {
INLINE str *__str_vsprintf(const char *fmt, va_list ap) {
char *r;
int l, pl;
str *ret;
@ -173,17 +174,9 @@ static inline str *__str_vsprintf(const char *fmt, va_list ap) {
ret->len = l - pl;
return ret;
}
static inline str *__str_sprintf(const char *fmt, ...) __attribute__((format(printf,1,2)));
static inline str *__str_sprintf(const char *fmt, ...) {
str *ret;
va_list ap;
va_start(ap, fmt);
ret = __str_vsprintf(fmt, ap);
va_end(ap);
return ret;
}
str *__str_sprintf(const char *fmt, ...) __attribute__((format(printf,1,2)));
static inline GString *g_string_new_str(void) {
INLINE GString *g_string_new_str(void) {
int pl;
GString *ret;
@ -193,7 +186,7 @@ static inline GString *g_string_new_str(void) {
g_string_append_len(ret, STR_MALLOC_PADDING, pl);
return ret;
}
static inline str *g_string_free_str(GString *gs) {
INLINE str *g_string_free_str(GString *gs) {
str *ret;
int pl;
@ -206,7 +199,7 @@ static inline str *g_string_free_str(GString *gs) {
g_string_free(gs, FALSE);
return ret;
}
static inline int str_memcmp(const str *s, void *m) {
INLINE int str_memcmp(const str *s, void *m) {
return memcmp(s->s, m, s->len);
}

@ -8,6 +8,7 @@
#include <glib.h>
#include <stdarg.h>
#include "compat.h"
#include "str.h"
@ -34,7 +35,7 @@ unsigned int streambuf_bufsize(struct streambuf *);
void streambuf_printf(struct streambuf *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
void streambuf_vprintf(struct streambuf *, const char *, va_list);
void streambuf_write(struct streambuf *, const char *, unsigned int);
static inline void streambuf_write_str(struct streambuf *b, str *s) {
INLINE void streambuf_write_str(struct streambuf *b, str *s) {
streambuf_write(b, s->s, s->len);
}

@ -7,6 +7,7 @@
#include <openssl/hmac.h>
#include <glib.h>
#include "compat.h"
#include "str.h"
#include "aux.h"
#include "log.h"
@ -196,7 +197,7 @@ static void output_init(struct msghdr *mh, struct iovec *iov, struct sockaddr_in
memcpy(&hdr->transaction, transaction, sizeof(hdr->transaction));
}
static inline void __output_add(struct msghdr *mh, struct tlv *tlv, unsigned int len, u_int16_t code,
INLINE void __output_add(struct msghdr *mh, struct tlv *tlv, unsigned int len, u_int16_t code,
void *append, unsigned int append_len)
{
struct iovec *iov;
@ -404,7 +405,7 @@ static int stun_binding_success(int fd, struct header *req, struct stun_attrs *a
return 0;
}
static inline int u_int16_t_arr_len(u_int16_t *arr) {
INLINE int u_int16_t_arr_len(u_int16_t *arr) {
int i;
for (i = 0; arr[i] != 0xffff; i++)
;

@ -4,6 +4,7 @@
#include <string.h>
#include <arpa/inet.h>
#include "compat.h"
#include "call.h"
#include "str.h"
@ -11,7 +12,7 @@
#define STUN_COOKIE 0x2112A442UL
static inline int is_stun(const str *s) {
INLINE int is_stun(const str *s) {
const unsigned char *b = (const void *) s->s;
const u_int32_t *u;

Loading…
Cancel
Save