1 | /*************************************** 2 | $Revision: 1.11 $ 3 | 4 | Protocol whois module (pw). Whois protocol. 5 | 6 | Status: NOT REVUED, NOT TESTED 7 | 8 | ******************/ /****************** 9 | Filename : protocol_whois.c 10 | Author : ottrey@ripe.net 11 | OSs Tested : Solaris 12 | ******************/ /****************** 13 | Copyright (c) 1999 RIPE NCC 14 | 15 | All Rights Reserved 16 | 17 | Permission to use, copy, modify, and distribute this software and its 18 | documentation for any purpose and without fee is hereby granted, 19 | provided that the above copyright notice appear in all copies and that 20 | both that copyright notice and this permission notice appear in 21 | supporting documentation, and that the name of the author not be 22 | used in advertising or publicity pertaining to distribution of the 23 | software without specific, written prior permission. 24 | 25 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 26 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL 27 | AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 28 | DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 29 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 30 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 31 | ***************************************/ 32 | #include <stdio.h> 33 | #include <glib.h> 34 | 35 | #include "NAME" 36 | 37 | #include "protocol_whois.h" 38 | #include "mysql_driver.h" 39 | #include "query_command.h" 40 | #include "query_instructions.h" 41 | #include "constants.h" 42 | #include "objects.h" 43 | 44 | /* PW_interact() */ 45 | /*++++++++++++++++++++++++++++++++++++++ 46 | Interact with the client. 47 | 48 | int sock Socket that client is connected to. 49 | 50 | More: 51 | +html+ <PRE> 52 | Authors: 53 | ottrey 54 | 55 | +html+ </PRE><DL COMPACT> 56 | +html+ <DT>Online References: 57 | +html+ <DD><UL> 58 | +html+ </UL></DL> 59 | 60 | ++++++++++++++++++++++++++++++++++++++*/ 61 | void PW_interact(int sock) { 62 | char input[MAX_INPUT_SIZE]; 63 | int connected = 1; 64 | int read_result; 65 | char *welcome=NULL; 66 | int input_length; 67 | int k_flag; 68 | char *str=NULL; 69 | 70 | Query_command *qc=NULL; 71 | Query_instructions *qis=NULL; 72 | 73 | /* Initialize the flag that instructs to keep the connection open. */ 74 | k_flag = 0; 75 | 76 | while ((connected == 1) && (CO_get_whois_suspended() == 0)) { 77 | /* Read input */ 78 | read_result = SK_gets(sock, input, MAX_INPUT_SIZE); 79 | if (read_result == -1) { 80 | connected = 0; 81 | } 82 | else if (read_result == -2) { 83 | printf("Thread received a control-c\n"); 84 | connected = 0; 85 | } 86 | 87 | /* Default to process the whois query */ 88 | input_length = strlen(input); 89 | if (input_length > 0) { 90 | SK_puts(sock, CVS_NAME); 91 | printf("whois %s\n", input); 92 | /* XXX NB. This will change as the WQ module changes. -- Sigh. */ 93 | QC_free(qc); 94 | qc = QC_new(input, sock); 95 | /* 96 | QC_environ_update(qc); 97 | */ 98 | 99 | /* Don't do a query if there are no keys. */ 100 | if (qc->keys != NULL) { 101 | if (strcmp(qc->keys, "") != 0) { 102 | QI_free(qis); 103 | qis = QI_new(qc, sock); 104 | g_list_foreach(qc->sources_list, QI_execute, qis); 105 | } 106 | else { 107 | if (qc->t != 0) { 108 | str = OB_attribute_i_to_string(qc->t, 0); 109 | if (str != NULL) { 110 | SK_puts(sock, str); 111 | SK_puts(sock, "\n"); 112 | free(str); 113 | } 114 | else { 115 | SK_puts(sock, "Not an object.\n"); 116 | SK_puts(sock, USAGE); 117 | } 118 | } 119 | if (qc->v != 0) { 120 | str = OB_attribute_i_to_string(qc->v, 1); 121 | if (str != NULL) { 122 | SK_puts(sock, str); 123 | free(str); 124 | } 125 | else { 126 | SK_puts(sock, "Not an object.\n"); 127 | SK_puts(sock, USAGE); 128 | } 129 | } 130 | } 131 | } 132 | 133 | /* Put a newline at the end of the query. */ 134 | SK_puts(sock, "\n"); 135 | 136 | /* This is a tricky XOR operation.... ;-) 137 | State transition for k_flag: 138 | 0 -> 0 then k_flag = 0, connected = 0 139 | 0 -> 1 then k_flag = 1, connected = 1 140 | 1 -> 0 then k_flag = 1, connected = 1 141 | 1 -> 1 then k_flag = 0, connected = 0 142 | */ 143 | k_flag = k_flag ^ qc->k; 144 | connected = k_flag; 145 | } 146 | else { 147 | printf("whois WHAT???\n"); 148 | SK_puts(sock, "whois WHAT???\n"); 149 | connected = 0; 150 | } 151 | } 152 | 153 | SK_close(sock); 154 | 155 | 156 | } /* PW_interact() */