1    | #ifndef READ_QUERY_COMMAND
2    | #define READ_QUERY_COMMAND
3    | 
4    | /***************************************
5    |   $Revision: 1.20 $
6    | 
7    |   Query command module (qc)
8    | 
9    |   Status: NOT REVUED, TESTED
10   | 
11   |   ******************/ /******************
12   |   Copyright (c) 1999                              RIPE NCC
13   |  
14   |   All Rights Reserved
15   |   
16   |   Permission to use, copy, modify, and distribute this software and its
17   |   documentation for any purpose and without fee is hereby granted,
18   |   provided that the above copyright notice appear in all copies and that
19   |   both that copyright notice and this permission notice appear in
20   |   supporting documentation, and that the name of the author not be
21   |   used in advertising or publicity pertaining to distribution of the
22   |   software without specific, written prior permission.
23   |   
24   |   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
25   |   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
26   |   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
27   |   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
28   |   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
29   |   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30   |   ***************************************/
31   | #define USAGE  "Usage: whois [-aFKlLmMrRx] [-s sources] [-T type(s)] [-i attr] keys\n" \
32   | "whois {-t|-v} type\n"\
33   | "whois -q {version|sources}\n"\
34   | "\n"\
35   | "Where:\n"\
36   | "\n"\
37   | "-k                         open/close session (persistent connection)\n"\
38   | "-r                         turn off recursive lookups\n"\
39   | "-F                         fast raw output (implies -r)\n"\
40   | "-K                         print only primary keys (implies -r)\n"\
41   | "-R                         show local copy of the domain object (no referral)\n"\
42   | "-a                         search all databases\n"\
43   | "-s source[[,source] ... ]  search only databases with source 'source'\n"\
44   | "-T type[[,type] ... ]      only look for objects of type 'type'\n"\
45   | "-i [attr][[,attr] ... ]    do an inverse lookup for specified attributes\n"\
46   | "-l                         find first level Less specific matches\n"\
47   | "-L                         find all Less specific matches\n"\
48   | "-m                         find first level more specific matches\n"\
49   | "-M                         find all More specific matches\n"\
50   | "-x                         find exact matches only\n"\
51   | "-t type                    requests template for object of type 'type'\n"\
52   | "-v type                    requests verbose template for object of type 'type'\n"\
53   | "\n"\
54   | "Please note that most of these flags are NOT understood by\n"\
55   | "non RIPE whois servers\n\n"
56   | 
57   | #include <glib.h>
58   | #include "bitmask.h"
59   | #include "socket.h"
60   | 
61   | 
62   | typedef enum {
63   |   QC_EMPTY,
64   |   QC_PARERR,
65   |   QC_SYNERR,
66   |   QC_NOKEY,
67   |   QC_TEMPLATE,
68   |   QC_HELP,
69   |   QC_REAL,
70   |   QC_FILTERED,
71   | 
72   |   QC_TYPE_MAX
73   | } qc_qtype_t;
74   | /* now this must be sync'ed with that: */
75   | #ifdef QC_IMPL
76   | char *qrytype_str[] = {
77   |   "EMPTY",
78   |   "PARAMETER ERROR",
79   |   "SYNTAX ERROR",
80   |   "NO KEY",
81   |   "TEMPLATE",
82   |   "HELP",
83   |   "REAL",
84   |   "FILTERED"
85   | };
86   | #endif
87   | 
88   | 
89   | /* types of -q queries */
90   | #define QC_Q_SOURCES 0
91   | #define QC_Q_VERSION 1
92   | 
93   | 
94   | 
95   | typedef struct Query_environ_t {
96   |   sk_conn_st   condat;
97   |   unsigned int k;
98   |   GList *sources_list;
99   |   char *version;
100  |   ip_addr_t pIP; /* passed IP */
101  | } Query_environ;
102  | 
103  | typedef struct Query_command_t {
104  |   qc_qtype_t   query_type;
105  |   int e;
106  |   int fast;
107  |   int g;
108  |   mask_t inv_attrs_bitmap;
109  |   int recursive;
110  |   int l;
111  |   int m;
112  |   int q;
113  |   int t;
114  |   int v;
115  |   int x;
116  |   int filtered;
117  |   int L;
118  |   int M;
119  |   int R;
120  |   int S;
121  |   mask_t object_type_bitmap;
122  |   mask_t keytypes_bitmap;
123  |   char *keys;
124  | } Query_command;
125  | 
126  | char *QC_bitmap_to_string(mask_t bitmap);
127  | char *QC_environ_to_string(Query_environ qe);
128  | char *QC_query_command_to_string(Query_command *query_command);
129  | void QC_environ_free(Query_environ *qe);
130  | void QC_free(Query_command *qc);
131  | Query_command *QC_create(char *query_str, Query_environ *qe);
132  | Query_environ *QC_environ_new(char *ip, unsigned sock);
133  | Query_environ *QC_environ_update(Query_command *qc, Query_environ *qe);
134  | char *QC_get_qrytype(qc_qtype_t qrytype);
135  | #endif /* READ_QUERY_COMMAND */