Example #1
0
File: curi.c Project: Deanzou/DLNA
void cg_net_uri_rebuild(CgNetURI *uri)
{
	char portStr[32];
	char *path;
	
	cg_log_debug_l4("Entering...\n");

	cg_string_setvalue(uri->uri, cg_net_uri_getprotocol(uri));
	cg_string_addvalue(uri->uri, CG_NET_URI_PROTOCOL_DELIM);
	cg_string_addvalue(uri->uri, cg_net_uri_gethost(uri));
	cg_string_addvalue(uri->uri, CG_NET_URI_COLON_DELIM);
	cg_string_addvalue(uri->uri, cg_int2str(cg_net_uri_getport(uri), portStr, sizeof(portStr)));
	if (0 < cg_strlen(cg_net_uri_getpath(uri))) {
		path = cg_net_uri_getpath(uri);
		if (path[0] != '/')
			cg_string_addvalue(uri->uri, CG_NET_URI_SLASH_DELIM);
		cg_string_addvalue(uri->uri, cg_net_uri_getpath(uri));
		if (cg_strchr(cg_net_uri_getpath(uri), "?", 1) == -1 && 0 < cg_strlen(cg_net_uri_getquery(uri))) {
			cg_string_addvalue(uri->uri, CG_NET_URI_QUESTION_DELIM);
			cg_string_addvalue(uri->uri, cg_net_uri_getquery(uri));
		}
	}
	
	cg_log_debug_l4("Leaving...\n");
}
Example #2
0
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");
}
Example #3
0
void cg_http_packet_setheaderinteger(CgHttpPacket *httpPkt, const char* name, int value)
{
	char svalue[CG_STRING_INTEGER_BUFLEN];

	cg_log_debug_l4("Entering...\n");

	cg_http_packet_setheadervalue(httpPkt, name, cg_int2str(value, svalue, sizeof(svalue)));

	cg_log_debug_l4("Leaving...\n");
}
Example #4
0
void cg_string_setintvalue(CgString *str, int value)
{
	char buf[CG_STRING_INTEGER_BUFLEN];

	cg_log_debug_l5("Entering...\n");

	cg_string_setvalue(str, cg_int2str(value, buf, sizeof(buf)));

	cg_log_debug_l5("Leaving...\n");
}
Example #5
0
BOOL cg_bittorrent_propertymgr_setintegervalue(CgBittorrentPropertyMgr *propMgr, char *category, char *key, int value)
{
	char buf[CG_STRING_INTEGER_BUFLEN];

	if (!propMgr)
		return FALSE;

	if (!cg_int2str(value, buf, (sizeof(buf)-1)))
		return FALSE;

	return  cg_bittorrent_propertymgr_setstringvalue(propMgr, category, key, buf);
}
Example #6
0
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;
}