Exemplo n.º 1
0
static void SpecVersion(HTTP_STREAM *stream)
{
    s_puts("<specVersion>\r\n", stream);
    s_puts("<major>1</major>\r\n", stream);
    s_puts("<minor>0</minor>\r\n", stream);
    s_puts("</specVersion>\r\n", stream);
}
Exemplo n.º 2
0
static void XmlHead(HTTP_STREAM *stream)
{
    HttpSendStreamHeaderTop(stream, 200);
    s_puts("SERVER: NutOS/5.0 UPnP/1.0 TestUPnP/1.0\r\n", stream);
    HttpSendStreamHeaderBottom(stream, "text", "xml", HTTP_CONN_CLOSE, -1);
    s_puts("<?xml version=\"1.0\"?>\r\n", stream);
}
Exemplo n.º 3
0
static int CgiClock(HTTPD_SESSION *hs)
{
    time_t now;
    const struct tm *ltm;

#if defined(NUT_OS)
    NutSleep(1000);
#elif defined(_WIN32)
    Sleep(1000);
#else
#warning Unknown OS, sleep missing
#endif

    HttpSendHeaderTop(hs, 200);
    s_puts("Cache-Control: no-cache, must-revalidate\r\n", hs->s_stream);
    s_puts("Content-Type: text/html; charset=iso-8859-1\r\n", hs->s_stream);
    s_puts("Expires: Mon, 26 Jul 1997 05:00:00 GMT\r\n", hs->s_stream);
    chprintf((BaseSequentialStream *)&itm_port, "%s\n", "****CgiClock****");
    HttpSendHeaderBottom(hs, "text", "html", -1);

    time(&now);
    ltm = localtime(&now);
    s_printf(hs->s_stream, "{\"time\": \"%02d:%02d:%02d\"}\r\n", ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
    s_flush(hs->s_stream);

    return 0;
}
Exemplo n.º 4
0
/*!
 * \brief Send device description.
 *
 * This uHTTP CGI function will be registered when UpnpRegisterDeviceTree()
 * is called for the first time.
 */
static int UpnpCgiDeviceDescription(HTTPD_SESSION *hs)
{
    HTTP_STREAM *stream = hs->s_stream;
    SSDP_DEVICE *sdev = NULL;
    SSDP_SERVICE *ssvc;
    char *type;

    type = HttpArgParseFirst(&hs->s_req);
    if (type) {
        for (sdev = device_registration; sdev; sdev = sdev->sdev_next) {
            if (strcmp(sdev->sdev_type, type) == 0) {
                break;
            }
        }
    }
    if (sdev) {
        UPNP_DEVICE_INFO *udev = sdev->sdev_info;

        XmlHead(hs->s_stream);
        s_puts("<root xmlns=\"urn:schemas-upnp-org:device-1-0\">\r\n", hs->s_stream);
        SpecVersion(stream);

        s_puts("<device>\r\n", stream);
        s_printf(stream, "<deviceType>urn:%s:device:%s:1</deviceType>\r\n", sdev->sdev_domain, sdev->sdev_type);
        WriteTag(stream, "friendlyName", udev->udev_name);
        WriteTag(stream, "manufacturer", udev->udev_mnf->umnf_name);
        WritePrepTag(stream, "manufacturerURL", udev->udev_mnf->umnf_url, "http://");
        WriteTag(stream, "modelDescription", udev->udev_mdl->umdl_desc);
        WriteTag(stream, "modelName", udev->udev_mdl->umdl_name);
        WriteTag(stream, "modelNumber", udev->udev_mdl->umdl_num);
        WritePrepTag(stream, "modelURL", udev->udev_mdl->umdl_url, "http://");
        WriteTag(stream, "UDN", sdev->sdev_uuid);
        if (sdev->sdev_svc) {
            s_puts("<serviceList>\r\n", stream);
            for (ssvc = sdev->sdev_svc; ssvc; ssvc = ssvc->ssvc_next) {
                UPNP_SERVICE_INFO *usvc = sdev->sdev_svc->ssvc_info;

                s_puts("<service>\r\n", stream);
                s_printf(stream, "<serviceType>urn:schemas-upnp-org:service:%s:1</serviceType>\r\n", sdev->sdev_svc->ssvc_type);
                s_printf(stream, "<serviceId>urn:upnp-org:serviceId:%s:1</serviceId>\r\n", sdev->sdev_svc->ssvc_type);
                s_printf(stream, "<SCPDURL>%s?%s=%s</SCPDURL>", usvc->usvc_url_scpd, sdev->sdev_type, ssvc->ssvc_type);
                s_printf(stream, "<controlURL>%s?%s=%s</controlURL>", usvc->usvc_url_ctrl, sdev->sdev_type, ssvc->ssvc_type);
                s_printf(stream, "<eventSubURL>%s?%s=%s</eventSubURL>", usvc->usvc_url_event, sdev->sdev_type, ssvc->ssvc_type);
                s_puts("</service>\r\n", stream);
            }
            s_puts("</serviceList>\r\n", stream);
        }
        WriteTag(stream, "presentationURL", udev->udev_presentation);
        s_puts("</device>\r\n", stream);
        s_puts("</root>\r\n", stream);
    }
    s_flush(stream);

    return 0;
}
Exemplo n.º 5
0
void
u_put_server(
	const char *string)
{
	s_puts(string, nntp_wr_fp);
#		ifdef DEBUG
	debug_nntp(">>>", string);
#		endif /* DEBUG */
}
Exemplo n.º 6
0
/*
 * Send 'string' to the NNTP server, terminating it with CR and LF, as per
 * ARPA standard.
 *
 * Returns: Nothing.
 *
 *	Side effects: Talks to the server.
 *			Closes connection if things are not right.
 *
 * Note: This routine flushes the buffer each time it is called. For large
 *	      transmissions (i.e., posting news) don't use it. Instead, do the
 *	      fprintf's yourself, and then a final fflush.
 *       Only cache commands, don't cache data transmissions.
 *
 */
void
put_server(
	const char *string)
{
	if (*string && strlen(string)) {
		DEBUG_IO((stderr, "put_server(%s)\n", string));
		s_puts(string, nntp_wr_fp);
		s_puts("\r\n", nntp_wr_fp);
#		ifdef DEBUG
		debug_nntp(">>>", string);
#		endif /* DEBUG */
		/*
		 * remember the last command we wrote to be able to resend it after a
		 * reconnect. reconnection is handled by get_server()
		 */
		strcpy(last_put, string);
	}
	(void) s_flush(nntp_wr_fp);
}
Exemplo n.º 7
0
static void WritePrepTag(HTTP_STREAM *stream, const char *tag, const char *val, const char *prepend)
{
    if (val) {
        s_printf(stream, "<%s>", tag);
        if (prepend && *val == '+') {
            val++;
            s_puts(prepend, stream);
        }
        s_printf(stream, "%s</%s>\r\n", val, tag);
    }
}
Exemplo n.º 8
0
void HttpSendStreamHeaderBottom(HTTP_STREAM *stream, char *type, char *subtype, int conn, long bytes)
{
#if HTTP_VERSION >= 0x10
    if (type && subtype) {
        s_vputs(stream, ct_Content_Type, ": ", type, "/", subtype, "\r\n", NULL);
    }
    if (bytes >= 0) {
        s_printf(stream, "%s: %ld\r\n", ct_Content_Length, bytes);
    }
#if HTTP_VERSION >= 0x11
#if HTTP_KEEP_ALIVE_REQ
    if (conn != HTTP_CONN_KEEP_ALIVE)
#endif
    {
        s_puts("Connection: close\r\n", stream);
    }
#elif HTTP_KEEP_ALIVE_REQ
    if (conn == HTTP_CONN_KEEP_ALIVE) {
        s_puts("Connection: keep-alive\r\n", stream);
    }
#endif
    s_puts("\r\n", stream);
#endif
}
Exemplo n.º 9
0
void HttpSendHeaderBottom(HTTPD_SESSION *hs, char *type, char *subtype, long bytes)
{
#if HTTP_VERSION >= 0x10

#if HTTP_KEEP_ALIVE_REQ
    if (bytes < 0) {
        hs->s_req.req_connection = HTTP_CONN_CLOSE;
    }
#endif
#if 0
#define GZIP_ID  0x8b1f
    if (first2bytes == GZIP_ID) {
        s_puts("Content-Encoding: gzip\r\n", hs->s_stream);
    }
#endif
    HttpSendStreamHeaderBottom(hs->s_stream, type, subtype, hs->s_req.req_connection, bytes);
#endif
}
Exemplo n.º 10
0
static int SendResult(HTTPD_SESSION *hs, char *first, char *last)
{
    static const char head[] =
        "<html>"
        "<head>"
        "<title>Form Result</title>"
        "</head>";
    static const char body[] =
        "<body>"
        "<p>Hello %s %s!</p>"
        "<a href=\"/index.html\">back</a>"
        "</body>"
        "<html>";

    HttpSendHeaderTop(hs, 200);
    HttpSendHeaderBottom(hs, "text", "html", -1);

    s_puts(head, hs->s_stream);
    s_printf(hs->s_stream, body, first, last);
    s_flush(hs->s_stream);

    return 0;
}
Exemplo n.º 11
0
/*!
 * \brief Send service description.
 *
 * This uHTTP CGI function will be registered when UpnpRegisterDeviceTree()
 * is called for the first time.
 */
static int UpnpCgiServiceDescription(HTTPD_SESSION *hs)
{
    SSDP_SERVICE *ssvc = NULL;
    SSDP_DEVICE *sdev = NULL;
    HTTP_STREAM *stream = hs->s_stream;
    const char *dev_type;

    dev_type = HttpArgParseFirst(&hs->s_req);
    if (dev_type) {
        const char *svc_type = HttpArgValue(&hs->s_req);

        if (dev_type) {
            for (sdev = device_registration; sdev; sdev = sdev->sdev_next) {
                if (strcmp(sdev->sdev_type, dev_type) == 0) {
                    for (ssvc = sdev->sdev_svc; ssvc; ssvc = ssvc->ssvc_next) {
                        if (strcmp(ssvc->ssvc_type, svc_type) == 0) {
                            break;
                        }
                    }
                    break;
                }
            }
        }
    }
    if (ssvc) {
        SOAP_PROCEDURE *act;
        UPNP_VARIABLE *stv;
        UPNP_SERVICE_INFO *usvc = ssvc->ssvc_info;

        XmlHead(hs->s_stream);
        s_puts("<scpd xmlns=\"urn:schemas-upnp-org:service-1-0\">\r\n", stream);
        SpecVersion(stream);

        act = usvc->usvc_proc;
        if (act) {
            s_puts("<actionList>\r\n", stream);
            do {
                s_puts("<action>\r\n", stream);
                WriteTag(stream, "name", act->proc_name);
                if (act->proc_argi || act->proc_argo) {
                    SOAP_ARG *arg;

                    s_puts("<argumentList>\r\n", stream);
                    for (arg = act->proc_argi; arg; arg = arg->arg_next) {
                        s_puts("<argument>\r\n", stream);
                        WriteTag(stream, "name", arg->arg_name);
                        WriteTag(stream, "relatedStateVariable", ((UPNP_VARIABLE *) arg->arg_info)->ustv_name);
                        WriteTag(stream, "direction", "in");
                        s_puts("</argument>\r\n", stream);
                    }
                    for (arg = act->proc_argo; arg; arg = (SOAP_ARG *) arg->arg_next) {
                        s_puts("<argument>\r\n", stream);
                        WriteTag(stream, "name", arg->arg_name);
                        WriteTag(stream, "relatedStateVariable", ((UPNP_VARIABLE *) arg->arg_info)->ustv_name);
                        WriteTag(stream, "direction", "out");
                        s_puts("</argument>\r\n", stream);
                    }
                    s_puts("</argumentList>\r\n", stream);
                }
                s_puts("</action>\r\n", stream);
            } while ((act = act->proc_next) != NULL);
            s_puts("</actionList>\r\n", stream);
        }

        stv = usvc->usvc_stv;
        if (stv) {
            s_puts("<serviceStateTable>\r\n", stream);
            do {
                s_printf(stream, "<stateVariable sendEvents=\"%s\">\r\n", stv->ustv_events ? "yes" : "no");
                WriteTag(stream, "name", stv->ustv_name);
                WriteTag(stream, "dataType", UpnpVarTypeString(stv->ustv_type));
                WriteTag(stream, "defaultValue", stv->ustv_default);
                s_puts("</stateVariable>\r\n", stream);
            } while((stv = stv->ustv_next) != NULL);
            s_puts("</serviceStateTable>\r\n", stream);
        }
        s_puts("</scpd>\r\n", stream);
    }
    s_flush(stream);

    return 0;
}