lost: added civic address parsing via xpath
[kamailio] / src / modules / lost / utilities.h
1 /*
2  * lost module utility functions
3  *
4  * Copyright (C) 2020 Wolfgang Kampichler
5  * DEC112, FREQUENTIS AG
6  *
7  * This file is part of Kamailio, a free SIP server.
8  *
9  * Kamailio is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version
13  *
14  * Kamailio is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  */
24
25 /*!
26  * \file
27  * \brief Kamailio lost :: functions
28  * \ingroup lost
29  * Module: \ref lost
30  */
31
32 #ifndef LOST_UTILITIES_H
33 #define LOST_UTILITIES_H
34
35 #define LOST_GEOLOC_HEADER "Geolocation: "
36 #define LOST_GEOLOC_HEADER_SIZE strlen(LOST_GEOLOC_HEADER)
37 #define LOST_PAI_HEADER "P-Asserted-Identity: "
38 #define LOST_PAI_HEADER_SIZE strlen(LOST_PAI_HEADER)
39
40 #define LOST_RECURSION_TRUE 1
41 #define LOST_RECURSION_FALSE 0
42 #define LOST_XPATH_DPTH 3
43 #define LOST_XPATH_GP "//gp:location-info/*"
44
45 #define XPATH_NS                                         \
46         "gp=urn:ietf:params:xml:ns:pidf:geopriv10"           \
47         " "                                                  \
48         "xmlns=urn:ietf:params:xml:ns:pidf"                  \
49         " "                                                  \
50         "ca=urn:ietf:params:xml:ns:pidf:geopriv10:civicAddr" \
51         " "                                                  \
52         "gm=http://www.opengis.net/gml"
53
54 #define LOST_PRO_GEO2D "geodetic-2d"
55 #define LOST_PRO_CIVIC "civic"
56
57 #define LOST_PNT "Point"
58 #define LOST_CIR "Circle"
59 #define LOST_CIV "civicAddress"
60
61 #define HELD_TYPE "geodetic locationURI"
62 #define HELD_TIME "3"
63 #define HELD_EXACT_TRUE 1
64 #define HELD_EXACT_FALSE 0
65
66 #define BUFSIZE 128     /* temporary buffer to hold geolocation */
67 #define RANDSTRSIZE 16 /* temporary id in a findService request */
68
69 typedef struct LOC
70 {
71         char *identity;         /* location idendity (findServiceRequest) */
72         char *urn;                      /* service URN (findServiceRequest) */ 
73         char *civic;            /* civic address (findServiceRequest) */
74         char *geodetic;         /* geodetic location (findServiceRequest) */
75         char *longitude;        /* geo longitude */
76         char *latitude;         /* geo latitude */
77         char *profile;          /* location profile (findServiceRequest) */
78         int radius;                     /* geo radius (findServiceRequest) */
79         int recursive;          /* recursion true|false (findServiceRequest)*/
80         int boundary;       /* boundary ref|value (findServiceRequest)*/
81 } s_loc_t, *p_loc_t;
82
83 typedef struct HELD
84 {
85         char *identity;         /* location idendity (locationRequest) */
86         char *type;                     /* location type (locationRequest) */ 
87         char *time;                     /* response time (locationRequest) */
88         int exact;                      /* exact true|false (locationRequest)*/
89 } s_held_t, *p_held_t;
90
91
92 void lost_rand_str(char *, size_t);
93 void lost_free_loc(p_loc_t);
94 void lost_free_held(p_held_t);
95 void lost_free_string(str *);
96
97 int lost_parse_location_info(xmlNodePtr, p_loc_t);
98 int lost_xpath_location(xmlDocPtr, char *, p_loc_t);
99 int lost_parse_geo(xmlNodePtr, p_loc_t);
100
101 char *lost_find_service_request(p_loc_t, int *);
102 char *lost_held_location_request(p_held_t, int *);
103 char *lost_get_content(xmlNodePtr, const char *, int *);
104 char *lost_get_property(xmlNodePtr, const char *, int *);
105 char *lost_get_geolocation_header(struct sip_msg *, int *);
106 char *lost_get_from_header(struct sip_msg *, int *);
107 char *lost_get_pai_header(struct sip_msg *, int *);
108 char *lost_get_childname(xmlNodePtr, const char *, int *);
109 char *lost_trim_content(char *, int *);
110
111 p_loc_t lost_new_loc(str);
112 p_held_t lost_new_held(str, str, str, int);
113
114 #endif