]>
Commit | Line | Data |
---|---|---|
5b95b903 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
5b95b903 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
c152a447 | 9 | /* |
8432a09e AJ |
10 | * Copyright (c) 2009-2014, Treehouse Networks Ltd. New Zealand |
11 | * All rights reserved. | |
c152a447 | 12 | * |
8432a09e AJ |
13 | * Redistribution and use in source and binary forms, with or without |
14 | * modification, are permitted provided that the following conditions | |
15 | * are met: | |
16 | * | |
17 | * 1. Redistributions of source code must retain the above copyright | |
18 | * notice, this list of conditions and the following disclaimer. | |
19 | * | |
20 | * 2. Redistributions in binary form must reproduce the above copyright | |
21 | * notice, this list of conditions and the following disclaimer in the | |
22 | * documentation and/or other materials provided with the distribution. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
25 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
26 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
27 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
28 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
30 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
31 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
35 | * POSSIBILITY OF SUCH DAMAGE. | |
36 | */ | |
37 | ||
38 | /* | |
c152a447 AJ |
39 | * Fake Basic Authentication program for Squid. |
40 | * | |
41 | * This code gets the user details and returns OK. | |
42 | * It is intended for testing use and as a base for further implementation. | |
c152a447 AJ |
43 | */ |
44 | ||
f7f3304a | 45 | #include "squid.h" |
079b1d0f | 46 | #include "helper/protocol_defines.h" |
c152a447 | 47 | |
900809ea FC |
48 | #include <iostream> |
49 | #include <string> | |
c152a447 AJ |
50 | |
51 | /** | |
52 | * options: | |
53 | * -d enable debugging. | |
54 | * -h interface help. | |
55 | */ | |
900809ea | 56 | std::string program_name; |
c152a447 AJ |
57 | |
58 | static void | |
59 | usage(void) | |
60 | { | |
900809ea | 61 | std::cerr << |
c7b8175a SM |
62 | "Usage: " << program_name << " [-d] [-h]" << std::endl << |
63 | " -d enable debugging." << std::endl << | |
64 | " -h this message" << std::endl << std::endl; | |
c152a447 AJ |
65 | } |
66 | ||
67 | static void | |
68 | process_options(int argc, char *argv[]) | |
69 | { | |
70 | int opt; | |
71 | ||
72 | opterr = 0; | |
73 | while (-1 != (opt = getopt(argc, argv, "hd"))) { | |
74 | switch (opt) { | |
75 | case 'd': | |
76 | debug_enabled = 1; | |
77 | break; | |
78 | case 'h': | |
79 | usage(); | |
24885773 | 80 | exit(EXIT_SUCCESS); |
c152a447 | 81 | default: |
900809ea | 82 | std::cerr << program_name << ": FATAL: unknown option: -" << |
c7b8175a | 83 | static_cast<char>(optopt) << ". Exiting" << std::endl; |
c152a447 | 84 | usage(); |
24885773 | 85 | exit(EXIT_FAILURE); |
c152a447 AJ |
86 | } |
87 | } | |
88 | } | |
89 | ||
90 | int | |
91 | main(int argc, char *argv[]) | |
92 | { | |
c152a447 | 93 | program_name = argv[0]; |
c152a447 AJ |
94 | process_options(argc, argv); |
95 | ||
900809ea | 96 | ndebug(program_name << ' ' << VERSION << ' ' << SQUID_BUILD_INFO << |
c7b8175a | 97 | " starting up..."); |
900809ea FC |
98 | std::string buf; |
99 | while (getline(std::cin,buf)) { // will return false at EOF | |
100 | ndebug("Got " << buf.length() << " bytes '" << buf << "' from Squid"); | |
c152a447 AJ |
101 | |
102 | /* send 'OK' result back to Squid */ | |
103 | SEND_OK(""); | |
104 | } | |
900809ea | 105 | ndebug(program_name << ' ' << VERSION << ' ' << SQUID_BUILD_INFO << |
c7b8175a | 106 | " shutting down..."); |
24885773 | 107 | return EXIT_SUCCESS; |
c152a447 | 108 | } |
f53969cc | 109 |