Hi,

I'd like to parse the result of a posted form .

For exemple, if I fill a form in a certain, way I may have after submitting the page something like :
<html>
        <body>
        <p> Wrong id </p>
        </body>
</html>

or I would have :

<html>
        <body>
        <p> Good id</p>
        </body>
</html>

So I'd like to parse this file and do one thing or another depending of the page .

I've seen that there are "AFTER filters" that may execute functions after the result page has been loaded in memory but don't know how to use those .

What can I do ?

Here's my C code :



---------------------------------
#include <stdio.h>
#include "WWWLib.h"
#include "WWWInit.h"
#include "list.h"

PRIVATE HTChunk * result = NULL;

PRIVATE int printer (const char * fmt, va_list pArgs)
{
    return (vfprintf(stdout, fmt, pArgs));
}

PRIVATE int tracer (const char * fmt, va_list pArgs)
{
    return (vfprintf(stderr, fmt, pArgs));
}

PRIVATE int terminate_handler (HTRequest * request, HTResponse * response,
                               void * param, int status)
{
  if (status == HT_LOADED && result && HTChunk_data(result)) {
    HTPrint("%s", HTChunk_data(result));   
    HTChunk_delete(result);
  }
 
  /* We are done with this request */
  HTRequest_delete(request);
 
  /* Terminate libwww */
    HTProfile_delete();
   
    HTEventList_stopLoop();
   
    exit(0);
}

void    main()
{
    char *string;
    HTRequest * request = NULL;
    HTAnchor * anchor = NULL;
    HTAssocList * formfields = NULL;
    char * uri = NULL;
   
    string = "http://hal/cgi-bin/bluntman/log.cgi?lname=Duchemin&fname=Pascal"
    /* Create a new premptive client */
    HTProfile_newNoCacheClient("TestApp", "1.0");

    /* Need our own trace and print functions */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);

    /* Get trace messages */
#if 0
    HTSetTraceMessageMask("sop");
#endif

    /* Add our own filter to update the history list */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /* Set the timeout for long we are going to wait for a response */
    HTHost_setEventTimeout(20000);

    
    /* Create a list to hold the form arguments */
    if (!formfields) formfields = HTAssocList_new();
   
    /* Parse the content and add it to the association list */
    HTParseFormInput(formfields, string);
   
    uri = string;
    if (uri && formfields) {
     
      /* Create a request */
      request = HTRequest_new();

        /* Set the default output to "asis" */
        HTRequest_setOutputFormat(request, WWW_SOURCE);

        /* Get an anchor object for the URI */
        anchor = HTAnchor_findAddress(uri);

        /* Post the data and get the result in a chunk */
        result = HTPostFormAnchorToChunk(formfields, anchor, request);

        /* Clean up the form fields */
        HTAssocList_delete(formfields);

        /* Go into the event loop... */
        HTEventList_loop(result);
                
    } else {
      HTPrint("Type the URI to post to and the arguments for the POST operation. Encode spaces as '+'\n");
      HTPrint("\t%s <uri> 'a=1' 'b=+2+' 'c=3 ...'\n");
    }
}

-----------------------------

                        Pascal Duchemin
                Computer Science Student
                  Telecom section - EPITA
Email:          bluntman@inerd.fr - duchem_p@epita.fr
Homepage:               http://bluntman.inerd.fr
ICQ:                    #2955715