Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / apps / JAWS / clients / WebSTONE / src / nsapi-send.c
bloba3cac43dc81d06928e2a2f315c95fea9c5871c96
1 /*
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.
7 * For example:
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
11 * etc.
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:
17 * in magnus.conf
18 * Init fn=load-modules shlib=example.so funcs=nsapi-send
20 * in obj.conf
21 * Service method=(GET|HEAD) fn=nsapi-send type=magnus-internal/dyn-send
23 * in mime.types
24 * type=magnus-internal/dyn-send exts=dyn-send
26 * Mike Belshe
27 * mbelshe@netscape.com
28 * 11-5-95
31 #ifndef WIN32
32 #include <stdio.h>
33 #include <stdlib.h>
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"
39 #else
40 #include <windows.h>
41 #define FILE_STDIO 1
42 #endif
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"
48 #ifdef WIN32
49 __declspec(dllexport)
50 #endif
52 int nsapi_send(pblock *pb, Session *sn, Request *rq)
54 char *query_string;
55 char buffer[sizeof(HEADERS) + 204800 + 1];
56 int filesize;
57 unsigned int maxindex;
58 unsigned int index;
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)) )
64 filesize = FILE_SIZE;
65 else {
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;
77 /* Send the output */
78 if (net_write(sn->csd, buffer, sizeof(HEADERS)-1+filesize, 0) == IO_ERROR)
79 return REQ_EXIT;
81 return REQ_PROCEED;