forked from KoynovStas/wsdd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsdd_utils.c
102 lines (74 loc) · 2.85 KB
/
wsdd_utils.c
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
#include <stdio.h>
#include "wsdd_param.h"
#include "net_utils.h"
/*
* This function converts the template parameter (option) --xaddr
* to final URL for the ONVIF service. If this option is specified on the command line
* does not contain a template parameter %s function snprintf() just make a copy in a static array.
* If option contains template parameter %s, it will be replaced by
* IP addres of Network interface specified by --if_name option.
*
* Example:
* ./wsdd --xaddr "http://192.168.1.1:2000/onvif/device_service" - will not be changed
*
* ./wsdd --xaddr "http://%s:2000/onvif/device_service" --if_name eth1
* template %s will be replaced to the IP address of the network interface eth1
*/
const char* get_xaddr(struct wsdd_param_t *wsdd_param)
{
static char xaddr[128];
char ip[INET_ADDRSTRLEN];
if( get_ip_of_if(wsdd_param->if_name, AF_INET, ip) == 0 )
{
snprintf(xaddr, sizeof(xaddr), wsdd_param->xaddr, ip);
}
else
{
snprintf(xaddr, sizeof(xaddr), wsdd_param->xaddr, "127.0.0.1");
}
return xaddr;
}
const char* get_rand_endpoint(struct soap *soap_srv)
{
static char tmp[48]; //UUID "urn:uuid:xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
const char *random_UUID = soap_wsa_rand_uuid(soap_srv);
if(!random_UUID)
return NULL;
snprintf(tmp, sizeof(tmp), "%s", random_UUID);
return tmp;
}
void send_hello(struct soap *soap_srv, struct wsdd_param_t *wsdd_param)
{
int res = soap_wsdd_Hello(soap_srv,
SOAP_WSDD_ADHOC, // mode
SOAP_WSDD_TS_ADDRESS, // address of TS
soap_wsa_rand_uuid(soap_srv),// message ID
NULL,
wsdd_param->endpoint,
wsdd_param->type,
wsdd_param->scope,
NULL,
get_xaddr(wsdd_param),
wsdd_param->metadata_ver);
if(res == SOAP_OK)
soap_wsdd_listen(soap_srv, 1);
else
soap_print_fault(soap_srv, stderr);
}
void send_bye(struct soap *soap_srv, struct wsdd_param_t *wsdd_param)
{
int res = soap_wsdd_Bye(soap_srv,
SOAP_WSDD_ADHOC, // mode
SOAP_WSDD_TS_ADDRESS, // address of TS
soap_wsa_rand_uuid(soap_srv),// message ID
wsdd_param->endpoint,
wsdd_param->type,
wsdd_param->scope,
NULL,
get_xaddr(wsdd_param),
wsdd_param->metadata_ver);
if(res == SOAP_OK)
soap_wsdd_listen(soap_srv, 1);
else
soap_print_fault(soap_srv, stderr);
}