* This method is used to parse the from header. It was decided not to parse * anything in core that is not *needed* so this method gets called by * rad_acc module and any other modules that needs the FROM header. * * params: msg : sip msg * returns =0 on success, * <0 on failure. */
| 44 | * <0 on failure. |
| 45 | */ |
| 46 | int parse_from_header( struct sip_msg *msg) |
| 47 | { |
| 48 | struct to_body* from_b; |
| 49 | |
| 50 | if ( !msg->from && ( parse_headers(msg,HDR_FROM_F,0)==-1 || !msg->from)) { |
| 51 | LM_ERR("bad msg or missing FROM header\n"); |
| 52 | goto error; |
| 53 | } |
| 54 | |
| 55 | /* maybe the header is already parsed! */ |
| 56 | if (msg->from->parsed) |
| 57 | return 0; |
| 58 | |
| 59 | /* bad luck! :-( - we have to parse it */ |
| 60 | /* first, get some memory */ |
| 61 | from_b = pkg_malloc(sizeof(struct to_body)); |
| 62 | if (from_b == 0) { |
| 63 | LM_ERR("out of pkg_memory\n"); |
| 64 | goto error; |
| 65 | } |
| 66 | |
| 67 | /* now parse it!! */ |
| 68 | memset(from_b, 0, sizeof(struct to_body)); |
| 69 | parse_to(msg->from->body.s,msg->from->body.s+msg->from->body.len+1,from_b); |
| 70 | if (from_b->error == PARSE_ERROR) { |
| 71 | LM_ERR("bad from header\n"); |
| 72 | pkg_free(from_b); |
| 73 | set_err_info(OSER_EC_PARSER, OSER_EL_MEDIUM, |
| 74 | "error parsing From header"); |
| 75 | set_err_reply(400, "bad header"); |
| 76 | goto error; |
| 77 | } |
| 78 | /* REGISTER doesn't have a from tag :( -bogdan |
| 79 | if (from_b->tag_value.len==0 || from_b->tag_value.s==0) { |
| 80 | LM_ERR("missing TAG value\n"); |
| 81 | free_to(from_b); |
| 82 | goto error; |
| 83 | } |
| 84 | */ |
| 85 | msg->from->parsed = from_b; |
| 86 | |
| 87 | return 0; |
| 88 | error: |
| 89 | return -1; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * |
no test coverage detected