n_reghitcb() - Register hit callback function

SYNOPSIS

#include "napi.h"
int n_reghitcb(SERVER *se,void *usr,func cb(void *usr,SRCH *sr,str url))


DESCRIPTION
This function assigns the callback routine that the server is to call each time it locates an item that matches the user's query. The client program can pass along a pointer to a "user" object to the register function that will be in turn passed to the callback routine on each invocation.

n_reghitcb() will return true if the registration was successful, and will return false (0) on error.


EXAMPLE

#define USERDATA my_data_structure
USERDATA
{
 FILE   *outfile;  /* where I will log the hits */
 long   hitcount;  /* just for fun */
};

int
hit_handler(usr,sr,url)
void *usr;  /* my USERDATA POINTER */
SRCH *sr;   /* The search info data structure */
str url;    /* The Uniform Resource Locator string AKA filename */
{
 USERDATA *ud=(USERDATA *)usr;   /* cast the void into the real type */

 ++ud->hitcount;                       /* add one to the hit counter */

 fprintf(ud->outfile,"hit number: %d , File: %s\n",ud->hitcount,url);

 if(ud->hitcount>=100)          /* tell the server to stop after 100 */
    return(0);
 return(1);           /* tell the server to keep giving me more hits */
}

int
main()
{
 SERVER  *se;
 USERDATA mydata;
 ...
 n_reghitcb(se,mydata,hit_handler);
 ...
}


CAVEATS
none


SEE ALSO
The example program netex1.c, URL Description.


Copyright © Thunderstone Software     Last updated: Dec 10 2018
Copyright © 2019 Thunderstone Software LLC. All rights reserved.