-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosdp.h
More file actions
352 lines (269 loc) · 7.16 KB
/
osdp.h
File metadata and controls
352 lines (269 loc) · 7.16 KB
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
* Copyright (c) 2011-2012 Anton Yabchinskiy <arn@users.berlios.de>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#ifndef __OSDP_H_INCLUDED__
#define __OSDP_H_INCLUDED__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#if defined(_MSC_VER)
typedef unsigned __int64 osdp_uint64_t;
#elif defined(__GNUC__)
# if defined(__LP64__)
typedef unsigned long osdp_uint64_t;
# else /* defined(__LP64__) */
typedef unsigned long long osdp_uint64_t;
# endif /* defined(__LP64__) */
#endif /* defined(_MSC_VER) */
struct osdp_attribute;
struct osdp_bandwidth;
struct osdp_connection;
struct osdp_email;
struct osdp_key;
struct osdp_media;
struct osdp_media_descr;
struct osdp_origin;
struct osdp_phone;
struct osdp_repeat_time;
struct osdp_session_descr;
struct osdp_time;
struct osdp_time_zone;
/**
* Parse Session Description Protocol message from a text buffer.
*
* @param session_descr Pointer to initialized session description
* object. It must be initialized with OSDP_SESSION_DESCR_INIT macro
* or by call to osdp_reset_session_descr if object is reused.
* @param str TODO
* @param str_sz TODO
* @return Returns 0 on success. In case of system error, -errno value
* will be returned (e.g. -ENOMEM). If syntax error is detected,
* positive offset (starting from 1) into the input string is
* returned.
*/
int
osdp_parse_session_descr(struct osdp_session_descr*, const char*, size_t);
void
osdp_reset_attribute(struct osdp_attribute*);
void
osdp_reset_bandwidth(struct osdp_bandwidth*);
void
osdp_reset_connection(struct osdp_connection*);
void
osdp_reset_email(struct osdp_email*);
void
osdp_reset_key(struct osdp_key*);
void
osdp_reset_media(struct osdp_media*);
void
osdp_reset_media_descr(struct osdp_media_descr*);
void
osdp_reset_origin(struct osdp_origin*);
void
osdp_reset_phone(struct osdp_phone*);
void
osdp_reset_repeat_time(struct osdp_repeat_time*);
/**
* Reset session description object.
*
* Frees all memory allocated during osdp_parse_session_descr and
* reinitializes session description object.
*
* @param session_descr Pointer to session description object.
*/
void
osdp_reset_session_descr(struct osdp_session_descr*);
void
osdp_reset_time(struct osdp_time*);
void
osdp_reset_time_zone(struct osdp_time_zone*);
extern void (*osdp_free)(void*);
extern void* (*osdp_calloc)(size_t, size_t);
extern void* (*osdp_realloc)(void*, size_t);
struct osdp_attribute
{
char* name;
char* value;
};
#define OSDP_ATTRIBUTE_INIT \
{ NULL, NULL }
struct osdp_bandwidth
{
char* type;
int value;
};
#define OSDP_BANDWIDTH_INIT \
{ NULL, -1 }
struct osdp_connection
{
char* network_type;
char* address_type;
char* address;
int ttl;
int n_addresses;
};
#define OSDP_CONNECTION_INIT \
{ NULL, NULL, NULL, -1, -1 }
struct osdp_email
{
char* address;
char* name;
};
#define OSDP_EMAIL_INIT \
{ NULL, NULL }
struct osdp_key
{
char* method;
char* value;
};
#define OSDP_KEY_INIT \
{ NULL, NULL }
struct osdp_media
{
char* type;
int port;
int n_ports;
char* protocol;
char** formats;
size_t n_formats;
};
#define OSDP_MEDIA_INIT \
{ NULL, -1, -1, NULL, NULL, 0 }
struct osdp_media_descr
{
struct osdp_media* media;
char* information;
struct osdp_connection* connections;
size_t n_connections;
struct osdp_bandwidth* bandwidths;
size_t n_bandwidths;
struct osdp_key* key;
struct osdp_attribute* attributes;
size_t n_attributes;
};
#define OSDP_MEDIA_DESCR_INIT \
{ NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, 0 }
struct osdp_origin
{
char* username;
osdp_uint64_t session_id;
osdp_uint64_t session_version;
char* network_type;
char* address_type;
char* address;
};
#define OSDP_ORIGIN_INIT \
{ NULL, 0, 0, NULL, NULL, NULL }
struct osdp_phone
{
char* number;
char* name;
};
#define OSDP_PHONE_INIT \
{ NULL, NULL }
struct osdp_repeat_time
{
osdp_uint64_t interval;
osdp_uint64_t duration;
int* offsets;
size_t n_offsets;
};
#define OSDP_REPEAT_TIME_INIT \
{ 0, 0, NULL, 0 }
struct osdp_session_descr
{
#ifdef __cplusplus
osdp_session_descr() :
protocol_version(-1),
origin(0),
name(0),
information(0),
uri(0),
emails(0),
n_emails(0),
phones(0),
n_phones(0),
connection(0),
bandwidths(0),
n_bandwidths(0),
times(0),
n_times(0),
time_zones(0),
n_time_zones(0),
key(0),
attributes(0),
n_attributes(0),
media_descrs(0),
n_media_descrs(0)
{
}
~osdp_session_descr()
{
osdp_reset_session_descr(this);
}
#endif /* __cplusplus */
int protocol_version;
struct osdp_origin* origin;
char* name;
char* information;
char* uri;
struct osdp_email* emails;
size_t n_emails;
struct osdp_phone* phones;
size_t n_phones;
struct osdp_connection* connection;
struct osdp_bandwidth* bandwidths;
size_t n_bandwidths;
struct osdp_time* times;
size_t n_times;
struct osdp_time_zone* time_zones;
size_t n_time_zones;
struct osdp_key* key;
struct osdp_attribute* attributes;
size_t n_attributes;
struct osdp_media_descr* media_descrs;
size_t n_media_descrs;
};
#define OSDP_SESSION_DESCR_INIT \
{ -1, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL, 0, \
NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0 }
struct osdp_time
{
osdp_uint64_t start;
osdp_uint64_t stop;
struct osdp_repeat_time* repeats;
size_t n_repeats;
};
#define OSDP_TIME_INIT \
{ 0, 0, NULL, 0 }
struct osdp_time_zone
{
osdp_uint64_t adjustment_time;
int offset;
};
#define OSDP_TIME_ZONE_INIT \
{ 0, 0 }
#ifdef __cplusplus
} // extern "C"
#endif /* __cplusplus */
#endif /* __OSDP_H_INCLUDED__ */