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