void cg_upnp_control_request_sethostfromservice(CgSoapRequest *soapReq, CgUpnpService *service) { CgHttpRequest *httpReq; CgNetURL *ctrlURL; cg_log_debug_l4("Entering...\n"); httpReq = cg_soap_request_gethttprequest(soapReq); ctrlURL = cg_upnp_service_getcontrolurl(service); cg_log_debug_s("Ctrl URL: %s - %d -%s", cg_net_url_gethost(ctrlURL), cg_net_url_getport(ctrlURL), cg_net_url_getpath(ctrlURL)); //cg_http_request_seturi(httpReq, cg_xml_node_getchildnodevalue(cg_upnp_service_getservicenode(service), CG_UPNP_SERVICE_CONTROL_URL)); cg_http_request_seturi(httpReq, cg_net_url_getrequest(ctrlURL)); /**** Host ****/ cg_net_url_delete(httpReq->postURL); httpReq->postURL = ctrlURL; cg_log_debug_s("Post URL: %s - %d -%s", cg_net_url_gethost(httpReq->postURL), cg_net_url_getport(httpReq->postURL), cg_net_url_getpath(httpReq->postURL)); cg_log_debug_l4("Leaving...\n"); }
/**************************************** * cg_upnp_event_notify_request_setpropertysetnode ****************************************/ BOOL cg_upnp_event_notify_request_setpropertysetnode(CgUpnpNotifyRequest *notifyReq, CgUpnpSubscriber *sub, /* CgUpnpService */void *pservice, CgUpnpStateVariable *statVar) { CgHttpRequest *httpReq; CgXmlNode *propSetNode; CgUpnpService* service; char server[CG_UPNP_SEVERNAME_MAXLEN]; cg_log_debug_l4("Entering...\n"); service = (CgUpnpService *)pservice; httpReq = cg_soap_request_gethttprequest(notifyReq); cg_http_request_setmethod(httpReq, CG_HTTP_NOTIFY); cg_http_request_setconnection(httpReq, CG_HTTP_CLOSE); cg_http_request_seturi(httpReq, cg_upnp_subscriber_getdeliverypath(sub)); cg_http_request_sethost(httpReq, cg_upnp_subscriber_getdeliveryhost(sub), cg_upnp_subscriber_getdeliveryport(sub)); cg_upnp_getservername(server, sizeof(server)); cg_http_packet_setheadervalue((CgHttpPacket*)httpReq, CG_HTTP_SERVER, server); cg_upnp_event_notify_request_setnt(notifyReq, CG_UPNP_NT_EVENT); cg_upnp_event_notify_request_setnts(notifyReq, CG_UPNP_NTS_PROPCHANGE); cg_upnp_event_notify_request_setsid(notifyReq, cg_upnp_subscriber_getsid(sub)); cg_upnp_event_notify_request_setseq(notifyReq, cg_upnp_subscriber_getnotifycount(sub)); propSetNode = cg_upnp_event_notify_request_createpropertysetnode(service, statVar); cg_soap_request_setcontent(notifyReq, propSetNode); cg_xml_node_delete(propSetNode); cg_log_debug_l4("Leaving...\n"); return TRUE; }
void cg_http_request_copy(CgHttpRequest *destHttpReq, CgHttpRequest *srcHttpReq) { cg_log_debug_l4("Entering...\n"); cg_http_request_setmethod(destHttpReq, cg_http_request_getmethod(srcHttpReq)); cg_http_request_seturi(destHttpReq, cg_http_request_geturi(srcHttpReq)); cg_http_request_setversion(destHttpReq, cg_http_request_getversion(srcHttpReq)); cg_http_packet_copy((CgHttpPacket *)destHttpReq, (CgHttpPacket *)srcHttpReq); cg_log_debug_l4("Leaving...\n"); }
void cg_http_request_clear(CgHttpRequest *httpReq) { cg_log_debug_l4("Entering...\n"); cg_http_packet_clear((CgHttpPacket *)httpReq); cg_http_request_setmethod(httpReq, NULL); cg_http_request_seturi(httpReq, NULL); cg_http_request_setversion(httpReq, NULL); cg_net_url_clear(httpReq->postURL); cg_http_request_setuserdata(httpReq, NULL); cg_log_debug_l4("Leaving...\n"); }
static void cg_upnp_event_subscription_request_setservice(CgUpnpSubscriptionRequest *subReq, CgUpnpService *service) { CgNetURL *eventSubURL; cg_log_debug_l4("Entering...\n"); eventSubURL = cg_upnp_service_geteventsuburl(service); cg_http_request_seturi(subReq, cg_net_url_getrequest(eventSubURL)); cg_net_url_delete(subReq->postURL); subReq->postURL = eventSubURL; cg_log_debug_l4("Leaving...\n"); }
CgUpnpSSDPRequest *cg_upnp_ssdprequest_new() { CgUpnpSSDPRequest *ssdpReq; cg_log_debug_l4("Entering...\n"); ssdpReq = cg_http_request_new(); cg_http_request_seturi(ssdpReq, "*"); cg_http_request_setversion(ssdpReq, CG_HTTP_VER11); cg_http_request_setcontentlength(ssdpReq, 0); cg_log_debug_l4("Leaving...\n"); return ssdpReq; }
BOOL cg_http_request_read(CgHttpRequest *httpReq, CgSocket *sock) { char lineBuf[CG_HTTP_READLINE_BUFSIZE]; CgStringTokenizer *strTok; int readLen; CgNetURI *uri = NULL; BOOL failed = FALSE; cg_log_debug_l4("Entering...\n"); cg_http_request_clear(httpReq); /* If first character(s) is \n or \r\n we ignore it(them) and read second line. */ do { readLen = cg_socket_readline(sock, lineBuf, sizeof(lineBuf)); } while (readLen >= 1 && readLen <=2); if (readLen <= 0) return FALSE; strTok = cg_string_tokenizer_new(lineBuf, CG_HTTP_STATUSLINE_DELIM); if (cg_string_tokenizer_hasmoretoken(strTok) == TRUE) cg_http_request_setmethod(httpReq, cg_string_tokenizer_nexttoken(strTok)); else failed = TRUE; if (cg_string_tokenizer_hasmoretoken(strTok) == TRUE) cg_http_request_seturi(httpReq, cg_string_tokenizer_nexttoken(strTok)); else failed = TRUE; if (cg_string_tokenizer_hasmoretoken(strTok) == TRUE) cg_http_request_setversion(httpReq, cg_string_tokenizer_nexttoken(strTok)); else failed = TRUE; cg_string_tokenizer_delete(strTok); if (failed == TRUE) return FALSE; /* We could do some further validation for the HTTP-request? */ /* Change URI to be relative (absolute not needed anymore) */ uri = cg_net_uri_new(); if (uri != NULL) { cg_net_uri_set(uri, cg_http_request_geturi(httpReq)); if (cg_net_uri_isabsolute(uri) == TRUE && cg_net_uri_getrequest(uri) != NULL) { cg_http_request_seturi(httpReq, cg_net_uri_getrequest(uri)); } cg_net_uri_delete(uri); uri = NULL; } /* Read headers */ cg_http_packet_clear((CgHttpPacket *)httpReq); cg_http_packet_read_headers((CgHttpPacket *)httpReq, sock, lineBuf, sizeof(lineBuf)); /* HTTP-request must have Content-Length or Transfer-Encoding header in order to have body */ if (cg_http_packet_hasheader((CgHttpPacket *)httpReq, CG_HTTP_CONTENT_LENGTH) || cg_http_packet_hasheader((CgHttpPacket *)httpReq, CG_HTTP_TRANSFER_ENCODING)) cg_http_packet_read_body((CgHttpPacket *)httpReq, sock, lineBuf, sizeof(lineBuf)); cg_log_debug_l4("Leaving...\n"); return TRUE; }