2 * Send random bits file
3 * Once this service function is installed, any file with the extension
4 * "dyn-send" will be serviced with this function. An optional query
5 * string may be passed to alter the amount of data in the response.
8 * /file.dyn-send - returns a 10240 byte file
9 * /file.dyn-send?size=20 - returns a 20 byte file
10 * /file.dyn-send?size=1024 - returns a 1024 byte file
13 * To install the service routine, compile it as per the makefile
14 * included with your Netscape server distribution (serverroot/nsapi/examples)
15 * and then add the following lines to your netscape server configuration:
18 * Init fn=load-modules shlib=example.so funcs=nsapi-send
21 * Service method=(GET|HEAD) fn=nsapi-send type=magnus-internal/dyn-send
24 * type=magnus-internal/dyn-send exts=dyn-send
27 * mbelshe@netscape.com
34 #include "base/pblock.h"
35 #include "base/session.h"
36 #include "frame/protocol.h"
37 #include "base/util.h"
38 #include "frame/http.h"
43 #include "frame/req.h"
45 #define FILE_SIZE 10240
46 #define HEADERS "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
52 int nsapi_send(pblock
*pb
, Session
*sn
, Request
*rq
)
55 char buffer
[sizeof(HEADERS
) + 204800 + 1];
57 unsigned int maxindex
;
60 /* Get the query string, if any; check to see if an alternate
61 * file size was specified.
63 if ( !(query_string
= pblock_findval("query", rq
->reqpb
)) )
66 filesize
= atoi(&(query_string
[5]));
69 memcpy(&buffer
, HEADERS
, sizeof(HEADERS
)-1);
71 /* Generate the output */
72 maxindex
= sizeof(HEADERS
) + filesize
;
73 for (index
=sizeof(HEADERS
); index
< (maxindex
); index
++)
74 /* generate random characters from A-Z */
75 buffer
[index
] = rand() %26 + 63;
78 if (net_write(sn
->csd
, buffer
, sizeof(HEADERS
)-1+filesize
, 0) == IO_ERROR
)