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