From 3ae378cdc9362eeaf57536e1afd20d6d31151934 Mon Sep 17 00:00:00 2001 From: Justin Maggard Date: Mon, 9 Mar 2009 20:53:21 +0000 Subject: [PATCH] * Treat an empty Filter argument as "*". * Make sure we allocate enough memory to hold SourceProtocolInfo response data. --- upnpevents.c | 9 +++------ upnpsoap.c | 25 ++++++------------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/upnpevents.c b/upnpevents.c index ad9d2ab..af5d8ab 100644 --- a/upnpevents.c +++ b/upnpevents.c @@ -297,19 +297,16 @@ static void upnp_event_prepare(struct upnp_event_notify * obj) xml = NULL; l = 0; } - obj->buffersize = 2048; - obj->buffer = malloc(obj->buffersize); - /*if(!obj->buffer) { - }*/ - obj->tosend = snprintf(obj->buffer, obj->buffersize, notifymsg, + obj->tosend = asprintf(&(obj->buffer), notifymsg, obj->path, obj->addrstr, obj->portstr, l+2, obj->sub->uuid, obj->sub->seq, l, xml); + obj->buffersize = obj->tosend; if(xml) { free(xml); xml = NULL; } - //DEBUG printf("Preparing buffer:\n%s\n", obj->buffer); + DPRINTF(E_DEBUG, L_HTTP, "Sending UPnP Event response:\n%s\n", obj->buffer); obj->state = ESending; } diff --git a/upnpsoap.c b/upnpsoap.c index 09abc80..d502d61 100644 --- a/upnpsoap.c +++ b/upnpsoap.c @@ -112,11 +112,10 @@ GetProtocolInfo(struct upnphttp * h, const char * action) "" ""; - - char body[1536]; + char * body; int bodylen; - bodylen = snprintf(body, sizeof(body), resp, + bodylen = asprintf(&body, resp, action, "urn:schemas-upnp-org:service:ConnectionManager:1", action); BuildSendAndCloseSoapResp(h, body, bodylen); @@ -431,7 +430,7 @@ BrowseContentDirectory(struct upnphttp * h, const char * action) memset(&args, 0, sizeof(args)); strcpy(resp, resp0); /* See if we need to include DLNA namespace reference */ - if( (strlen(Filter) <= 1) || strstr(Filter, "dlna") ) + if( Filter && ((strlen(Filter) <= 1) || strstr(Filter, "dlna")) ) strcat(resp, DLNA_NAMESPACE); strcat(resp, ">\n"); @@ -460,13 +459,7 @@ BrowseContentDirectory(struct upnphttp * h, const char * action) ObjectId, RequestedCount, StartingIndex, BrowseFlag, Filter, SortCriteria); - if( !Filter ) - { - ClearNameValueList(&data); - SoapError(h, 402, "Invalid Args"); - return; - } - if( strlen(Filter) > 1 ) + if( Filter && (strlen(Filter) > 1) ) args.filter = Filter; args.resp = resp; @@ -566,17 +559,11 @@ SearchContentDirectory(struct upnphttp * h, const char * action) strcpy(resp, resp0); /* See if we need to include DLNA namespace reference */ - if( (strlen(Filter) <= 1) || strstr(Filter, "dlna") ) + if( Filter && ((strlen(Filter) <= 1) || strstr(Filter, "dlna")) ) strcat(resp, DLNA_NAMESPACE); strcat(resp, ">\n"); - if( !Filter ) - { - ClearNameValueList(&data); - SoapError(h, 402, "Invalid Args"); - return; - } - if( strlen(Filter) > 1 ) + if( Filter && (strlen(Filter) > 1) ) args.filter = Filter; if( strcmp(ContainerID, "0") == 0 ) *ContainerID = '*';