Документ взят из кэша поисковой машины. Адрес оригинального документа : http://rtm-cs.sinp.msu.ru/manual/xmlrpc-howto/xmlrpc-howto-c-cgi.html
Дата изменения: Mon Jan 22 01:11:45 2001
Дата индексирования: Mon Oct 1 21:19:23 2012
Кодировка:
A CGI-Based C Server

A CGI-Based C Server

Save the following code in a file called sumAndDifference.c:

    #include <xmlrpc.h>
    #include <xmlrpc_cgi.h>
    
    xmlrpc_value *
    sumAndDifference (xmlrpc_env *env, xmlrpc_value *param_array, void *user_data)
    {
        xmlrpc_int32 x, y;
    
        /* Parse our argument array. */
        xmlrpc_parse_value(env, param_array, "(ii)", &x, &y);
        if (env->fault_occurred)
            return NULL;
    
        /* Return our result. */
        return xmlrpc_build_value(env, "{s:i,s:i}",
                                  "sum", x + y,
                                  "difference", x - y);
    }
    
    int main (int argc, char **argv)
    {
        /* Set up our CGI library. */
        xmlrpc_cgi_init(XMLRPC_CGI_NO_FLAGS);
    
        /* Install our only method. */
        xmlrpc_cgi_add_method("sample.sumAndDifference", &sumAndDifference, NULL);
    
        /* Call the appropriate method. */
        xmlrpc_cgi_process_call();
    
        /* Clean up our CGI library. */
        xmlrpc_cgi_cleanup();
    }

To compile it, you can type:

    $ CGI_CFLAGS=`xmlrpc-c-config cgi-server --cflags`
    $ CGI_LIBS=`xmlrpc-c-config cgi-server --libs`
    $ gcc $CGI_CFLAGS -o sumAndDifference.cgi sumAndDifference.c $CGI_LIBS

Once this is done, copy sumAndDifference.cgi into your webserver's cgi-bin directory.