]> git.ipfire.org Git - thirdparty/squid.git/blob - helpers/basic_auth/fake/fake.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[thirdparty/squid.git] / helpers / basic_auth / fake / fake.cc
1 /*
2 * AUTHOR: Amos Jeffries <squid3@treenet.co.nz>
3 *
4 * Fake Basic Authentication program for Squid.
5 *
6 * This code gets the user details and returns OK.
7 * It is intended for testing use and as a base for further implementation.
8 *
9 *
10 * This code is copyright (C) 2009 by Treehouse Networks Ltd
11 * of New Zealand. It is published and Licensed as an extension of
12 * squid under the same conditions as the main squid application.
13 */
14
15 #include "squid.h"
16 #include "helpers/defines.h"
17
18 #if HAVE_CSTRING
19 #include <cstring>
20 #endif
21 #if HAVE_STRING_H
22 #include <string.h>
23 #endif
24
25 /**
26 * options:
27 * -d enable debugging.
28 * -h interface help.
29 */
30 char *program_name = NULL;
31
32 static void
33 usage(void)
34 {
35 fprintf(stderr,
36 "Usage: %s [-d] [-v] [-h]\n"
37 " -d enable debugging.\n"
38 " -h this message\n\n",
39 program_name);
40 }
41
42 static void
43 process_options(int argc, char *argv[])
44 {
45 int opt;
46
47 opterr = 0;
48 while (-1 != (opt = getopt(argc, argv, "hd"))) {
49 switch (opt) {
50 case 'd':
51 debug_enabled = 1;
52 break;
53 case 'h':
54 usage();
55 exit(0);
56 default:
57 fprintf(stderr, "%s: FATAL: unknown option: -%c. Exiting\n", program_name, opt);
58 usage();
59 exit(1);
60 }
61 }
62 }
63
64 int
65 main(int argc, char *argv[])
66 {
67 char buf[HELPER_INPUT_BUFFER];
68 int buflen = 0;
69
70 setbuf(stdout, NULL);
71 setbuf(stderr, NULL);
72
73 program_name = argv[0];
74
75 process_options(argc, argv);
76
77 debug("%s build " __DATE__ ", " __TIME__ " starting up...\n", program_name);
78
79 while (fgets(buf, HELPER_INPUT_BUFFER, stdin) != NULL) {
80 char *p;
81
82 if ((p = strchr(buf, '\n')) != NULL) {
83 *p = '\0'; /* strip \n */
84 buflen = p - buf; /* length is known already */
85 } else
86 buflen = strlen(buf); /* keep this so we only scan the buffer for \0 once per loop */
87
88 debug("Got %d bytes '%s' from Squid\n", buflen, buf);
89
90 /* send 'OK' result back to Squid */
91 SEND_OK("");
92 }
93 debug("%s build " __DATE__ ", " __TIME__ " shutting down...\n", program_name);
94 exit(0);
95 }