avp: typedef hdr name struct to simplify memory allocation
authorDaniel-Constantin Mierla <miconda@gmail.com>
Thu, 27 Jul 2017 07:12:46 +0000 (09:12 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Thu, 27 Jul 2017 07:12:46 +0000 (09:12 +0200)
src/modules/avp/avp.c

index 84ecf4d..d6c8b33 100644 (file)
@@ -60,7 +60,7 @@ MODULE_VERSION
 #define VAL_TYPE_INT (1<<0)
 #define VAL_TYPE_STR (1<<1)
 
-struct hdr_name {
+typedef struct hdr_name {
        enum {hdrId, hdrStr} kind;
        union {
                int n;
@@ -69,7 +69,7 @@ struct hdr_name {
        char field_delimiter;
        char array_delimiter;
        int val_types;
-};
+} hdr_name_t;
 
 static int xlbuf_size=256;
 static char* xlbuf=NULL;
@@ -1379,7 +1379,7 @@ static int attr_hdr_body2attrs2(struct sip_msg* msg, char* header_, char* prefix
 static int attr_hdr_body2attrs_fixup(void **param, int param_no)
 {
        char *c, *params;
-       struct hdr_name *h;
+       hdr_name_t *h;
        int n;
        str *s;
        if(param_no == 1) {
@@ -1408,7 +1408,7 @@ static int attr_hdr_body2attrs_fixup(void **param, int param_no)
                                                        c, n);
                                        return E_CFG;
                        }
-                       h = pkg_malloc(sizeof(*h));
+                       h = pkg_malloc(sizeof(hdr_name_t));
                        if(!h) {
                                LOG(L_ERR, "attr_hdr_body2attrs_fixup: out of memory\n");
                                return E_OUT_OF_MEM;
@@ -1428,14 +1428,14 @@ static int attr_hdr_body2attrs_fixup(void **param, int param_no)
                                LOG(L_ERR, "attr_hdr_body2attrs_fixup: header name is empty\n");
                                return E_CFG;
                        }
-                       h = pkg_malloc(sizeof(*h) + n + 1);
+                       h = pkg_malloc(sizeof(hdr_name_t) + n + 1);
                        if(!h) {
                                LOG(L_ERR, "attr_hdr_body2attrs_fixup: out of memory\n");
                                return E_OUT_OF_MEM;
                        }
                        h->kind = HDR_STR;
                        h->name.s.len = n;
-                       h->name.s.s = (char *)h + sizeof(*h);
+                       h->name.s.s = (char *)h + sizeof(hdr_name_t);
                        memcpy(h->name.s.s, c, n + 1);
                }
                if(params) {
@@ -1478,13 +1478,13 @@ static int attr_hdr_body2attrs_fixup(void **param, int param_no)
                if(n == 0) {
                        s = NULL;
                } else {
-                       s = pkg_malloc(sizeof(*s) + n + 1);
+                       s = pkg_malloc(sizeof(str) + n + 1);
                        if(!s) {
                                LOG(L_ERR, "attr_hdr_body2attrs_fixup: out of memory\n");
                                return E_OUT_OF_MEM;
                        }
                        s->len = n;
-                       s->s = (char *)s + sizeof(*s);
+                       s->s = (char *)s + sizeof(str);
                        memcpy(s->s, *param, n + 1);
                }
                pkg_free(*param);
@@ -1506,7 +1506,6 @@ static int attr_hdr_body2attrs2_fixup(void** param, int param_no)
 }
 
 
-
 static int avpgroup_fixup(void** param, int param_no)
 {
        unsigned long flags;
@@ -1581,7 +1580,6 @@ static int avpgroup_fixup(void** param, int param_no)
 }
 
 
-
 static int select_attr_fixup(str* res, select_t* s, struct sip_msg* msg)
 {
        avp_ident_t *avp_ident;