"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "upnpevents.c" between
minidlna-1.2.0.tar.gz and minidlna-1.2.1.tar.gz

About: ReadyMedia (formerly known as MiniDLNA) is a simple media server software, with the aim of being fully compliant with DLNA/UPnP-AV clients.

upnpevents.c  (minidlna-1.2.0):upnpevents.c  (minidlna-1.2.1)
skipping to change at line 86 skipping to change at line 86
struct upnp_event_notify * notify; struct upnp_event_notify * notify;
time_t timeout; time_t timeout;
uint32_t seq; uint32_t seq;
enum subscriber_service_enum service; enum subscriber_service_enum service;
char uuid[42]; char uuid[42];
char callback[]; char callback[];
}; };
struct upnp_event_notify { struct upnp_event_notify {
LIST_ENTRY(upnp_event_notify) entries; LIST_ENTRY(upnp_event_notify) entries;
int s; /* socket */ int s; /* socket */
enum { ECreated=1, enum { ECreated=1,
EConnecting, EConnecting,
ESending, ESending,
EWaitingForResponse, EWaitingForResponse,
EFinished, EFinished,
EError } state; EError } state;
struct subscriber * sub; struct subscriber * sub;
char * buffer; char * buffer;
int buffersize; int buffersize;
int tosend; int tosend;
int sent; int sent;
const char * path; const char * path;
char addrstr[16]; char addrstr[16];
char portstr[8]; char portstr[8];
}; };
/* prototypes */ /* prototypes */
static void static void
upnp_event_create_notify(struct subscriber * sub); upnp_event_create_notify(struct subscriber * sub);
/* Subscriber list */ /* Subscriber list */
LIST_HEAD(listhead, subscriber) subscriberlist = { NULL }; LIST_HEAD(listhead, subscriber) subscriberlist = { NULL };
/* notify list */ /* notify list */
LIST_HEAD(listheadnotif, upnp_event_notify) notifylist = { NULL }; LIST_HEAD(listheadnotif, upnp_event_notify) notifylist = { NULL };
#define MAX_SUBSCRIBERS 500
static uint16_t nsubscribers = 0;
/* create a new subscriber */ /* create a new subscriber */
static struct subscriber * static struct subscriber *
newSubscriber(const char * eventurl, const char * callback, int callbacklen) newSubscriber(const char * eventurl, const char * callback, int callbacklen)
{ {
struct subscriber * tmp; struct subscriber * tmp;
if(!eventurl || !callback || !callbacklen) if(!eventurl || !callback || !callbacklen)
return NULL; return NULL;
tmp = calloc(1, sizeof(struct subscriber)+callbacklen+1); tmp = calloc(1, sizeof(struct subscriber)+callbacklen+1);
if(strcmp(eventurl, CONTENTDIRECTORY_EVENTURL)==0) if(strcmp(eventurl, CONTENTDIRECTORY_EVENTURL)==0)
tmp->service = EContentDirectory; tmp->service = EContentDirectory;
skipping to change at line 154 skipping to change at line 157
/* creates a new subscriber and adds it to the subscriber list /* creates a new subscriber and adds it to the subscriber list
* also initiate 1st notify */ * also initiate 1st notify */
const char * const char *
upnpevents_addSubscriber(const char * eventurl, upnpevents_addSubscriber(const char * eventurl,
const char * callback, int callbacklen, const char * callback, int callbacklen,
int timeout) int timeout)
{ {
struct subscriber * tmp; struct subscriber * tmp;
DPRINTF(E_DEBUG, L_HTTP, "addSubscriber(%s, %.*s, %d)\n", DPRINTF(E_DEBUG, L_HTTP, "addSubscriber(%s, %.*s, %d)\n",
eventurl, callbacklen, callback, timeout); eventurl, callbacklen, callback, timeout);
if (nsubscribers >= MAX_SUBSCRIBERS)
return NULL;
tmp = newSubscriber(eventurl, callback, callbacklen); tmp = newSubscriber(eventurl, callback, callbacklen);
if(!tmp) if(!tmp)
return NULL; return NULL;
if(timeout) if(timeout)
tmp->timeout = time(NULL) + timeout; tmp->timeout = time(NULL) + timeout;
LIST_INSERT_HEAD(&subscriberlist, tmp, entries); LIST_INSERT_HEAD(&subscriberlist, tmp, entries);
nsubscribers++;
upnp_event_create_notify(tmp); upnp_event_create_notify(tmp);
return tmp->uuid; return tmp->uuid;
} }
/* renew a subscription (update the timeout) */ /* renew a subscription (update the timeout) */
int int
renewSubscription(const char * sid, int sidlen, int timeout) renewSubscription(const char * sid, int sidlen, int timeout)
{ {
struct subscriber * sub; struct subscriber * sub;
for(sub = subscriberlist.lh_first; sub != NULL; sub = sub->entries.le_nex t) { for(sub = subscriberlist.lh_first; sub != NULL; sub = sub->entries.le_nex t) {
skipping to change at line 192 skipping to change at line 198
if(!sid) if(!sid)
return -1; return -1;
DPRINTF(E_DEBUG, L_HTTP, "removeSubscriber(%.*s)\n", DPRINTF(E_DEBUG, L_HTTP, "removeSubscriber(%.*s)\n",
sidlen, sid); sidlen, sid);
for(sub = subscriberlist.lh_first; sub != NULL; sub = sub->entries.le_nex t) { for(sub = subscriberlist.lh_first; sub != NULL; sub = sub->entries.le_nex t) {
if(memcmp(sid, sub->uuid, 41) == 0) { if(memcmp(sid, sub->uuid, 41) == 0) {
if(sub->notify) { if(sub->notify) {
sub->notify->sub = NULL; sub->notify->sub = NULL;
} }
LIST_REMOVE(sub, entries); LIST_REMOVE(sub, entries);
nsubscribers--;
free(sub); free(sub);
return 0; return 0;
} }
} }
return -1; return -1;
} }
void void
upnpevents_removeSubscribers(void) upnpevents_removeSubscribers(void)
{ {
skipping to change at line 471 skipping to change at line 478
} }
obj = notifylist.lh_first; obj = notifylist.lh_first;
while(obj != NULL) { while(obj != NULL) {
next = obj->entries.le_next; next = obj->entries.le_next;
if(obj->state == EError || obj->state == EFinished) { if(obj->state == EError || obj->state == EFinished) {
if(obj->s >= 0) { if(obj->s >= 0) {
close(obj->s); close(obj->s);
} }
if(obj->sub) if(obj->sub)
obj->sub->notify = NULL; obj->sub->notify = NULL;
#if 0 /* Just let it time out instead of explicitly removing the subscriber */
/* remove also the subscriber from the list if there was an error */ /* remove also the subscriber from the list if there was an error */
if(obj->state == EError && obj->sub) { if(obj->state == EError && obj->sub) {
LIST_REMOVE(obj->sub, entries); LIST_REMOVE(obj->sub, entries);
nsubscribers--;
free(obj->sub); free(obj->sub);
} }
#endif
free(obj->buffer); free(obj->buffer);
LIST_REMOVE(obj, entries); LIST_REMOVE(obj, entries);
free(obj); free(obj);
} }
obj = next; obj = next;
} }
/* remove timeouted subscribers */ /* remove timed-out subscribers */
curtime = time(NULL); curtime = time(NULL);
for(sub = subscriberlist.lh_first; sub != NULL; ) { for(sub = subscriberlist.lh_first; sub != NULL; ) {
subnext = sub->entries.le_next; subnext = sub->entries.le_next;
if(sub->timeout && curtime > sub->timeout && sub->notify == NULL) { if(sub->timeout && curtime > sub->timeout && sub->notify == NULL) {
LIST_REMOVE(sub, entries); LIST_REMOVE(sub, entries);
nsubscribers--;
free(sub); free(sub);
} }
sub = subnext; sub = subnext;
} }
} }
 End of changes. 12 change blocks. 
9 lines changed or deleted 16 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)