1 | #ifndef READ_QUERY_COMMAND
2 | #define READ_QUERY_COMMAND
3 |
4 | /***************************************
5 | $Revision: 1.19 $
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_ERROR,
65 | QC_NOKEY,
66 | QC_TEMPLATE,
67 | QC_HELP,
68 | QC_REAL,
69 | QC_FILTERED,
70 |
71 | QC_TYPE_MAX
72 | } qc_qtype_t;
73 | /* now this must be sync'ed with that: */
74 | #ifdef QC_IMPL
75 | char *qrytype_str[] = {
76 | "EMPTY",
77 | "SYNTAX ERROR",
78 | "NO KEY",
79 | "TEMPLATE",
80 | "HELP",
81 | "REAL",
82 | "FILTERED"
83 | };
84 | #endif
85 |
86 |
87 | /* types of -q queries */
88 | #define QC_Q_SOURCES 0
89 | #define QC_Q_VERSION 1
90 |
91 |
92 |
93 | typedef struct Query_environ_t {
94 | sk_conn_st condat;
95 | unsigned int k;
96 | GList *sources_list;
97 | char *version;
98 | ip_addr_t pIP; /* passed IP */
99 | } Query_environ;
100 |
101 | typedef struct Query_command_t {
102 | qc_qtype_t query_type;
103 | int e;
104 | int fast;
105 | int g;
106 | mask_t inv_attrs_bitmap;
107 | int recursive;
108 | int l;
109 | int m;
110 | int q;
111 | int t;
112 | int v;
113 | int x;
114 | int filtered;
115 | int L;
116 | int M;
117 | int R;
118 | int S;
119 | mask_t object_type_bitmap;
120 | mask_t keytypes_bitmap;
121 | char *keys;
122 | } Query_command;
123 |
124 | char *QC_bitmap_to_string(mask_t bitmap);
125 | char *QC_environ_to_string(Query_environ qe);
126 | char *QC_query_command_to_string(Query_command *query_command);
127 | void QC_environ_free(Query_environ *qe);
128 | void QC_free(Query_command *qc);
129 | Query_command *QC_create(char *query_str, Query_environ *qe);
130 | Query_environ *QC_environ_new(char *ip, unsigned sock);
131 | Query_environ *QC_environ_update(Query_command *qc, Query_environ *qe);
132 | char *QC_get_qrytype(qc_qtype_t qrytype);
133 | #endif /* READ_QUERY_COMMAND */