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