Ejemplo n.º 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;
}
Ejemplo n.º 2
0
CgHttpResponse *cg_http_request_post_main(CgHttpRequest *httpReq, char *ipaddr, int port, BOOL isSecure)
{
    CgSocket *sock;
    char *method, *uri, *version;
#ifdef CG_SHOW_TIMINGS
    struct timeval start_time, end_time, elapsed_time;
#endif
    CgString *firstLine;

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

#ifdef CG_SHOW_TIMINGS
    gettimeofday(&start_time, NULL);
#endif

    cg_http_response_clear(httpReq->httpRes);

    cg_log_debug_s("(HTTP) Posting:\n");
    cg_http_request_print(httpReq);

#if defined(CG_USE_OPENSSL)
    if (isSecure == FALSE)
        sock = cg_socket_stream_new();
    else
        sock = cg_socket_ssl_new();
#else
    sock = cg_socket_stream_new();
#endif

    cg_socket_settimeout(sock, cg_http_request_gettimeout(httpReq));
    if (cg_socket_connect(sock, ipaddr, port) == FALSE) {
        cg_socket_delete(sock);
        return httpReq->httpRes;
    }

    cg_http_request_sethost(httpReq, ipaddr, port);
    cg_http_packet_setheadervalue((CgHttpPacket*)httpReq, CG_HTTP_USERAGENT, cg_http_request_getuseragent(httpReq));

    method = cg_http_request_getmethod(httpReq);
    uri = cg_http_request_geturi(httpReq);
    version = cg_http_request_getversion(httpReq);

    if (method == NULL || uri == NULL || version == NULL) {
        cg_socket_close(sock);
        cg_socket_delete(sock);
        return httpReq->httpRes;
    }

#ifdef CG_SHOW_TIMINGS
    cg_log_debug_s("\nRequest: %s%s%s:%d%s%s%s\n", method, CG_HTTP_SP, ipaddr, port, uri, CG_HTTP_SP, version);
#endif
    /**** send first line ****/
    firstLine = cg_string_new();
    cg_string_addvalue(firstLine, method);
    cg_string_addvalue(firstLine, CG_HTTP_SP);
    cg_string_addvalue(firstLine, uri);
    cg_string_addvalue(firstLine, CG_HTTP_SP);
    cg_string_addvalue(firstLine, version);
    cg_string_addvalue(firstLine, CG_HTTP_CRLF);
    cg_socket_write(sock, cg_string_getvalue(firstLine), cg_string_length(firstLine));
    cg_string_delete(firstLine);

    /**** send header and content ****/
    cg_http_packet_post((CgHttpPacket *)httpReq, sock);

    /**** read response ****/
    cg_http_response_read(httpReq->httpRes, sock, cg_http_request_isheadrequest(httpReq));

#ifdef CG_SHOW_TIMINGS
    gettimeofday(&end_time, NULL);
    timersub(&end_time, &start_time, &elapsed_time);
    cg_log_debug_s("Getting HTTP-response completed. Elapsed time: "
                   "%ld msec\n", ((elapsed_time.tv_sec*1000) +
                                  (elapsed_time.tv_usec/1000)));
    cg_total_elapsed_time += (elapsed_time.tv_sec*1000000)+
                             (elapsed_time.tv_usec);
#endif
    cg_socket_close(sock);
    cg_socket_delete(sock);

    cg_http_response_print(httpReq->httpRes);

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

    return httpReq->httpRes;
}