Beispiel #1
0
S32 btmtk_goep_fs_findnext(void *ptr , bt_ftp_obj_info_struct *ftp_file_info) {
#ifdef BTMTK_GOEP_USE_WIN32_FS
    long *plong;
    U32 test_arrtibe;
    struct _wfinddata_t c_file;

    if( NULL == ptr || NULL == ftp_file_info) {
        return EXT_FS_ERR;
    }

    plong = ptr;
    GOEP_MEMSET( (U8 *) ftp_file_info, 0, sizeof(bt_ftp_obj_info_struct) );
    if( 0 == _wfindnext( (long)*plong, &c_file ) ) {
        //ext_asc_str_n_to_ucs2_str( ftp_file_info->file_name, c_file.name, 260/2);
        ext_ucs2ncpy( (S8 *)ftp_file_info->file_name, (const S8 *)c_file.name, sizeof(ftp_file_info->file_name)/2 );
        update_win32_file_time(ftp_file_info);
        // ok. find the next
        test_arrtibe = (_A_SUBDIR & c_file.attrib);
        ftp_file_info->file_size = c_file.size;

        if( _A_SUBDIR == test_arrtibe  ) {
            ftp_file_info->isFile = FALSE;
        } else {
            ftp_file_info->isFile = TRUE;
        }

        return EXT_FS_OK;
    }
#endif

#ifdef BTMTK_ON_WISE
    FS_DOSDirEntry dir_entry;
    bt_ftp_find_struct *findstruct;
    U8 filename[ BTMTK_EP_MAX_FILENAME_LEN ];
    U8 ucfilename[ BTMTK_EP_MAX_FILENAME_LEN ];

    if( NULL != ptr ) {
        findstruct = (bt_ftp_find_struct *) ptr;
        if( 0 <= FS_FindNext( (FS_HANDLE) findstruct->hFile , &dir_entry, (U16 *) filename, sizeof(filename) ) ) {
            static_convert_DirEntry_to_file_info( &dir_entry, ftp_file_info , filename);

            memset( ucfilename, 0, sizeof( ucfilename) );
            ext_chset_ucs2_to_utf8_string( (U8 *)ucfilename, sizeof(ucfilename) - 1, (U8 *)filename );
            GOEP_Report("[ftp][fs] findnext file:(%s)", ucfilename);
            return EXT_FS_OK;
        }
    }
#endif

#ifdef BTMTK_ON_LINUX

    return static_linux_fill_file_info(ftp_file_info);

#endif

    return EXT_FS_ERR;
}
Beispiel #2
0
/**
* @param ucfolder
*/
BT_BOOL btmtk_ftpc_get_folder_content(const U8 *ucFolderpath, const U8 *ucFilename) {

    char debug[256];

    if (NULL == act_client_cntx_p) {
	return FALSE;
    }

    // copy it to folder_obj
    if (BT_FTPC_STATE_CONNECTED == act_client_cntx_p->ftpc_state) {
	// check folder path
	if ((U32) (ext_ucs2strlen((S8 *) ucFolderpath) + ext_ucs2strlen((S8 *)ucFilename))+1 > (sizeof(act_client_cntx_p->folder_obj)/2)) {
	    //GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_TARGET_FOLDERPATH_NO_RESOURCE) );
	    // not be able to save in right place
	    GOEP_Report("[FTPC] get_folder_content no resource for filepath");
	    return FALSE;
	}
		
	if (NULL != ucFolderpath && NULL != ucFilename) {
	    GOEP_TRACE_PATH(BT_FTP_TRC_CLASS, BT_FTPC_TARGET_FOLDERPATH, ucFolderpath);
	    GOEP_TRACE_PATH(BT_FTP_TRC_CLASS, BT_FTPC_TARGET_FILENAME, ucFilename);

	    btmtk_goep_compose_filepath((const U8 *) ucFolderpath,
		    (const U8 *) ucFilename,
		    act_client_cntx_p->folder_obj,
		    sizeof(act_client_cntx_p->folder_obj)/2);

	    GOEP_TRACE_PATH(BT_FTP_TRC_CLASS, BT_FTPC_TARGET_FILEPATH, act_client_cntx_p->folder_obj);

	} else if (NULL == ucFolderpath && NULL == ucFilename) {
	    // Use default folder object path.
	    ext_ucs2_str_n_to_asc_str(debug,
		    (S8 *) act_client_cntx_p->folder_obj,
		    sizeof(act_client_cntx_p->folder_obj)/2);
	} else {
	    btmtk_goep_compose_filepath((const U8 *) ucFolderpath,
		    (const U8 *) ucFilename,
		    act_client_cntx_p->folder_obj,
		    sizeof(act_client_cntx_p->folder_obj)/2);

	    GOEP_TRACE_PATH(BT_FTP_TRC_CLASS, BT_FTPC_TARGET_FILEPATH, act_client_cntx_p->folder_obj);
	}

	return bt_ftpc_start_get_folder_content_routine(0);

    } else {
	GOEP_TRACE((BT_FTP_TRC_CLASS,
		BT_FTPC_FILE_STATE_CHECK,
		(act_client_cntx_p)->ftpc_fs_status,
		(act_client_cntx_p)->ftpc_total_len,
		(act_client_cntx_p)->ftpc_push_remain,
		(act_client_cntx_p)->fh_ftpc_push));
    }

    return FALSE;
}
Beispiel #3
0
FS_STATUS btmtk_goep_get_file_basename(const U8 *filepath, U8 *basename, U32 u4MaxSize){
    S8 *pDelimitor;
    if( NULL == filepath ||  0 == ext_ucs2strlen((const S8*)filepath) ){
        return EXT_FS_ERR;
    }
    pDelimitor = ext_ucs2rchr((const S8 *)filepath, (U16)0x005c); // "\\" 0x5c
    if( NULL != pDelimitor ){
        ext_ucs2ncpy((S8 *)basename, (const S8 *)pDelimitor+2, u4MaxSize); // skip the delimitor
    }else{
		pDelimitor = ext_ucs2rchr((const S8 *)filepath, (U16) 0x002f); // "\\" 0x5c
		if( NULL != pDelimitor ){
			ext_ucs2ncpy((S8 *)basename, (const S8 *)pDelimitor+2, u4MaxSize); // skip the delimitor
		}else{
			GOEP_Report("[goep][warn] func:get_file_basename cannot find basename\n");
	        return EXT_FS_ERR;
		}
    }
    return     EXT_FS_OK;
}
Beispiel #4
0
/**
* @brief This function is to browse a new folder or refresh the current folder
* FTP Client Change Folder
* Only could enter one level directory
* @param name the sub folder to enter
* @return TRUE send request success wait for changed BT_FTPCUI_SETPATHED event
* @see BT_FTPCUI_EVNT_T
**/
BT_BOOL btmtk_ftpc_enter_folder(const U16 * name)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	goep_set_folder_req_struct *req;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    GOEP_TRACE((BT_FTP_TRC_CLASS, BT_FTPC_CHANGE_FOLDER, act_client_cntx_p->ftpc_state, ftpc_cntx_p->goep_conn_id[0]));

    if (NULL == act_client_cntx_p) {
        //TODO fault error
        return FALSE;
    }

	// refresh current folder

    GOEP_TRACE((BT_FTP_TRC_CLASS, BT_FTPC_CHANGE_FOLDER_FORWARD));

    switch (act_client_cntx_p->ftpc_state) {
	case BT_FTPC_STATE_CONNECTED:
	    BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_SETTING_FOLDER);
            break;

        default:
			// Incorrect state, callback and return error
            GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_STATE_ERROR, act_client_cntx_p->ftpc_state));
            return FALSE;
    }

    GOEP_Report("[FTPC] enter_folder setup copy obj_name");
    GOEP_MEMSET((U8 *)act_client_cntx_p->ftpc_obj_name, 0, sizeof(act_client_cntx_p->ftpc_obj_name));

    ext_ucs2ncpy((S8 *) act_client_cntx_p->ftpc_obj_name,
	    (const S8 *) name,
	    (sizeof(act_client_cntx_p->ftpc_obj_name)-2)/2);

    GOEP_TRACE_PATH(BT_FTP_TRC_CLASS, BT_FTPC_TARGET_FILENAME, act_client_cntx_p->ftpc_obj_name);
        
    GOEP_Report("[FTPC] enter_folder setup build a msg");

	// send set folder req
    req = (goep_set_folder_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(goep_set_folder_req_struct), TD_CTRL);
    GOEP_MEMSET((U8 *)req, 0, sizeof(goep_set_folder_req_struct));
    req->goep_conn_id = ftpc_cntx_p->goep_conn_id[0];
    GOEP_MEMCPY(req->uuid, OBEX_FTP_UUID, 16);
    req->uuid_len = 16;

    if (2 == ext_ucs2strlen((const S8 *) act_client_cntx_p->ftpc_obj_name) &&
	0 == ext_ucs2cmp((const U8 *) L"..", (const U8 *)act_client_cntx_p->ftpc_obj_name)) {
	    req->setpath_flag = GOEP_BACK_FOLDER;

    } else {
       	GOEP_Report("[FTPC] enter_folder setup msg's folder_name");
        req->setpath_flag = GOEP_FORWARD_FOLDER;
        ext_ucs2ncpy((S8 *) req->folder_name,
		(S8 *) act_client_cntx_p->ftpc_obj_name,
		sizeof(req->folder_name)/2);
    }

    req->folder_name[sizeof(req->folder_name)-2] = req->folder_name[sizeof(req->folder_name)-1] = 0;

    bt_ftp_ucs2_htons((U8 *)req->folder_name, (U8 *)req->folder_name);

    bt_ftp_send_msg(MSG_ID_BT_FTPC_SET_FOLDER_REQ, req ,sizeof(goep_set_folder_req_struct));
    return TRUE;
}
Beispiel #5
0
/**
* @brief This function is to get file object.
* FTP Client Get File
*/
BT_BOOL btmtk_ftpc_get_file_obj(const U8 *local_path, const U8 *ucName, const U8 *ucNewName)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    //U32 i;
    goep_pull_req_struct *req;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    GOEP_TRACE((BT_FTP_TRC_CLASS, BT_FTPC_GET_FILE_OBJ, act_client_cntx_p->ftpc_state));
    if (NULL == act_client_cntx_p) {
        //TODO fault error
        return FALSE;
    }

    if (NULL == local_path || FALSE == btmtk_goep_is_folder_exist((const U16 *) local_path)) {
	GOEP_Report("[ftpc] func:get_file_obj  wrong foldpath parameter\n");
	return FALSE;
    }

    if( NULL == ucName || 0 == ext_ucs2strlen( (const S8 *) ucName ) ){
	GOEP_Report( "[ftpc] func:get_file_obj  wrong filename parameter\n");
	return FALSE;
    }

    // Init the statistics for received object length
    act_client_cntx_p->ftpc_total_len = 0;
    act_client_cntx_p->ftpc_reamin_len = 0;
    act_client_cntx_p->ftpc_data_len = 0;
    act_client_cntx_p->total_len_type = BT_FTPC_TOTAL_LEN_NO_FIRST_PKT;
    act_client_cntx_p->flag_abort_req_sent = FALSE;

    GOEP_Report("[FTPC] get_file_obj set default attribute = 0");

    ext_ucs2ncpy((S8 *) act_client_cntx_p->push_local_path,
	    (S8 *)local_path,
	    sizeof(act_client_cntx_p->push_local_path)/2);

    if (NULL == ucNewName || 0 == ext_ucs2strlen((const S8 *) ucNewName)) {
	GOEP_Report("[FTPC] get_file_obj compose name");
	bt_ftp_compose_path(local_path, ucName,
		(U8 *) act_client_cntx_p->ftpc_filepath,
		sizeof(act_client_cntx_p->ftpc_filepath)/2);

    } else {
	bt_ftp_compose_path(local_path,	ucNewName,
		(U8 *) act_client_cntx_p->ftpc_filepath,
		sizeof(act_client_cntx_p->ftpc_filepath)/2);
    }

    GOEP_Report("[FTPC] get_file_obj set default attribute = 0");
    ext_ucs2ncpy((S8 *) act_client_cntx_p->ftpc_obj_name,
	    (S8 *) ucName,
	    sizeof(act_client_cntx_p->ftpc_obj_name));

    if (!ucName) {
        GOEP_Report("[ftpc][wrn] func:get_file_obj wrong param\n");
        BT_FTP_ASSERT(0);
        return FALSE;
    }

    switch (act_client_cntx_p->ftpc_state) {
        case BT_FTPC_STATE_CONNECTED:
            BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_GETTING_OBJ);
            break;

        default: 
            // Incorrect state, callback and return error
            GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_STATE_ERROR, act_client_cntx_p->ftpc_state));
            return FALSE;
    }

    // send get obj req
    GOEP_Report("[FTPC] get_file_obj prepare msg");
    req = (goep_pull_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(goep_pull_req_struct),TD_CTRL);
    GOEP_MEMSET((U8 *)req, 0, sizeof(goep_pull_req_struct));
    req->goep_conn_id = ftpc_cntx_p->goep_conn_id[0];
    req->pkt_type = GOEP_FIRST_PKT;
    GOEP_MEMCPY(req->uuid, OBEX_FTP_UUID, 16);
    req->uuid_len = 16;

    ext_ucs2ncpy((S8 *) req->obj_name,
	    (S8 *) act_client_cntx_p->ftpc_obj_name,
	    sizeof(req->obj_name)/2 );

    req->obj_name[sizeof(req->obj_name)-2] = req->obj_name[sizeof(req->obj_name)-1] = 0;
    bt_ftp_ucs2_htons((U8 *)req->obj_name, (U8 *)req->obj_name);
    bt_ftp_send_msg(MSG_ID_BT_FTPC_PULL_REQ, req,sizeof(goep_pull_req_struct));
    return TRUE;
}
Beispiel #6
0
BT_BOOL btmtk_ftpc_connect_server_ex(btbm_bd_addr_t bd_addr, U8 type){
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    static U8 req_id =0;
    U32 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_CONNECT_SERVER) );

    if( NULL == act_client_cntx_p || FALSE == ftpc_cntx_p->enable ){
        GOEP_Report("[ftpc][int] func:connect_server Not active !");
        return FALSE;
    }

	// Reset root folder content flag
    if( NULL == act_client_cntx_p || act_client_cntx_p != &(ftpc_cntx_p->conn_cntx[0]) ){
        GOEP_Report("[ftpc][int] func:connect_server Not active !");
        return FALSE;
    }

    req_id++;
    for (i = 0; i < FTP_MAX_SERVER_SUPPORT; i++) {
        goep_connect_req_struct *req;

        // TOOD: UI notify the connting to remoet device'addr

        if ((act_client_cntx_p + i)->ftpc_state == BT_FTPC_STATE_IDLE) {
			// update context
            ftpc_cntx_p->req_id[i] = req_id;
            (act_client_cntx_p + i)->got_root = 0;
            
            (act_client_cntx_p + i)->ftpc_bt_device.lap = bd_addr.lap;
            (act_client_cntx_p + i)->ftpc_bt_device.uap = bd_addr.uap;
            (act_client_cntx_p + i)->ftpc_bt_device.nap = bd_addr.nap;
            (act_client_cntx_p + i)->challeng_options = 0;
            GOEP_MEMSET( (act_client_cntx_p + i)->realm, 0, sizeof((act_client_cntx_p + i)->realm) );

			// connect server
			// film res pkt_type attibute
            //FTP_DEBUG(kal_print("FTPC CONNECT_SERVER TRY TO FILM ILM\n");)

            if (FALSE == ext_nbuffer_isInit(&act_client_cntx_p->ftpc_mempool)) {
                if (FALSE == ext_nbuffer_init(&act_client_cntx_p->ftpc_mempool,
			act_client_cntx_p->ftpc_obj_buff_size)) {
                    /// fail to alloc nbuffer
                    GOEP_Report( "[FTPS][WRN] btmtk_ftpc_connect_server ext_nbuffer_init fail");
                }
            }

            req = (goep_connect_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(goep_connect_req_struct),TD_CTRL);
            GOEP_MEMSET( (U8 *)req, 0, sizeof(goep_connect_req_struct));
            req->bd_addr.lap = bd_addr.lap;
            req->bd_addr.uap = bd_addr.uap;
            req->bd_addr.nap = bd_addr.nap;
            req->buf_ptr = (act_client_cntx_p + i)->ftpc_obj_buff;
            req->buf_size = (U16) (act_client_cntx_p+ i)->ftpc_obj_buff_size; //FTPC_MEM_BUFF_SIZE;
#ifdef __BT_GOEP_V2__ 
            req->buf_size = (0xfff0); // 10M unit
#endif
            req->req_id = req_id;
            req->tp_type = GOEP_TP_BT;
            req->tptype = type; /* rfcomm or l2cap or both */
	    GOEP_Report("[FTPC] req->tptype:%d", type);            
            (act_client_cntx_p + i)->discon_from_cm = FALSE;

            GOEP_MEMCPY(req->uuid, OBEX_FTP_UUID, 16);
            req->uuid_len = 16;

            /* send connect req to server */
            BT_FTPC_STATE_TRANS(i, BT_FTPC_STATE_CONNECTING);
            bt_ftp_send_msg(MSG_ID_BT_FTPC_CONNECT_REQ, req ,sizeof(goep_connect_req_struct));
     
	    return TRUE;

        } else {
            GOEP_Report( "[ftpc][int] func:connect_server wrong state:%d\n", act_client_cntx_p->ftpc_state );
        }
    }
    
    return FALSE;
}
Beispiel #7
0
void btmtk_deinit_ftp_client(void){
    GOEP_Report("[FTPC] btmtk_deinit_ftp_client");
    ftpc_cntx_p->enable = FALSE;
    act_client_cntx_p = NULL;
    GOEP_MEMSET( (U8 *) ftpc_cntx_p, 0, sizeof(ftpc_cntx_p));
}
Beispiel #8
0
/*
* @param ucFilename ucs2 filename
* @u4MaxLen bytes
*/
BT_BOOL btmtk_goep_get_private_filepath(U8 type, const U8 *ucFilename, U8 *ucOutFilepath, U32 u4MaxLen) {
    BT_BOOL l_bret = FALSE;

#if defined(BTMTK_ON_WISESDK)
    //SDK
    U8 tempPath[512];
    U8 l_u2RootPath[512];

    btmtk_os_memset( l_u2RootPath, 0, sizeof(l_u2RootPath));
    ext_chset_utf8_to_ucs2_string( l_u2RootPath, sizeof(l_u2RootPath)-2, g_bt_dir_buf);
    if( FALSE == btmtk_goep_is_folder_exist( (const U16*) l_u2RootPath) ) {
        GOEP_Report("[GOEP] btmtk_goep_get_private_filepath no root folder");
        return FALSE;
    }

    /// <sdk root path>\\xxx\\@btmtk\\ folder
    ext_ucs2ncpy( (S8*)tempPath, l_u2RootPath, sizeof(tempPath)/2);
    ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\Component\\MBT\\HWAdapt\\MTK\\LIB\\@btmtk", sizeof(tempPath)/2);
    if( 0 != ext_ucs2strlen((const S8*)tempPath) && FALSE == btmtk_goep_is_folder_exist((const U16*)tempPath) ) {
        btmtk_goep_create_folder((const U16*)tempPath);
    }

    switch(type) {
    case 0:  /// <sdk root path>\\xxx\\@btmtk\\ .
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, ucFilename, sizeof(tempPath)/2);
        ext_ucs2ncpy((S8 *) ucOutFilepath, tempPath, u4MaxLen );
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }

        break;
    case 1:  /// <sdk root path>\\xxx\\@btmtk\\profile
        ext_ucs2ncpy( (S8*)tempPath, l_u2RootPath, sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\Component\\MBT\\HWAdapt\\MTK\\LIB\\@btmtk\\profile", sizeof(tempPath)/2);
        if( FALSE == btmtk_goep_is_folder_exist((const U16*)tempPath) ) {
            btmtk_goep_create_folder((const U16*)tempPath);
        }
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, ucFilename, sizeof(tempPath)/2);
        ext_ucs2ncpy((S8 *) ucOutFilepath, tempPath, u4MaxLen );
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }

        break;
    case 2:  /// <sdk root path>\\xxx\\@btmtk\\data
        ext_ucs2ncpy( (S8*)tempPath, l_u2RootPath, sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\Component\\MBT\\HWAdapt\\MTK\\LIB\\@btmtk\\data", sizeof(tempPath)/2);
        if( FALSE == btmtk_goep_is_folder_exist((const U16*)tempPath) ) {
            btmtk_goep_create_folder((const U16*)tempPath);
        }
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, ucFilename, sizeof(tempPath)/2);
        ext_ucs2ncpy((S8 *) ucOutFilepath, tempPath, u4MaxLen );
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }
        break;
    default:
        GOEP_Report("[OBEX][Err] btmtk_goep_get_private_filepath fail param:%d");
        break;
    }

#else
    // Target
    U8 tempPath[512];

    switch(type) {
    case 0: /// Z:\\@btmtk
        ext_ucs2ncpy( (S8 *) tempPath, (const S8*)L"Z:\\@btmtk", sizeof( tempPath ) );
        break;
    case 1: /// C:\\@btmtk\\profiles
        ext_ucs2ncpy( (S8 *) tempPath, (const S8*)L"C:\\@btmtk\\profiles", sizeof( tempPath ) );
        break;
    case 2: /// C:\\@btmtk\\data
        ext_ucs2ncpy( (S8 *) tempPath, (const S8*)L"C:\\@btmtk\\data", sizeof( tempPath ) );
        break;
    default:
        break;
    }

    if( 0 != ext_ucs2strlen((const S8*)tempPath) ) {
        if (FALSE == btmtk_goep_is_folder_exist( (const U16*) tempPath) ) {
            btmtk_goep_create_folder((const U16*)tempPath);
        }
        ext_ucs2ncat( (S8*)tempPath, (const S8*)L"\\", sizeof(tempPath)/2);
        ext_ucs2ncat( (S8*)tempPath, (const S8*)ucFilename, sizeof(tempPath)/2);

        ext_ucs2ncpy( (S8 *)ucOutFilepath, (const S8*)tempPath, u4MaxLen);
        if( ext_ucs2strlen((const S8*)ucOutFilepath) == ext_ucs2strlen((const S8*)tempPath) ) {
            l_bret = TRUE;
        }
    }

#endif
    return l_bret;
}
Beispiel #9
0
S32 btmtk_goep_fs_findfirst(U8 *ucFolderPath, bt_ftp_find_struct **findstruct, bt_ftp_obj_info_struct *ftp_file_info) {
#ifdef BTMTK_GOEP_USE_WIN32_FS
    char sdir[256];
    char filter[64];
    U32 test_arrtibe;
    struct _wfinddata_t c_file;
    long hFile;
    bt_ftp_find_struct *pfind;

    GOEP_MEMSET((U8 *)ftp_file_info, 0, sizeof(bt_ftp_obj_info_struct) );

    ext_ucs2_str_n_to_asc_str(sdir, ucFolderPath, sizeof(sdir));

    // keep the previous folder path
    g_oldcwd[0] = 0;
    if ( NULL == _wgetcwd( (U16 *)g_oldcwd, sizeof(g_oldcwd)/2 ) ) {
        /// cannot keep the current folder
        GOEP_Report("[FS][ERR] fail to get cwd bufsize:(%d) err:%d!", sizeof(g_oldcwd)/2, GetLastError());
        return EXT_FS_ERR;
    }

    printf( "[fs] getcwd is '%s'\n", g_oldcwd);
    printf( "[fs] fs findfirst '%s' \n", sdir );
    _wchdir( (U16 *) ucFolderPath );


    ext_strncpy (filter, "*.*", 64);
    hFile = _wfindfirst(L"*.*", &c_file);

    if( -1 == hFile ) {
        return EXT_FS_ERR;
    } else {
        //plong = (long * )malloc(sizeof(long));
        pfind = (bt_ftp_find_struct *) malloc( sizeof(bt_ftp_find_struct) );
        *findstruct = pfind;

        if( *findstruct == NULL ) {
            return EXT_FS_ERR;
        }
        ((bt_ftp_find_struct *)*findstruct)->hFile = hFile;

        ext_ucs2ncpy( (S8 *) ftp_file_info->file_name, (const S8 *) c_file.name, sizeof(ftp_file_info->file_name)/2);
        update_win32_file_time(ftp_file_info);
        test_arrtibe = (_A_SUBDIR & c_file.attrib);
        if( _A_SUBDIR == test_arrtibe) {
            ftp_file_info->isFile = FALSE;
        } else {
            ftp_file_info->isFile = TRUE;
        }
        return EXT_FS_OK;
    }
#endif

#ifdef BTMTK_ON_WISE
    U8 *filter;
    S32 hFile;
    S32 len;
    bt_ftp_find_struct *pfind;
    FS_DOSDirEntry dir_entry;
    U8 filename[ BTMTK_EP_MAX_FILENAME_LEN ]; /// output

    //ext_ucs2ncpy (filter, (const U8 *)L"\\*.*", sizeof(filter)/2);
    len = ext_ucs2strlen((const S8*)ucFolderPath)*2 + 10;
    filter = (U8 *) get_ctrl_buffer( len ); // plus L"\\*.*"
    if( NULL == filter ) {
        return EXT_FS_ERR;
    }
    btmtk_os_memset( filter, 0, len);
    ext_ucs2ncpy( (U8 *) filter,  (const U8 *) ucFolderPath , len-2);
    ext_ucs2ncat( (U8 *) filter, (const U8 *) L"\\*.*", len-2);

    ext_ucs2ncpy((S8 *)filename, (const U8 *)L"", (sizeof(filename)/2)-1);

    hFile = (S32) FS_FindFirst(
                (const WCHAR*)filter,
                0,
                0,
                &dir_entry,
                (U16*) filename,
                sizeof(filename) );
    if( NULL == filter ) {
        free_ctrl_buffer(filter);
        filter = NULL;
    }
    if ( hFile >= 0) {
        GOEP_MEMSET((U8 *)ftp_file_info, 0, sizeof(bt_ftp_obj_info_struct) );
        pfind = (bt_ftp_find_struct *) get_ctrl_buffer( sizeof(bt_ftp_find_struct) );
        *findstruct = pfind;
        if( *findstruct == NULL ) {
            FS_FindClose( (FS_HANDLE) hFile );
            return EXT_FS_ERR;
        }
        ((bt_ftp_find_struct *)*findstruct)->hFile = hFile;

        static_convert_DirEntry_to_file_info( &dir_entry, ftp_file_info , filename);

        return EXT_FS_OK;
    } else {
        return EXT_FS_ERR;
    }

#endif

#ifdef BTMTK_ON_LINUX

    int ret;
    int err_num;

    bt_ext_log("[GOEP_FS] btmtk_goep_fs_findfirst(): Linux Version.");

    ext_chset_ucs2_to_utf8_string((U8 *) g_folder_path, sizeof(g_folder_path)-1, ucFolderPath);
    // strncpy(g_folder_path, ucFolderPath, sizeof(g_folder_path));
    bt_ext_log("[GOEP_FS] g_folder_path: %s", g_folder_path);

    g_opened_dir = opendir( g_folder_path);
    if (g_opened_dir == NULL) {
        err_num = errno;
        bt_ext_err("[FS_ERR] opendir() failed. %s", (char*) strerror(err_num));
        return EXT_FS_ERR;
    }

    return static_linux_fill_file_info(ftp_file_info);

#endif

    return EXT_FS_ERR;
}