]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/curl/lib/dict.c
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / curl / lib / dict.c
1 /***************************************************************************
2  *                                  _   _ ____  _     
3  *  Project                     ___| | | |  _ \| |    
4  *                             / __| | | | |_) | |    
5  *                            | (__| |_| |  _ <| |___ 
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
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.
13  * 
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.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  * $Id: dict.c,v 1.34 2004/03/09 22:52:50 bagder Exp $
22  ***************************************************************************/
23
24 #include "setup.h"
25
26 /* -- WIN32 approved -- */
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdarg.h>
30 #include <stdlib.h>
31 #include <ctype.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34
35 #include <errno.h>
36
37 #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
38 #include <time.h>
39 #include <io.h>
40 #else
41 #ifdef HAVE_SYS_SOCKET_H
42 #include <sys/socket.h>
43 #endif
44 #include <netinet/in.h>
45 #include <sys/time.h>
46 #ifdef HAVE_UNISTD_H
47 #include <unistd.h>
48 #endif
49 #include <netdb.h>
50 #ifdef HAVE_ARPA_INET_H
51 #include <arpa/inet.h>
52 #endif
53 #ifdef HAVE_NET_IF_H
54 #include <net/if.h>
55 #endif
56 #include <sys/ioctl.h>
57 #include <signal.h>
58
59 #ifdef HAVE_SYS_PARAM_H
60 #include <sys/param.h>
61 #endif
62
63 #ifdef HAVE_SYS_SELECT_H
64 #include <sys/select.h>
65 #endif
66
67
68 #endif
69
70 #include "urldata.h"
71 #include <curl/curl.h>
72 #include "transfer.h"
73 #include "sendf.h"
74
75 #include "progress.h"
76 #include "strequal.h"
77 #include "dict.h"
78
79 #define _MPRINTF_REPLACE /* use our functions only */
80 #include <curl/mprintf.h>
81
82 CURLcode Curl_dict(struct connectdata *conn)
83 {
84   char *word;
85   char *ppath;
86   char *database = NULL;
87   char *strategy = NULL;
88   char *nthdef = NULL; /* This is not part of the protocol, but required
89                           by RFC 2229 */
90   CURLcode result=CURLE_OK;
91   struct SessionHandle *data=conn->data;
92   curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
93
94   char *path = conn->path;
95   curl_off_t *bytecount = &conn->bytecount;
96
97   if(conn->bits.user_passwd) {
98     /* AUTH is missing */
99   }
100
101   if (strnequal(path, DICT_MATCH, sizeof(DICT_MATCH)-1) ||
102       strnequal(path, DICT_MATCH2, sizeof(DICT_MATCH2)-1) ||
103       strnequal(path, DICT_MATCH3, sizeof(DICT_MATCH3)-1)) {
104       
105     word = strchr(path, ':');
106     if (word) {
107       word++;
108       database = strchr(word, ':');
109       if (database) {
110         *database++ = (char)0;
111         strategy = strchr(database, ':');
112         if (strategy) {
113           *strategy++ = (char)0;
114           nthdef = strchr(strategy, ':');
115           if (nthdef) {
116             *nthdef++ = (char)0;
117           }
118         }
119       }
120     }
121       
122     if ((word == NULL) || (*word == (char)0)) {
123       failf(data, "lookup word is missing");
124     }
125     if ((database == NULL) || (*database == (char)0)) {
126       database = (char *)"!";
127     }
128     if ((strategy == NULL) || (*strategy == (char)0)) {
129       strategy = (char *)".";
130     }
131       
132     result = Curl_sendf(sockfd, conn,
133                         "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\n"
134                         "MATCH "
135                         "%s "    /* database */
136                         "%s "    /* strategy */
137                         "%s\n"   /* word */
138                         "QUIT\n",
139                         
140                         database,
141                         strategy,
142                         word
143                         );
144     if(result)
145       failf(data, "Failed sending DICT request");
146     else
147       result = Curl_Transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
148                              -1, NULL); /* no upload */      
149     if(result)
150       return result;
151   }
152   else if (strnequal(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) ||
153            strnequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) ||
154            strnequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3)-1)) {
155     
156     word = strchr(path, ':');
157     if (word) {
158       word++;
159       database = strchr(word, ':');
160       if (database) {
161         *database++ = (char)0;
162         nthdef = strchr(database, ':');
163         if (nthdef) {
164           *nthdef++ = (char)0;
165         }
166       }
167     }
168       
169     if ((word == NULL) || (*word == (char)0)) {
170       failf(data, "lookup word is missing");
171     }
172     if ((database == NULL) || (*database == (char)0)) {
173       database = (char *)"!";
174     }
175       
176     result = Curl_sendf(sockfd, conn,
177                         "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\n"
178                         "DEFINE "
179                         "%s "     /* database */
180                         "%s\n"    /* word */
181                         "QUIT\n",
182                         database,
183                         word);
184     if(result)
185       failf(data, "Failed sending DICT request");
186     else
187       result = Curl_Transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
188                              -1, NULL); /* no upload */
189     
190     if(result)
191       return result;
192       
193   }
194   else {
195       
196     ppath = strchr(path, '/');
197     if (ppath) {
198       int i;
199         
200       ppath++;
201       for (i = 0; ppath[i]; i++) {
202         if (ppath[i] == ':')
203           ppath[i] = ' ';
204       }
205       result = Curl_sendf(sockfd, conn,
206                           "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\n"
207                           "%s\n"
208                           "QUIT\n", ppath);
209       if(result)
210         failf(data, "Failed sending DICT request");
211       else
212         result = Curl_Transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount,
213                                -1, NULL);
214       if(result)
215         return result;
216     }
217   }
218
219   return CURLE_OK;
220 }