~ubuntu-branches/debian/sid/kamailio/sid

« back to all changes in this revision

Viewing changes to lib/kcore/parse_ppi.c

  • Committer: Package Import Robot
  • Author(s): Victor Seva
  • Date: 2014-01-06 11:47:13 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140106114713-t8xidp4arzrnyeya
Tags: 4.1.1-1
* New upstream release
* debian/patches:
  - add upstream fixes
* Added tls outbound websocket autheph dnssec modules
  - openssl exception added to their license
* removing sparc and ia64 from supported archs
  for mono module (Closes: #728915)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id$
3
 
 *
4
 
 * Copyright (C) 2006 Juha Heinanen
5
 
 *
6
 
 * This file is part of Kamailio, a free SIP server.
7
 
 *
8
 
 * Kamailio is free software; you can redistribute it and/or modify
9
 
 * it under the terms of the GNU General Public License as published by
10
 
 * the Free Software Foundation; either version 2 of the License, or
11
 
 * (at your option) any later version
12
 
 *
13
 
 * Kamailio is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 * GNU General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU General Public License 
19
 
 * along with this program; if not, write to the Free Software 
20
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
 
 */
22
 
 
23
 
/*!
24
 
 * \file
25
 
 * \brief P-Preferred-Identity header parser
26
 
 * \ingroup parser
27
 
 */
28
 
 
29
 
#include "parse_ppi.h"
30
 
#include "../../parser/parse_to.h"
31
 
#include "../../parser/parse_uri.h"
32
 
#include <stdlib.h>
33
 
#include <string.h>
34
 
#include "../../dprint.h"
35
 
#include "../../parser/msg_parser.h"
36
 
#include "../../ut.h"
37
 
#include "../../mem/mem.h"
38
 
 
39
 
 
40
 
/*!
41
 
 * \brief This method is used to parse P-Preferred-Identity header (RFC 3325).
42
 
 *
43
 
 * Currently only one name-addr / addr-spec is supported in the header
44
 
 * and it must contain a sip or sips URI.
45
 
 * \param msg sip msg
46
 
 * \return 0 on success, -1 on failure.
47
 
 */
48
 
int parse_ppi_header( struct sip_msg *msg )
49
 
{
50
 
    struct to_body* ppi_b;
51
 
 
52
 
    if ( !msg->ppi &&
53
 
         (parse_headers(msg, HDR_PPI_F,0)==-1 || !msg->ppi)) {
54
 
        goto error;
55
 
    }
56
 
 
57
 
    /* maybe the header is already parsed! */
58
 
    if (msg->ppi->parsed)
59
 
        return 0;
60
 
 
61
 
    /* bad luck! :-( - we have to parse it */
62
 
    /* first, get some memory */
63
 
    ppi_b = pkg_malloc(sizeof(struct to_body));
64
 
    if (ppi_b == 0) {
65
 
        LM_ERR("out of pkg_memory\n");
66
 
        goto error;
67
 
    }
68
 
 
69
 
    /* now parse it!! */
70
 
    memset(ppi_b, 0, sizeof(struct to_body));
71
 
    parse_to(msg->ppi->body.s,
72
 
             msg->ppi->body.s + msg->ppi->body.len+1,
73
 
             ppi_b);
74
 
    if (ppi_b->error == PARSE_ERROR) {
75
 
        LM_ERR("bad P-Preferred-Identity header\n");
76
 
        free_to(ppi_b);
77
 
        goto error;
78
 
    }
79
 
        msg->ppi->parsed = ppi_b;
80
 
 
81
 
        return 0;
82
 
 error:
83
 
        return -1;
84
 
}
85
 
 
86
 
 
87
 
/*!
88
 
 * \brief Parse P-Preferred-Identity header URI
89
 
 */
90
 
struct sip_uri *parse_ppi_uri(struct sip_msg *msg)
91
 
{
92
 
        struct to_body *tb = NULL;
93
 
        
94
 
        if(msg==NULL)
95
 
                return NULL;
96
 
 
97
 
        if(parse_ppi_header(msg)<0)
98
 
        {
99
 
                LM_ERR("cannot parse P-P-I header\n");
100
 
                return NULL;
101
 
        }
102
 
        
103
 
        if(msg->ppi==NULL || get_ppi(msg)==NULL)
104
 
                return NULL;
105
 
 
106
 
        tb = get_ppi(msg);
107
 
 
108
 
        if(tb->parsed_uri.user.s!=NULL || tb->parsed_uri.host.s!=NULL)
109
 
                return &tb->parsed_uri;
110
 
 
111
 
        if (parse_uri(tb->uri.s, tb->uri.len , &tb->parsed_uri)<0)
112
 
        {
113
 
                LM_ERR("failed to parse P-P-I URI\n");
114
 
                memset(&tb->parsed_uri, 0, sizeof(struct sip_uri));
115
 
                return NULL;
116
 
        }
117
 
 
118
 
        return &tb->parsed_uri;
119
 
}