forked from jiangbing9293/onvif_discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deviceserver.c
301 lines (120 loc) · 6.02 KB
/
deviceserver.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
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
/******************************************************************************
* Copyright 2010-2013
* FileName: deviceserver.c
* Desc: 监视网络摄像头设备发现服务器文件
*
*
* Author: Tom-hongtao.gao
* Date: 2013/05/30
* Notes: 数据结构使用链表
*
* -----------------------------------------------------------------
* Histroy: v1.0 2013/05/30, Tom-hongtao.gao create this file
*
******************************************************************************/
/*-------------------------------- Includes ----------------------------------*/
#include "uuid32.h"
#include "soapStub.h"
#include "RemoteDiscoveryBinding.nsmap"
#include "wsddapi.h"
/*-------------------- Global Definitions and Declarations -------------------*/
/*----------------------- Constant / Macro Definitions -----------------------*/
/*------------------------ Type Declarations ---------------------------------*/
/*------------------------ Variable Declarations -----------------------------*/
/*------------------------ Function Prototype --------------------------------*/
/*------------------------ Function Implement --------------------------------*/
int main(int argc, char **argv)
{
int m, s;
struct ip_mreq mcast;
//初始化SOAP执行环境
struct soap probe_soap;
soap_init2(&probe_soap, SOAP_IO_UDP|SOAP_IO_FLUSH, SOAP_IO_UDP|SOAP_IO_FLUSH);
soap_set_namespaces(&probe_soap, namespaces);
/*下面的函数是将创建的SOAP与指定的监听端口进行绑定,即通过SOAP创建监听
套接字,并将该套接字绑定到指定端口,从而在该端口上监听Web服务请求,
返回创建的套接字标识 */
if(!soap_valid_socket(soap_bind(&probe_soap, NULL, 3702, 10)))
{
soap_print_fault(&probe_soap, stderr);
exit(1);
}
mcast.imr_multiaddr.s_addr = inet_addr("239.255.255.250");
mcast.imr_interface.s_addr = htonl(INADDR_ANY);
if(setsockopt(probe_soap.master, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mcast, sizeof(mcast)) < 0)
{
printf("setsockopt error!\n");
return 0;
}
//成功绑定之后,便开始监听
for (;;)
{
//监听直到有连接请求
s = soap_accept(&probe_soap);
if (s < 0) {
soap_print_fault(&probe_soap, stderr);
exit(-1);
}
fprintf(stderr, "Socket connection successful: slave socket = %d\n", s);
/* 连接成功后,便处理并响应请求,下面的函数就是用来处理并响应请求的,
它封装了所有的处理与响应过程,在该函数中调用了本地所实现的相关Web
服务方法,它所需要的所有请求信息都在SOAP结构体中。*/
soap_serve(&probe_soap);
soap_destroy(&probe_soap); //服务完成后,便撤销SOAP环境
soap_end(&probe_soap); //清除所有资源,关闭套接字
}
soap_done(&probe_soap);
return 0;
}
SOAP_FMAC5 int SOAP_FMAC6 SOAP_ENV__Fault(struct soap* soap, char *faultcode, char *faultstring, char *faultactor,
struct SOAP_ENV__Detail *detail, struct SOAP_ENV__Code *SOAP_ENV__Code,
struct SOAP_ENV__Reason *SOAP_ENV__Reason,
char *SOAP_ENV__Node, char *SOAP_ENV__Role,
struct SOAP_ENV__Detail *SOAP_ENV__Detail )
{
printf("%s,%d\n",__FUNCTION__, __LINE__);
return 0;
}
void wsdd_event_Hello(struct soap *soap, unsigned int InstanceId, const char *SequenceId, unsigned int MessageNumber, const char *MessageID, const char *RelatesTo, const char *EndpointReference, const char *Types, const char *Scopes, const char *MatchBy, const char *XAddrs, unsigned int MetadataVersion)
{
printf("%s,%d\n",__FUNCTION__, __LINE__);
return 0;
}
void wsdd_event_Bye(struct soap *soap, unsigned int InstanceId, const char *SequenceId, unsigned int MessageNumber, const char *MessageID, const char *RelatesTo, const char *EndpointReference, const char *Types, const char *Scopes, const char *MatchBy, const char *XAddrs, unsigned int *MetadataVersion)
{
printf("%s,%d\n",__FUNCTION__, __LINE__);
return 0;
}
soap_wsdd_mode wsdd_event_Probe(struct soap *soap, const char *MessageID, const char *ReplyTo, const char *Types, const char *Scopes, const char *MatchBy, struct wsdd__ProbeMatchesType *matches)
{
printf("%s,%d\n",__FUNCTION__, __LINE__);
printf("MessageID:%s\n", MessageID);
printf("ReplyTo:%s\n",ReplyTo);
printf("Types:%s\n",Types);
printf("Scopes:%s\n",Scopes);
printf("MatchBy:%s\n",MatchBy);
//测试代码
soap_wsdd_init_ProbeMatches(soap,matches);
soap_wsdd_add_ProbeMatch(soap,matches,
"urn:uuid:464A4854-4656-5242-4530-313035394100",
"ns1:NetworkVideoTransmitter",
"onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/hardware/IPC-model onvif://www.onvif.org/name/IPC-model",
NULL,
"http://192.168.0.243/onvif/device_service",10);
return 0;
}
void wsdd_event_ProbeMatches(struct soap *soap, unsigned int InstanceId, const char *SequenceId, unsigned int MessageNumber, const char *MessageID, const char *RelatesTo, struct wsdd__ProbeMatchesType *matches)
{
printf("%s,%d\n",__FUNCTION__, __LINE__);
return 0;
}
soap_wsdd_mode wsdd_event_Resolve(struct soap *soap, const char *MessageID, const char *ReplyTo, const char *EndpointReference, struct wsdd__ResolveMatchType *match)
{
printf("%s,%d\n",__FUNCTION__, __LINE__);
return 0;
}
void wsdd_event_ResolveMatches(struct soap *soap, unsigned int InstanceId, const char *SequenceId, unsigned int MessageNumber, const char *MessageID, const char *RelatesTo, struct wsdd__ResolveMatchType *match)
{
printf("%s,%d\n",__FUNCTION__, __LINE__);
return 0;
}