コード例 #1
0
/****************************************
* 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;
}
コード例 #2
0
CgSoapRequest *cg_soap_request_new()
{
    CgSoapRequest *soapReq;

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

    soapReq = (CgSoapRequest *)malloc(sizeof(CgSoapRequest));

    if ( NULL != soapReq )
    {
        soapReq->rootNodeList = cg_xml_nodelist_new();
        soapReq->soapRes = cg_soap_response_new();

        soapReq->httpReq = cg_http_request_new();
        soapReq->isHttpReqCreated = TRUE;
        cg_http_request_setcontenttype(soapReq->httpReq, CG_SOAP_CONTENT_TYPE);
        cg_http_request_setmethod(soapReq->httpReq, CG_HTTP_POST);

        cg_soap_request_setuserdata(soapReq, NULL);
    }

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

    return soapReq;
}
コード例 #3
0
void cg_upnp_event_subscription_request_setunsubscription(CgUpnpSubscriptionRequest *subReq, CgUpnpService *service)
{
    cg_log_debug_l4("Entering...\n");

    cg_http_request_setmethod(subReq, CG_HTTP_UNSUBSCRIBE);
    cg_upnp_event_subscription_request_setservice(subReq, service);
    cg_upnp_event_subscription_request_setsid(subReq, cg_upnp_service_getsubscriptionsid(service));
    cg_log_debug_l4("Leaving...\n");
}
コード例 #4
0
void cg_upnp_event_subscription_request_setrenewsubscription(CgUpnpSubscriptionRequest *subReq, CgUpnpService *service, const char *uuid, CgTime timeout)
{
    cg_log_debug_l4("Entering...\n");

    cg_http_request_setmethod(subReq, CG_HTTP_SUBSCRIBE);
    cg_upnp_event_subscription_request_setservice(subReq, service);
    cg_upnp_event_subscription_request_setsid(subReq, uuid);
    cg_upnp_event_subscription_request_settimeout(subReq, timeout);
    cg_log_debug_l4("Leaving...\n");
}
コード例 #5
0
void cg_upnp_event_subscription_request_setnewsubscription(CgUpnpSubscriptionRequest *subReq, CgUpnpService *service, const char *callback, CgTime timeout)
{
    cg_log_debug_l4("Entering...\n");

    cg_http_request_setmethod(subReq, CG_HTTP_SUBSCRIBE);
    cg_upnp_event_subscription_request_setservice(subReq, service);
    cg_upnp_event_subscription_request_setcallback(subReq, callback);
    cg_upnp_event_subscription_request_setnt(subReq, CG_UPNP_NT_EVENT);
    cg_upnp_event_subscription_request_settimeout(subReq, timeout);
    cg_log_debug_l4("Leaving...\n");
}
コード例 #6
0
ファイル: chttp_request.c プロジェクト: dallasderk/DLNA
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");
}
コード例 #7
0
ファイル: chttp_request.c プロジェクト: dallasderk/DLNA
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");
}
コード例 #8
0
CgSoapResponse *cg_soap_request_post(CgSoapRequest *soapReq, const char *ipaddr, int port)
{
    CgHttpResponse *httpRes;
    char *content;
    size_t contentLen;
    CgXmlParser *xmlParser;
    CgHttpHeader *header = NULL;

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

    httpRes = cg_http_request_post(soapReq->httpReq, ipaddr, port);

    /* Check for HTTP response 405 Method Not Allowed */
    if (cg_http_response_getstatuscode(httpRes) == CG_HTTP_STATUS_METHOD_NOT_ALLOWED)
    {
        /* Status code implies that we need to use M-POST */
        cg_http_request_setmethod(soapReq->httpReq, CG_HTTP_MPOST);

        /* Add MAN header */
        header = cg_http_header_new();
        cg_http_header_setname(header, CG_HTTP_MAN);
        cg_http_header_setvalue(header, CG_HTTP_SOAP_MAN_VALUE);
        cg_http_packet_addheader((CgHttpPacket*)soapReq->httpReq, header);

        /* Change soapaction header name to include namespace */
        header = cg_http_packet_getheader((CgHttpPacket*)soapReq->httpReq,
                          CG_HTTP_SOAP_ACTION);
        if (header != NULL)
        {
            cg_http_header_setname(header, CG_HTTP_SOAP_ACTION_WITH_NS);
        }

        /* New attempt */
        httpRes = cg_http_request_post(soapReq->httpReq, ipaddr, port);
    }

    cg_soap_response_sethttpresponse(soapReq->soapRes,httpRes);

    content = cg_http_response_getcontent(httpRes);
    contentLen = cg_http_response_getcontentlength(httpRes);
    if (content == NULL || contentLen <= 0)
        return soapReq->soapRes;

    xmlParser = cg_xml_parser_new();
    cg_xml_parse(xmlParser, soapReq->soapRes->rootNodeList, content, contentLen);
    cg_xml_parser_delete(xmlParser);

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

    return soapReq->soapRes;
}
コード例 #9
0
void cg_soap_request_clear(CgSoapRequest *soapReq)
{
    cg_log_debug_l4("Entering...\n");

    cg_xml_nodelist_clear(soapReq->rootNodeList);

    if (soapReq->isHttpReqCreated == TRUE)
        cg_http_request_delete(soapReq->httpReq);

    soapReq->httpReq = cg_http_request_new();
    soapReq->isHttpReqCreated = TRUE;
    cg_http_request_setcontenttype(soapReq->httpReq, CG_SOAP_CONTENT_TYPE);
    cg_http_request_setmethod(soapReq->httpReq, CG_HTTP_POST);

    cg_log_debug_l4("Leaving...\n");
}
コード例 #10
0
ファイル: chttp_request.c プロジェクト: dallasderk/DLNA
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;
}