/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* Copyright (c) 1999-2005 IVT Corporation
*
* All rights reserved.
*
---------------------------------------------------------------------------*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Module Name:
ftpopp_tst.c
Abstract:
this module is to test FTP and OPP profiles relative functionality.
Revision History:
2007-3-19 Huyi Created
---------------------------------------------------------------------------*/
#include "sdk_tst.h"
#include "profiles_tst.h"
#define MAX_FTP_FOLDER_LIST 128
#define MAX_FILENAME 256
typedef struct tagFILEINFO
{
UCHAR ucFileName[MAX_FILENAME];
int iSize;
int iType;
} FILEINFOSTRU;
/* current folder number. */
static BTINT32 s_CurrentFolderNum = 0;
/* current selected file/folder number. */
static BTINT32 s_CurrentSelectNum = -1;
/* FTP current remote shared directory. */
static BTUINT8 s_szRemoteCurrentDir[MAX_FILENAME] = { 0 };
/* current file size */
static BTUINT32 s_CurrentFileSize = 0;
static BTUINT32 s_TotalFileSize = 0;
static FILEINFOSTRU rmtFileInfoStru[MAX_FTP_FOLDER_LIST];
static BTDEVHDL s_currRmtFTPDevHdl = BTSDK_INVALID_HANDLE;
static BTSHCHDL s_currFTPSvcHdl = BTSDK_INVALID_HANDLE;
static BTCONNHDL s_currFTPConnHdl = BTSDK_INVALID_HANDLE;
static BTDEVHDL s_currRmtOPPDevHdl = BTSDK_INVALID_HANDLE;
static BTSHCHDL s_currOPPSvcHdl = BTSDK_INVALID_HANDLE;
static BTCONNHDL s_currOPPConnHdl = BTSDK_INVALID_HANDLE;
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
This function is to select expected remote FTP device according to device class.
Arguments:
Return:
void
---------------------------------------------------------------------------*/
void TestSelectRmtFTPDev()
{
s_currRmtFTPDevHdl = SelectRemoteDevice(0);
if (BTSDK_INVALID_HANDLE == s_currRmtFTPDevHdl)
{
printf("Please make sure that the expected device is in discoverable state and search again.\n");
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
This function is to select expected remote OPP device according to device class.
Arguments:
Return:
void
---------------------------------------------------------------------------*/
void TestSelectRmtOPPDev()
{
s_currRmtOPPDevHdl = SelectRemoteDevice(0);
if (BTSDK_INVALID_HANDLE == s_currRmtOPPDevHdl)
{
printf("Please make sure that the expected device is in discoverable state and search again.\n");
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
This function is to get FTP service handle according to given device handle.
Arguments:
Return:
void
---------------------------------------------------------------------------*/
void TestSelectFTPSvc()
{
s_currFTPSvcHdl = SelectRemoteService(s_currRmtFTPDevHdl);
if (BTSDK_INVALID_HANDLE == s_currFTPSvcHdl)
{
printf("Cann't get expected service handle.\n");
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
This function is to get OPP service handle according to given device handle.
Arguments:
Return:
void
---------------------------------------------------------------------------*/
void TestSelectOPPSvc()
{
s_currOPPSvcHdl = SelectRemoteService(s_currRmtOPPDevHdl);
if (BTSDK_INVALID_HANDLE == s_currOPPSvcHdl)
{
printf("Cann't get expected service handle.\n");
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
This function is to connect specified device's FTP service with it's service handle.
Arguments:
Return:
void
---------------------------------------------------------------------------*/
void TestConnectFTPSvc()
{
BTINT32 ulRet = BTSDK_FALSE;
ulRet = Btsdk_Connect(s_currFTPSvcHdl, 0, &s_currFTPConnHdl);
if (BTSDK_OK != ulRet)
{
printf("Please make sure that the expected device is powered on and connectable.\n");
return;
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
This function is to connect specified device's OPP service with it's service handle.
Arguments:
Return:
void
---------------------------------------------------------------------------*/
void TestConnectOPPSvc()
{
BTINT32 ulRet = BTSDK_FALSE;
ulRet = Btsdk_Connect(s_currOPPSvcHdl, 0, &s_currOPPConnHdl);
if (BTSDK_OK != ulRet)
{
printf("Please make sure that the expected device is powered on and connectable.\n");
return;
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
This function is to list browsed files and folders.
Arguments:
pFileInfo: [in] pointer to WIN32_FIND_DATA.
Return:
void
---------------------------------------------------------------------------*/
void ListRemoteOneFile(BTUINT8 *pFileInfo)
{
WIN32_FIND_DATA *pFindData = NULL;
UCHAR ucFileType[MAX_FILENAME]= {0};
if (NULL == pFileInfo)
{
return;
}
pFindData = (WIN32_FIND_DATA *)pFileInfo;
strcpy(rmtFileInfoStru[s_CurrentFolderNum].ucFileName, pFindData->cFileName);
rmtFileInfoStru[s_CurrentFolderNum].iSize =pFindData->nFileSizeLow;
rmtFileInfoStru[s_CurrentFolderNum].iType = pFindData->dwFileAttributes;
if (rmtFileInfoStru[s_CurrentFolderNum].iType & FILE_ATTRIBUTE_DIRECTORY)
{
strcpy(ucFileType, "DIR");
printf(" <%d> %-28hs************%s***********\n",s_CurrentFolderNum + 1,
rmtFileInfoStru[s_CurrentFolderNum].ucFileName,ucFileType);
s_CurrentFolderNum++;
}
else
{
printf(" <%d> %-28hs************%d***********\n",s_CurrentFolderNum + 1,
rmtFileInfoStru[s_CurrentFolderNum].ucFileName,rmtFileInfoStru[s_CurrentFolderNum].iSize);
s_CurrentFolderNum++;
}
return;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
This function is for you to select file or folder to be operated.
Arguments:
hConnHdl : [in] connection handle
Return:
BTINT32 : File number you select
---------------------------------------------------------------------------*/
BTINT32 SelectFileNumFromList(BTCONNHDL hConnHdl)
{
BTINT32 iErrorCode = 0;
char szChoice[8] = { 0 };
BTUINT32 ucCurrentFolderNum = 0;
printf("*********Name**************************************Size(B)**********\n");
s_CurrentFolderNum = 0;
iErrorCode = Btsdk_FTPBrowseFolder(hConnHdl, s_szRemoteCurrentDir, ListRemoteOneFile, FTP_OP_REFRESH);
if (iErrorCode != BTSDK_OK)
{
if (iErrorCode ==0X6a4)
{
printf("The current remote folder is empty.\n");
}
else
{
printf("Browsing remote folder list returns error code = 0x%x \n",iErrorCode);
}
return 0;
}
printf("Select the target:\n");
printf("(Press key 'q' to return to the function testing menu.)\n");
do
{
printf("Target number = ");
scanf(" %s", szChoice);
getchar();
if (('q' == szChoice[0]) || ('Q' == szChoice[0]))
{
printf("\nUser abort the operation.\n");
break;
}
ucCurrentFolderNum = atoi(szChoice);
if ((ucCurrentFolderNum <= 0) || (ucCurrentFolderNum > MAX_FTP_FOLDER_LIST))
{
printf("%d is not a valid datum, please select again.\n", ucCurrentFolderNum);
continue;
}
else
{
break;
}
} while (1);
return ucCurrentFolderNum;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
This function is a callback function to show transferred file information.
Arguments:
first: [in]first callback flag
last: [in]last callback flag
filename: [in]file name, only valid when first flag is setted.
filesize: [in]total transfer file size, only valid when first flag is setted.
cursize: [in]current transfer size
Return:
void
----------------------------
- 1
- 2
- 3
- 4
前往页