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

📄 netdiagnostics.c

📁 基于高通的brew平台上的手机网络诊断程序netdiagnostics
💻 C
📖 第 1 页 / 共 4 页
字号:
   pApp->m_pszMsg = "";

   // Duplicte form data so we can write over it
   
   StrReplace(&pApp->m_pszFormData, pszSubmit);

   // Locate, decode, and process form fields
   
   pszIter = pApp->m_pszFormData;

   if (!pszIter) {
      return;
   }

   pszIter = STRCHREND(pszIter, '?');
   if (*pszIter) {
      ++pszIter;
   }

   {
      IWebUtil     *piwu;
      WebFormField  wff;

      // go get me a gosh-darn parsin' machine
      if (SUCCESS != ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_WEBUTIL,
                                           (void **)&piwu)) {
         return;
      }
      
      // all pointers into a string we STRDUP'ed, all NULL terminated
      // by IWebUtil in place for me
      
      // IWebUtil can parse a bunch at a time, but we'll just iterate here

      while (0 != IWEBUTIL_ParseFormFields(piwu,&pszIter,&wff,1,0)) {
         boolean bOn = STREQ(wff.pcValue, "on");
         if (STREQ(wff.pcName, "HOST")) {
            pApp->m_pszHost = wff.pcValue;
         } else if (STREQ(wff.pcName, "URL")) {
            pApp->m_pszURL = wff.pcValue;
         } else if (STREQ(wff.pcName, "MSG")) {
            pApp->m_pszMsg = wff.pcValue;
         } else if (STREQ(wff.pcName, "RS")) {
            pApp->m_bRS = bOn;
         } else if (STREQ(wff.pcName, "RT")) {
            pApp->m_bRT = bOn;
         } else if (STREQ(wff.pcName, "PROTOCOL")) {
            if (STREQ(wff.pcValue, "1")) {
               pApp->m_bTCP = 1;
            }
         }
      }
      IWEBUTIL_Release(piwu);
      piwu = 0;
   }

   pApp->m_nDataLength = STRLEN(pApp->m_pszMsg);
   
   // Create Static Control to Display Messages
   if (ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_STATIC,(void**)&pApp->m_pIStatic) == AEE_SUCCESS)
      pStatic = pApp->m_pIStatic;   // Cache Pointer
   else
      return;

   ISTATIC_SetRect(pStatic, &pApp->m_rc);
   ISTATIC_SetProperties(pStatic, ST_ASCII|ST_NOSCROLL);

   // Disable Browser
   SETAEERECT(&rc, 0, 0, 0, 0);
   IHTMLVIEWER_SetRect(pApp->m_pHTMLViewer, &rc);

   // Clear Screen
   IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);

   ND_Print(pApp, "** starting...\n");

   if (STRBEGINS(JUMP_ECHOTEST, pszSubmit)) {

      // Make note of type of cleanup to be performed when we exit this state   
      pApp->m_pfnViewCleanup = ND_EchoCleanup;
      
      // Start Echo Test
      Echoer_Start(pApp);

   } else {
      // Make note of type of cleanup to be performed when we exit this state   
      pApp->m_pfnViewCleanup = ND_HTTPCleanup;

      // Start HTTP test(s)
      FOR_ALL_WEBACTIONS(pApp, p, WebAction_Start(p, pApp->m_pszURL) );
   }
}

/*===========================================================================

FUNCTION: Echoer_Start

DESCRIPTION:
	Starts Echo Test

PARAMETERS:
	pApp [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
    information specific to this applet. 

DEPENDENCIES:
  Assumes the displayed controls have been previously created and 
  initialized.

RETURN VALUE:
  None

SIDE EFFECTS:
  Causes the phone display to be updated.
===========================================================================*/
static void Echoer_Start(CNetDiagnosticsApp * pApp)
{
   // Reset statistics
   pApp->m_nTotalTime = pApp->m_nSendTime = pApp->m_nReceiveTime = 0;

   pApp->m_pISocket = INETMGR_OpenSocket(pApp->m_pINetMgr, (pApp->m_bTCP ? AEE_SOCK_STREAM : AEE_SOCK_DGRAM));

   if (pApp->m_pISocket == NULL) {
      ND_Print(pApp, "** OpenSocket Failed: Error %d\n", INETMGR_GetLastError(pApp->m_pINetMgr));
      return;
   }

   if (pApp->m_bTCP)
      Echoer_TCPConnect(pApp);
   else
      Echoer_UDPWrite(pApp);
}

/*===========================================================================

FUNCTION: Echoer_TCPConnected

DESCRIPTION:
	Callback for ISOCKET_Connect.

PARAMETERS:
	p [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
    information specific to this applet.
   nErr - Error Code 

DEPENDENCIES:
   None

RETURN VALUE:
   None

SIDE EFFECTS:
   None
===========================================================================*/
static void Echoer_TCPConnected(void *p, int nErr)
{
   CNetDiagnosticsApp * pApp = (CNetDiagnosticsApp *)p;

   if ((nErr == AEE_NET_SUCCESS) || (nErr == AEE_NET_EISCONN)){
      pApp->m_nTCPIdx = 0;

      // Cache Write Start Time
      pApp->m_nSendTime = GETUPTIMEMS();

      Echoer_TCPWrite(pApp);    
   } else {
      ND_Print(pApp, "** Connect Failed: Error %d\n", nErr);
      ReleaseObj((void**)&pApp->m_pISocket);
   }
}

/*===========================================================================

FUNCTION: Echoer_TCPConnect

DESCRIPTION:
	Connects to a socket

PARAMETERS:
	pApp [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
    information specific to this applet.

DEPENDENCIES:
   None

RETURN VALUE:
   None

SIDE EFFECTS:
   None
===========================================================================*/
static void Echoer_TCPConnect(CNetDiagnosticsApp * pApp)
{
   // GetHostByName() understands dot-notation IP addresses as well as domain
   // names so we don't need to call INET_ATON() separately (as on other
   // platforms).

   CALLBACK_Init(&pApp->m_cb,Echoer_TCPDNSConnect,pApp);
   INETMGR_GetHostByName(pApp->m_pINetMgr,&pApp->m_dnsr, pApp->m_pszHost,&pApp->m_cb);
}

/*===========================================================================

FUNCTION: Echoer_TCPDNSConnect

DESCRIPTION:
	Connects to a socket when IP address is to be resolved using DNS.

PARAMETERS:
	pApp [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
    information specific to this applet.

DEPENDENCIES:
   None

RETURN VALUE:
   None

SIDE EFFECTS:
   None
===========================================================================*/
static void Echoer_TCPDNSConnect(void *p)
{
   int nErr;
   CNetDiagnosticsApp * pApp = (CNetDiagnosticsApp *)p;

   nErr = pApp->m_dnsr.nResult;

   if (nErr > AEEDNSMAXADDRS) {
      ND_Print(pApp, "** DNS Lookup Failed: Error %d\n", nErr);
      ReleaseObj((void**)&pApp->m_pISocket);
      return;
   }

   // Cache Start Time
   pApp->m_nTotalTime = GETUPTIMEMS();

   nErr = ISOCKET_Connect(pApp->m_pISocket, pApp->m_dnsr.addrs[0], 0x700, Echoer_TCPConnected, pApp);

   if (nErr != AEE_NET_SUCCESS) {
      ND_Print(pApp, "** Connect Failed: Error %d\n", ISOCKET_GetLastError(pApp->m_pISocket));
      ReleaseObj((void**)&pApp->m_pISocket);
   } else {
      ND_Print(pApp, "** connecting...\n");
   }
}
/*===========================================================================

FUNCTION: Echoer_TCPWrite

DESCRIPTION:
	Writes to a socket

PARAMETERS:
	pApp [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
    information specific to this applet.

DEPENDENCIES:
   None

RETURN VALUE:
   None

SIDE EFFECTS:
   None
===========================================================================*/
static void Echoer_TCPWrite(CNetDiagnosticsApp * pApp)
{
   int         nSent;

   nSent = ISOCKET_Write(pApp->m_pISocket,((byte *)pApp->m_pszMsg) + pApp->m_nTCPIdx,
                         (uint16)(pApp->m_nDataLength - pApp->m_nTCPIdx));
   
   if (nSent == AEE_NET_ERROR) {
      ND_Print(pApp, "** Write Failed: Error %d\n", ISOCKET_GetLastError(pApp->m_pISocket));
      ReleaseObj((void**)&pApp->m_pISocket);
      return;
   }
   else if (nSent == AEE_NET_WOULDBLOCK) {
      ND_Print(pApp, "** writing...\n");
      ISOCKET_Writeable(pApp->m_pISocket,(PFNNOTIFY)Echoer_TCPWrite,pApp);
   }
   else {
      pApp->m_nTCPIdx += nSent;
      if (pApp->m_nTCPIdx >= pApp->m_nDataLength) {
         // Writing Complete
         // Calculate Send Time
         pApp->m_nSendTime = (GETUPTIMEMS() - pApp->m_nSendTime);
         // Reset Index
         pApp->m_nTCPIdx = 0;
         // Reset Buffer
         MEMSET(pApp->m_pszMsg, 0, pApp->m_nDataLength);
         // Display Message
         ND_Print(pApp, "** writing complete...\n");
         // Cache Read Time
         pApp->m_nReceiveTime = GETUPTIMEMS();
         // Start Reading
         Echoer_TCPRead(pApp);
         return;
      }
      else {
         Echoer_TCPWrite(pApp);
      }
   }

}

/*===========================================================================

FUNCTION: Echoer_TCPRead

DESCRIPTION:
	Reads from a socket

PARAMETERS:
	pApp [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
    information specific to this applet.

DEPENDENCIES:
   None

RETURN VALUE:
   None

SIDE EFFECTS:
   None
===========================================================================*/
static void Echoer_TCPRead(CNetDiagnosticsApp * pApp)
{
   int       nRead;

   nRead = ISOCKET_Read(pApp->m_pISocket, ((byte *)pApp->m_pszMsg) + pApp->m_nTCPIdx, 
                        pApp->m_nDataLength - pApp->m_nTCPIdx);
   
   if (nRead == AEE_NET_ERROR) {
      ND_Print(pApp, "** Read Failed: Error %d\n", ISOCKET_GetLastError(pApp->m_pISocket));
      ReleaseObj((void**)&pApp->m_pISocket);
      return;
   }
   else if (nRead == AEE_NET_WOULDBLOCK) {
      ND_Print(pApp, "** reading...\n");
      ISOCKET_Readable(pApp->m_pISocket, (PFNNOTIFY)Echoer_TCPRead, pApp);
   }
   else {
      pApp->m_nTCPIdx += nRead;
      if (pApp->m_nTCPIdx >= pApp->m_nDataLength) {
         // Calulate Receive Time
         pApp->m_nReceiveTime = (GETUPTIMEMS() - pApp->m_nReceiveTime);
         // Calculate Total Time
         pApp->m_nTotalTime = (GETUPTIMEMS() - pApp->m_nTotalTime);
         pApp->m_nTCPIdx = 0;
         ND_Print(pApp, "** reading Complete...\n");
         if (pApp->m_bRS) {
            ND_Print(pApp, "%s\n", pApp->m_pszMsg);
         }
         if (pApp->m_bRT) {
            ND_Print(pApp, ("Total Time: %d ms\n"
                            "Send Time: %d ms @ %d bps\n"
                            "Receive Time: %d ms @ %d bps\n"),
                     pApp->m_nTotalTime,
                     pApp->m_nSendTime, (pApp->m_nSendTime ? (pApp->m_nDataLength*1000)/pApp->m_nSendTime : 0),
                     pApp->m_nReceiveTime, (pApp->m_nReceiveTime ? (pApp->m_nDataLength*1000)/pApp->m_nReceiveTime : 0));
         }
         ReleaseObj((void**)&pApp->m_pISocket);
         return;
      }
      else {
         Echoer_TCPRead(pApp);
      }
   }
}

/*===========================================================================

FUNCTION: Echoer_UDPWrite

DESCRIPTION:
	Send UDP data to a socket

PARAMETERS:
	pApp [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
    information specific to this applet.

DEPENDENCIES:
   None

RETURN VALUE:
   None

SIDE EFFECTS:
   None
===========================================================================*/
static void Echoer_UDPWrite(CNetDiagnosticsApp * pApp)
{
   // GetHostByName() understands dot-notation IP addresses as well as domain
   // names so we don't need to call INET_ATON() separately (as on other
   // platforms).
   
   CALLBACK_Init(&pApp->m_cb,Echoer_UDPDNSWrite,pApp);
   INETMGR_GetHostByName(pApp->m_pINetMgr,&pApp->m_dnsr, pApp->m_pszHost,&pApp->m_cb);
}

/*===========================================================================

FUNCTION: Echoer_UDPDNSWrite

DESCRIPTION:
	Send UDP packet to a socket when IP address is to be resolved using DNS.

PARAMETERS:
	pApp [in] - Pointer to the CNetDiagnosticsApp structure. This structure contains 
    information specific to this applet.

DEPENDENCIES:
   None

RETURN VALUE:
   None

SIDE EFFECTS:
   None
===========================================================================*/
static void Echoer_UDPDNSWrite(void *p)
{
   int            nErr;
   CNetDiagnosticsApp * pApp = (CNetDiagnosticsApp *)p;

   nErr = pApp->m_dnsr.nResult;

   if (nErr > AEEDNSMAXADDRS) {

⌨️ 快捷键说明

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