~ubuntu-branches/ubuntu/gutsy/curl/gutsy

« back to all changes in this revision

Viewing changes to lib/dict.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-29 15:04:24 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060629150424-pn00qumt9sml8p4m
Tags: 7.15.4-1ubuntu1
Synchronize to Debian. Only change left: Removal of stunnel and
libdb4.2-dev build dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: dict.c,v 1.39 2005/02/09 13:06:40 bagder Exp $
 
21
 * $Id: dict.c,v 1.41 2006-05-10 11:44:31 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
38
38
#include <sys/stat.h>
39
39
#endif
40
40
 
41
 
#include <errno.h>
42
 
 
43
41
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
44
42
#include <time.h>
45
43
#include <io.h>
85
83
#define _MPRINTF_REPLACE /* use our functions only */
86
84
#include <curl/mprintf.h>
87
85
 
 
86
/* The last #include file should be: */
 
87
#include "memdebug.h"
 
88
 
 
89
static char *unescape_word(struct SessionHandle *data, char *inp)
 
90
{
 
91
  char *newp;
 
92
  char *dictp;
 
93
  char *ptr;
 
94
  int len;
 
95
  unsigned char byte;
 
96
  int olen=0;
 
97
 
 
98
  newp = curl_easy_unescape(data, inp, 0, &len);
 
99
  if(!newp)
 
100
    return NULL;
 
101
 
 
102
  dictp = malloc(len*2 + 1); /* add one for terminating zero */
 
103
  if(dictp) {
 
104
    /* According to RFC2229 section 2.2, these letters need to be escaped with
 
105
       \[letter] */
 
106
    for(ptr = newp;
 
107
        (byte = (unsigned char)*ptr);
 
108
        ptr++) {
 
109
      if ((byte <= 32) || (byte == 127) ||
 
110
          (byte == '\'') || (byte == '\"') || (byte == '\\')) {
 
111
        dictp[olen++] = '\\';
 
112
      }
 
113
      dictp[olen++] = byte;
 
114
    }
 
115
    dictp[olen]=0;
 
116
 
 
117
    free(newp);
 
118
  }
 
119
  return dictp;
 
120
}
 
121
 
88
122
CURLcode Curl_dict(struct connectdata *conn, bool *done)
89
123
{
90
124
  char *word;
 
125
  char *eword;
91
126
  char *ppath;
92
127
  char *database = NULL;
93
128
  char *strategy = NULL;
137
172
      strategy = (char *)".";
138
173
    }
139
174
 
 
175
    eword = unescape_word(data, word);
 
176
    if(!eword)
 
177
      return CURLE_OUT_OF_MEMORY;
 
178
 
140
179
    result = Curl_sendf(sockfd, conn,
141
180
                        "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\r\n"
142
181
                        "MATCH "
147
186
 
148
187
                        database,
149
188
                        strategy,
150
 
                        word
 
189
                        eword
151
190
                        );
 
191
 
 
192
    free(eword);
 
193
 
152
194
    if(result)
153
195
      failf(data, "Failed sending DICT request");
154
196
    else
181
223
      database = (char *)"!";
182
224
    }
183
225
 
 
226
    eword = unescape_word(data, word);
 
227
    if(!eword)
 
228
      return CURLE_OUT_OF_MEMORY;
 
229
 
184
230
    result = Curl_sendf(sockfd, conn,
185
231
                        "CLIENT " LIBCURL_NAME " " LIBCURL_VERSION "\r\n"
186
232
                        "DEFINE "
188
234
                        "%s\r\n"  /* word */
189
235
                        "QUIT\r\n",
190
236
                        database,
191
 
                        word);
 
237
                        eword);
 
238
 
 
239
    free(eword);
 
240
 
192
241
    if(result)
193
242
      failf(data, "Failed sending DICT request");
194
243
    else