dict.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2002, Daniel Stenberg, <[email protected]>, 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$
  22. ***************************************************************************/
  23. #include "setup.h"
  24. /* -- WIN32 approved -- */
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <stdarg.h>
  28. #include <stdlib.h>
  29. #include <ctype.h>
  30. #include <sys/types.h>
  31. #include <sys/stat.h>
  32. #include <errno.h>
  33. #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
  34. #include <winsock.h>
  35. #include <time.h>
  36. #include <io.h>
  37. #else
  38. #ifdef HAVE_SYS_SOCKET_H
  39. #include <sys/socket.h>
  40. #endif
  41. #include <netinet/in.h>
  42. #include <sys/time.h>
  43. #include <sys/resource.h>
  44. #ifdef HAVE_UNISTD_H
  45. #include <unistd.h>
  46. #endif
  47. #include <netdb.h>
  48. #ifdef HAVE_ARPA_INET_H
  49. #include <arpa/inet.h>
  50. #endif
  51. #ifdef HAVE_NET_IF_H
  52. #include <net/if.h>
  53. #endif
  54. #include <sys/ioctl.h>
  55. #include <signal.h>
  56. #ifdef HAVE_SYS_PARAM_H
  57. #include <sys/param.h>
  58. #endif
  59. #ifdef HAVE_SYS_SELECT_H
  60. #include <sys/select.h>
  61. #endif
  62. #endif
  63. #include "urldata.h"
  64. #include <curl/curl.h>
  65. #include "transfer.h"
  66. #include "sendf.h"
  67. #include "progress.h"
  68. #include "strequal.h"
  69. #define _MPRINTF_REPLACE /* use our functions only */
  70. #include <curl/mprintf.h>
  71. CURLcode Curl_dict(struct connectdata *conn)
  72. {
  73. int nth;
  74. char *word;
  75. char *ppath;
  76. char *database = NULL;
  77. char *strategy = NULL;
  78. char *nthdef = NULL; /* This is not part of the protocol, but required
  79. by RFC 2229 */
  80. CURLcode result=CURLE_OK;
  81. struct SessionHandle *data=conn->data;
  82. char *path = conn->path;
  83. long *bytecount = &conn->bytecount;
  84. if(conn->bits.user_passwd) {
  85. /* AUTH is missing */
  86. }
  87. if (strnequal(path, DICT_MATCH, sizeof(DICT_MATCH)-1) ||
  88. strnequal(path, DICT_MATCH2, sizeof(DICT_MATCH2)-1) ||
  89. strnequal(path, DICT_MATCH3, sizeof(DICT_MATCH3)-1)) {
  90. word = strchr(path, ':');
  91. if (word) {
  92. word++;
  93. database = strchr(word, ':');
  94. if (database) {
  95. *database++ = (char)0;
  96. strategy = strchr(database, ':');
  97. if (strategy) {
  98. *strategy++ = (char)0;
  99. nthdef = strchr(strategy, ':');
  100. if (nthdef) {
  101. *nthdef++ = (char)0;
  102. }
  103. }
  104. }
  105. }
  106. if ((word == NULL) || (*word == (char)0)) {
  107. failf(data, "lookup word is missing");
  108. }
  109. if ((database == NULL) || (*database == (char)0)) {
  110. database = (char *)"!";
  111. }
  112. if ((strategy == NULL) || (*strategy == (char)0)) {
  113. strategy = (char *)".";
  114. }
  115. if ((nthdef == NULL) || (*nthdef == (char)0)) {
  116. nth = 0;
  117. }
  118. else {
  119. nth = atoi(nthdef);
  120. }
  121. result = Curl_sendf(conn->firstsocket, conn,
  122. "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\n"
  123. "MATCH "
  124. "%s " /* database */
  125. "%s " /* strategy */
  126. "%s\n" /* word */
  127. "QUIT\n",
  128. database,
  129. strategy,
  130. word
  131. );
  132. if(result)
  133. failf(data, "Failed sending DICT request");
  134. else
  135. result = Curl_Transfer(conn, conn->firstsocket, -1, FALSE, bytecount,
  136. -1, NULL); /* no upload */
  137. if(result)
  138. return result;
  139. }
  140. else if (strnequal(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) ||
  141. strnequal(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) ||
  142. strnequal(path, DICT_DEFINE3, sizeof(DICT_DEFINE3)-1)) {
  143. word = strchr(path, ':');
  144. if (word) {
  145. word++;
  146. database = strchr(word, ':');
  147. if (database) {
  148. *database++ = (char)0;
  149. nthdef = strchr(database, ':');
  150. if (nthdef) {
  151. *nthdef++ = (char)0;
  152. }
  153. }
  154. }
  155. if ((word == NULL) || (*word == (char)0)) {
  156. failf(data, "lookup word is missing");
  157. }
  158. if ((database == NULL) || (*database == (char)0)) {
  159. database = (char *)"!";
  160. }
  161. if ((nthdef == NULL) || (*nthdef == (char)0)) {
  162. nth = 0;
  163. }
  164. else {
  165. nth = atoi(nthdef);
  166. }
  167. result = Curl_sendf(conn->firstsocket, conn,
  168. "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\n"
  169. "DEFINE "
  170. "%s " /* database */
  171. "%s\n" /* word */
  172. "QUIT\n",
  173. database,
  174. word);
  175. if(result)
  176. failf(data, "Failed sending DICT request");
  177. else
  178. result = Curl_Transfer(conn, conn->firstsocket, -1, FALSE, bytecount,
  179. -1, NULL); /* no upload */
  180. if(result)
  181. return result;
  182. }
  183. else {
  184. ppath = strchr(path, '/');
  185. if (ppath) {
  186. int i;
  187. ppath++;
  188. for (i = 0; ppath[i]; i++) {
  189. if (ppath[i] == ':')
  190. ppath[i] = ' ';
  191. }
  192. result = Curl_sendf(conn->firstsocket, conn,
  193. "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\n"
  194. "%s\n"
  195. "QUIT\n", ppath);
  196. if(result)
  197. failf(data, "Failed sending DICT request");
  198. else
  199. result = Curl_Transfer(conn, conn->firstsocket, -1, FALSE, bytecount,
  200. -1, NULL);
  201. if(result)
  202. return result;
  203. }
  204. }
  205. return CURLE_OK;
  206. }
  207. /*
  208. * local variables:
  209. * eval: (load-file "../curl-mode.el")
  210. * end:
  211. * vim600: fdm=marker
  212. * vim: et sw=2 ts=2 sts=2 tw=78
  213. */