char *mupnp_ssdprequest_tostring(mUpnpSSDPRequest *ssdpReq, mUpnpString *ssdpMsg) { mUpnpHttpHeader *header; const char *name; const char *value; mupnp_log_debug_l4("Entering...\n"); mupnp_string_addvalue(ssdpMsg, mupnp_http_request_getmethod(ssdpReq)); mupnp_string_addvalue(ssdpMsg, MUPNP_HTTP_SP); mupnp_string_addvalue(ssdpMsg, mupnp_http_request_geturi(ssdpReq)); mupnp_string_addvalue(ssdpMsg, MUPNP_HTTP_SP); mupnp_string_addvalue(ssdpMsg, mupnp_http_request_getversion(ssdpReq)); mupnp_string_addvalue(ssdpMsg, MUPNP_HTTP_CRLF); for (header = mupnp_http_packet_getheaders((mUpnpHttpPacket *)ssdpReq); header != NULL; header = mupnp_http_header_next(header)) { name = mupnp_http_header_getname(header); value = mupnp_http_header_getvalue(header); mupnp_string_addvalue(ssdpMsg, name); mupnp_string_addvalue(ssdpMsg, MUPNP_HTTP_COLON); mupnp_string_addvalue(ssdpMsg, MUPNP_HTTP_SP); mupnp_string_addvalue(ssdpMsg, value); mupnp_string_addvalue(ssdpMsg, MUPNP_HTTP_CRLF); } mupnp_string_addvalue(ssdpMsg, MUPNP_HTTP_CRLF); return mupnp_string_getvalue(ssdpMsg); mupnp_log_debug_l4("Leaving...\n"); }
bool round_upnp_server_isrootrequest(mUpnpHttpRequest* httpReq) { if (!mupnp_http_request_isgetrequest(httpReq)) return false; char* uri = mupnp_http_request_geturi(httpReq); if (!round_streq(uri, "/")) return false; return true; }
bool round_upnp_server_isjsonrpcrequest(mUpnpHttpRequest* httpReq) { if (!mupnp_http_request_ispostrequest(httpReq)) return false; char* uri = mupnp_http_request_geturi(httpReq); if (!round_streq(uri, ROUND_RPC_HTTP_ENDPOINT)) return false; // TODO : Check content type return true; }
void upnp_clock_device_httprequestrecieved(mUpnpHttpRequest *httpReq) { mUpnpTime currTime; mUpnpDevice *dev; char *uri; char content[2048]; char sysTimeStr[SYSTEM_TIME_BUF_LEN]; char serverName[MUPNP_SEVERNAME_MAXLEN]; mUpnpHttpResponse *httpRes; BOOL postRet; dev = (mUpnpDevice *)mupnp_http_request_getuserdata(httpReq); uri = mupnp_http_request_geturi(httpReq); if (strcmp(uri, "/presentation") != 0) { mupnp_device_httprequestrecieved(httpReq); return; } currTime = mupnp_getcurrentsystemtime(); #if defined(HAVE_SNPRINTF) snprintf(content, sizeof(content), #else sprintf(content, #endif "<HTML>" "<HEAD>" "<TITLE>UPnP Clock Sample</TITLE>" "</HEAD>" "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=/presentation\">" "<BODY><CENTER>" "<H1>UPnP Clock Sample</H1>" "<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" "<TR>" "<TD style=\"width: 50px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>" "<TD style=\"background-color: rgb(176, 176, 176);\"></TD>" "<TD style=\"width: 50px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>" "</TR>" "<TR>" "<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>" "<TD style=\"height: 50px; background-color: rgb(221, 236, 245);\" align=\"center\"><H1>" "%s" "</H1></TD>" "<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>" "</TR>" "<TR>" "<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>" "<TD style=\"height: 50px; background-color: rgb(221, 236, 245);\" align=\"center\"><H3>" "Server : %s" "</H3></TD>" "<TD style=\"height: 30px; background-color: rgb(176, 176, 176);\"></TD>" "</TR>" "<TR>" "<TD style=\"width: 30px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>" "<TD style=\"background-color: rgb(176, 176, 176);\"></TD>" "<TD style=\"width: 30px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>" "</TR>" "</TABLE>" "<CENTER></BODY>" "</HTML>", GetSystemTimeString(currTime, sysTimeStr), mupnp_getservername(serverName, sizeof(serverName))); httpRes = mupnp_http_response_new(); mupnp_http_response_setstatuscode(httpRes, CG_HTTP_STATUS_OK); mupnp_http_response_setcontent(httpRes, content); mupnp_http_response_setcontenttype(httpRes, "text/html"); mupnp_http_response_setcontentlength(httpRes, strlen(content)); postRet = mupnp_http_request_postresponse(httpReq, httpRes); mupnp_http_response_delete(httpRes); }