doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dict.c
Go to the documentation of this file.
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 
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 */
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 }
struct ConnectBits bits
Definition: urldata.h:462
curl_off_t bytecount
Definition: urldata.h:437
int curl_socket_t
Definition: setup.h:254
#define FIRSTSOCKET
Definition: urldata.h:394
CURLcode Curl_dict(struct connectdata *conn)
Definition: dict.c:82
#define failf
Definition: sendf.h:32
#define strnequal(a, b, c)
Definition: strequal.h:33
CURLcode
Definition: curl.h:209
off_t curl_off_t
Definition: curl.h:96
#define LIBCURL_NAME
Definition: urldata.h:911
int i
Definition: process.py:33
Boolean result
#define DICT_MATCH
Definition: urldata.h:39
#define NULL
Definition: Lib.h:88
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:2853
#define DICT_MATCH2
Definition: urldata.h:40
const char * path
Definition: sws.c:117
#define DICT_DEFINE3
Definition: urldata.h:44
#define LIBCURL_VERSION
Definition: curl.h:32
#define DICT_DEFINE2
Definition: urldata.h:43
CURLcode Curl_Transfer(struct connectdata *c_conn, int sockindex, curl_off_t size, bool getheader, curl_off_t *bytecountp, int writesockindex, curl_off_t *writecountp)
Definition: transfer.c:1998
Definition: curl.h:210
struct SessionHandle * data
Definition: urldata.h:403
unsigned short word
Definition: Lib.h:76
curl_socket_t sock[2]
Definition: urldata.h:454
#define FALSE
Definition: mprintf.c:70
char * path
Definition: urldata.h:431
CURLcode Curl_sendf(curl_socket_t sockfd, struct connectdata *conn, const char *fmt,...)
Definition: sendf.c:172
#define DICT_DEFINE
Definition: urldata.h:42
bool user_passwd
Definition: urldata.h:282
#define DICT_MATCH3
Definition: urldata.h:41