~ubuntu-branches/ubuntu/vivid/curl/vivid

« back to all changes in this revision

Viewing changes to lib/telnet.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2008, 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: telnet.c,v 1.99 2008-06-03 18:03:11 danf Exp $
 
21
 * $Id: telnet.c,v 1.109 2009-02-27 08:53:10 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
52
52
#ifdef HAVE_NET_IF_H
53
53
#include <net/if.h>
54
54
#endif
 
55
#ifdef HAVE_SYS_IOCTL_H
55
56
#include <sys/ioctl.h>
56
 
#include <signal.h>
 
57
#endif
57
58
 
58
59
#ifdef HAVE_SYS_PARAM_H
59
60
#include <sys/param.h>
77
78
#include "arpa_telnet.h"
78
79
#include "memory.h"
79
80
#include "select.h"
 
81
#include "strequal.h"
 
82
#include "rawstr.h"
80
83
 
81
84
/* The last #include file should be: */
82
85
#include "memdebug.h"
190
193
  ZERO_NULL,                            /* doing */
191
194
  ZERO_NULL,                            /* proto_getsock */
192
195
  ZERO_NULL,                            /* doing_getsock */
 
196
  ZERO_NULL,                            /* perform_getsock */
193
197
  ZERO_NULL,                            /* disconnect */
194
198
  PORT_TELNET,                          /* defport */
195
199
  PROT_TELNET                           /* protocol */
241
245
{
242
246
  struct TELNET *tn;
243
247
 
244
 
  tn = (struct TELNET *)calloc(1, sizeof(struct TELNET));
 
248
  tn = calloc(1, sizeof(struct TELNET));
245
249
  if(!tn)
246
250
    return CURLE_OUT_OF_MEMORY;
247
251
 
834
838
              option_keyword, option_arg) == 2) {
835
839
 
836
840
      /* Terminal type */
837
 
      if(curl_strequal(option_keyword, "TTYPE")) {
 
841
      if(Curl_raw_equal(option_keyword, "TTYPE")) {
838
842
        strncpy(tn->subopt_ttype, option_arg, 31);
839
843
        tn->subopt_ttype[31] = 0; /* String termination */
840
844
        tn->us_preferred[CURL_TELOPT_TTYPE] = CURL_YES;
842
846
      }
843
847
 
844
848
      /* Display variable */
845
 
      if(curl_strequal(option_keyword, "XDISPLOC")) {
 
849
      if(Curl_raw_equal(option_keyword, "XDISPLOC")) {
846
850
        strncpy(tn->subopt_xdisploc, option_arg, 127);
847
851
        tn->subopt_xdisploc[127] = 0; /* String termination */
848
852
        tn->us_preferred[CURL_TELOPT_XDISPLOC] = CURL_YES;
850
854
      }
851
855
 
852
856
      /* Environment variable */
853
 
      if(curl_strequal(option_keyword, "NEW_ENV")) {
 
857
      if(Curl_raw_equal(option_keyword, "NEW_ENV")) {
854
858
        buf = strdup(option_arg);
855
859
        if(!buf)
856
860
          return CURLE_OUT_OF_MEMORY;
1120
1124
/* Escape and send a telnet data block */
1121
1125
/* TODO: write large chunks of data instead of one byte at a time */
1122
1126
static CURLcode send_telnet_data(struct connectdata *conn,
1123
 
                                 char *buffer, ssize_t nread)
 
1127
                                 char *buffer, ssize_t nread)
1124
1128
{
1125
1129
  unsigned char outbuf[2];
1126
1130
  ssize_t bytes_written, total_written;
1140
1144
      pfd[0].fd = conn->sock[FIRSTSOCKET];
1141
1145
      pfd[0].events = POLLOUT;
1142
1146
      switch (Curl_poll(pfd, 1, -1)) {
1143
 
        case -1:                    /* error, abort writing */
1144
 
        case 0:                     /* timeout (will never happen) */
1145
 
          rc = CURLE_SEND_ERROR;
1146
 
          break;
1147
 
        default:                    /* write! */
1148
 
          bytes_written = 0;
1149
 
          rc = Curl_write(conn, conn->sock[FIRSTSOCKET], outbuf+total_written,
1150
 
                          out_count-total_written, &bytes_written);
1151
 
          total_written += bytes_written;
1152
 
          break;
 
1147
        case -1:                    /* error, abort writing */
 
1148
        case 0:                     /* timeout (will never happen) */
 
1149
          rc = CURLE_SEND_ERROR;
 
1150
          break;
 
1151
        default:                    /* write! */
 
1152
          bytes_written = 0;
 
1153
          rc = Curl_write(conn, conn->sock[FIRSTSOCKET], outbuf+total_written,
 
1154
                          out_count-total_written, &bytes_written);
 
1155
          total_written += bytes_written;
 
1156
          break;
1153
1157
      }
1154
1158
    /* handle partial write */
1155
1159
    } while (rc == CURLE_OK && total_written < out_count);
1289
1293
  if(event_select_func(sockfd, event_handle, FD_READ|FD_CLOSE) == SOCKET_ERROR) {
1290
1294
    close_event_func(event_handle);
1291
1295
    FreeLibrary(wsock2);
1292
 
    return 0;
 
1296
    return CURLE_OK;
1293
1297
  }
1294
1298
 
1295
1299
  /* If stdin_handle is a pipe, use PeekNamedPipe() method to check it,
1313
1317
      while(1) {
1314
1318
        if(!PeekNamedPipe(stdin_handle, NULL, 0, NULL, &readfile_read, NULL)) {
1315
1319
          keepon = FALSE;
1316
 
          code = CURLE_READ_ERROR;
 
1320
          code = CURLE_READ_ERROR;
1317
1321
          break;
1318
1322
        }
1319
1323
 
1323
1327
        if(!ReadFile(stdin_handle, buf, sizeof(data->state.buffer),
1324
1328
                     &readfile_read, NULL)) {
1325
1329
          keepon = FALSE;
1326
 
          code = CURLE_READ_ERROR;
 
1330
          code = CURLE_READ_ERROR;
1327
1331
          break;
1328
1332
        }
1329
1333
 
1330
1334
        code = send_telnet_data(conn, buf, readfile_read);
1331
 
        if(code) {
 
1335
        if(code) {
1332
1336
          keepon = FALSE;
1333
 
          break;
1334
 
        }
 
1337
          break;
 
1338
        }
1335
1339
      }
1336
1340
    }
1337
1341
    break;
1341
1345
      if(!ReadFile(stdin_handle, buf, sizeof(data->state.buffer),
1342
1346
                   &readfile_read, NULL)) {
1343
1347
        keepon = FALSE;
1344
 
        code = CURLE_READ_ERROR;
 
1348
        code = CURLE_READ_ERROR;
1345
1349
        break;
1346
1350
      }
1347
1351
 
1348
1352
      code = send_telnet_data(conn, buf, readfile_read);
1349
1353
      if(code) {
1350
 
        keepon = FALSE;
1351
 
        break;
 
1354
        keepon = FALSE;
 
1355
        break;
1352
1356
      }
1353
1357
    }
1354
1358
    break;
1413
1417
      if(pfd[1].revents & POLLIN) { /* read from stdin */
1414
1418
        nread = read(0, buf, 255);
1415
1419
        code = send_telnet_data(conn, buf, nread);
1416
 
        if(code) {
 
1420
        if(code) {
1417
1421
          keepon = FALSE;
1418
 
          break;
1419
 
        }
 
1422
          break;
 
1423
        }
1420
1424
      }
1421
1425
 
1422
1426
      if(pfd[0].revents & POLLIN) {