parse_sipifmatch.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <string.h>
00030
00031 #include "parse_sipifmatch.h"
00032 #include "../dprint.h"
00033 #include "parse_def.h"
00034 #include "../mem/mem.h"
00035 #include "../trim.h"
00036
00037 static inline char* skip_token(char* _b, int _l)
00038 {
00039 int i = 0;
00040
00041 for(i = 0; i < _l; i++) {
00042 switch(_b[i]) {
00043 case ' ':
00044 case '\r':
00045 case '\n':
00046 case '\t':
00047 case ';':
00048 return _b + i;
00049 }
00050 }
00051
00052 return _b + _l;
00053 }
00054
00055
00056 int
00057 etag_parser(char *_s, int _l, str *_e)
00058 {
00059 char* end;
00060
00061 _e->s = _s;
00062 _e->len = _l;
00063
00064 trim_leading(_e);
00065
00066 if (_e->len == 0) {
00067 LM_ERR("empty body\n");
00068 return -1;
00069 }
00070
00071 end = skip_token(_e->s, _e->len);
00072 _e->len = end - _e->s;
00073
00074 return 0;
00075 }
00076
00077
00078 int
00079 parse_sipifmatch(struct hdr_field* _h)
00080 {
00081 str *e;
00082
00083 LM_DBG("called\n");
00084
00085 if (_h->parsed != 0) {
00086 return 0;
00087 }
00088
00089 e = (str*)pkg_malloc(sizeof(str));
00090 if (e == 0) {
00091 LM_ERR("no pkg memory left\n");
00092 return -1;
00093 }
00094
00095 memset(e, 0, sizeof(str));
00096
00097 if (etag_parser(_h->body.s, _h->body.len, e) < 0) {
00098 LM_ERR("error in tag_parser\n");
00099 pkg_free(e);
00100 return -2;
00101 }
00102
00103 _h->parsed = (void*)e;
00104 return 0;
00105 }
00106
00107
00108 void free_sipifmatch(str** _e)
00109 {
00110 if (*_e)
00111 pkg_free(*_e);
00112 *_e = 0;
00113 }