Below is a sample dosleep.c:
#ifdef XP_WIN32
#define NSAPI_PUBLIC __declspec(dllexport)
#else /* !XP_WIN32 */
#define NSAPI_PUBLIC
#endif /* !XP_WIN32 */
#include "nsapi.h"
#define BUFFER_SIZE 1024
#ifdef __cplusplus
extern "C"
#endif
NSAPI_PUBLIC int dosleep(pblock *pb, Session *sn, Request *rq)
{
char buf[BUFFER_SIZE];
int length, duration;
char *dur = pblock_findval("duration", pb);
if (!dur) {
log_error(LOG_WARN, "dosleep", sn, rq, "Value for duration
is not set.");
return REQ_ABORTED;
}
duration = atoi(dur);
/* We need to get rid of the internal content type. */
param_free(pblock_remove("content-type", rq->srvhdrs));
pblock_nvinsert("content-type", "text/html", rq>srvhdrs);
protocol_status(sn, rq, PROTOCOL_OK, NULL);
/* get ready to send page */
protocol_start_response(sn, rq);
/* fill the buffer with our message */
length = util_snprintf(buf, BUFFER_SIZE,
"<title>%s</title><h1>%s</h1>\n", "Sleeping", "Sleeping");
length += util_snprintf(&buf[length], BUFFER_SIZE - length,
"Sample NSAPI that is sleeping for %d seconds...\n", duration);
/* write the message to the client */
if (net_write(sn->csd, buf, length) == IO_ERROR)
{
return REQ_EXIT;
}
sleep(duration);
return REQ_PROCEED;
}