parse_sipifmatch.c

Go to the documentation of this file.
00001 
00007 #include <string.h>
00008 
00009 #include "parse_sipifmatch.h"
00010 #include "../dprint.h"
00011 #include "parse_def.h"
00012 #include "../mem/mem.h"
00013 #include "../trim.h"
00014 
00015 static inline char* skip_token(char* _b, int _l)
00016 {
00017         int i = 0;
00018 
00019         for(i = 0; i < _l; i++) {
00020                 switch(_b[i]) {
00021                 case ' ':
00022                 case '\r':
00023                 case '\n':
00024                 case '\t':
00025                 case ';':
00026                         return _b + i;
00027                 }
00028         }
00029 
00030         return _b + _l;
00031 }
00032 
00033 
00034 int etag_parser(char *_s, int _l, str *_e)
00035 {
00036         char* end;
00037 
00038         _e->s = _s;
00039         _e->len = _l;
00040 
00041         trim_leading(_e);
00042 
00043         if (_e->len == 0) {
00044                 LOG(L_ERR, "etag_parser(): Empty body\n");
00045                 return -1;
00046         }
00047 
00048         end = skip_token(_e->s, _e->len);
00049         _e->len = end - _e->s;
00050 
00051         return 0;
00052 }
00053 
00054 
00055 int parse_sipifmatch(struct hdr_field* _h)
00056 {
00057         str *e;
00058 
00059         DBG("parse_sipifmatch() called\n");
00060 
00061         if (_h->parsed != 0) {
00062                 return 0;
00063         }
00064 
00065         e = (str*)pkg_malloc(sizeof(str));
00066         if (e == 0) {
00067                 LOG(L_ERR, "parse_ifsipmatch(): No memory left\n");
00068                 return -1;
00069         }
00070 
00071         memset(e, 0, sizeof(str));
00072 
00073         if (etag_parser(_h->body.s, _h->body.len, e) < 0) {
00074                 LOG(L_ERR, "parse_sipifmatch(): Error in tag_parser\n");
00075                 pkg_free(e);
00076                 return -2;
00077         }
00078 
00079         _h->parsed = (void*)e;
00080         return 0;
00081 }
00082 
00083 
00084 void free_sipifmatch(str** _e)
00085 {
00086         if (*_e)
00087                 pkg_free(*_e);
00088         *_e = 0;
00089 }