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
00034 #include "parse_from.h"
00035 #include "parse_to.h"
00036 #include <stdlib.h>
00037 #include <string.h>
00038 #include "../dprint.h"
00039 #include "msg_parser.h"
00040 #include "parse_uri.h"
00041 #include "../ut.h"
00042 #include "../mem/mem.h"
00043
00055 int parse_from_header( struct sip_msg *msg)
00056 {
00057 struct to_body* from_b;
00058
00059 if ( !msg->from && ( parse_headers(msg,HDR_FROM_F,0)==-1 || !msg->from)) {
00060 LOG(L_ERR,"ERROR:parse_from_header: bad msg or missing FROM header\n");
00061 goto error;
00062 }
00063
00064
00065 if (msg->from->parsed)
00066 return 0;
00067
00068
00069
00070 from_b = pkg_malloc(sizeof(struct to_body));
00071 if (from_b == 0) {
00072 LOG(L_ERR, "ERROR:parse_from_header: out of pkg_memory\n");
00073 goto error;
00074 }
00075
00076
00077 memset(from_b, 0, sizeof(struct to_body));
00078 parse_to(msg->from->body.s,msg->from->body.s+msg->from->body.len+1,from_b);
00079 if (from_b->error == PARSE_ERROR) {
00080 LOG(L_ERR, "ERROR:parse_from_header: bad from header [%.*s]\n",
00081 msg->from->body.len, msg->from->body.s);
00082 free_to(from_b);
00083 goto error;
00084 }
00085 msg->from->parsed = from_b;
00086
00087 return 0;
00088 error:
00089 return -1;
00090 }
00091
00092 sip_uri_t *parse_from_uri(sip_msg_t *msg)
00093 {
00094 to_body_t *tb = NULL;
00095
00096 if(msg==NULL)
00097 return NULL;
00098
00099 if(parse_from_header(msg)<0)
00100 {
00101 LM_ERR("cannot parse FROM header\n");
00102 return NULL;
00103 }
00104
00105 if(msg->from==NULL || get_from(msg)==NULL)
00106 return NULL;
00107
00108 tb = get_from(msg);
00109
00110 if(tb->parsed_uri.user.s!=NULL || tb->parsed_uri.host.s!=NULL)
00111 return &tb->parsed_uri;
00112
00113 if (parse_uri(tb->uri.s, tb->uri.len , &tb->parsed_uri)<0)
00114 {
00115 LM_ERR("failed to parse From uri\n");
00116 memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
00117 return NULL;
00118 }
00119 return &tb->parsed_uri;
00120 }