|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <assert.h>
|
#include "proto_comm.h"
|
#include "proto_dbg.h"
|
|
void soap_perror(struct soap *soap, const char *str)
|
{
|
if (NULL == str) {
|
SOAP_DBGERR("[soap] error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
|
} else {
|
SOAP_DBGERR("[soap] %s error: %d, %s, %s\n", str, soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
|
}
|
return;
|
}
|
|
void* proto_soap_malloc(struct soap *soap, unsigned int n)
|
{
|
void *p = NULL;
|
|
if (n > 0) {
|
p = soap_malloc(soap, n);
|
SOAP_ASSERT(NULL != p);
|
memset(p, 0x00 ,n);
|
}
|
return p;
|
}
|
|
struct soap *proto_soap_new(int timeout)
|
{
|
struct soap *soap = NULL; // soap»·¾³±äÁ¿
|
|
SOAP_ASSERT(NULL != (soap = soap_new()));
|
|
soap_set_namespaces(soap, namespaces); // ÉèÖÃsoapµÄnamespaces
|
soap->recv_timeout = timeout;
|
soap->send_timeout = timeout;
|
soap->connect_timeout = timeout;
|
|
#if defined(__linux__) || defined(__linux)
|
soap->socket_flags = MSG_NOSIGNAL;
|
#endif
|
|
soap_set_mode(soap, SOAP_C_UTFSTRING);
|
|
return soap;
|
}
|
|
void proto_soap_delete(struct soap *soap)
|
{
|
soap_destroy(soap); // remove deserialized class instances (C++ only)
|
soap_end(soap); // Clean up deserialized data (except class instances) and temporary data
|
soap_done(soap); // Reset, close communications, and remove callbacks
|
soap_free(soap); // Reset and deallocate the context created with soap_new or soap_copy
|
}
|
|
int proto_SetAuthInfo(struct soap *soap, const char *username, const char *password)
|
{
|
int result = 0;
|
|
SOAP_ASSERT(NULL != username);
|
SOAP_ASSERT(NULL != password);
|
|
result = soap_wsse_add_UsernameTokenDigest(soap, NULL, username, password);
|
SOAP_CHECK_ERROR(result, soap, "add_UsernameTokenDigest");
|
|
EXIT:
|
|
return result;
|
}
|
|
float para_check(float data)
|
{
|
float ret;
|
|
if (data > PARA_MAX) {
|
ret = PARA_MAX;
|
} else if (data < PARA_MIN) {
|
ret = PARA_MIN;
|
} else {
|
ret = data;
|
}
|
|
return ret;
|
}
|
|
/************************************************************************
|
*³õʼ»¯soapÃèÊöÏûϢͷ
|
|
*ÔÚ±¾º¯ÊýÄÚ²¿Í¨¹ýproto_soap_malloc·ÖÅäµÄÄڴ棬½«ÔÚproto_soap_deleteÖб»ÊÍ·Å
|
************************************************************************/
|
void proto_init_header(struct soap *soap)
|
{
|
struct SOAP_ENV__Header *header = NULL;
|
|
SOAP_ASSERT(NULL != soap);
|
|
header = (struct SOAP_ENV__Header *)proto_soap_malloc(soap, sizeof(struct SOAP_ENV__Header));
|
soap_default_SOAP_ENV__Header(soap, header);
|
header->wsa__MessageID = (char*)soap_wsa_rand_uuid(soap);
|
header->wsa__MessageID = (char *)soap_strdup(soap, soap_rand_uuid(soap, "urn:uuid:"));
|
header->wsa__To = (char*)proto_soap_malloc(soap, strlen(SOAP_TO) + 1);
|
header->wsa__Action = (char*)proto_soap_malloc(soap, strlen(SOAP_ACTION) + 1);
|
strcpy(header->wsa__To, SOAP_TO);
|
strcpy(header->wsa__Action, SOAP_ACTION);
|
soap->header = header;
|
|
return;
|
}
|
|
/************************************************************************
|
*³õʼ»¯Ì½²âÉ豸µÄ·¶Î§ºÍÀàÐÍ
|
|
*ÔÚ±¾º¯ÊýÄÚ²¿Í¨¹ýproto_soap_malloc·ÖÅäµÄÄڴ棬½«ÔÚproto_soap_deleteÖб»ÊÍ·Å
|
************************************************************************/
|
void proto_init_ProbeType(struct soap *soap, struct wsdd__ProbeType *probe)
|
{
|
struct wsdd__ScopesType *scope = NULL; // ÓÃÓÚÃèÊö²éÕÒÄÄÀàµÄWeb·þÎñ
|
|
SOAP_ASSERT(NULL != soap);
|
SOAP_ASSERT(NULL != probe);
|
|
scope = (struct wsdd__ScopesType *)proto_soap_malloc(soap, sizeof(struct wsdd__ScopesType));
|
soap_default_wsdd__ScopesType(soap, scope); // ÉèÖÃѰÕÒÉ豸µÄ·¶Î§
|
scope->__item = (char*)proto_soap_malloc(soap, strlen(SOAP_ITEM) + 1);
|
strcpy(scope->__item, SOAP_ITEM);
|
|
memset(probe, 0x00, sizeof(struct wsdd__ProbeType));
|
soap_default_wsdd__ProbeType(soap, probe);
|
probe->Scopes = scope;
|
probe->Types = (char*)proto_soap_malloc(soap, strlen(SOAP_TYPES) + 1); // ÉèÖÃѰÕÒÉ豸µÄÀàÐÍ
|
strcpy(probe->Types, SOAP_TYPES);
|
|
return;
|
}
|
|
/************************************************************************
|
*rtsp://100.100.100.140:554/av0_0
|
*rtsp://username:password@100.100.100.140:554/av0_0
|
************************************************************************/
|
int make_uri_withauth(char *src_uri, char *username, char *password, char *dest_uri, unsigned int size_dest_uri)
|
{
|
int result = 0;
|
unsigned int needBufSize = 0;
|
|
SOAP_ASSERT(NULL != src_uri);
|
SOAP_ASSERT(NULL != username);
|
SOAP_ASSERT(NULL != password);
|
SOAP_ASSERT(NULL != dest_uri);
|
memset(dest_uri, 0x00, size_dest_uri);
|
|
needBufSize = strlen(src_uri) + strlen(username) + strlen(password) + 3; // ¼ì²é»º´æÊÇ·ñ×ã¹»£¬°üÀ¨¡®:¡¯ºÍ¡®@¡¯ºÍ×Ö·û´®½áÊø·û
|
if (size_dest_uri < needBufSize) {
|
SOAP_DBGERR("dest uri buf size is not enough.\n");
|
result = -1;
|
goto EXIT;
|
}
|
|
if (0 == strlen(username) && 0 == strlen(password)) { // Éú³ÉеÄuriµØÖ·
|
strcpy(dest_uri, src_uri);
|
} else {
|
char *p = strstr(src_uri, "//");
|
if (NULL == p) {
|
SOAP_DBGERR("can't found '//', src uri is: %s.\n", src_uri);
|
result = -1;
|
goto EXIT;
|
}
|
p += 2;
|
|
memcpy(dest_uri, src_uri, p - src_uri);
|
sprintf(dest_uri + strlen(dest_uri), "%s:%s@", username, password);
|
strcat(dest_uri, p);
|
}
|
|
EXIT:
|
|
return result;
|
}
|
|
|