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
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include "../dprint.h"
00031 #include "../mem/mem.h"
00032 #include "parse_allow.h"
00033 #include "parse_methods.h"
00034 #include "msg_parser.h"
00035
00036
00043 int parse_allow_header(struct hdr_field* _hf)
00044 {
00045 struct allow_body* ab = 0;
00046
00047 if (!_hf) {
00048 LOG(L_ERR, "parse_allow_header: Invalid parameter value\n");
00049 return -1;
00050 }
00051
00052
00053 if (_hf->parsed) {
00054 return 0;
00055 }
00056
00057 ab = (struct allow_body*)pkg_malloc(sizeof(struct allow_body));
00058 if (ab == 0) {
00059 LOG(L_ERR, "ERROR:parse_allow_header: out of pkg_memory\n");
00060 return -1;
00061 }
00062 memset(ab,'\0', sizeof(struct allow_body));
00063
00064 if (parse_methods(&(_hf->body), &(ab->allow)) !=0 ) {
00065 LOG(L_ERR, "ERROR:parse_allow_header: bad allow body header\n");
00066 goto error;
00067 }
00068
00069 ab->allow_all = 0;
00070 _hf->parsed = (void*)ab;
00071 return 0;
00072
00073 error:
00074 if (ab) pkg_free(ab);
00075 return -1;
00076 }
00077
00083 int parse_allow(struct sip_msg *msg)
00084 {
00085 unsigned int allow;
00086 struct hdr_field *hdr;
00087
00088
00089 if (msg->allow && msg->allow->parsed) {
00090 return 0;
00091 }
00092
00093
00094 if (parse_headers(msg,HDR_EOH_F,0)==-1 || !msg->allow) {
00095 return -1;
00096 }
00097 allow = 0;
00098
00099 for(hdr = msg->allow ; hdr ; hdr = next_sibling_hdr(hdr)) {
00100 if (hdr->parsed == 0) {
00101 if(parse_allow_header(hdr) < 0) {
00102 return -1;
00103 }
00104 }
00105
00106 allow |= ((struct allow_body*)hdr->parsed)->allow;
00107 }
00108
00109 ((struct allow_body*)msg->allow->parsed)->allow_all = allow;
00110 return 0;
00111 }
00112
00113
00114
00115
00116
00117 void free_allow_body(struct allow_body **ab)
00118 {
00119 if (ab && *ab) {
00120 pkg_free(*ab);
00121 *ab = 0;
00122 }
00123 }
00124
00125
00126 void free_allow_header(struct hdr_field* hf)
00127 {
00128 free_allow_body((struct allow_body**)(void*)(&(hf->parsed)));
00129 }