* This method is used to parse all Allow HF body. * * params: msg : sip msg * returns 0 on success, * -1 on failure. */
| 41 | * -1 on failure. |
| 42 | */ |
| 43 | int parse_allow(struct sip_msg *msg) |
| 44 | { |
| 45 | unsigned int allow; |
| 46 | struct hdr_field *hdr; |
| 47 | struct allow_body *ab = 0; |
| 48 | |
| 49 | /* maybe the header is already parsed! */ |
| 50 | if (msg->allow && msg->allow->parsed) |
| 51 | return 0; |
| 52 | |
| 53 | /* parse to the end in order to get all ALLOW headers */ |
| 54 | if (parse_headers(msg,HDR_EOH_F,0)==-1 || !msg->allow) |
| 55 | return -1; |
| 56 | |
| 57 | /* bad luck! :-( - we have to parse them */ |
| 58 | allow = 0; |
| 59 | for( hdr=msg->allow ; hdr ; hdr=hdr->sibling) { |
| 60 | if (hdr->parsed) { |
| 61 | allow |= ((struct allow_body*)hdr->parsed)->allow; |
| 62 | continue; |
| 63 | } |
| 64 | |
| 65 | ab = (struct allow_body*)pkg_malloc(sizeof(struct allow_body)); |
| 66 | if (ab == 0) { |
| 67 | LM_ERR("out of pkg_memory\n"); |
| 68 | return -1; |
| 69 | } |
| 70 | |
| 71 | if (parse_methods(&(hdr->body), &(ab->allow))!=0) { |
| 72 | LM_ERR("bad allow body header\n"); |
| 73 | set_err_info(OSER_EC_PARSER, OSER_EL_MEDIUM, |
| 74 | "error parsing ALLOW header"); |
| 75 | set_err_reply(400, "bad headers"); |
| 76 | goto error; |
| 77 | } |
| 78 | ab->allow_all = 0; |
| 79 | hdr->parsed = (void*)ab; |
| 80 | allow |= ab->allow; |
| 81 | } |
| 82 | |
| 83 | ((struct allow_body*)msg->allow->parsed)->allow_all = allow; |
| 84 | return 0; |
| 85 | |
| 86 | error: |
| 87 | if(ab!=0) |
| 88 | pkg_free(ab); |
| 89 | return -1; |
| 90 | } |
| 91 |
no test coverage detected