Browse Source

introduce kamailio-style "str" data type/struct

also remove several occurences of "const" that keep biting me in the rear.
git.mgm/mediaproxy-ng/2.2
Richard Fuchs 13 years ago
parent
commit
8db7ab6c94
5 changed files with 36 additions and 29 deletions
  1. +2
    -2
      daemon/bencode.h
  2. +1
    -1
      daemon/call.c
  3. +21
    -25
      daemon/sdp.c
  4. +1
    -1
      daemon/sdp.h
  5. +11
    -0
      daemon/str.h

+ 2
- 2
daemon/bencode.h View File

@ -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)


+ 1
- 1
daemon/call.c View File

@ -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;


+ 21
- 25
daemon/sdp.c View File

@ -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);
}


+ 1
- 1
daemon/sdp.h View File

@ -3,7 +3,7 @@
#include <glib.h>
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);


+ 11
- 0
daemon/str.h View File

@ -0,0 +1,11 @@
#ifndef _STR_H_
#define _STR_H_
struct _str {
char *s;
int len;
};
typedef struct _str str;
#endif

Loading…
Cancel
Save