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