1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
/* $Header: /pjproject/pjsip/src/pjsip/sip_uri.h 7 6/19/05 6:12p Bennylp $ */
#ifndef __PJSIP_SIP_URI_H__
#define __PJSIP_SIP_URI_H__
/**
* @file sip_uri.h
* @brief SIP URL Structures and Manipulations
*/
#include <pjsip/sip_types.h>
#include <pjsip/sip_config.h>
PJ_BEGIN_DECL
/**
* @defgroup PJSIP_URL URL Structures
* @brief SIP Url, tel: Url, and generic URI.
* @ingroup PJSIP_MSG
* @{
*/
/**
* URI context.
*/
typedef enum pjsip_uri_context_e
{
PJSIP_URI_IN_REQ_URI, /**< The URI is in Request URI. */
PJSIP_URI_IN_FROMTO_HDR, /**< The URI is in From/To header. */
PJSIP_URI_IN_CONTACT_HDR, /**< The URI is in Contact header. */
PJSIP_URI_IN_ROUTING_HDR, /**< The URI is in Route/Record-Route header. */
PJSIP_URI_IN_OTHER, /**< Other context (web page, business card, etc.) */
} pjsip_uri_context_e;
/**
* URI 'virtual' function table.
* All types of URI in this library (such as sip:, sips:, tel:, and name-addr)
* will have pointer to this table as their first struct member. This table
* provides polimorphic behaviour to the URI.
*/
typedef struct pjsip_uri_vptr
{
/**
* Get URI scheme.
* @param uri the URI (self).
* @return the URI scheme.
*/
const pj_str_t* (*p_get_scheme)(const void *uri);
/**
* Get the URI object contained by this URI, or the URI itself if
* it doesn't contain another URI.
* @param uri the URI (self).
*/
void* (*p_get_uri)(void *uri);
/**
* Print URI components to the buffer, following the rule of which
* components are allowed for the context.
* @param context the context where the URI will be placed.
* @param uri the URI (self).
* @param buf the buffer.
* @param size the size of the buffer.
* @return the length printed.
*/
int (*p_print)(pjsip_uri_context_e context,
const void *uri,
char *buf, pj_size_t size);
/**
* Compare two URIs according to the context.
* @param context the context.
* @param uri1 the first URI (self).
* @param uri2 the second URI.
* @return zero if equal.
*/
int (*p_compare)(pjsip_uri_context_e context,
const void *uri1, const void *uri2);
/**
* Clone URI.
* @param pool the pool.
* @param the URI to clone (self).
* @return new URI.
*/
void *(*p_clone)(pj_pool_t *pool, const void *uri);
} pjsip_uri_vptr;
/**
* The declaration of 'base class' for all URI scheme.
*/
struct pjsip_uri
{
/** All URIs must have URI virtual function table as their first member. */
pjsip_uri_vptr *vptr;
};
/**
* This macro checks that the URL is a "sip:" or "sips:" URL.
* @param url The URL (pointer to)
* @return non-zero if TRUE.
*/
#define PJSIP_URI_SCHEME_IS_SIP(url) \
(pj_strnicmp2(pjsip_uri_get_scheme(url), "sip", 3)==0)
/**
* This macro checks that the URL is a "sips:" URL (not SIP).
* @param url The URL (pointer to)
* @return non-zero if TRUE.
*/
#define PJSIP_URI_SCHEME_IS_SIPS(url) \
(pj_strnicmp2(pjsip_uri_get_scheme(url), "sips", 4)==0)
/**
* This macro checks that the URL is a "tel:" URL.
* @param url The URL (pointer to)
* @return non-zero if TRUE.
*/
#define PJSIP_URI_SCHEME_IS_TEL(url) \
(pj_strnicmp2(pjsip_uri_get_scheme(url), "tel", 3)==0)
/**
* SIP and SIPS URL scheme.
*/
typedef struct pjsip_url
{
pjsip_uri_vptr *vptr; /**< Pointer to virtual function table.*/
pj_str_t user; /**< Optional user part. */
pj_str_t passwd; /**< Optional password part. */
pj_str_t host; /**< Host part, always exists. */
int port; /**< Optional port number, or zero. */
pj_str_t user_param; /**< Optional user parameter */
pj_str_t method_param; /**< Optional method parameter. */
pj_str_t transport_param; /**< Optional transport parameter. */
int ttl_param; /**< Optional TTL param, or -1. */
int lr_param; /**< Optional loose routing param, or zero */
pj_str_t maddr_param; /**< Optional maddr param */
pj_str_t other_param; /**< Other parameters grouped together. */
pj_str_t header_param; /**< Optional header parameter. */
} pjsip_url;
/**
* SIP name-addr, which typically appear in From, To, and Contact header.
* The SIP name-addr contains a generic URI and a display name.
*/
typedef struct pjsip_name_addr
{
/** Pointer to virtual function table. */
pjsip_uri_vptr *vptr;
/** Optional display name. */
pj_str_t display;
/** URI part. */
pjsip_uri *uri;
} pjsip_name_addr;
/**
* Generic function to get the URI scheme.
* @param uri the URI object.
* @return the URI scheme.
*/
PJ_INLINE(const pj_str_t*) pjsip_uri_get_scheme(const void *uri)
{
return (*((pjsip_uri*)uri)->vptr->p_get_scheme)(uri);
}
/**
* Generic function to get the URI object contained by this URI, or the URI
* itself if it doesn't contain another URI.
*
* @param uri the URI.
* @return the URI.
*/
PJ_INLINE(void*) pjsip_uri_get_uri(void *uri)
{
return (*((pjsip_uri*)uri)->vptr->p_get_uri)(uri);
}
/**
* Generic function to compare two URIs.
*
* @param context Comparison context.
* @param uri1 The first URI.
* @param uri2 The second URI.
* @return Zero if equal.
*/
PJ_INLINE(int) pjsip_uri_cmp(pjsip_uri_context_e context,
const void *uri1, const void *uri2)
{
return (*((const pjsip_uri*)uri1)->vptr->p_compare)(context, uri1, uri2);
}
/**
* Generic function to print an URI object.
*
* @param context Print context.
* @param uri The URI to print.
* @param buf The buffer.
* @param size Size of the buffer.
* @return Length printed.
*/
PJ_INLINE(int) pjsip_uri_print(pjsip_uri_context_e context,
const void *uri,
char *buf, pj_size_t size)
{
return (*((const pjsip_uri*)uri)->vptr->p_print)(context, uri, buf, size);
}
/**
* Generic function to clone an URI object.
*
* @param pool Pool.
* @param uri URI to clone.
* @return New URI.
*/
PJ_INLINE(void*) pjsip_uri_clone( pj_pool_t *pool, const void *uri )
{
return (*((const pjsip_uri*)uri)->vptr->p_clone)(pool, uri);
}
/**
* Create new SIP URL and initialize all fields with zero or NULL.
* @param pool The pool.
* @param secure Tlag to indicate whether secure transport should be used.
* @return SIP URL.
*/
PJ_DECL(pjsip_url*) pjsip_url_create( pj_pool_t *pool, int secure );
/**
* Create new SIPS URL and initialize all fields with zero or NULL.
* @param pool The pool.
* @return SIPS URL.
*/
PJ_DECL(pjsip_url*) pjsips_url_create( pj_pool_t *pool );
/**
* Initialize SIP URL (all fields are set to NULL or zero).
* @param url The URL.
*/
PJ_DECL(void) pjsip_url_init(pjsip_url *url, int secure);
/**
* Perform full assignment to the SIP URL.
* @param pool The pool.
* @param url Destination URL.
* @param rhs The source URL.
*/
PJ_DECL(void) pjsip_url_assign(pj_pool_t *pool, pjsip_url *url, const pjsip_url *rhs);
/**
* Create new instance of name address and initialize all fields with zero or
* NULL.
* @param pool The pool.
* @return New SIP name address.
*/
PJ_DECL(pjsip_name_addr*) pjsip_name_addr_create(pj_pool_t *pool);
/**
* Initialize with default value.
* @param name_addr The name address.
*/
PJ_DECL(void) pjsip_name_addr_init(pjsip_name_addr *name_addr);
/**
* Perform full assignment to the name address.
* @param pool The pool.
* @param addr The destination name address.
* @param rhs The source name address.
*/
PJ_DECL(void) pjsip_name_addr_assign(pj_pool_t *pool,
pjsip_name_addr *addr,
const pjsip_name_addr *rhs);
/**
* @}
*/
PJ_END_DECL
#endif /* __PJSIP_URL_H__ */
|