Separation of the ClientSubscription object.
git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@543 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
parent
ad9bcc9100
commit
d33ad5c03e
@ -2,7 +2,10 @@
|
||||
Version 1.8.0
|
||||
*******************************************************************************
|
||||
|
||||
2010-03-27 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||
2010-04-25 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||
Separation of the ClientSubscription object.
|
||||
|
||||
2010-04-24 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||
Protect the object destructors agains null pointers on deletion, which
|
||||
should be something valid.
|
||||
|
||||
|
@ -53,6 +53,7 @@ libupnp_la_LDFLAGS = \
|
||||
libupnp_la_SOURCES = \
|
||||
src/inc/config.h \
|
||||
src/inc/client_table.h \
|
||||
src/inc/ClientSubscription.h \
|
||||
src/inc/gena.h \
|
||||
src/inc/gena_ctrlpt.h \
|
||||
src/inc/gena_device.h \
|
||||
@ -103,12 +104,13 @@ libupnp_la_SOURCES += \
|
||||
# genlib
|
||||
libupnp_la_SOURCES += \
|
||||
src/genlib/miniserver/miniserver.c \
|
||||
src/genlib/client_table/client_table.c \
|
||||
src/genlib/client_table/ClientSubscription.c \
|
||||
src/genlib/service_table/service_table.c \
|
||||
src/genlib/util/membuffer.c \
|
||||
src/genlib/util/strintmap.c \
|
||||
src/genlib/util/upnp_timeout.c \
|
||||
src/genlib/util/util.c \
|
||||
src/genlib/client_table/client_table.c \
|
||||
src/genlib/net/sock.c \
|
||||
src/genlib/net/http/httpparser.c \
|
||||
src/genlib/net/http/httpreadwrite.c \
|
||||
|
@ -159,8 +159,8 @@ static int ScheduleGenaAutoRenew(
|
||||
// schedule expire event
|
||||
UpnpEventSubscribe_set_ErrCode(RenewEventStruct, UPNP_E_SUCCESS);
|
||||
UpnpEventSubscribe_set_TimeOut(RenewEventStruct, TimeOut);
|
||||
UpnpEventSubscribe_set_SID(RenewEventStruct, UpnpClientSubscription_get_SID(sub));
|
||||
UpnpEventSubscribe_set_PublisherUrl(RenewEventStruct, UpnpClientSubscription_get_EventURL(sub));
|
||||
UpnpEventSubscribe_set_SID(RenewEventStruct, GenlibClientSubscription_get_SID(sub));
|
||||
UpnpEventSubscribe_set_PublisherUrl(RenewEventStruct, GenlibClientSubscription_get_EventURL(sub));
|
||||
|
||||
// RenewEvent->EventType=UPNP_EVENT_SUBSCRIPTION_EXPIRE;
|
||||
RenewEvent->handle = client_handle;
|
||||
@ -183,7 +183,7 @@ static int ScheduleGenaAutoRenew(
|
||||
goto end_function;
|
||||
}
|
||||
|
||||
UpnpClientSubscription_set_RenewEventId(sub, RenewEvent->eventId);
|
||||
GenlibClientSubscription_set_RenewEventId(sub, RenewEvent->eventId);
|
||||
|
||||
return_code = GENA_SUCCESS;
|
||||
|
||||
@ -394,7 +394,7 @@ static int gena_subscribe(
|
||||
|
||||
int genaUnregisterClient(UpnpClient_Handle client_handle)
|
||||
{
|
||||
ClientSubscription *sub_copy = UpnpClientSubscription_new();
|
||||
ClientSubscription *sub_copy = GenlibClientSubscription_new();
|
||||
int return_code = UPNP_E_SUCCESS;
|
||||
struct Handle_Info *handle_info = NULL;
|
||||
http_parser_t response;
|
||||
@ -411,16 +411,16 @@ int genaUnregisterClient(UpnpClient_Handle client_handle)
|
||||
return_code = UPNP_E_SUCCESS;
|
||||
break;
|
||||
}
|
||||
UpnpClientSubscription_assign(sub_copy, handle_info->ClientSubList);
|
||||
GenlibClientSubscription_assign(sub_copy, handle_info->ClientSubList);
|
||||
RemoveClientSubClientSID(
|
||||
&handle_info->ClientSubList,
|
||||
UpnpClientSubscription_get_SID(sub_copy));
|
||||
GenlibClientSubscription_get_SID(sub_copy));
|
||||
|
||||
HandleUnlock();
|
||||
|
||||
return_code = gena_unsubscribe(
|
||||
UpnpClientSubscription_get_EventURL(sub_copy),
|
||||
UpnpClientSubscription_get_ActualSID(sub_copy),
|
||||
GenlibClientSubscription_get_EventURL(sub_copy),
|
||||
GenlibClientSubscription_get_ActualSID(sub_copy),
|
||||
&response);
|
||||
if (return_code == 0) {
|
||||
httpmsg_destroy(&response.msg);
|
||||
@ -432,7 +432,7 @@ int genaUnregisterClient(UpnpClient_Handle client_handle)
|
||||
HandleUnlock();
|
||||
|
||||
exit_function:
|
||||
UpnpClientSubscription_delete(sub_copy);
|
||||
GenlibClientSubscription_delete(sub_copy);
|
||||
return return_code;
|
||||
}
|
||||
|
||||
@ -445,7 +445,7 @@ int genaUnSubscribe(
|
||||
ClientSubscription *sub = NULL;
|
||||
int return_code = GENA_SUCCESS;
|
||||
struct Handle_Info *handle_info;
|
||||
ClientSubscription *sub_copy = UpnpClientSubscription_new();
|
||||
ClientSubscription *sub_copy = GenlibClientSubscription_new();
|
||||
http_parser_t response;
|
||||
|
||||
// validate handle and sid
|
||||
@ -461,12 +461,12 @@ int genaUnSubscribe(
|
||||
return_code = GENA_E_BAD_SID;
|
||||
goto exit_function;
|
||||
}
|
||||
UpnpClientSubscription_assign(sub_copy, sub);
|
||||
GenlibClientSubscription_assign(sub_copy, sub);
|
||||
HandleUnlock();
|
||||
|
||||
return_code = gena_unsubscribe(
|
||||
UpnpClientSubscription_get_EventURL(sub_copy),
|
||||
UpnpClientSubscription_get_ActualSID(sub_copy),
|
||||
GenlibClientSubscription_get_EventURL(sub_copy),
|
||||
GenlibClientSubscription_get_ActualSID(sub_copy),
|
||||
&response);
|
||||
if (return_code == 0) {
|
||||
httpmsg_destroy(&response.msg);
|
||||
@ -483,7 +483,7 @@ int genaUnSubscribe(
|
||||
HandleUnlock();
|
||||
|
||||
exit_function:
|
||||
UpnpClientSubscription_delete(sub_copy);
|
||||
GenlibClientSubscription_delete(sub_copy);
|
||||
return return_code;
|
||||
}
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
@ -497,7 +497,7 @@ int genaSubscribe(
|
||||
UpnpString *out_sid)
|
||||
{
|
||||
int return_code = GENA_SUCCESS;
|
||||
ClientSubscription *newSubscription = UpnpClientSubscription_new();
|
||||
ClientSubscription *newSubscription = GenlibClientSubscription_new();
|
||||
uuid_upnp uid;
|
||||
Upnp_SID temp_sid;
|
||||
Upnp_SID temp_sid2;
|
||||
@ -548,11 +548,11 @@ int genaSubscribe(
|
||||
return_code = UPNP_E_OUTOF_MEMORY;
|
||||
goto error_handler;
|
||||
}
|
||||
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);
|
||||
GenlibClientSubscription_set_RenewEventId(newSubscription, -1);
|
||||
GenlibClientSubscription_set_SID(newSubscription, out_sid);
|
||||
GenlibClientSubscription_set_ActualSID(newSubscription, ActualSID);
|
||||
GenlibClientSubscription_set_EventURL(newSubscription, EventURL);
|
||||
GenlibClientSubscription_set_Next(newSubscription, handle_info->ClientSubList);
|
||||
handle_info->ClientSubList = newSubscription;
|
||||
|
||||
// schedule expiration event
|
||||
@ -562,7 +562,7 @@ error_handler:
|
||||
if (return_code != UPNP_E_SUCCESS) {
|
||||
UpnpString_delete(ActualSID);
|
||||
UpnpString_delete(EventURL);
|
||||
UpnpClientSubscription_delete(newSubscription);
|
||||
GenlibClientSubscription_delete(newSubscription);
|
||||
}
|
||||
HandleUnlock();
|
||||
SubscribeUnlock();
|
||||
@ -579,7 +579,7 @@ int genaRenewSubscription(
|
||||
{
|
||||
int return_code = GENA_SUCCESS;
|
||||
ClientSubscription *sub = NULL;
|
||||
ClientSubscription *sub_copy = UpnpClientSubscription_new();
|
||||
ClientSubscription *sub_copy = GenlibClientSubscription_new();
|
||||
struct Handle_Info *handle_info;
|
||||
UpnpString *ActualSID = UpnpString_new();
|
||||
ThreadPoolJob tempJob;
|
||||
@ -605,22 +605,22 @@ int genaRenewSubscription(
|
||||
// remove old events
|
||||
if (TimerThreadRemove(
|
||||
&gTimerThread,
|
||||
UpnpClientSubscription_get_RenewEventId(sub),
|
||||
GenlibClientSubscription_get_RenewEventId(sub),
|
||||
&tempJob) == 0 ) {
|
||||
free_upnp_timeout((upnp_timeout *)tempJob.arg);
|
||||
}
|
||||
|
||||
UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, "REMOVED AUTO RENEW EVENT");
|
||||
|
||||
UpnpClientSubscription_set_RenewEventId(sub, -1);
|
||||
UpnpClientSubscription_assign(sub_copy, sub);
|
||||
GenlibClientSubscription_set_RenewEventId(sub, -1);
|
||||
GenlibClientSubscription_assign(sub_copy, sub);
|
||||
|
||||
HandleUnlock();
|
||||
|
||||
return_code = gena_subscribe(
|
||||
UpnpClientSubscription_get_EventURL(sub_copy),
|
||||
GenlibClientSubscription_get_EventURL(sub_copy),
|
||||
TimeOut,
|
||||
UpnpClientSubscription_get_ActualSID(sub_copy),
|
||||
GenlibClientSubscription_get_ActualSID(sub_copy),
|
||||
ActualSID);
|
||||
|
||||
HandleLock();
|
||||
@ -651,21 +651,21 @@ int genaRenewSubscription(
|
||||
}
|
||||
|
||||
// store actual sid
|
||||
UpnpClientSubscription_set_ActualSID(sub, ActualSID);
|
||||
GenlibClientSubscription_set_ActualSID(sub, ActualSID);
|
||||
|
||||
// start renew subscription timer
|
||||
return_code = ScheduleGenaAutoRenew(client_handle, *TimeOut, sub);
|
||||
if (return_code != GENA_SUCCESS) {
|
||||
RemoveClientSubClientSID(
|
||||
&handle_info->ClientSubList,
|
||||
UpnpClientSubscription_get_SID(sub));
|
||||
GenlibClientSubscription_get_SID(sub));
|
||||
}
|
||||
free_client_subscription(sub_copy);
|
||||
HandleUnlock();
|
||||
|
||||
exit_function:
|
||||
UpnpString_delete(ActualSID);
|
||||
UpnpClientSubscription_delete(sub_copy);
|
||||
GenlibClientSubscription_delete(sub_copy);
|
||||
return return_code;
|
||||
}
|
||||
|
||||
@ -781,7 +781,7 @@ void gena_process_notification_event(
|
||||
// fill event struct
|
||||
UpnpEvent_set_EventKey(event_struct, eventKey);
|
||||
UpnpEvent_set_ChangedVariables(event_struct, ChangedVars);
|
||||
UpnpEvent_set_SID(event_struct, UpnpClientSubscription_get_SID(subscription));
|
||||
UpnpEvent_set_SID(event_struct, GenlibClientSubscription_get_SID(subscription));
|
||||
|
||||
// copy callback
|
||||
callback = handle_info->Callback;
|
||||
|
200
upnp/src/genlib/client_table/ClientSubscription.c
Normal file
200
upnp/src/genlib/client_table/ClientSubscription.c
Normal file
@ -0,0 +1,200 @@
|
||||
|
||||
/************************************************************************
|
||||
* 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 "ClientSubscription.h"
|
||||
|
||||
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
|
||||
|
||||
#include <stdlib.h> // for calloc(), free()
|
||||
|
||||
|
||||
struct SClientSubscription {
|
||||
int m_renewEventId;
|
||||
UpnpString *m_SID;
|
||||
UpnpString *m_actualSID;
|
||||
UpnpString *m_eventURL;
|
||||
struct SClientSubscription *m_next;
|
||||
};
|
||||
|
||||
|
||||
ClientSubscription *GenlibClientSubscription_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;
|
||||
}
|
||||
|
||||
|
||||
void GenlibClientSubscription_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);
|
||||
}
|
||||
|
||||
|
||||
ClientSubscription *GenlibClientSubscription_dup(const ClientSubscription *p)
|
||||
{
|
||||
ClientSubscription *q = GenlibClientSubscription_new();
|
||||
|
||||
GenlibClientSubscription_assign(q, p);
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
|
||||
void GenlibClientSubscription_assign(ClientSubscription *q, const ClientSubscription *p)
|
||||
{
|
||||
if (q != p) {
|
||||
/*struct SClientSubscription *_p = (struct SClientSubscription *)p;*/
|
||||
struct SClientSubscription *_q = (struct SClientSubscription *)q;
|
||||
// Do not copy RenewEventId
|
||||
_q->m_renewEventId = -1;
|
||||
GenlibClientSubscription_set_SID(q, GenlibClientSubscription_get_SID(p));
|
||||
GenlibClientSubscription_set_ActualSID(q, GenlibClientSubscription_get_ActualSID(p));
|
||||
GenlibClientSubscription_set_EventURL(q, GenlibClientSubscription_get_EventURL(p));
|
||||
// Do not copy m_next
|
||||
_q->m_next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int GenlibClientSubscription_get_RenewEventId(const ClientSubscription *p)
|
||||
{
|
||||
return ((struct SClientSubscription *)p)->m_renewEventId;
|
||||
}
|
||||
|
||||
|
||||
void GenlibClientSubscription_set_RenewEventId(ClientSubscription *p, int n)
|
||||
{
|
||||
((struct SClientSubscription *)p)->m_renewEventId = n;
|
||||
}
|
||||
|
||||
|
||||
const UpnpString *GenlibClientSubscription_get_SID(const ClientSubscription *p)
|
||||
{
|
||||
return ((struct SClientSubscription *)p)->m_SID;
|
||||
}
|
||||
|
||||
const char *GenlibClientSubscription_get_SID_cstr(const ClientSubscription *p)
|
||||
{
|
||||
return UpnpString_get_String(GenlibClientSubscription_get_SID(p));
|
||||
}
|
||||
|
||||
|
||||
void GenlibClientSubscription_set_SID(ClientSubscription *p, const UpnpString *s)
|
||||
{
|
||||
UpnpString_delete(((struct SClientSubscription *)p)->m_SID);
|
||||
((struct SClientSubscription *)p)->m_SID = UpnpString_dup(s);
|
||||
}
|
||||
|
||||
|
||||
void GenlibClientSubscription_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 *GenlibClientSubscription_get_ActualSID(const ClientSubscription *p)
|
||||
{
|
||||
return ((struct SClientSubscription *)p)->m_actualSID;
|
||||
}
|
||||
|
||||
|
||||
const char *GenlibClientSubscription_get_ActualSID_cstr(const ClientSubscription *p)
|
||||
{
|
||||
return UpnpString_get_String(GenlibClientSubscription_get_ActualSID(p));
|
||||
}
|
||||
|
||||
|
||||
void GenlibClientSubscription_set_ActualSID(ClientSubscription *p, const UpnpString *s)
|
||||
{
|
||||
UpnpString_delete(((struct SClientSubscription *)p)->m_actualSID);
|
||||
((struct SClientSubscription *)p)->m_actualSID = UpnpString_dup(s);
|
||||
}
|
||||
|
||||
|
||||
void GenlibClientSubscription_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 *GenlibClientSubscription_get_EventURL(const ClientSubscription *p)
|
||||
{
|
||||
return ((struct SClientSubscription *)p)->m_eventURL;
|
||||
}
|
||||
|
||||
|
||||
const char *GenlibClientSubscription_get_EventURL_cstr(const ClientSubscription *p)
|
||||
{
|
||||
return UpnpString_get_String(GenlibClientSubscription_get_EventURL(p));
|
||||
}
|
||||
|
||||
|
||||
void GenlibClientSubscription_set_EventURL(ClientSubscription *p, const UpnpString *s)
|
||||
{
|
||||
UpnpString_delete(((struct SClientSubscription *)p)->m_eventURL);
|
||||
((struct SClientSubscription *)p)->m_eventURL = UpnpString_dup(s);
|
||||
}
|
||||
|
||||
|
||||
void GenlibClientSubscription_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 *GenlibClientSubscription_get_Next(const ClientSubscription *p)
|
||||
{
|
||||
return (ClientSubscription *)(((struct SClientSubscription *)p)->m_next);
|
||||
}
|
||||
|
||||
|
||||
void GenlibClientSubscription_set_Next(ClientSubscription *p, ClientSubscription *q)
|
||||
{
|
||||
((struct SClientSubscription *)p)->m_next = (struct SClientSubscription *)q;
|
||||
}
|
||||
|
||||
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
|
@ -1,33 +1,3 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
* 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
|
||||
@ -49,194 +19,14 @@
|
||||
#include <stdlib.h> // for calloc(), free()
|
||||
|
||||
|
||||
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, "");
|
||||
int renewEventId = GenlibClientSubscription_get_RenewEventId(sub);
|
||||
GenlibClientSubscription_strcpy_ActualSID(sub, "");
|
||||
GenlibClientSubscription_strcpy_EventURL(sub, "");
|
||||
if (renewEventId != -1) {
|
||||
// do not remove timer event of copy
|
||||
// invalid timer event id
|
||||
@ -245,7 +35,7 @@ void free_client_subscription(ClientSubscription *sub)
|
||||
free_upnp_timeout(event);
|
||||
}
|
||||
}
|
||||
UpnpClientSubscription_set_RenewEventId(sub, -1);
|
||||
GenlibClientSubscription_set_RenewEventId(sub, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -255,8 +45,8 @@ void freeClientSubList(ClientSubscription *list)
|
||||
ClientSubscription *next;
|
||||
while (list) {
|
||||
free_client_subscription(list);
|
||||
next = UpnpClientSubscription_get_Next(list);
|
||||
UpnpClientSubscription_delete(list);
|
||||
next = GenlibClientSubscription_get_Next(list);
|
||||
GenlibClientSubscription_delete(list);
|
||||
list = next;
|
||||
}
|
||||
}
|
||||
@ -270,20 +60,20 @@ void RemoveClientSubClientSID(ClientSubscription **head, const UpnpString *sid)
|
||||
while (finger) {
|
||||
found = !strcmp(
|
||||
UpnpString_get_String(sid),
|
||||
UpnpClientSubscription_get_SID_cstr(finger));
|
||||
GenlibClientSubscription_get_SID_cstr(finger));
|
||||
if (found) {
|
||||
if (previous) {
|
||||
UpnpClientSubscription_set_Next(previous,
|
||||
UpnpClientSubscription_get_Next(finger));
|
||||
GenlibClientSubscription_set_Next(previous,
|
||||
GenlibClientSubscription_get_Next(finger));
|
||||
} else {
|
||||
*head = UpnpClientSubscription_get_Next(finger);
|
||||
*head = GenlibClientSubscription_get_Next(finger);
|
||||
}
|
||||
UpnpClientSubscription_set_Next(finger, NULL);
|
||||
GenlibClientSubscription_set_Next(finger, NULL);
|
||||
freeClientSubList(finger);
|
||||
finger = NULL;
|
||||
} else {
|
||||
previous = finger;
|
||||
finger = UpnpClientSubscription_get_Next(finger);
|
||||
finger = GenlibClientSubscription_get_Next(finger);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -295,12 +85,12 @@ ClientSubscription *GetClientSubClientSID(ClientSubscription *head, const UpnpSt
|
||||
int found = 0;
|
||||
while (next) {
|
||||
found = !strcmp(
|
||||
UpnpClientSubscription_get_SID_cstr(next),
|
||||
GenlibClientSubscription_get_SID_cstr(next),
|
||||
UpnpString_get_String(sid));
|
||||
if(found) {
|
||||
break;
|
||||
} else {
|
||||
next = UpnpClientSubscription_get_Next(next);
|
||||
next = GenlibClientSubscription_get_Next(next);
|
||||
}
|
||||
}
|
||||
|
||||
@ -313,11 +103,11 @@ ClientSubscription *GetClientSubActualSID(ClientSubscription *head, token *sid)
|
||||
ClientSubscription *next = head;
|
||||
while (next) {
|
||||
if (!memcmp(
|
||||
UpnpClientSubscription_get_ActualSID_cstr(next),
|
||||
GenlibClientSubscription_get_ActualSID_cstr(next),
|
||||
sid->buff, sid->size)) {
|
||||
break;
|
||||
} else {
|
||||
next = UpnpClientSubscription_get_Next(next);
|
||||
next = GenlibClientSubscription_get_Next(next);
|
||||
}
|
||||
}
|
||||
|
||||
|
199
upnp/src/inc/ClientSubscription.h
Normal file
199
upnp/src/inc/ClientSubscription.h
Normal file
@ -0,0 +1,199 @@
|
||||
|
||||
#ifndef CLIENTSUBSCRIPTION_H
|
||||
#define CLIENTSUBSCRIPTION_H
|
||||
|
||||
|
||||
/*!
|
||||
* \file
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "UpnpString.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
|
||||
|
||||
typedef struct s_ClientSubscription ClientSubscription;
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Constructor.
|
||||
*/
|
||||
ClientSubscription *GenlibClientSubscription_new();
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Destructor.
|
||||
*/
|
||||
void GenlibClientSubscription_delete(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Copy Constructor.
|
||||
*/
|
||||
ClientSubscription *GenlibClientSubscription_dup(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Assignment operator.
|
||||
*/
|
||||
void GenlibClientSubscription_assign(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *q,
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
int GenlibClientSubscription_get_RenewEventId(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void GenlibClientSubscription_set_RenewEventId(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
/*! [in] . */
|
||||
int n);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
const UpnpString *GenlibClientSubscription_get_SID(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
const char *GenlibClientSubscription_get_SID_cstr(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void GenlibClientSubscription_set_SID(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const UpnpString *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void GenlibClientSubscription_strcpy_SID(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const char *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
const UpnpString *GenlibClientSubscription_get_ActualSID(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
const char *GenlibClientSubscription_get_ActualSID_cstr(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void GenlibClientSubscription_set_ActualSID(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const UpnpString *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void GenlibClientSubscription_strcpy_ActualSID(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const char *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
const UpnpString *GenlibClientSubscription_get_EventURL(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void GenlibClientSubscription_set_EventURL(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const UpnpString *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void GenlibClientSubscription_strcpy_EventURL(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
const char *s);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
ClientSubscription *GenlibClientSubscription_get_Next(
|
||||
/*! [in] The \b this pointer. */
|
||||
const ClientSubscription *p);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief
|
||||
*/
|
||||
void GenlibClientSubscription_set_Next(
|
||||
/*! [in] The \b this pointer. */
|
||||
ClientSubscription *p,
|
||||
ClientSubscription *q);
|
||||
|
||||
|
||||
#endif /* INCLUDE_CLIENT_APIS */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
#endif /* CLIENTSUBSCRIPTION_H */
|
||||
|
@ -13,6 +13,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include "ClientSubscription.h"
|
||||
#include "service_table.h"
|
||||
#include "upnp.h"
|
||||
#include "UpnpString.h"
|
||||
@ -32,154 +33,6 @@ extern TimerThread gTimerThread;
|
||||
#ifdef INCLUDE_CLIENT_APIS
|
||||
|
||||
|
||||
typedef struct s_ClientSubscription ClientSubscription;
|
||||
|
||||
|
||||
/*!
|
||||
* \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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user