1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2006, 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.
21 * $Id: dict.c,v 1.2 2007/03/15 19:22:13 andy Exp $
22 ***************************************************************************/
26 #ifndef CURL_DISABLE_DICT
28 /* -- WIN32 approved -- */
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
37 #ifdef HAVE_SYS_STAT_H
45 #ifdef HAVE_SYS_SOCKET_H
46 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #ifdef HAVE_SYS_TIME_H
56 #ifdef HAVE_ARPA_INET_H
57 #include <arpa/inet.h>
62 #include <sys/ioctl.h>
65 #ifdef HAVE_SYS_PARAM_H
66 #include <sys/param.h>
69 #ifdef HAVE_SYS_SELECT_H
70 #include <sys/select.h>
77 #include <curl/curl.h>
85 #define _MPRINTF_REPLACE /* use our functions only */
86 #include <curl/mprintf.h>
88 /* The last #include file should be: */
91 static char *unescape_word(struct SessionHandle
*data
, char *inp
)
100 newp
= curl_easy_unescape(data
, inp
, 0, &len
);
104 dictp
= malloc(len
*2 + 1); /* add one for terminating zero */
106 /* According to RFC2229 section 2.2, these letters need to be escaped with
109 (byte
= (unsigned char)*ptr
) != 0;
111 if ((byte
<= 32) || (byte
== 127) ||
112 (byte
== '\'') || (byte
== '\"') || (byte
== '\\')) {
113 dictp
[olen
++] = '\\';
115 dictp
[olen
++] = byte
;
124 CURLcode
Curl_dict(struct connectdata
*conn
, bool *done
)
129 char *database
= NULL
;
130 char *strategy
= NULL
;
131 char *nthdef
= NULL
; /* This is not part of the protocol, but required
133 CURLcode result
=CURLE_OK
;
134 struct SessionHandle
*data
=conn
->data
;
135 curl_socket_t sockfd
= conn
->sock
[FIRSTSOCKET
];
137 char *path
= data
->reqdata
.path
;
138 curl_off_t
*bytecount
= &data
->reqdata
.keep
.bytecount
;
140 *done
= TRUE
; /* unconditionally */
142 if(conn
->bits
.user_passwd
) {
143 /* AUTH is missing */
146 if (strnequal(path
, DICT_MATCH
, sizeof(DICT_MATCH
)-1) ||
147 strnequal(path
, DICT_MATCH2
, sizeof(DICT_MATCH2
)-1) ||
148 strnequal(path
, DICT_MATCH3
, sizeof(DICT_MATCH3
)-1)) {
150 word
= strchr(path
, ':');
153 database
= strchr(word
, ':');
155 *database
++ = (char)0;
156 strategy
= strchr(database
, ':');
158 *strategy
++ = (char)0;
159 nthdef
= strchr(strategy
, ':');
167 if ((word
== NULL
) || (*word
== (char)0)) {
168 failf(data
, "lookup word is missing");
170 if ((database
== NULL
) || (*database
== (char)0)) {
171 database
= (char *)"!";
173 if ((strategy
== NULL
) || (*strategy
== (char)0)) {
174 strategy
= (char *)".";
177 eword
= unescape_word(data
, word
);
179 return CURLE_OUT_OF_MEMORY
;
181 result
= Curl_sendf(sockfd
, conn
,
182 "CLIENT " LIBCURL_NAME
" " LIBCURL_VERSION
"\r\n"
197 failf(data
, "Failed sending DICT request");
199 result
= Curl_setup_transfer(conn
, FIRSTSOCKET
, -1, FALSE
, bytecount
,
200 -1, NULL
); /* no upload */
204 else if (strnequal(path
, DICT_DEFINE
, sizeof(DICT_DEFINE
)-1) ||
205 strnequal(path
, DICT_DEFINE2
, sizeof(DICT_DEFINE2
)-1) ||
206 strnequal(path
, DICT_DEFINE3
, sizeof(DICT_DEFINE3
)-1)) {
208 word
= strchr(path
, ':');
211 database
= strchr(word
, ':');
213 *database
++ = (char)0;
214 nthdef
= strchr(database
, ':');
221 if ((word
== NULL
) || (*word
== (char)0)) {
222 failf(data
, "lookup word is missing");
224 if ((database
== NULL
) || (*database
== (char)0)) {
225 database
= (char *)"!";
228 eword
= unescape_word(data
, word
);
230 return CURLE_OUT_OF_MEMORY
;
232 result
= Curl_sendf(sockfd
, conn
,
233 "CLIENT " LIBCURL_NAME
" " LIBCURL_VERSION
"\r\n"
244 failf(data
, "Failed sending DICT request");
246 result
= Curl_setup_transfer(conn
, FIRSTSOCKET
, -1, FALSE
, bytecount
,
247 -1, NULL
); /* no upload */
255 ppath
= strchr(path
, '/');
260 for (i
= 0; ppath
[i
]; i
++) {
264 result
= Curl_sendf(sockfd
, conn
,
265 "CLIENT " LIBCURL_NAME
" " LIBCURL_VERSION
"\r\n"
269 failf(data
, "Failed sending DICT request");
271 result
= Curl_setup_transfer(conn
, FIRSTSOCKET
, -1, FALSE
, bytecount
,
280 #endif /*CURL_DISABLE_DICT*/