コード例 #1
0
ファイル: telnet.c プロジェクト: revelator/Revelator-Doom3
static void suboption(struct connectdata *conn)
{
    struct curl_slist *v;
    unsigned char temp[2048];
    int len;
    int tmplen;
    char varname[128];
    char varval[128];
    struct SessionHandle *data = conn->data;
    struct TELNET *tn = (struct TELNET *)conn->proto.telnet;

    printsub(data, '<', (unsigned char *)tn->subbuffer, CURL_SB_LEN(tn)+2);
    switch (CURL_SB_GET(tn))
    {
    case CURL_TELOPT_TTYPE:
        len = strlen(tn->subopt_ttype) + 4 + 2;
        snprintf((char *)temp, sizeof(temp),
                 "%c%c%c%c%s%c%c", CURL_IAC, CURL_SB, CURL_TELOPT_TTYPE,
                 CURL_TELQUAL_IS, tn->subopt_ttype, CURL_IAC, CURL_SE);
        (void)swrite(conn->sock[FIRSTSOCKET], temp, len);
        printsub(data, '>', &temp[2], len-2);
        break;
    case CURL_TELOPT_XDISPLOC:
        len = strlen(tn->subopt_xdisploc) + 4 + 2;
        snprintf((char *)temp, sizeof(temp),
                 "%c%c%c%c%s%c%c", CURL_IAC, CURL_SB, CURL_TELOPT_XDISPLOC,
                 CURL_TELQUAL_IS, tn->subopt_xdisploc, CURL_IAC, CURL_SE);
        (void)swrite(conn->sock[FIRSTSOCKET], temp, len);
        printsub(data, '>', &temp[2], len-2);
        break;
    case CURL_TELOPT_NEW_ENVIRON:
        snprintf((char *)temp, sizeof(temp),
                 "%c%c%c%c", CURL_IAC, CURL_SB, CURL_TELOPT_NEW_ENVIRON,
                 CURL_TELQUAL_IS);
        len = 4;

        for(v = tn->telnet_vars; v; v = v->next)
        {
            tmplen = (strlen(v->data) + 1);
            /* Add the variable only if it fits */
            if(len + tmplen < (int)sizeof(temp)-6)
            {
                sscanf(v->data, "%127[^,],%s", varname, varval);
                snprintf((char *)&temp[len], sizeof(temp) - len,
                         "%c%s%c%s", CURL_NEW_ENV_VAR, varname,
                         CURL_NEW_ENV_VALUE, varval);
                len += tmplen;
            }
        }
        snprintf((char *)&temp[len], sizeof(temp) - len,
                 "%c%c", CURL_IAC, CURL_SE);
        len += 2;
        (void)swrite(conn->sock[FIRSTSOCKET], temp, len);
        printsub(data, '>', &temp[2], len-2);
        break;
    }
    return;
}
コード例 #2
0
ファイル: telnet.c プロジェクト: AndyUI/curl
static void sendsuboption(struct connectdata *conn, int option)
{
  ssize_t bytes_written;
  int err;
  unsigned short x, y;
  unsigned char*uc1, *uc2;

  struct SessionHandle *data = conn->data;
  struct TELNET *tn = (struct TELNET *)data->req.protop;

  switch (option) {
  case CURL_TELOPT_NAWS:
    /* We prepare data to be sent */
    CURL_SB_CLEAR(tn);
    CURL_SB_ACCUM(tn, CURL_IAC);
    CURL_SB_ACCUM(tn, CURL_SB);
    CURL_SB_ACCUM(tn, CURL_TELOPT_NAWS);
    /* We must deal either with litte or big endien processors */
    /* Window size must be sent according to the 'network order' */
    x=htons(tn->subopt_wsx);
    y=htons(tn->subopt_wsy);
    uc1 = (unsigned char*)&x;
    uc2 = (unsigned char*)&y;
    CURL_SB_ACCUM(tn, uc1[0]);
    CURL_SB_ACCUM(tn, uc1[1]);
    CURL_SB_ACCUM(tn, uc2[0]);
    CURL_SB_ACCUM(tn, uc2[1]);

    CURL_SB_ACCUM(tn, CURL_IAC);
    CURL_SB_ACCUM(tn, CURL_SE);
    CURL_SB_TERM(tn);
    /* data suboption is now ready */

    printsub(data, '>', (unsigned char *)tn->subbuffer+2,
             CURL_SB_LEN(tn)-2);

    /* we send the header of the suboption... */
    bytes_written = swrite(conn->sock[FIRSTSOCKET], tn->subbuffer, 3);
    if(bytes_written < 0) {
      err = SOCKERRNO;
      failf(data, "Sending data failed (%d)", err);
    }
    /* ... then the window size with the send_telnet_data() function
       to deal with 0xFF cases ... */
    send_telnet_data(conn, (char *)tn->subbuffer+3, 4);
    /* ... and the footer */
    bytes_written = swrite(conn->sock[FIRSTSOCKET], tn->subbuffer+7, 2);
    if(bytes_written < 0) {
      err = SOCKERRNO;
      failf(data, "Sending data failed (%d)", err);
    }
    break;
  }
}
コード例 #3
0
ファイル: telnet.c プロジェクト: chengdong0421/curl
static void suboption(struct connectdata *conn)
{
  struct curl_slist *v;
  unsigned char temp[2048];
  ssize_t bytes_written;
  size_t len;
  size_t tmplen;
  int err;
  char varname[128] = "";
  char varval[128] = "";
  struct Curl_easy *data = conn->data;
  struct TELNET *tn = (struct TELNET *)data->req.protop;

  printsub(data, '<', (unsigned char *)tn->subbuffer, CURL_SB_LEN(tn)+2);
  switch(CURL_SB_GET(tn)) {
    case CURL_TELOPT_TTYPE:
      len = strlen(tn->subopt_ttype) + 4 + 2;
      snprintf((char *)temp, sizeof(temp),
               "%c%c%c%c%s%c%c", CURL_IAC, CURL_SB, CURL_TELOPT_TTYPE,
               CURL_TELQUAL_IS, tn->subopt_ttype, CURL_IAC, CURL_SE);
      bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
      if(bytes_written < 0) {
        err = SOCKERRNO;
        failf(data,"Sending data failed (%d)",err);
      }
      printsub(data, '>', &temp[2], len-2);
      break;
    case CURL_TELOPT_XDISPLOC:
      len = strlen(tn->subopt_xdisploc) + 4 + 2;
      snprintf((char *)temp, sizeof(temp),
               "%c%c%c%c%s%c%c", CURL_IAC, CURL_SB, CURL_TELOPT_XDISPLOC,
               CURL_TELQUAL_IS, tn->subopt_xdisploc, CURL_IAC, CURL_SE);
      bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
      if(bytes_written < 0) {
        err = SOCKERRNO;
        failf(data,"Sending data failed (%d)",err);
      }
      printsub(data, '>', &temp[2], len-2);
      break;
    case CURL_TELOPT_NEW_ENVIRON:
      snprintf((char *)temp, sizeof(temp),
               "%c%c%c%c", CURL_IAC, CURL_SB, CURL_TELOPT_NEW_ENVIRON,
               CURL_TELQUAL_IS);
      len = 4;

      for(v = tn->telnet_vars;v;v = v->next) {
        tmplen = (strlen(v->data) + 1);
        /* Add the variable only if it fits */
        if(len + tmplen < (int)sizeof(temp)-6) {
          if(sscanf(v->data, "%127[^,],%127s", varname, varval)) {
            snprintf((char *)&temp[len], sizeof(temp) - len,
                     "%c%s%c%s", CURL_NEW_ENV_VAR, varname,
                     CURL_NEW_ENV_VALUE, varval);
            len += tmplen;
          }
        }
      }
      snprintf((char *)&temp[len], sizeof(temp) - len,
               "%c%c", CURL_IAC, CURL_SE);
      len += 2;
      bytes_written = swrite(conn->sock[FIRSTSOCKET], temp, len);
      if(bytes_written < 0) {
        err = SOCKERRNO;
        failf(data,"Sending data failed (%d)",err);
      }
      printsub(data, '>', &temp[2], len-2);
      break;
  }
  return;
}