1
2 /************************************************************************
3 * Purpose: This file defines the functions for clients. It defines
4 * functions for adding and removing clients to and from the client table,
5 * adding and accessing subscription and other attributes pertaining to the
6 * client
7 ************************************************************************/
8
9
10 #include "config.h"
11
12
13 #include "client_table.h"
14
15
16 #ifdef INCLUDE_CLIENT_APIS
17
18
19 #include <stdlib.h> /* for calloc(), free() */
20
21
free_client_subscription(GenlibClientSubscription * sub)22 void free_client_subscription(GenlibClientSubscription *sub)
23 {
24 upnp_timeout *event;
25 ThreadPoolJob tempJob;
26 if (sub) {
27 int renewEventId = GenlibClientSubscription_get_RenewEventId(sub);
28 GenlibClientSubscription_strcpy_ActualSID(sub, "");
29 GenlibClientSubscription_strcpy_EventURL(sub, "");
30 if (renewEventId != -1) {
31 /* do not remove timer event of copy */
32 /* invalid timer event id */
33 if (TimerThreadRemove(&gTimerThread, renewEventId, &tempJob) == 0) {
34 event = (upnp_timeout *)tempJob.arg;
35 free_upnp_timeout(event);
36 }
37 }
38 GenlibClientSubscription_set_RenewEventId(sub, -1);
39 }
40 }
41
42
freeClientSubList(GenlibClientSubscription * list)43 void freeClientSubList(GenlibClientSubscription *list)
44 {
45 GenlibClientSubscription *next;
46 while (list) {
47 free_client_subscription(list);
48 next = GenlibClientSubscription_get_Next(list);
49 GenlibClientSubscription_delete(list);
50 list = next;
51 }
52 }
53
54
RemoveClientSubClientSID(GenlibClientSubscription ** head,const UpnpString * sid)55 void RemoveClientSubClientSID(GenlibClientSubscription **head, const UpnpString *sid)
56 {
57 GenlibClientSubscription *finger = *head;
58 GenlibClientSubscription *previous = NULL;
59 int found = 0;
60 while (finger) {
61 found = !strcmp(
62 UpnpString_get_String(sid),
63 GenlibClientSubscription_get_SID_cstr(finger));
64 if (found) {
65 if (previous) {
66 GenlibClientSubscription_set_Next(previous,
67 GenlibClientSubscription_get_Next(finger));
68 } else {
69 *head = GenlibClientSubscription_get_Next(finger);
70 }
71 GenlibClientSubscription_set_Next(finger, NULL);
72 freeClientSubList(finger);
73 finger = NULL;
74 } else {
75 previous = finger;
76 finger = GenlibClientSubscription_get_Next(finger);
77 }
78 }
79 }
80
81
GetClientSubClientSID(GenlibClientSubscription * head,const UpnpString * sid)82 GenlibClientSubscription *GetClientSubClientSID(GenlibClientSubscription *head, const UpnpString *sid)
83 {
84 GenlibClientSubscription *next = head;
85 int found = 0;
86 while (next) {
87 found = !strcmp(
88 GenlibClientSubscription_get_SID_cstr(next),
89 UpnpString_get_String(sid));
90 if(found) {
91 break;
92 } else {
93 next = GenlibClientSubscription_get_Next(next);
94 }
95 }
96
97 return next;
98 }
99
100
GetClientSubActualSID(GenlibClientSubscription * head,token * sid)101 GenlibClientSubscription *GetClientSubActualSID(GenlibClientSubscription *head, token *sid)
102 {
103 GenlibClientSubscription *next = head;
104 while (next) {
105 if (!memcmp(
106 GenlibClientSubscription_get_ActualSID_cstr(next),
107 sid->buff, sid->size)) {
108 break;
109 } else {
110 next = GenlibClientSubscription_get_Next(next);
111 }
112 }
113
114 return next;
115 }
116
117
118 #endif /* INCLUDE_CLIENT_APIS */
119
120