1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
22 ***************************************************************************/
26 #ifndef CURL_DISABLE_DICT
28 /* -- WIN32 approved -- */
39 #ifdef HAVE_SYS_SOCKET_H
40 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #ifdef HAVE_SYS_TIME_H
50 #ifdef HAVE_ARPA_INET_H
51 #include <arpa/inet.h>
56 #include <sys/ioctl.h>
59 #ifdef HAVE_SYS_PARAM_H
60 #include <sys/param.h>
63 #ifdef HAVE_SYS_SELECT_H
64 #include <sys/select.h>
71 #include <curl/curl.h>
79 #define _MPRINTF_REPLACE /* use our functions only */
80 #include <curl/mprintf.h>
82 /* The last #include file should be: */
85 static char *unescape_word(struct SessionHandle *data, const char *inp)
94 newp = curl_easy_unescape(data, inp, 0, &len);
98 dictp = malloc(len*2 + 1); /* add one for terminating zero */
100 /* According to RFC2229 section 2.2, these letters need to be escaped with
105 if ((byte <= 32) || (byte == 127) ||
106 (byte == '\'') || (byte == '\"') || (byte == '\\')) {
107 dictp[olen++] = '\\';
109 dictp[olen++] = byte;
118 CURLcode Curl_dict(struct connectdata *conn, bool *done)
123 char *database = NULL;
124 char *strategy = NULL;
125 char *nthdef = NULL; /* This is not part of the protocol, but required
127 CURLcode result=CURLE_OK;
128 struct SessionHandle *data=conn->data;
129 curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
131 char *path = data->reqdata.path;
132 curl_off_t *bytecount = &data->reqdata.keep.bytecount;
134 *done = TRUE; /* unconditionally */
136 if(conn->bits.user_passwd) {
137 /* AUTH is missing */
140 if (strnequal(path, DICT_MATCH, sizeof(DICT_MATCH)-1) ||
141 strnequal(path, DICT_MATCH2, sizeof(DICT_MATCH2)-1) ||
142 strnequal(path, DICT_MATCH3, sizeof(DICT_MATCH3)-1)) {
144 word = strchr(path, ':');
147 database = strchr(word, ':');
149 *database++ = (char)0;
150 strategy = strchr(database, ':');
152 *strategy++ = (char)0;
153 nthdef = strchr(strategy, ':');
161 if ((word == NULL) || (*word == (char)0)) {
162 infof(data, "lookup word is missing");
163 word=(char *)"default";
165 if ((database == NULL) || (*database == (char)0)) {
166 database = (char *)"!";
168 if ((strategy == NULL) || (*strategy == (char)0)) {
169 strategy = (char *)".";
172 eword = unescape_word(data, word);
174 return CURLE_OUT_OF_MEMORY;
176 result = Curl_sendf(sockfd, conn,
177 "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\r\n"
192 failf(data, "Failed sending DICT request");
194 result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
195 -1, NULL); /* no upload */
199 else if (strnequal(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) ||
200 strnequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) ||
201 strnequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3)-1)) {
203 word = strchr(path, ':');
206 database = strchr(word, ':');
208 *database++ = (char)0;
209 nthdef = strchr(database, ':');
216 if ((word == NULL) || (*word == (char)0)) {
217 infof(data, "lookup word is missing");
218 word=(char *)"default";
220 if ((database == NULL) || (*database == (char)0)) {
221 database = (char *)"!";
224 eword = unescape_word(data, word);
226 return CURLE_OUT_OF_MEMORY;
228 result = Curl_sendf(sockfd, conn,
229 "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\r\n"
240 failf(data, "Failed sending DICT request");
242 result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
243 -1, NULL); /* no upload */
251 ppath = strchr(path, '/');
256 for (i = 0; ppath[i]; i++) {
260 result = Curl_sendf(sockfd, conn,
261 "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\r\n"
265 failf(data, "Failed sending DICT request");
267 result = Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
276 #endif /*CURL_DISABLE_DICT*/