Code convergence for client_table (ClientSubscription).
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/branches/branch-1.6.x@539 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
@@ -1739,7 +1739,8 @@ int UpnpSubscribe(
|
||||
{
|
||||
int retVal;
|
||||
struct Handle_Info *SInfo = NULL;
|
||||
char *EvtUrl = (char *)EvtUrl_const;
|
||||
UpnpString *EvtUrl = UpnpString_new();
|
||||
UpnpString *SubsIdTmp = UpnpString_new();
|
||||
|
||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpSubscribe\n");
|
||||
|
||||
@@ -1756,11 +1757,17 @@ int UpnpSubscribe(
|
||||
retVal = UPNP_E_INVALID_PARAM;
|
||||
goto exit_function;
|
||||
}
|
||||
UpnpString_set_String(EvtUrl, EvtUrl_const);
|
||||
|
||||
if (SubsIdTmp == NULL) {
|
||||
retVal = UPNP_E_OUTOF_MEMORY;
|
||||
goto exit_function;
|
||||
}
|
||||
if (SubsId == NULL) {
|
||||
retVal = UPNP_E_INVALID_PARAM;
|
||||
goto exit_function;
|
||||
}
|
||||
UpnpString_set_String(SubsIdTmp, SubsId);
|
||||
|
||||
if (TimeOut == NULL) {
|
||||
retVal = UPNP_E_INVALID_PARAM;
|
||||
@@ -1775,12 +1782,16 @@ int UpnpSubscribe(
|
||||
}
|
||||
HandleUnlock();
|
||||
|
||||
retVal = genaSubscribe(Hnd, EvtUrl, TimeOut, SubsId);
|
||||
retVal = genaSubscribe(Hnd, EvtUrl, TimeOut, SubsIdTmp);
|
||||
strcpy(SubsId, UpnpString_get_String(SubsIdTmp));
|
||||
|
||||
exit_function:
|
||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Exiting UpnpSubscribe, retVal=%d\n", retVal);
|
||||
|
||||
UpnpString_delete(SubsIdTmp);
|
||||
UpnpString_delete(EvtUrl);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
@@ -1791,6 +1802,7 @@ int UpnpUnSubscribe(UpnpClient_Handle Hnd, const Upnp_SID SubsId)
|
||||
{
|
||||
struct Handle_Info *SInfo = NULL;
|
||||
int retVal;
|
||||
UpnpString *SubsIdTmp = UpnpString_new();
|
||||
|
||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpUnSubscribe\n");
|
||||
|
||||
@@ -1799,10 +1811,16 @@ int UpnpUnSubscribe(UpnpClient_Handle Hnd, const Upnp_SID SubsId)
|
||||
goto exit_function;
|
||||
}
|
||||
|
||||
if (SubsIdTmp == NULL) {
|
||||
retVal = UPNP_E_OUTOF_MEMORY;
|
||||
goto exit_function;
|
||||
}
|
||||
if (SubsId == NULL) {
|
||||
HandleUnlock();
|
||||
return UPNP_E_INVALID_PARAM;
|
||||
}
|
||||
UpnpString_set_String(SubsIdTmp, SubsId);
|
||||
|
||||
HandleReadLock();
|
||||
if (GetHandleInfo(Hnd, &SInfo) != HND_CLIENT) {
|
||||
HandleUnlock();
|
||||
@@ -1811,12 +1829,14 @@ int UpnpUnSubscribe(UpnpClient_Handle Hnd, const Upnp_SID SubsId)
|
||||
}
|
||||
HandleUnlock();
|
||||
|
||||
retVal = genaUnSubscribe(Hnd, SubsId);
|
||||
retVal = genaUnSubscribe(Hnd, SubsIdTmp);
|
||||
|
||||
exit_function:
|
||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Exiting UpnpUnSubscribe, retVal=%d\n", retVal);
|
||||
|
||||
UpnpString_delete(SubsIdTmp);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
@@ -1890,6 +1910,7 @@ int UpnpRenewSubscription(
|
||||
{
|
||||
struct Handle_Info *SInfo = NULL;
|
||||
int retVal;
|
||||
UpnpString *SubsIdTmp = UpnpString_new();
|
||||
|
||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpRenewSubscription\n");
|
||||
|
||||
@@ -1897,10 +1918,15 @@ int UpnpRenewSubscription(
|
||||
return UPNP_E_FINISH;
|
||||
}
|
||||
|
||||
if (SubsIdTmp == NULL) {
|
||||
retVal = UPNP_E_OUTOF_MEMORY;
|
||||
goto exit_function;
|
||||
}
|
||||
if (SubsId == NULL) {
|
||||
retVal = UPNP_E_INVALID_PARAM;
|
||||
goto exit_function;
|
||||
}
|
||||
UpnpString_set_String(SubsIdTmp, SubsId);
|
||||
|
||||
if (TimeOut == NULL) {
|
||||
retVal = UPNP_E_INVALID_PARAM;
|
||||
@@ -1915,12 +1941,14 @@ int UpnpRenewSubscription(
|
||||
}
|
||||
HandleUnlock();
|
||||
|
||||
retVal = genaRenewSubscription(Hnd, SubsId, TimeOut);
|
||||
retVal = genaRenewSubscription(Hnd, SubsIdTmp, TimeOut);
|
||||
|
||||
exit_function:
|
||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Exiting UpnpRenewSubscription, retVal=%d\n", retVal);
|
||||
|
||||
UpnpString_delete(SubsIdTmp);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
@@ -3171,6 +3199,8 @@ int UpnpGetIfInfo(const char *IfName)
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
void UpnpThreadDistribution(struct UpnpNonblockParam *Param)
|
||||
{
|
||||
/*int errCode = 0;*/
|
||||
|
||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||
"Inside UpnpThreadDistribution \n");
|
||||
|
||||
@@ -3178,39 +3208,50 @@ void UpnpThreadDistribution(struct UpnpNonblockParam *Param)
|
||||
#if EXCLUDE_GENA == 0
|
||||
case SUBSCRIBE: {
|
||||
struct Upnp_Event_Subscribe Evt;
|
||||
|
||||
UpnpString *Sid = UpnpString_new();
|
||||
UpnpString *Url = UpnpString_new();
|
||||
UpnpString_set_String(Url, Param->Url);
|
||||
UpnpString_set_String(Sid, (char *)Evt.Sid);
|
||||
Evt.ErrCode = genaSubscribe(
|
||||
Param->Handle,
|
||||
Param->Url,
|
||||
Url,
|
||||
(int *)&Param->TimeOut,
|
||||
(char *)Evt.Sid);
|
||||
Sid);
|
||||
strcpy(Evt.PublisherUrl, Param->Url);
|
||||
Evt.TimeOut = Param->TimeOut;
|
||||
Param->Fun(UPNP_EVENT_SUBSCRIBE_COMPLETE, &Evt, Param->Cookie);
|
||||
UpnpString_delete(Sid);
|
||||
UpnpString_delete(Url);
|
||||
free(Param);
|
||||
break;
|
||||
}
|
||||
case UNSUBSCRIBE: {
|
||||
struct Upnp_Event_Subscribe Evt;
|
||||
UpnpString *Sid = UpnpString_new();
|
||||
UpnpString_set_String(Sid, Param->SubsId);
|
||||
Evt.ErrCode = genaUnSubscribe(
|
||||
Param->Handle,
|
||||
Param->SubsId);
|
||||
strcpy((char *)Evt.Sid, Param->SubsId);
|
||||
Sid);
|
||||
strcpy((char *)Evt.Sid, UpnpString_get_String(Sid));
|
||||
strcpy(Evt.PublisherUrl, "");
|
||||
Evt.TimeOut = 0;
|
||||
Param->Fun(UPNP_EVENT_UNSUBSCRIBE_COMPLETE, &Evt, Param->Cookie);
|
||||
UpnpString_delete(Sid);
|
||||
free(Param);
|
||||
break;
|
||||
}
|
||||
case RENEW: {
|
||||
struct Upnp_Event_Subscribe Evt;
|
||||
UpnpString *Sid = UpnpString_new();
|
||||
UpnpString_set_String(Sid, Param->SubsId);
|
||||
Evt.ErrCode = genaRenewSubscription(
|
||||
Param->Handle,
|
||||
Param->SubsId,
|
||||
Sid,
|
||||
&Param->TimeOut);
|
||||
Evt.TimeOut = Param->TimeOut;
|
||||
strcpy((char *)Evt.Sid, Param->SubsId);
|
||||
strcpy((char *)Evt.Sid, UpnpString_get_String(Sid));
|
||||
Param->Fun(UPNP_EVENT_RENEWAL_COMPLETE, &Evt, Param->Cookie);
|
||||
UpnpString_delete(Sid);
|
||||
free(Param);
|
||||
break;
|
||||
}
|
||||
|
@@ -72,6 +72,7 @@ static void GenaAutoRenewSubscription(
|
||||
int eventType = 0;
|
||||
int timeout = 0;
|
||||
int errCode = 0;
|
||||
UpnpString *tmpSID = UpnpString_new();
|
||||
|
||||
if (AUTO_RENEW_TIME == 0) {
|
||||
UpnpPrintf( UPNP_INFO, GENA, __FILE__, __LINE__, "GENA SUB EXPIRED");
|
||||
@@ -81,9 +82,10 @@ static void GenaAutoRenewSubscription(
|
||||
} else {
|
||||
UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "GENA AUTO RENEW");
|
||||
timeout = sub_struct->TimeOut;
|
||||
UpnpString_set_String(tmpSID, sub_struct->Sid);
|
||||
errCode = genaRenewSubscription(
|
||||
event->handle,
|
||||
sub_struct->Sid,
|
||||
tmpSID,
|
||||
&timeout);
|
||||
sub_struct->ErrCode = errCode;
|
||||
sub_struct->TimeOut = timeout;
|
||||
@@ -100,8 +102,7 @@ static void GenaAutoRenewSubscription(
|
||||
if( GetHandleInfo( event->handle, &handle_info ) != HND_CLIENT ) {
|
||||
HandleUnlock();
|
||||
free_upnp_timeout(event);
|
||||
|
||||
return;
|
||||
goto end_function;
|
||||
}
|
||||
UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "HANDLE IS VALID");
|
||||
|
||||
@@ -113,6 +114,10 @@ static void GenaAutoRenewSubscription(
|
||||
}
|
||||
|
||||
free_upnp_timeout(event);
|
||||
|
||||
end_function:
|
||||
UpnpString_delete(tmpSID);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,27 +139,33 @@ static int ScheduleGenaAutoRenew(
|
||||
upnp_timeout *RenewEvent = NULL;
|
||||
int return_code = GENA_SUCCESS;
|
||||
ThreadPoolJob job;
|
||||
const UpnpString *tmpSID = UpnpClientSubscription_get_SID(sub);
|
||||
const UpnpString *tmpEventURL = UpnpClientSubscription_get_EventURL(sub);
|
||||
|
||||
if( TimeOut == UPNP_INFINITE ) {
|
||||
return GENA_SUCCESS;
|
||||
if (TimeOut == UPNP_INFINITE) {
|
||||
return_code = GENA_SUCCESS;
|
||||
goto end_function;
|
||||
}
|
||||
|
||||
RenewEventStruct = (struct Upnp_Event_Subscribe *)malloc(sizeof (struct Upnp_Event_Subscribe));
|
||||
if( RenewEventStruct == NULL ) {
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
if (RenewEventStruct == NULL) {
|
||||
return_code = UPNP_E_OUTOF_MEMORY;
|
||||
goto end_function;
|
||||
}
|
||||
|
||||
RenewEvent = (upnp_timeout *) malloc(sizeof(upnp_timeout));
|
||||
if( RenewEvent == NULL ) {
|
||||
free( RenewEventStruct );
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
if (RenewEvent == NULL) {
|
||||
free(RenewEventStruct);
|
||||
return_code = UPNP_E_OUTOF_MEMORY;
|
||||
goto end_function;
|
||||
}
|
||||
|
||||
// schedule expire event
|
||||
strcpy( RenewEventStruct->Sid, sub->sid );
|
||||
RenewEventStruct->ErrCode = UPNP_E_SUCCESS;
|
||||
strncpy( RenewEventStruct->PublisherUrl, sub->EventURL, NAME_SIZE - 1 );
|
||||
RenewEventStruct->TimeOut = TimeOut;
|
||||
strcpy(RenewEventStruct->Sid, UpnpString_get_String(tmpSID));
|
||||
strncpy(RenewEventStruct->PublisherUrl,
|
||||
UpnpString_get_String(tmpEventURL), NAME_SIZE - 1);
|
||||
|
||||
// RenewEvent->EventType=UPNP_EVENT_SUBSCRIPTION_EXPIRE;
|
||||
RenewEvent->handle = client_handle;
|
||||
@@ -174,13 +185,15 @@ static int ScheduleGenaAutoRenew(
|
||||
if (return_code != UPNP_E_SUCCESS) {
|
||||
free(RenewEvent);
|
||||
free(RenewEventStruct);
|
||||
|
||||
return return_code;
|
||||
goto end_function;
|
||||
}
|
||||
|
||||
sub->RenewEventId = RenewEvent->eventId;
|
||||
UpnpClientSubscription_set_RenewEventId(sub, RenewEvent->eventId);
|
||||
|
||||
return GENA_SUCCESS;
|
||||
return_code = GENA_SUCCESS;
|
||||
|
||||
end_function:
|
||||
return return_code;
|
||||
}
|
||||
|
||||
|
||||
@@ -192,9 +205,9 @@ static int ScheduleGenaAutoRenew(
|
||||
*/
|
||||
static int gena_unsubscribe(
|
||||
/*! [in] Event URL of the service. */
|
||||
IN const char *url,
|
||||
IN const UpnpString *url,
|
||||
/*! [in] The subcription ID. */
|
||||
IN const char *sid,
|
||||
IN const UpnpString *sid,
|
||||
/*! [out] The UNSUBCRIBE response from the device. */
|
||||
OUT http_parser_t *response )
|
||||
{
|
||||
@@ -203,7 +216,10 @@ static int gena_unsubscribe(
|
||||
membuffer request;
|
||||
|
||||
// parse url
|
||||
return_code = http_FixStrUrl(url, strlen(url), &dest_url);
|
||||
return_code = http_FixStrUrl(
|
||||
UpnpString_get_String(url),
|
||||
UpnpString_get_Length(url),
|
||||
&dest_url);
|
||||
if (return_code != 0) {
|
||||
return return_code;
|
||||
}
|
||||
@@ -215,7 +231,7 @@ static int gena_unsubscribe(
|
||||
&request, 1, 1,
|
||||
"q" "ssc" "Uc",
|
||||
HTTPMETHOD_UNSUBSCRIBE, &dest_url,
|
||||
"SID: ", sid);
|
||||
"SID: ", UpnpString_get_String(sid));
|
||||
|
||||
// Not able to make the message so destroy the existing buffer
|
||||
if (return_code != 0) {
|
||||
@@ -249,14 +265,14 @@ static int gena_unsubscribe(
|
||||
*/
|
||||
static int gena_subscribe(
|
||||
/*! [in] URL of service to subscribe. */
|
||||
IN const char *url,
|
||||
IN const UpnpString *url,
|
||||
/*! [in,out] Subscription time desired (in secs). */
|
||||
INOUT int *timeout,
|
||||
/*! [in] for renewal, this contains a currently held subscription SID.
|
||||
* For first time subscription, this must be NULL. */
|
||||
IN const char *renewal_sid,
|
||||
IN const UpnpString *renewal_sid,
|
||||
/*! [out] SID returned by the subscription or renew msg. */
|
||||
OUT char **sid)
|
||||
OUT UpnpString *sid)
|
||||
{
|
||||
int return_code;
|
||||
int parse_ret = 0;
|
||||
@@ -268,7 +284,7 @@ static int gena_subscribe(
|
||||
uri_type dest_url;
|
||||
http_parser_t response;
|
||||
|
||||
*sid = NULL; // init
|
||||
UpnpString_clear(sid);
|
||||
|
||||
// request timeout to string
|
||||
if (timeout == NULL) {
|
||||
@@ -283,7 +299,10 @@ static int gena_subscribe(
|
||||
}
|
||||
|
||||
// parse url
|
||||
return_code = http_FixStrUrl( url, strlen( url ), &dest_url );
|
||||
return_code = http_FixStrUrl(
|
||||
UpnpString_get_String(url),
|
||||
UpnpString_get_Length(url),
|
||||
&dest_url);
|
||||
if (return_code != 0) {
|
||||
return return_code;
|
||||
}
|
||||
@@ -297,7 +316,7 @@ static int gena_subscribe(
|
||||
&request, 1, 1,
|
||||
"q" "ssc" "sscc",
|
||||
HTTPMETHOD_SUBSCRIBE, &dest_url,
|
||||
"SID: ", renewal_sid,
|
||||
"SID: ", UpnpString_get_String(renewal_sid),
|
||||
"TIMEOUT: Second-", timeout_str );
|
||||
} else {
|
||||
// subscribe
|
||||
@@ -365,8 +384,8 @@ static int gena_subscribe(
|
||||
}
|
||||
|
||||
// save SID
|
||||
*sid = str_alloc( sid_hdr.buf, sid_hdr.length );
|
||||
if( *sid == NULL ) {
|
||||
UpnpString_set_StringN(sid, sid_hdr.buf, sid_hdr.length);
|
||||
if (UpnpString_get_String(sid) == NULL) {
|
||||
httpmsg_destroy(&response.msg);
|
||||
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
@@ -379,7 +398,7 @@ static int gena_subscribe(
|
||||
|
||||
int genaUnregisterClient(UpnpClient_Handle client_handle)
|
||||
{
|
||||
ClientSubscription sub_copy;
|
||||
ClientSubscription *sub_copy = UpnpClientSubscription_new();
|
||||
int return_code = UPNP_E_SUCCESS;
|
||||
struct Handle_Info *handle_info = NULL;
|
||||
http_parser_t response;
|
||||
@@ -396,25 +415,28 @@ int genaUnregisterClient(UpnpClient_Handle client_handle)
|
||||
return_code = UPNP_E_SUCCESS;
|
||||
break;
|
||||
}
|
||||
return_code = copy_client_subscription( handle_info->ClientSubList, &sub_copy);
|
||||
RemoveClientSubClientSID(&handle_info->ClientSubList, sub_copy.sid);
|
||||
UpnpClientSubscription_assign(sub_copy, handle_info->ClientSubList);
|
||||
RemoveClientSubClientSID(
|
||||
&handle_info->ClientSubList,
|
||||
UpnpClientSubscription_get_SID(sub_copy));
|
||||
|
||||
HandleUnlock();
|
||||
|
||||
return_code = gena_unsubscribe(
|
||||
sub_copy.EventURL,
|
||||
sub_copy.ActualSID,
|
||||
UpnpClientSubscription_get_EventURL(sub_copy),
|
||||
UpnpClientSubscription_get_ActualSID(sub_copy),
|
||||
&response);
|
||||
if (return_code == 0) {
|
||||
httpmsg_destroy(&response.msg);
|
||||
}
|
||||
free_client_subscription(&sub_copy);
|
||||
free_client_subscription(sub_copy);
|
||||
}
|
||||
|
||||
freeClientSubList(handle_info->ClientSubList);
|
||||
HandleUnlock();
|
||||
|
||||
exit_function:
|
||||
UpnpClientSubscription_delete(sub_copy);
|
||||
return return_code;
|
||||
}
|
||||
|
||||
@@ -422,12 +444,12 @@ exit_function:
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
int genaUnSubscribe(
|
||||
UpnpClient_Handle client_handle,
|
||||
const Upnp_SID in_sid)
|
||||
const UpnpString *in_sid)
|
||||
{
|
||||
ClientSubscription *sub = NULL;
|
||||
int return_code = GENA_SUCCESS;
|
||||
struct Handle_Info *handle_info;
|
||||
ClientSubscription sub_copy;
|
||||
ClientSubscription *sub_copy = UpnpClientSubscription_new();
|
||||
http_parser_t response;
|
||||
|
||||
// validate handle and sid
|
||||
@@ -443,17 +465,17 @@ int genaUnSubscribe(
|
||||
return_code = GENA_E_BAD_SID;
|
||||
goto exit_function;
|
||||
}
|
||||
return_code = copy_client_subscription( sub, &sub_copy );
|
||||
UpnpClientSubscription_assign(sub_copy, sub);
|
||||
HandleUnlock();
|
||||
|
||||
return_code = gena_unsubscribe(
|
||||
sub_copy.EventURL,
|
||||
sub_copy.ActualSID,
|
||||
UpnpClientSubscription_get_EventURL(sub_copy),
|
||||
UpnpClientSubscription_get_ActualSID(sub_copy),
|
||||
&response);
|
||||
if (return_code == 0) {
|
||||
httpmsg_destroy(&response.msg);
|
||||
}
|
||||
free_client_subscription(&sub_copy);
|
||||
free_client_subscription(sub_copy);
|
||||
|
||||
HandleLock();
|
||||
if (GetHandleInfo(client_handle, &handle_info) != HND_CLIENT) {
|
||||
@@ -465,6 +487,7 @@ int genaUnSubscribe(
|
||||
HandleUnlock();
|
||||
|
||||
exit_function:
|
||||
UpnpClientSubscription_delete(sub_copy);
|
||||
return return_code;
|
||||
}
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
@@ -473,21 +496,22 @@ exit_function:
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
int genaSubscribe(
|
||||
UpnpClient_Handle client_handle,
|
||||
const char *PublisherURL,
|
||||
const UpnpString *PublisherURL,
|
||||
int *TimeOut,
|
||||
Upnp_SID out_sid)
|
||||
UpnpString *out_sid)
|
||||
{
|
||||
int return_code = GENA_SUCCESS;
|
||||
ClientSubscription *newSubscription = NULL;
|
||||
ClientSubscription *newSubscription = UpnpClientSubscription_new();
|
||||
uuid_upnp uid;
|
||||
Upnp_SID temp_sid;
|
||||
char *ActualSID = NULL;
|
||||
Upnp_SID temp_sid2;
|
||||
UpnpString *ActualSID = UpnpString_new();
|
||||
UpnpString *EventURL = UpnpString_new();
|
||||
struct Handle_Info *handle_info;
|
||||
char *EventURL = NULL;
|
||||
|
||||
UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "GENA SUBSCRIBE BEGIN");
|
||||
|
||||
memset( out_sid, 0, sizeof( Upnp_SID ) );
|
||||
UpnpString_clear(out_sid);
|
||||
|
||||
HandleReadLock();
|
||||
// validate handle
|
||||
@@ -500,7 +524,7 @@ int genaSubscribe(
|
||||
|
||||
// subscribe
|
||||
SubscribeLock();
|
||||
return_code = gena_subscribe(PublisherURL, TimeOut, NULL, &ActualSID);
|
||||
return_code = gena_subscribe(PublisherURL, TimeOut, NULL, ActualSID);
|
||||
HandleLock();
|
||||
if (return_code != UPNP_E_SUCCESS) {
|
||||
UpnpPrintf( UPNP_CRITICAL, GENA, __FILE__, __LINE__,
|
||||
@@ -517,27 +541,22 @@ int genaSubscribe(
|
||||
// generate client SID
|
||||
uuid_create(&uid );
|
||||
uuid_unpack(&uid, temp_sid);
|
||||
sprintf( out_sid, "uuid:%s", temp_sid );
|
||||
sprintf(temp_sid2, "uuid:%s", temp_sid);
|
||||
UpnpString_set_String(out_sid, temp_sid2);
|
||||
|
||||
// create event url
|
||||
EventURL = ( char * )malloc( strlen( PublisherURL ) + 1 );
|
||||
if( EventURL == NULL ) {
|
||||
return_code = UPNP_E_OUTOF_MEMORY;
|
||||
goto error_handler;
|
||||
}
|
||||
strcpy( EventURL, PublisherURL );
|
||||
UpnpString_assign(EventURL, PublisherURL);
|
||||
|
||||
// fill subscription
|
||||
newSubscription = (ClientSubscription *)malloc(sizeof (ClientSubscription));
|
||||
if (newSubscription == NULL) {
|
||||
return_code = UPNP_E_OUTOF_MEMORY;
|
||||
goto error_handler;
|
||||
}
|
||||
newSubscription->EventURL = EventURL;
|
||||
newSubscription->ActualSID = ActualSID;
|
||||
strcpy(newSubscription->sid, out_sid);
|
||||
newSubscription->RenewEventId = -1;
|
||||
newSubscription->next = handle_info->ClientSubList;
|
||||
UpnpClientSubscription_set_RenewEventId(newSubscription, -1);
|
||||
UpnpClientSubscription_set_SID(newSubscription, out_sid);
|
||||
UpnpClientSubscription_set_ActualSID(newSubscription, ActualSID);
|
||||
UpnpClientSubscription_set_EventURL(newSubscription, EventURL);
|
||||
UpnpClientSubscription_set_Next(newSubscription, handle_info->ClientSubList);
|
||||
handle_info->ClientSubList = newSubscription;
|
||||
|
||||
// schedule expiration event
|
||||
@@ -545,9 +564,9 @@ int genaSubscribe(
|
||||
|
||||
error_handler:
|
||||
if (return_code != UPNP_E_SUCCESS) {
|
||||
free(ActualSID);
|
||||
free(EventURL);
|
||||
free(newSubscription);
|
||||
UpnpString_delete(ActualSID);
|
||||
UpnpString_delete(EventURL);
|
||||
UpnpClientSubscription_delete(newSubscription);
|
||||
}
|
||||
HandleUnlock();
|
||||
SubscribeUnlock();
|
||||
@@ -559,14 +578,14 @@ error_handler:
|
||||
|
||||
int genaRenewSubscription(
|
||||
UpnpClient_Handle client_handle,
|
||||
const char *in_sid,
|
||||
const UpnpString *in_sid,
|
||||
int *TimeOut)
|
||||
{
|
||||
int return_code = GENA_SUCCESS;
|
||||
ClientSubscription *sub = NULL;
|
||||
ClientSubscription sub_copy;
|
||||
ClientSubscription *sub_copy = UpnpClientSubscription_new();
|
||||
struct Handle_Info *handle_info;
|
||||
char *ActualSID;
|
||||
UpnpString *ActualSID = UpnpString_new();
|
||||
ThreadPoolJob tempJob;
|
||||
|
||||
HandleLock();
|
||||
@@ -590,27 +609,23 @@ int genaRenewSubscription(
|
||||
// remove old events
|
||||
if (TimerThreadRemove(
|
||||
&gTimerThread,
|
||||
sub->RenewEventId,
|
||||
UpnpClientSubscription_get_RenewEventId(sub),
|
||||
&tempJob) == 0 ) {
|
||||
free_upnp_timeout((upnp_timeout *)tempJob.arg);
|
||||
}
|
||||
|
||||
UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "REMOVED AUTO RENEW EVENT");
|
||||
|
||||
sub->RenewEventId = -1;
|
||||
return_code = copy_client_subscription(sub, &sub_copy);
|
||||
UpnpClientSubscription_set_RenewEventId(sub, -1);
|
||||
UpnpClientSubscription_assign(sub_copy, sub);
|
||||
|
||||
HandleUnlock();
|
||||
|
||||
if( return_code != HTTP_SUCCESS ) {
|
||||
return return_code;
|
||||
}
|
||||
|
||||
return_code = gena_subscribe(
|
||||
sub_copy.EventURL,
|
||||
UpnpClientSubscription_get_EventURL(sub_copy),
|
||||
TimeOut,
|
||||
sub_copy.ActualSID,
|
||||
&ActualSID);
|
||||
UpnpClientSubscription_get_ActualSID(sub_copy),
|
||||
ActualSID);
|
||||
|
||||
HandleLock();
|
||||
|
||||
@@ -625,7 +640,7 @@ int genaRenewSubscription(
|
||||
if (return_code != UPNP_E_SUCCESS) {
|
||||
// network failure (remove client sub)
|
||||
RemoveClientSubClientSID(&handle_info->ClientSubList, in_sid);
|
||||
free_client_subscription(&sub_copy);
|
||||
free_client_subscription(sub_copy);
|
||||
HandleUnlock();
|
||||
goto exit_function;
|
||||
}
|
||||
@@ -633,29 +648,28 @@ int genaRenewSubscription(
|
||||
// get subscription
|
||||
sub = GetClientSubClientSID(handle_info->ClientSubList, in_sid);
|
||||
if (sub == NULL) {
|
||||
free_client_subscription(&sub_copy);
|
||||
free_client_subscription(sub_copy);
|
||||
HandleUnlock();
|
||||
return_code = GENA_E_BAD_SID;
|
||||
goto exit_function;
|
||||
}
|
||||
|
||||
// store actual sid
|
||||
free( sub->ActualSID );
|
||||
sub->ActualSID = ActualSID;
|
||||
UpnpClientSubscription_set_ActualSID(sub, ActualSID);
|
||||
|
||||
// start renew subscription timer
|
||||
return_code = ScheduleGenaAutoRenew(client_handle, *TimeOut, sub);
|
||||
if (return_code != GENA_SUCCESS) {
|
||||
RemoveClientSubClientSID(
|
||||
&handle_info->ClientSubList,
|
||||
sub->sid);
|
||||
UpnpClientSubscription_get_SID(sub));
|
||||
}
|
||||
free_client_subscription(&sub_copy);
|
||||
free_client_subscription(sub_copy);
|
||||
HandleUnlock();
|
||||
|
||||
exit_function:
|
||||
free(ActualSID);
|
||||
|
||||
UpnpString_delete(ActualSID);
|
||||
UpnpClientSubscription_delete(sub_copy);
|
||||
return return_code;
|
||||
}
|
||||
|
||||
@@ -673,6 +687,7 @@ void gena_process_notification_event(
|
||||
void *cookie;
|
||||
Upnp_FunPtr callback;
|
||||
UpnpClient_Handle client_handle;
|
||||
const UpnpString *tmpSID = NULL;
|
||||
|
||||
memptr sid_hdr;
|
||||
memptr nt_hdr,
|
||||
@@ -769,7 +784,8 @@ void gena_process_notification_event(
|
||||
error_respond(info, HTTP_OK, event);
|
||||
|
||||
// fill event struct
|
||||
strcpy(event_struct.Sid, subscription->sid);
|
||||
tmpSID = UpnpClientSubscription_get_SID(subscription);
|
||||
strcpy(event_struct.Sid, UpnpString_get_String(tmpSID));
|
||||
event_struct.EventKey = eventKey;
|
||||
event_struct.ChangedVariables = ChangedVars;
|
||||
|
||||
|
@@ -1,209 +1,329 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2000-2003 Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* - Neither name of Intel Corporation nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Purpose: This file defines the functions for clients. It defines
|
||||
* functions for adding and removing clients to and from the client table,
|
||||
* adding and accessing subscription and other attributes pertaining to the
|
||||
* client
|
||||
************************************************************************/
|
||||
* Purpose: This file defines the functions for clients. It defines
|
||||
* functions for adding and removing clients to and from the client table,
|
||||
* adding and accessing subscription and other attributes pertaining to the
|
||||
* client
|
||||
************************************************************************/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
#include "client_table.h"
|
||||
|
||||
/************************************************************************
|
||||
* Function : copy_client_subscription
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription * in ; - source client subscription
|
||||
* ClientSubscription * out ; - destination client subscription
|
||||
*
|
||||
* Description : Make a copy of the client subscription data
|
||||
*
|
||||
* Return : int ;
|
||||
* UPNP_E_OUTOF_MEMORY - On Failure to allocate memory
|
||||
* HTTP_SUCCESS - On Success
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
CLIENTONLY( int copy_client_subscription( ClientSubscription * in,
|
||||
ClientSubscription * out ) {
|
||||
int len = strlen( in->ActualSID ) + 1;
|
||||
int len1 = strlen( in->EventURL ) + 1;
|
||||
memcpy( out->sid, in->sid, SID_SIZE );
|
||||
out->sid[SID_SIZE] = 0;
|
||||
out->ActualSID = ( char * )malloc( len );
|
||||
if( out->ActualSID == NULL )
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
out->EventURL = ( char * )malloc( len1 );
|
||||
if( out->EventURL == NULL ) {
|
||||
free(out->ActualSID);
|
||||
return UPNP_E_OUTOF_MEMORY;
|
||||
}
|
||||
memcpy( out->ActualSID, in->ActualSID, len );
|
||||
memcpy( out->EventURL, in->EventURL, len1 );
|
||||
//copies do not get RenewEvent Ids or next
|
||||
out->RenewEventId = -1; out->next = NULL; return HTTP_SUCCESS;}
|
||||
|
||||
/************************************************************************
|
||||
* Function : free_client_subscription
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription * sub ; - Client subscription to be freed
|
||||
*
|
||||
* Description : Free memory allocated for client subscription data.
|
||||
* Remove timer thread associated with this subscription event.
|
||||
*
|
||||
* Return : void ;
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
void free_client_subscription( ClientSubscription * sub ) {
|
||||
upnp_timeout * event; ThreadPoolJob tempJob; if( sub ) {
|
||||
if( sub->ActualSID )
|
||||
free( sub->ActualSID ); if( sub->EventURL )
|
||||
free( sub->EventURL ); if( sub->RenewEventId != -1 ) //do not remove timer event of copy
|
||||
//invalid timer event id
|
||||
{
|
||||
if( TimerThreadRemove
|
||||
( &gTimerThread, sub->RenewEventId, &tempJob ) == 0 ) {
|
||||
event = ( upnp_timeout * ) tempJob.arg;
|
||||
free_upnp_timeout( event );}
|
||||
}
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
|
||||
sub->RenewEventId = -1;}
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : freeClientSubList
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription * list ; Client subscription
|
||||
*
|
||||
* Description : Free the client subscription table.
|
||||
*
|
||||
* Return : void ;
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
void freeClientSubList( ClientSubscription * list ) {
|
||||
ClientSubscription * next; while( list ) {
|
||||
free_client_subscription( list );
|
||||
next = list->next; free( list ); list = next;}
|
||||
}
|
||||
#include <stdlib.h> // for calloc(), free()
|
||||
|
||||
/************************************************************************
|
||||
* Function : RemoveClientSubClientSID
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription **head ; Head of the subscription list
|
||||
* const Upnp_SID sid ; Subscription ID to be mactched
|
||||
*
|
||||
* Description : Remove the client subscription matching the
|
||||
* subscritpion id represented by the const Upnp_SID sid parameter
|
||||
* from the table and update the table.
|
||||
*
|
||||
* Return : void ;
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
void RemoveClientSubClientSID( ClientSubscription ** head,
|
||||
const Upnp_SID sid ) {
|
||||
ClientSubscription * finger = ( *head );
|
||||
ClientSubscription * previous = NULL; while( finger ) {
|
||||
if( !( strcmp( sid, finger->sid ) ) ) {
|
||||
if( previous )
|
||||
previous->next = finger->next;
|
||||
else
|
||||
( *head ) = finger->next;
|
||||
finger->next = NULL;
|
||||
freeClientSubList( finger ); finger = NULL;}
|
||||
else
|
||||
{
|
||||
previous = finger; finger = finger->next;}
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Function : GetClientSubClientSID
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription *head ; Head of the subscription list
|
||||
* const Upnp_SID sid ; Subscription ID to be matched
|
||||
*
|
||||
* Description : Return the client subscription from the client table
|
||||
* that matches const Upnp_SID sid subscrition id value.
|
||||
*
|
||||
* Return : ClientSubscription * ; The matching subscription
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
ClientSubscription *
|
||||
GetClientSubClientSID( ClientSubscription * head,
|
||||
const Upnp_SID sid ) {
|
||||
ClientSubscription * next = head; while( next ) {
|
||||
if( !strcmp( next->sid, sid ) )
|
||||
struct SClientSubscription {
|
||||
int m_renewEventId;
|
||||
UpnpString *m_SID;
|
||||
UpnpString *m_actualSID;
|
||||
UpnpString *m_eventURL;
|
||||
struct SClientSubscription *m_next;
|
||||
};
|
||||
|
||||
|
||||
/** Constructor */
|
||||
ClientSubscription *UpnpClientSubscription_new()
|
||||
{
|
||||
struct SClientSubscription *p = calloc(1, sizeof (struct SClientSubscription));
|
||||
#if 0
|
||||
p->renewEventId = 0;
|
||||
#endif
|
||||
p->m_SID = UpnpString_new();
|
||||
p->m_actualSID = UpnpString_new();
|
||||
p->m_eventURL = UpnpString_new();
|
||||
p->m_next = NULL;
|
||||
|
||||
return (ClientSubscription *)p;
|
||||
}
|
||||
|
||||
|
||||
/** Destructor */
|
||||
void UpnpClientSubscription_delete(ClientSubscription *p)
|
||||
{
|
||||
struct SClientSubscription *q = (struct SClientSubscription *)p;
|
||||
|
||||
if (!q) return;
|
||||
|
||||
q->m_renewEventId = 0;
|
||||
|
||||
UpnpString_delete(q->m_SID);
|
||||
q->m_SID = NULL;
|
||||
|
||||
UpnpString_delete(q->m_actualSID);
|
||||
q->m_actualSID = NULL;
|
||||
|
||||
UpnpString_delete(q->m_eventURL);
|
||||
q->m_eventURL = NULL;
|
||||
|
||||
q->m_next = NULL;
|
||||
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
||||
/** Copy Constructor */
|
||||
ClientSubscription *UpnpClientSubscription_dup(const ClientSubscription *p)
|
||||
{
|
||||
ClientSubscription *q = UpnpClientSubscription_new();
|
||||
|
||||
UpnpClientSubscription_assign(q, p);
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
/** Assignment operator */
|
||||
void UpnpClientSubscription_assign(ClientSubscription *q, const ClientSubscription *p)
|
||||
{
|
||||
if (q != p) {
|
||||
// Do not copy RenewEventId
|
||||
((struct SClientSubscription *)q)->m_renewEventId = -1;
|
||||
UpnpClientSubscription_set_SID(q, UpnpClientSubscription_get_SID(p));
|
||||
UpnpClientSubscription_set_ActualSID(q, UpnpClientSubscription_get_ActualSID(p));
|
||||
UpnpClientSubscription_set_EventURL(q, UpnpClientSubscription_get_EventURL(p));
|
||||
// Do not copy m_next
|
||||
((struct SClientSubscription *)q)->m_next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int UpnpClientSubscription_get_RenewEventId(const ClientSubscription *p)
|
||||
{
|
||||
return ((struct SClientSubscription *)p)->m_renewEventId;
|
||||
}
|
||||
|
||||
|
||||
void UpnpClientSubscription_set_RenewEventId(ClientSubscription *p, int n)
|
||||
{
|
||||
((struct SClientSubscription *)p)->m_renewEventId = n;
|
||||
}
|
||||
|
||||
|
||||
const UpnpString *UpnpClientSubscription_get_SID(const ClientSubscription *p)
|
||||
{
|
||||
return ((struct SClientSubscription *)p)->m_SID;
|
||||
}
|
||||
|
||||
const char *UpnpClientSubscription_get_SID_cstr(const ClientSubscription *p)
|
||||
{
|
||||
return UpnpString_get_String(UpnpClientSubscription_get_SID(p));
|
||||
}
|
||||
|
||||
|
||||
void UpnpClientSubscription_set_SID(ClientSubscription *p, const UpnpString *s)
|
||||
{
|
||||
UpnpString_delete(((struct SClientSubscription *)p)->m_SID);
|
||||
((struct SClientSubscription *)p)->m_SID = UpnpString_dup(s);
|
||||
}
|
||||
|
||||
|
||||
void UpnpClientSubscription_strcpy_SID(ClientSubscription *p, const char *s)
|
||||
{
|
||||
UpnpString_delete(((struct SClientSubscription *)p)->m_SID);
|
||||
((struct SClientSubscription *)p)->m_SID = UpnpString_new();
|
||||
UpnpString_set_String(((struct SClientSubscription *)p)->m_SID, s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const UpnpString *UpnpClientSubscription_get_ActualSID(const ClientSubscription *p)
|
||||
{
|
||||
return ((struct SClientSubscription *)p)->m_actualSID;
|
||||
}
|
||||
|
||||
|
||||
const char *UpnpClientSubscription_get_ActualSID_cstr(const ClientSubscription *p)
|
||||
{
|
||||
return UpnpString_get_String(UpnpClientSubscription_get_ActualSID(p));
|
||||
}
|
||||
|
||||
|
||||
void UpnpClientSubscription_set_ActualSID(ClientSubscription *p, const UpnpString *s)
|
||||
{
|
||||
UpnpString_delete(((struct SClientSubscription *)p)->m_actualSID);
|
||||
((struct SClientSubscription *)p)->m_actualSID = UpnpString_dup(s);
|
||||
}
|
||||
|
||||
|
||||
void UpnpClientSubscription_strcpy_ActualSID(ClientSubscription *p, const char *s)
|
||||
{
|
||||
UpnpString_delete(((struct SClientSubscription *)p)->m_actualSID);
|
||||
((struct SClientSubscription *)p)->m_actualSID = UpnpString_new();
|
||||
UpnpString_set_String(((struct SClientSubscription *)p)->m_actualSID, s);
|
||||
}
|
||||
|
||||
|
||||
const UpnpString *UpnpClientSubscription_get_EventURL(const ClientSubscription *p)
|
||||
{
|
||||
return ((struct SClientSubscription *)p)->m_eventURL;
|
||||
}
|
||||
|
||||
|
||||
const char *UpnpClientSubscription_get_EventURL_cstr(const ClientSubscription *p)
|
||||
{
|
||||
return UpnpString_get_String(UpnpClientSubscription_get_EventURL(p));
|
||||
}
|
||||
|
||||
|
||||
void UpnpClientSubscription_set_EventURL(ClientSubscription *p, const UpnpString *s)
|
||||
{
|
||||
UpnpString_delete(((struct SClientSubscription *)p)->m_eventURL);
|
||||
((struct SClientSubscription *)p)->m_eventURL = UpnpString_dup(s);
|
||||
}
|
||||
|
||||
|
||||
void UpnpClientSubscription_strcpy_EventURL(ClientSubscription *p, const char *s)
|
||||
{
|
||||
UpnpString_delete(((struct SClientSubscription *)p)->m_eventURL);
|
||||
((struct SClientSubscription *)p)->m_eventURL = UpnpString_new();
|
||||
UpnpString_set_String(((struct SClientSubscription *)p)->m_eventURL, s);
|
||||
}
|
||||
|
||||
|
||||
ClientSubscription *UpnpClientSubscription_get_Next(const ClientSubscription *p)
|
||||
{
|
||||
return (ClientSubscription *)(((struct SClientSubscription *)p)->m_next);
|
||||
}
|
||||
|
||||
|
||||
void UpnpClientSubscription_set_Next(ClientSubscription *p, ClientSubscription *q)
|
||||
{
|
||||
((struct SClientSubscription *)p)->m_next = (struct SClientSubscription *)q;
|
||||
}
|
||||
|
||||
|
||||
void free_client_subscription(ClientSubscription *sub)
|
||||
{
|
||||
upnp_timeout *event;
|
||||
ThreadPoolJob tempJob;
|
||||
if (sub) {
|
||||
int renewEventId = UpnpClientSubscription_get_RenewEventId(sub);
|
||||
UpnpClientSubscription_strcpy_ActualSID(sub, "");
|
||||
UpnpClientSubscription_strcpy_EventURL(sub, "");
|
||||
if (renewEventId != -1) {
|
||||
// do not remove timer event of copy
|
||||
// invalid timer event id
|
||||
if (TimerThreadRemove(&gTimerThread, renewEventId, &tempJob) == 0) {
|
||||
event = (upnp_timeout *)tempJob.arg;
|
||||
free_upnp_timeout(event);
|
||||
}
|
||||
}
|
||||
UpnpClientSubscription_set_RenewEventId(sub, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void freeClientSubList(ClientSubscription *list)
|
||||
{
|
||||
ClientSubscription *next;
|
||||
while (list) {
|
||||
free_client_subscription(list);
|
||||
next = UpnpClientSubscription_get_Next(list);
|
||||
UpnpClientSubscription_delete(list);
|
||||
list = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RemoveClientSubClientSID(ClientSubscription **head, const UpnpString *sid)
|
||||
{
|
||||
ClientSubscription *finger = *head;
|
||||
ClientSubscription *previous = NULL;
|
||||
int found = 0;
|
||||
while (finger) {
|
||||
found = !strcmp(
|
||||
UpnpString_get_String(sid),
|
||||
UpnpClientSubscription_get_SID_cstr(finger));
|
||||
if (found) {
|
||||
if (previous) {
|
||||
UpnpClientSubscription_set_Next(previous,
|
||||
UpnpClientSubscription_get_Next(finger));
|
||||
} else {
|
||||
*head = UpnpClientSubscription_get_Next(finger);
|
||||
}
|
||||
UpnpClientSubscription_set_Next(finger, NULL);
|
||||
freeClientSubList(finger);
|
||||
finger = NULL;
|
||||
} else {
|
||||
previous = finger;
|
||||
finger = UpnpClientSubscription_get_Next(finger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ClientSubscription *GetClientSubClientSID(ClientSubscription *head, const UpnpString *sid)
|
||||
{
|
||||
ClientSubscription *next = head;
|
||||
int found = 0;
|
||||
while (next) {
|
||||
found = !strcmp(
|
||||
UpnpClientSubscription_get_SID_cstr(next),
|
||||
UpnpString_get_String(sid));
|
||||
if(found) {
|
||||
break;
|
||||
else
|
||||
{
|
||||
next = next->next;}
|
||||
} else {
|
||||
next = UpnpClientSubscription_get_Next(next);
|
||||
}
|
||||
}
|
||||
return next;}
|
||||
|
||||
/************************************************************************
|
||||
* Function : GetClientSubActualSID
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription *head ; Head of the subscription list
|
||||
* token * sid ; Subscription ID to be matched
|
||||
*
|
||||
* Description : Returns the client subscription from the client
|
||||
* subscription table that has the matching token * sid buffer
|
||||
* value.
|
||||
*
|
||||
* Return : ClientSubscription * ; The matching subscription
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
ClientSubscription *
|
||||
GetClientSubActualSID( ClientSubscription * head,
|
||||
token * sid ) {
|
||||
ClientSubscription * next = head; while( next ) {
|
||||
return next;
|
||||
}
|
||||
|
||||
if( !memcmp( next->ActualSID, sid->buff, sid->size ) )
|
||||
|
||||
ClientSubscription *GetClientSubActualSID(ClientSubscription *head, token *sid)
|
||||
{
|
||||
ClientSubscription *next = head;
|
||||
while (next) {
|
||||
if (!memcmp(
|
||||
UpnpClientSubscription_get_ActualSID_cstr(next),
|
||||
sid->buff, sid->size)) {
|
||||
break;
|
||||
else
|
||||
{
|
||||
next = next->next;}
|
||||
} else {
|
||||
next = UpnpClientSubscription_get_Next(next);
|
||||
}
|
||||
}
|
||||
return next;}
|
||||
|
||||
)
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
|
||||
|
@@ -1,166 +1,248 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2000-2003 Intel Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// * Neither name of Intel Corporation nor the names of its contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _CLIENT_TABLE
|
||||
#define _CLIENT_TABLE
|
||||
#ifndef CLIENT_TABLE_H
|
||||
#define CLIENT_TABLE_H
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "service_table.h"
|
||||
#include "upnp.h"
|
||||
#include "UpnpString.h"
|
||||
#include "upnp_timeout.h"
|
||||
#include "uri.h"
|
||||
#include "TimerThread.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
//#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "uri.h"
|
||||
#include "service_table.h"
|
||||
|
||||
#include "TimerThread.h"
|
||||
#include "upnp_timeout.h"
|
||||
|
||||
extern TimerThread gTimerThread;
|
||||
|
||||
CLIENTONLY(
|
||||
typedef struct CLIENT_SUBSCRIPTION {
|
||||
Upnp_SID sid;
|
||||
char * ActualSID;
|
||||
char * EventURL;
|
||||
int RenewEventId;
|
||||
struct CLIENT_SUBSCRIPTION *next;
|
||||
} ClientSubscription;
|
||||
|
||||
/************************************************************************
|
||||
* Function : copy_client_subscription
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription * in ; - source client subscription
|
||||
* ClientSubscription * out ; - destination client subscription
|
||||
*
|
||||
* Description : Make a copy of the client subscription data
|
||||
*
|
||||
* Return : int ;
|
||||
* UPNP_E_OUTOF_MEMORY - On Failure to allocate memory
|
||||
* HTTP_SUCCESS - On Success
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
int copy_client_subscription(ClientSubscription * in, ClientSubscription * out);
|
||||
|
||||
/************************************************************************
|
||||
* Function : free_client_subscription
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription * sub ; - Client subscription to be freed
|
||||
*
|
||||
* Description : Free memory allocated for client subscription data.
|
||||
* Remove timer thread associated with this subscription event.
|
||||
*
|
||||
* Return : void ;
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
void free_client_subscription(ClientSubscription * sub);
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* Function : freeClientSubList
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription * list ; Client subscription
|
||||
*
|
||||
* Description : Free the client subscription table.
|
||||
*
|
||||
* Return : void ;
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
void freeClientSubList(ClientSubscription * list);
|
||||
typedef struct s_ClientSubscription ClientSubscription;
|
||||
|
||||
/************************************************************************
|
||||
* Function : RemoveClientSubClientSID
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription **head ; Head of the subscription list
|
||||
* const Upnp_SID sid ; Subscription ID to be mactched
|
||||
*
|
||||
* Description : Remove the client subscription matching the
|
||||
* subscritpion id represented by the const Upnp_SID sid parameter
|
||||
* from the table and update the table.
|
||||
*
|
||||
* Return : void ;
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
void RemoveClientSubClientSID(ClientSubscription **head,
|
||||
const Upnp_SID sid);
|
||||
|
||||
/************************************************************************
|
||||
* Function : GetClientSubClientSID
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription *head ; Head of the subscription list
|
||||
* const Upnp_SID sid ; Subscription ID to be matched
|
||||
*
|
||||
* Description : Return the client subscription from the client table
|
||||
* that matches const Upnp_SID sid subscrition id value.
|
||||
*
|
||||
* Return : ClientSubscription * ; The matching subscription
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
ClientSubscription * GetClientSubClientSID(ClientSubscription *head
|
||||
, const Upnp_SID sid);
|
||||
/*!
|
||||
* \brief Constructor.
|
||||
*/
|
||||
ClientSubscription *UpnpClientSubscription_new();
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Destructor.
|
||||
*/
|
||||
void UpnpClientSubscription_delete(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Copy Constructor.
|
||||
*/
|
||||
ClientSubscription *UpnpClientSubscription_dup(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Assignment operator.
|
||||
*/
|
||||
void UpnpClientSubscription_assign(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *q,
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
int UpnpClientSubscription_get_RenewEventId(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void UpnpClientSubscription_set_RenewEventId(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
/*! [in] . */
|
||||
int n);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
const UpnpString *UpnpClientSubscription_get_SID(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void UpnpClientSubscription_set_SID(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const UpnpString *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void UpnpClientSubscription_strcpy_SID(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const char *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
const UpnpString *UpnpClientSubscription_get_ActualSID(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void UpnpClientSubscription_set_ActualSID(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const UpnpString *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void UpnpClientSubscription_strcpy_ActualSID(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const char *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
const UpnpString *UpnpClientSubscription_get_EventURL(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void UpnpClientSubscription_set_EventURL(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const UpnpString *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void UpnpClientSubscription_strcpy_EventURL(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const char *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
ClientSubscription *UpnpClientSubscription_get_Next(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void UpnpClientSubscription_set_Next(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
ClientSubscription *q);
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Free memory allocated for client subscription data.
|
||||
*
|
||||
* Remove timer thread associated with this subscription event.
|
||||
*/
|
||||
void free_client_subscription(
|
||||
/*! [in] Client subscription to be freed. */
|
||||
ClientSubscription *sub);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Free the client subscription table.
|
||||
*/
|
||||
void freeClientSubList(
|
||||
/*! [in] Client subscription list to be freed. */
|
||||
ClientSubscription *list);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Remove the client subscription matching the subscritpion id
|
||||
* represented by the const Upnp_SID sid parameter from the table and
|
||||
* update the table.
|
||||
*/
|
||||
void RemoveClientSubClientSID(
|
||||
/*! [in] Head of the subscription list. */
|
||||
ClientSubscription **head,
|
||||
/*! [in] Subscription ID to be mactched. */
|
||||
const UpnpString *sid);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Return the client subscription from the client table that matches
|
||||
* const Upnp_SID sid subscrition id value.
|
||||
*
|
||||
* \return The matching subscription.
|
||||
*/
|
||||
ClientSubscription *GetClientSubClientSID(
|
||||
/*! [in] Head of the subscription list. */
|
||||
ClientSubscription *head,
|
||||
/*! [in] Subscription ID to be mactched. */
|
||||
const UpnpString *sid);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Returns the client subscription from the client subscription table
|
||||
* that has the matching token *sid buffer value.
|
||||
*
|
||||
* \return The matching subscription.
|
||||
*/
|
||||
ClientSubscription *GetClientSubActualSID(
|
||||
/*! [in] Head of the subscription list. */
|
||||
ClientSubscription *head,
|
||||
/*! [in] Subscription ID to be mactched. */
|
||||
token *sid);
|
||||
|
||||
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
|
||||
/************************************************************************
|
||||
* Function : GetClientSubActualSID
|
||||
*
|
||||
* Parameters :
|
||||
* ClientSubscription *head ; Head of the subscription list
|
||||
* token * sid ; Subscription ID to be matched
|
||||
*
|
||||
* Description : Returns the client subscription from the client
|
||||
* subscription table that has the matching token * sid buffer
|
||||
* value.
|
||||
*
|
||||
* Return : ClientSubscription * ; The matching subscription
|
||||
*
|
||||
* Note :
|
||||
************************************************************************/
|
||||
ClientSubscription * GetClientSubActualSID(ClientSubscription *head, token * sid);
|
||||
)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* CLIENT_TABLE_H */
|
||||
|
||||
#endif /* _CLIENT_TABLE */
|
||||
|
@@ -53,6 +53,7 @@
|
||||
#include "sock.h"
|
||||
#include "ThreadPool.h"
|
||||
#include "upnp.h"
|
||||
#include "UpnpString.h"
|
||||
#include "uri.h"
|
||||
|
||||
|
||||
@@ -182,14 +183,14 @@ EXTERN_C int genaSubscribe(
|
||||
/*! [in] The client handle. */
|
||||
UpnpClient_Handle client_handle,
|
||||
/*! [in] Of the form: "http://134.134.156.80:4000/RedBulb/Event */
|
||||
const char *PublisherURL,
|
||||
const UpnpString *PublisherURL,
|
||||
/*! [in,out] requested Duration:
|
||||
* \li if -1, then "infinite".
|
||||
* \li in the OUT case: actual Duration granted by Service,
|
||||
* -1 for infinite. */
|
||||
int *TimeOut,
|
||||
/*! [out] sid of subscription, memory passed in by caller. */
|
||||
Upnp_SID out_sid);
|
||||
UpnpString *out_sid);
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
|
||||
|
||||
@@ -208,7 +209,7 @@ EXTERN_C int genaUnSubscribe(
|
||||
/*! [in] UPnP client handle. */
|
||||
UpnpClient_Handle client_handle,
|
||||
/*! [in] The subscription ID. */
|
||||
const Upnp_SID in_sid);
|
||||
const UpnpString *in_sid);
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
|
||||
|
||||
@@ -260,7 +261,7 @@ EXTERN_C int genaRenewSubscription(
|
||||
/*! [in] Client handle. */
|
||||
UpnpClient_Handle client_handle,
|
||||
/*! [in] Subscription ID. */
|
||||
const Upnp_SID in_sid,
|
||||
const UpnpString *in_sid,
|
||||
/*! [in,out] requested Duration, if -1, then "infinite". In the OUT case:
|
||||
* actual Duration granted by Service, -1 for infinite. */
|
||||
int *TimeOut);
|
||||
|
Reference in New Issue
Block a user