00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "curl_setup.h"
00024
00025 #ifndef CURL_DISABLE_DICT
00026
00027 #ifdef HAVE_NETINET_IN_H
00028 #include <netinet/in.h>
00029 #endif
00030 #ifdef HAVE_NETDB_H
00031 #include <netdb.h>
00032 #endif
00033 #ifdef HAVE_ARPA_INET_H
00034 #include <arpa/inet.h>
00035 #endif
00036 #ifdef HAVE_NET_IF_H
00037 #include <net/if.h>
00038 #endif
00039 #ifdef HAVE_SYS_IOCTL_H
00040 #include <sys/ioctl.h>
00041 #endif
00042
00043 #ifdef HAVE_SYS_PARAM_H
00044 #include <sys/param.h>
00045 #endif
00046
00047 #ifdef HAVE_SYS_SELECT_H
00048 #include <sys/select.h>
00049 #endif
00050
00051 #include "urldata.h"
00052 #include <curl/curl.h>
00053 #include "transfer.h"
00054 #include "sendf.h"
00055 #include "escape.h"
00056 #include "progress.h"
00057 #include "dict.h"
00058 #include "strcase.h"
00059 #include "curl_memory.h"
00060
00061 #include "memdebug.h"
00062
00063
00064
00065
00066
00067 static CURLcode dict_do(struct connectdata *conn, bool *done);
00068
00069
00070
00071
00072
00073 const struct Curl_handler Curl_handler_dict = {
00074 "DICT",
00075 ZERO_NULL,
00076 dict_do,
00077 ZERO_NULL,
00078 ZERO_NULL,
00079 ZERO_NULL,
00080 ZERO_NULL,
00081 ZERO_NULL,
00082 ZERO_NULL,
00083 ZERO_NULL,
00084 ZERO_NULL,
00085 ZERO_NULL,
00086 ZERO_NULL,
00087 ZERO_NULL,
00088 PORT_DICT,
00089 CURLPROTO_DICT,
00090 PROTOPT_NONE | PROTOPT_NOURLQUERY
00091 };
00092
00093 static char *unescape_word(struct Curl_easy *data, const char *inputbuff)
00094 {
00095 char *newp;
00096 char *dictp;
00097 char *ptr;
00098 size_t len;
00099 char ch;
00100 int olen=0;
00101
00102 CURLcode result = Curl_urldecode(data, inputbuff, 0, &newp, &len, FALSE);
00103 if(!newp || result)
00104 return NULL;
00105
00106 dictp = malloc(((size_t)len)*2 + 1);
00107 if(dictp) {
00108
00109
00110 for(ptr = newp;
00111 (ch = *ptr) != 0;
00112 ptr++) {
00113 if((ch <= 32) || (ch == 127) ||
00114 (ch == '\'') || (ch == '\"') || (ch == '\\')) {
00115 dictp[olen++] = '\\';
00116 }
00117 dictp[olen++] = ch;
00118 }
00119 dictp[olen]=0;
00120 }
00121 free(newp);
00122 return dictp;
00123 }
00124
00125 static CURLcode dict_do(struct connectdata *conn, bool *done)
00126 {
00127 char *word;
00128 char *eword;
00129 char *ppath;
00130 char *database = NULL;
00131 char *strategy = NULL;
00132 char *nthdef = NULL;
00133
00134 CURLcode result=CURLE_OK;
00135 struct Curl_easy *data=conn->data;
00136 curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
00137
00138 char *path = data->state.path;
00139 curl_off_t *bytecount = &data->req.bytecount;
00140
00141 *done = TRUE;
00142
00143 if(conn->bits.user_passwd) {
00144
00145 }
00146
00147 if(strncasecompare(path, DICT_MATCH, sizeof(DICT_MATCH)-1) ||
00148 strncasecompare(path, DICT_MATCH2, sizeof(DICT_MATCH2)-1) ||
00149 strncasecompare(path, DICT_MATCH3, sizeof(DICT_MATCH3)-1)) {
00150
00151 word = strchr(path, ':');
00152 if(word) {
00153 word++;
00154 database = strchr(word, ':');
00155 if(database) {
00156 *database++ = (char)0;
00157 strategy = strchr(database, ':');
00158 if(strategy) {
00159 *strategy++ = (char)0;
00160 nthdef = strchr(strategy, ':');
00161 if(nthdef) {
00162 *nthdef = (char)0;
00163 }
00164 }
00165 }
00166 }
00167
00168 if((word == NULL) || (*word == (char)0)) {
00169 infof(data, "lookup word is missing\n");
00170 word=(char *)"default";
00171 }
00172 if((database == NULL) || (*database == (char)0)) {
00173 database = (char *)"!";
00174 }
00175 if((strategy == NULL) || (*strategy == (char)0)) {
00176 strategy = (char *)".";
00177 }
00178
00179 eword = unescape_word(data, word);
00180 if(!eword)
00181 return CURLE_OUT_OF_MEMORY;
00182
00183 result = Curl_sendf(sockfd, conn,
00184 "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\r\n"
00185 "MATCH "
00186 "%s "
00187 "%s "
00188 "%s\r\n"
00189 "QUIT\r\n",
00190
00191 database,
00192 strategy,
00193 eword
00194 );
00195
00196 free(eword);
00197
00198 if(result) {
00199 failf(data, "Failed sending DICT request");
00200 return result;
00201 }
00202 Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
00203 -1, NULL);
00204 }
00205 else if(strncasecompare(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) ||
00206 strncasecompare(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) ||
00207 strncasecompare(path, DICT_DEFINE3, sizeof(DICT_DEFINE3)-1)) {
00208
00209 word = strchr(path, ':');
00210 if(word) {
00211 word++;
00212 database = strchr(word, ':');
00213 if(database) {
00214 *database++ = (char)0;
00215 nthdef = strchr(database, ':');
00216 if(nthdef) {
00217 *nthdef = (char)0;
00218 }
00219 }
00220 }
00221
00222 if((word == NULL) || (*word == (char)0)) {
00223 infof(data, "lookup word is missing\n");
00224 word=(char *)"default";
00225 }
00226 if((database == NULL) || (*database == (char)0)) {
00227 database = (char *)"!";
00228 }
00229
00230 eword = unescape_word(data, word);
00231 if(!eword)
00232 return CURLE_OUT_OF_MEMORY;
00233
00234 result = Curl_sendf(sockfd, conn,
00235 "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\r\n"
00236 "DEFINE "
00237 "%s "
00238 "%s\r\n"
00239 "QUIT\r\n",
00240 database,
00241 eword);
00242
00243 free(eword);
00244
00245 if(result) {
00246 failf(data, "Failed sending DICT request");
00247 return result;
00248 }
00249 Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
00250 -1, NULL);
00251 }
00252 else {
00253
00254 ppath = strchr(path, '/');
00255 if(ppath) {
00256 int i;
00257
00258 ppath++;
00259 for(i = 0; ppath[i]; i++) {
00260 if(ppath[i] == ':')
00261 ppath[i] = ' ';
00262 }
00263 result = Curl_sendf(sockfd, conn,
00264 "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\r\n"
00265 "%s\r\n"
00266 "QUIT\r\n", ppath);
00267 if(result) {
00268 failf(data, "Failed sending DICT request");
00269 return result;
00270 }
00271
00272 Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount, -1, NULL);
00273 }
00274 }
00275
00276 return CURLE_OK;
00277 }
00278 #endif