From 8db7ab6c94b89ee29aab8c568aa8455440cb7ffa Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 23 Jan 2013 15:34:34 -0500 Subject: [PATCH] introduce kamailio-style "str" data type/struct also remove several occurences of "const" that keep biting me in the rear. --- daemon/bencode.h | 4 ++-- daemon/call.c | 2 +- daemon/sdp.c | 46 +++++++++++++++++++++------------------------- daemon/sdp.h | 2 +- daemon/str.h | 11 +++++++++++ 5 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 daemon/str.h diff --git a/daemon/bencode.h b/daemon/bencode.h index 5814663f4..b49780b8f 100644 --- a/daemon/bencode.h +++ b/daemon/bencode.h @@ -197,7 +197,7 @@ 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 const char *bencode_dictionary_get_string(bencode_item_t *dict, const char *key, int *len); +static inline char *bencode_dictionary_get_string(bencode_item_t *dict, const char *key, int *len); /* 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. */ @@ -243,7 +243,7 @@ static inline bencode_item_t *bencode_dictionary_get(bencode_item_t *dict, const return bencode_dictionary_get_len(dict, key, strlen(key)); } -static inline const char *bencode_dictionary_get_string(bencode_item_t *dict, const char *key, int *len) { +static 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) diff --git a/daemon/call.c b/daemon/call.c index 92c1e7377..d72a56575 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2114,7 +2114,7 @@ struct callstream *callstream_new(struct call *ca, int num) { const char *call_offer(bencode_item_t *input, struct callmaster *m, bencode_item_t *output) { - const char *sdp, *errstr; + char *sdp, *errstr; int sdp_len; GQueue parsed = G_QUEUE_INIT; GQueue streams = G_QUEUE_INIT; diff --git a/daemon/sdp.c b/daemon/sdp.c index 55638b984..c945a17f4 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -6,23 +6,19 @@ #include "sdp.h" #include "call.h" #include "log.h" - -struct string { - const char *s; - int len; -}; +#include "str.h" struct network_address { - struct string network_type; - struct string address_type; - struct string address; + str network_type; + str address_type; + str address; struct in6_addr parsed; }; struct sdp_origin { - struct string username; - struct string session_id; - struct string version; + str username; + str session_id; + str version; struct network_address address; int parsed:1; }; @@ -40,9 +36,9 @@ struct sdp_session { }; struct sdp_media { - struct string media_type; - struct string port; - struct string transport; + str media_type; + str port; + str transport; /* ... format list */ long int port_num; @@ -56,8 +52,8 @@ struct sdp_media { /* hack hack */ -static inline int inet_pton_str(int af, struct string *src, void *dst) { - char *s = (void *) src->s; +static inline int inet_pton_str(int af, str *src, void *dst) { + char *s = src->s; char p; int ret; p = s[src->len]; @@ -94,8 +90,8 @@ static int parse_address(struct network_address *address) { return 0; } -static inline int extract_token(const char **sp, const char *end, struct string *out) { - const char *space; +static inline int extract_token(char **sp, char *end, str *out) { + char *space; out->s = *sp; space = memchr(*sp, ' ', end - *sp); @@ -120,7 +116,7 @@ static inline int extract_token(const char **sp, const char *end, struct string EXTRACT_TOKEN(field.address); \ if (parse_address(&output->address)) return -1 -static int parse_origin(const char *start, const char *end, struct sdp_origin *output) { +static int parse_origin(char *start, char *end, struct sdp_origin *output) { if (output->parsed) return -1; @@ -133,7 +129,7 @@ static int parse_origin(const char *start, const char *end, struct sdp_origin *o return 0; } -static int parse_connection(const char *start, const char *end, struct sdp_connection *output) { +static int parse_connection(char *start, char *end, struct sdp_connection *output) { if (output->parsed) return -1; @@ -143,7 +139,7 @@ static int parse_connection(const char *start, const char *end, struct sdp_conne return 0; } -static int parse_media(const char *start, const char *end, struct sdp_media *output) { +static int parse_media(char *start, char *end, struct sdp_media *output) { char *ep; EXTRACT_TOKEN(media_type); @@ -169,12 +165,12 @@ static int parse_media(const char *start, const char *end, struct sdp_media *out return 0; } -int sdp_parse(const char *body, int len, GQueue *sessions) { - const char *b, *end, *value, *line_end, *next_line; +int sdp_parse(char *body, int len, GQueue *sessions) { + char *b, *end, *value, *line_end, *next_line; struct sdp_session *session = NULL; struct sdp_media *media = NULL; const char *errstr; - struct string *attribute; + str *attribute; b = body; end = body + len; @@ -279,7 +275,7 @@ error: } static void __free_attributes(GQueue *a) { - struct string *str; + str *str; while ((str = g_queue_pop_head(a))) { g_slice_free1(sizeof(*str), str); } diff --git a/daemon/sdp.h b/daemon/sdp.h index 42bf995bd..180bd10e0 100644 --- a/daemon/sdp.h +++ b/daemon/sdp.h @@ -3,7 +3,7 @@ #include -int sdp_parse(const char *body, int len, GQueue *sessions); +int sdp_parse(char *body, int len, GQueue *sessions); int sdp_streams(const GQueue *sessions, GQueue *streams); void sdp_free(GQueue *sessions); diff --git a/daemon/str.h b/daemon/str.h new file mode 100644 index 000000000..c82eb4520 --- /dev/null +++ b/daemon/str.h @@ -0,0 +1,11 @@ +#ifndef _STR_H_ +#define _STR_H_ + +struct _str { + char *s; + int len; +}; + +typedef struct _str str; + +#endif