char *cg_upnp_ssdpresponse_tostring(CgUpnpSSDPResponse *ssdpRes, CgString *ssdpMsg) { CgHttpHeader *header; char statusCodeBuf[CG_STRING_INTEGER_BUFLEN]; const char *name; const char *value; cg_log_debug_l4("Entering...\n"); cg_string_addvalue(ssdpMsg, cg_http_response_getversion(ssdpRes)); cg_string_addvalue(ssdpMsg, CG_HTTP_SP); cg_string_addvalue(ssdpMsg, cg_int2str(cg_http_response_getstatuscode(ssdpRes), statusCodeBuf, sizeof(statusCodeBuf))); cg_string_addvalue(ssdpMsg, CG_HTTP_SP); cg_string_addvalue(ssdpMsg, cg_http_response_getreasonphrase(ssdpRes)); cg_string_addvalue(ssdpMsg, CG_HTTP_CRLF); for (header = cg_http_packet_getheaders((CgHttpPacket *)ssdpRes); header != NULL; header = cg_http_header_next(header)) { name = cg_http_header_getname(header); value = cg_http_header_getvalue(header); cg_string_addvalue(ssdpMsg, name); cg_string_addvalue(ssdpMsg, CG_HTTP_COLON); cg_string_addvalue(ssdpMsg, CG_HTTP_SP); cg_string_addvalue(ssdpMsg, value); cg_string_addvalue(ssdpMsg, CG_HTTP_CRLF); } cg_string_addvalue(ssdpMsg, CG_HTTP_CRLF); return cg_string_getvalue(ssdpMsg); cg_log_debug_l4("Leaving...\n"); }
BOOL cg_http_request_postresponse(CgHttpRequest *httpReq, CgHttpResponse *httpRes) { CgSocket *sock; char httpDate[CG_HTTP_DATE_MAXLEN]; char *version, *reasonPhrase; int statusCode; char statusCodeBuf[CG_STRING_INTEGER_BUFLEN]; cg_log_debug_l4("Entering...\n"); sock = cg_http_request_getsocket(httpReq); cg_log_debug_s("Got request:\n"); cg_http_request_print(httpReq); cg_http_response_setdate(httpRes, cg_http_getdate(cg_getcurrentsystemtime(), httpDate, sizeof(httpDate))); version = cg_http_response_getversion(httpRes); statusCode = cg_http_response_getstatuscode(httpRes); reasonPhrase = cg_http_response_getreasonphrase(httpRes); if (version == NULL || reasonPhrase == NULL) return FALSE; cg_int2str(statusCode, statusCodeBuf, sizeof(statusCodeBuf)); /**** send first line ****/ cg_socket_write(sock, version, cg_strlen(version)); cg_socket_write(sock, CG_HTTP_SP, sizeof(CG_HTTP_SP)-1); cg_socket_write(sock, statusCodeBuf, cg_strlen(statusCodeBuf)); cg_socket_write(sock, CG_HTTP_SP, sizeof(CG_HTTP_SP)-1); cg_socket_write(sock, reasonPhrase, cg_strlen(reasonPhrase)); cg_socket_write(sock, CG_HTTP_CRLF, sizeof(CG_HTTP_CRLF)-1); cg_log_debug_s("Posting response:\n"); cg_http_response_print(httpRes); /**** send header and content ****/ cg_http_packet_post((CgHttpPacket *)httpRes, sock); cg_log_debug_l4("Leaving...\n"); return TRUE; }