コード例 #1
0
ファイル: httpserv.c プロジェクト: niziak/ethernut-4.9
/*
 * CGI Sample: Dynamic output cgi included by ssi.shtml file
 *
 * This routine must have been registered by NutRegisterCgi() and is
 * automatically called by NutHttpProcessRequest() when the client
 * request the URL 'cgi-bin/form.cgi'.
 *
 * Thanks to Tom Boettger, who provided this sample for ICCAVR.
 */
int SSIDemoCGI(FILE * stream, REQUEST * req)
{
    if (req->req_query) {
        char *name;
        char *value;
        int i;
        int count;

        count = NutHttpGetParameterCount(req);
        
        /* Extract count parameters. */
#ifdef __IMAGECRAFT__        
        fprintf(stream, "CGI ssi-demo.cgi called with parameters: These are the parameters\r\n<p>");
#else
        fprintf_P(stream, PSTR("CGI ssi-demo.cgi called with parameters: These are the parameters\r\n<p>"));
#endif
        for (i = 0; i < count; i++) {
            name = NutHttpGetParameterName(req, i);
            value = NutHttpGetParameterValue(req, i);

            /* Send the parameters back to the client. */

#ifdef __IMAGECRAFT__
            fprintf(stream, "%s: %s<BR>\r\n", name, value);
#else
            fprintf_P(stream, PSTR("%s: %s<BR>\r\n"), name, value);
#endif
        }
    } else {
        time_t now;
        tm     loc_time;
        
        /* Called without any parameter, show the current time */
        now = time(NULL);
        localtime_r(&now, &loc_time);
#ifdef __IMAGECRAFT__        
        fprintf(stream, "CGI ssi-demo.cgi called without any parameter.<br><br>Current time is: %02d.%02d.%04d -- %02d:%02d:%02d<br>\r\n",
                  loc_time.tm_mday, loc_time.tm_mon+1, loc_time.tm_year+1900, loc_time.tm_hour, loc_time.tm_min, loc_time.tm_sec);
#else 
        fprintf_P(stream, PSTR("CGI ssi-demo.cgi called without any parameter.<br><br>Current time is: %02d.%02d.%04d -- %02d:%02d:%02d<br>\r\n"),
                  loc_time.tm_mday, loc_time.tm_mon+1, loc_time.tm_year+1900, loc_time.tm_hour, loc_time.tm_min, loc_time.tm_sec);
#endif
    }

    fflush(stream);

    return 0;
}
コード例 #2
0
ファイル: httpserv.c プロジェクト: niziak/ethernut-4.9
/*
 * CGI Sample: Proccessing a form.
 *
 * This routine must have been registered by NutRegisterCgi() and is
 * automatically called by NutHttpProcessRequest() when the client
 * request the URL 'cgi-bin/form.cgi'.
 *
 * Thanks to Tom Boettger, who provided this sample for ICCAVR.
 */
int ShowForm(FILE * stream, REQUEST * req)
{
    static prog_char html_head[] = "<HTML><BODY><BR><H1>Form Result</H1><BR><BR>";
    static prog_char html_body[] = "<BR><BR><p><a href=\"../index.html\">return to main</a></BODY></HTML></p>";

    NutHttpSendHeaderTop(stream, req, 200, "Ok");
    NutHttpSendHeaderBottom(stream, req, html_mt, -1);

    /* Send HTML header. */
    fputs_P(html_head, stream);

    if (req->req_query) {
        char *name;
        char *value;
        int i;
        int count;

        count = NutHttpGetParameterCount(req);
        /* Extract count parameters. */
        for (i = 0; i < count; i++) {
            name = NutHttpGetParameterName(req, i);
            value = NutHttpGetParameterValue(req, i);

            /* Send the parameters back to the client. */

#ifdef __IMAGECRAFT__
            fprintf(stream, "%s: %s<BR>\r\n", name, value);
#else
            fprintf_P(stream, PSTR("%s: %s<BR>\r\n"), name, value);
#endif
        }
    }

    fputs_P(html_body, stream);
    fflush(stream);

    return 0;
}
コード例 #3
0
int CgiNetIO( FILE * stream, REQUEST * req )
{
    char *name = 0;
    char *value = 0;

    char tmp[100] = "";

    if (req->req_query)
    {
        char *pname;
        char *pvalue;
        int i;
        int count;

        strncpy( tmp, req->req_query, sizeof(tmp)-1 );

        count = NutHttpGetParameterCount(req);
        /* Extract count parameters. */
        for (i = 0; i < count; i++)
        {
            pname = NutHttpGetParameterName(req, i);
            pvalue = NutHttpGetParameterValue(req, i);

            /* Send the parameters back to the client. */
//            fprintf_P(stream, PSTR("%s: %s<BR>\r\n"), pname, pvalue);

            if( 0 == strcmp( pname, "name" ) )		name = pvalue;
            if( 0 == strcmp( pname, "item" ) )		name = pvalue;
            if( 0 == strcmp( pname, "val" ) )		value = pvalue;
            if( 0 == strcmp( pname, "value" ) )		value = pvalue;
        }
    }


    if( name == 0 )
    {
        //httpSendString( stream, "Error: must be 'name' and, possibly, 'value' parameters" );
//    errmsg:
        //NutHttpSendHeaderTop(stream, req, 500, "Must have ?name= or ?name=&value=, name: adc{0-7}, dig{0-63}, temp{0-7}");
        web_header_200(stream, req);
        static prog_char h1[] = "<HTML><body> Must have ?name= or ?name=&value=, name: adc{0-7}, temp{0-7}, q='%s' </body></HTML>";
        fprintf_P( stream, h1, tmp );
        return 0;
    }

    if( value )
    {
        // Write
        int rc = setNamedParameter( name, value );

        if( rc )
        {
            web_header_200(stream, req);
            static prog_char h1[] = "<HTML><body>set %s rc=%d</body></HTML>";
            fprintf_P(stream, h1, name, rc );
            return 0;
        }

        httpSendString( stream, req, "Ok" );
        notice_activity();
    }
    else
    {
        char *data = getNamedParameter( name );
        if( data == 0 )
        {
            //        goto errmsg;
            web_header_200(stream, req);
            static prog_char h1[] = "<HTML><body>no data for %s</body></HTML>";
            fprintf_P(stream, h1, name );
            return 0;
        }

        httpSendString( stream, req, data );
        notice_activity();
    }
    return 0;
}
コード例 #4
0
ファイル: httpopt.c プロジェクト: Astralix/ethernut32
/*!
 * \brief Get the value of a request parameter
 *
 * \param req Request object
 * \param index Index to the requested parameter.
 *
 * \return Pointer to the parameter value at the given index,
 *         or NULL if index is out of range.
 */
char *NutHttpGetParameterValue(REQUEST * req, int index)
{
    if (index < 0 || index >= NutHttpGetParameterCount(req))
        return NULL;
    return req->req_qptrs[index * 2 + 1];
}