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_ANY "any"
62 #define HELD_TYPE_CIV "civic"
63 #define HELD_TYPE_GEO "geodetic"
64 #define HELD_TYPE_URI "locationURI"
65 #define HELD_TYPE_SEP " "
66 
67 #define HELD_EXACT_TRUE 1
68 #define HELD_EXACT_FALSE 0
69 
70 #define BUFSIZE 128	/* temporary buffer to hold geolocation */
71 #define RANDSTRSIZE 16 /* temporary id in a findService request */
72 
73 typedef struct LOC
74 {
75 	char *identity;		/* location idendity (findServiceRequest) */
76 	char *urn;			/* service URN (findServiceRequest) */
77 	char *xpath;		/* civic address (findServiceRequest) */
78 	char *geodetic;		/* geodetic location (findServiceRequest) */
79 	char *longitude;	/* geo longitude */
80 	char *latitude;		/* geo latitude */
81 	char *profile;		/* location profile (findServiceRequest) */
82 	int radius;			/* geo radius (findServiceRequest) */
83 	int recursive;		/* recursion true|false (findServiceRequest)*/
84 	int boundary;       /* boundary ref|value (findServiceRequest)*/
85 } s_loc_t, *p_loc_t;
86 
87 typedef struct HELD
88 {
89 	char *identity;		/* location idendity (locationRequest) */
90 	char *type;			/* location type (locationRequest) */
91 	int time;			/* response time (locationRequest) */
92 	int exact;			/* exact true|false (locationRequest)*/
93 } s_held_t, *p_held_t;
94 
95 void lost_rand_str(char *, size_t);
96 void lost_free_loc(p_loc_t);
97 void lost_free_held(p_held_t);
98 void lost_free_string(str *);
99 
100 int lost_parse_location_info(xmlNodePtr, p_loc_t);
101 int lost_xpath_location(xmlDocPtr, char *, p_loc_t);
102 int lost_parse_geo(xmlNodePtr, p_loc_t);
103 
104 char *lost_find_service_request(p_loc_t, int *);
105 char *lost_held_location_request(p_held_t, int *);
106 char *lost_get_content(xmlNodePtr, const char *, int *);
107 char *lost_get_property(xmlNodePtr, const char *, int *);
108 char *lost_get_geolocation_header(struct sip_msg *, int *);
109 char *lost_get_from_header(struct sip_msg *, int *);
110 char *lost_get_pai_header(struct sip_msg *, int *);
111 char *lost_get_childname(xmlNodePtr, const char *, int *);
112 char *lost_trim_content(char *, int *);
113 
114 p_loc_t lost_new_loc(str);
115 p_held_t lost_new_held(str, str, int, int);
116 
117 #endif
118