⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pppchat.c

📁 用于嵌入式系统的TCP/IP协议栈
💻 C
📖 第 1 页 / 共 4 页
字号:
            /*---------------------------------------------------------*/            /* Schedule the next command to occur after delay.         */            /*---------------------------------------------------------*/            Ppp->chat.timer.action = do_chat;            NetTimerStart(&Ppp->chat.timer, TICKS_PER_SEC * i);            return 0;          /*-----------------------------------------------------------*/          /* Check for "Password" command.                             */          /*-----------------------------------------------------------*/          case 'P':#if PPP_TRACE            /*---------------------------------------------------------*/            /* Log password notice if trace is enabled.                */            /*---------------------------------------------------------*/            pppLogn("CHAT sending password");#endif            /*---------------------------------------------------------*/            /* Set state and prepare pointers.                         */            /*---------------------------------------------------------*/            Ppp->chat.minor_state = SENDING;            Ppp->chat.saved = Ppp->chat.script + 1;            Ppp->chat.send = Ppp->public.chat.password;            Ppp->chat.script = NULL;            /*---------------------------------------------------------*/            /* Return and then start the "Sending" command.            */            /*---------------------------------------------------------*/            return 1;          /*-----------------------------------------------------------*/          /* Check for "Username" command.                             */          /*-----------------------------------------------------------*/          case 'N':#if PPP_TRACE            /*---------------------------------------------------------*/            /* Log user name if trace is enabled.                      */            /*---------------------------------------------------------*/            pppLogn("CHAT sending username \'%s\'",                    Ppp->public.chat.username);#endif            /*---------------------------------------------------------*/            /* Set state and prepare pointers.                         */            /*---------------------------------------------------------*/            Ppp->chat.minor_state = SENDING;            Ppp->chat.saved = Ppp->chat.script + 1;            Ppp->chat.send = Ppp->public.chat.username;            Ppp->chat.script = NULL;            /*---------------------------------------------------------*/            /* Return and then start the "Sending" command.            */            /*---------------------------------------------------------*/            return 1;          /*-----------------------------------------------------------*/          /* Check for "Send" command.                                 */          /*-----------------------------------------------------------*/          case 'S':#if PPP_TRACE            /*---------------------------------------------------------*/            /* Log send string if trace is enabled.                    */            /*---------------------------------------------------------*/            pppLogn("CHAT sending %s", string(Ppp->chat.script + 1));#endif            /*---------------------------------------------------------*/            /* Set state and ensure opening '\'' is present.           */            /*---------------------------------------------------------*/            Ppp->chat.minor_state = SENDING;            if (*++Ppp->chat.script != '\'')            {              fatal_error("missing \'");              return 0;            }            /*---------------------------------------------------------*/            /* Set send pointer to CHAT script and clear save pointer. */            /*---------------------------------------------------------*/            Ppp->chat.send = Ppp->chat.script + 1;            Ppp->chat.saved = NULL;            /*---------------------------------------------------------*/            /* Return and then start the "Sending" command.            */            /*---------------------------------------------------------*/            return 1;          /*-----------------------------------------------------------*/          /* Check for "Expecting" command.                            */          /*-----------------------------------------------------------*/          case 'E':#if PPP_TRACE            /*---------------------------------------------------------*/            /* Log expected input string if trace is enabled.          */            /*---------------------------------------------------------*/            pppLogn("CHAT expecting %s", string(Ppp->chat.script + 1));#endif            /*---------------------------------------------------------*/            /* Set state and ensure opening '\'' is present.           */            /*---------------------------------------------------------*/            Ppp->chat.minor_state = EXPECTING;            if (*++Ppp->chat.script != '\'')            {              fatal_error("missing \'");              return 0;            }            /*---------------------------------------------------------*/            /* Set script pointer to expect string and count length.   */            /*---------------------------------------------------------*/            Ppp->chat.match.string = ++Ppp->chat.script;            Ppp->chat.match.length = 0;            for (cp = Ppp->chat.script; *cp != '\''; ++cp)            {              if (*cp == '\0')              {                fatal_error("missing \'");                return 0;              }              ++Ppp->chat.match.length;            }            /*---------------------------------------------------------*/            /* Start timeout timer.                                    */            /*---------------------------------------------------------*/            Ppp->chat.timer.action = chat_timeout;            NetTimerStart(&Ppp->chat.timer, Ppp->chat.timeout);            /*---------------------------------------------------------*/            /* Return and then start the "Expecting" command.          */            /*---------------------------------------------------------*/            return 1;          /*-----------------------------------------------------------*/          /* Check for "Timeout" command.                              */          /*-----------------------------------------------------------*/          case 'T':            /*---------------------------------------------------------*/            /* Read number embedded in script string and set timeout.  */            /*---------------------------------------------------------*/            i = strtol(Ppp->chat.script + 1, &Ppp->chat.script, 10);            if (i <= 0)              i = DEFAULT_TIMEOUT;            Ppp->chat.timeout = TICKS_PER_SEC * i;#if PPP_TRACE            /*---------------------------------------------------------*/            /* Log new timeout value if trace is enabled.              */            /*---------------------------------------------------------*/            pppLogn("CHAT timeout set to %d seconds", i);#endif            /*---------------------------------------------------------*/            /* Return and then start the next command.                 */            /*---------------------------------------------------------*/            return 1;          /*-----------------------------------------------------------*/          /* Check for "Clear Abort" command.                          */          /*-----------------------------------------------------------*/          case 'C':#if PPP_TRACE            /*---------------------------------------------------------*/            /* Log command if trace is enabled.                        */            /*---------------------------------------------------------*/            pppLogn("CHAT clearing abort strings");#endif            /*---------------------------------------------------------*/            /* Clear previously defined abort strings.                 */            /*---------------------------------------------------------*/            for (i = 0; i < CHAT_ABORTS; ++i)              Ppp->chat.abort[i].string = NULL;            /*---------------------------------------------------------*/            /* Advance script pointer past 'C'.                        */            /*---------------------------------------------------------*/            ++Ppp->chat.script;            /*---------------------------------------------------------*/            /* Return and then start the next command.                 */            /*---------------------------------------------------------*/            return 1;        }      }      /*---------------------------------------------------------------*/      /* Finished with script for current state. Determine next state. */      /*---------------------------------------------------------------*/      next_state();      return 0;    case SENDING:      /*---------------------------------------------------------------*/      /* Process, looking for escape and terminal characters.          */      /*---------------------------------------------------------------*/      for (;; ++Ppp->chat.send)      {        /*-------------------------------------------------------------*/        /* Read character from send string, either main or substring.  */        /*-------------------------------------------------------------*/        ch = *Ppp->chat.send;        /*-------------------------------------------------------------*/        /* Send <CR> and break upon reaching send string end.          */        /*-------------------------------------------------------------*/        if (ch == '\'')        {          if (Ppp->chat.saved)          {            fatal_error("\' in substring");            return 0;          }          if (put_char('\r'))            return 0;          break;        }        /*-------------------------------------------------------------*/        /* Check for escape sequence.                                  */        /*-------------------------------------------------------------*/        if (ch == '\\')        {          /*-----------------------------------------------------------*/          /* Read escaped character and advance script pointer.        */          /*-----------------------------------------------------------*/          ch = *++Ppp->chat.send;          /*-----------------------------------------------------------*/          /* If '\c', enforce syntax and then just break.              */          /*-----------------------------------------------------------*/          if (ch == 'c')          {            ch = *++Ppp->chat.send;            if (ch != '\'')              fatal_error("\\c not at send string end");            break;          }          /*-----------------------------------------------------------*/          /* Parse the other escape commands.                          */          /*-----------------------------------------------------------*/          switch (ch)          {            case 'd':              /*-------------------------------------------------------*/              /* Continue after one second.                            */              /*-------------------------------------------------------*/              Ppp->chat.timer.action = do_chat;              NetTimerStart(&Ppp->chat.timer, TICKS_PER_SEC);              return 0;            case 'T':              /*-------------------------------------------------------*/              /* Switch to phone number substring.                     */              /*-------------------------------------------------------*/              if (Ppp->chat.saved)              {                fatal_error("\\T in substring");                return 0;              }              if (Ppp->public.chat.phone_number == NULL)              {                fatal_error("phone_number NULL");                return 0;              }              Ppp->chat.saved = Ppp->chat.send + 1;              Ppp->chat.send = Ppp->public.chat.phone_number;              ch = *Ppp->chat.send;              break;            case 'U':              /*-------------------------------------------------------*/              /* Switch to phone number two substring.                 */              /*-------------------------------------------------------*/              if (Ppp->chat.saved)              {                fatal_error("\\U in substring");                return 0;              }              if (Ppp->public.chat.phone_number2 == NULL)              {                fatal_error("phone_number2 NULL");                return 0;              }              Ppp->chat.saved = Ppp->chat.send + 1;              Ppp->chat.send = Ppp->public.chat.phone_number2;              ch = *Ppp->chat.send;              break;          }        }        /*-------------------------------------------------------------*/        /* Check for end of string or substring.                       */        /*-------------------------------------------------------------*/        if (ch == '\0')        {          /*-----------------------------------------------------------*/          /* Check if only sending substring (username or password).   */          /*-----------------------------------------------------------*/          if (Ppp->chat.script == NULL)          {            /*---------------------------------------------------------*/            /* Output '\r', returning if buffer is full.               */            /*---------------------------------------------------------*/            if (put_char('\r'))              return 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -