/** * @brief Refer OrigName and create a NewName * @param OrigName ucs2 filename for reference ex. "Test1.txt" * @param NewName Output ucs2 filename "Test1 * @param u4MaxSize NewName size in bytes */ U32 btmtk_goep_gen_temp_filename(U32 count,const U8 *OrigName, U8 *NewName, U32 u4MaxSize){ U8 d1, d2, d3; U8 buffer[16]; if( 0 == count ){ ext_ucs2ncpy((S8 *)NewName, (const S8 *)OrigName, u4MaxSize); return ext_ucs2strlen((const S8*) NewName ); } /// find the "." in Origname and append it with number /// ex. Test1.txt ot Test1(dup-xxx).txt count = count % 1000; // only support 3 digital d1 = (U8)(count/100); d2 = (U8)( (count - (d1 * 100) )/10); d3 = (U8)(count - (d1 * 100) - ( d2 * 10)); if( d3 != (count%10) ){ //ERROR! d1 = d2 = d3 = 0; } buffer[0] = '0'; buffer[1] = buffer[3] = buffer[5] = buffer[7] = buffer[8]= buffer[9]= 0; buffer[2] = '0' + d1; buffer[4] = '0' + d2; buffer[6] = '0' + d3; ext_ucs2ncpy((S8 *)NewName, "D u p ( ", u4MaxSize); ext_ucs2ncat((S8 *)NewName, (const S8 *)buffer, u4MaxSize); ext_ucs2ncat((S8 *)NewName, (const S8 *)") ", u4MaxSize); ext_ucs2ncat((S8 *)NewName, (const S8 *)OrigName, u4MaxSize); return ext_ucs2strlen((const S8*)NewName); }
/** * @brief pull a file from remote ftp server * @param ucFilePath the send file's path and filename that will be using by btmtk_goep_open_rstream * @see btmtk_goep_open_rstream */ BT_BOOL btmtk_ftpc_pull_file_ex(const U8 *local_folderpath, const U8 *ucName, const U8 *ucNewName, U8 srm_enable, U8 waitCount) { bt_ftpc_pullfile_req_struct *req; if( NULL == act_client_cntx_p ) { return FALSE; } if( NULL == ucName && NULL == ucNewName ){ return FALSE; } if( NULL == ucName || NULL == ucNewName ){ /* one of them is NULL. Set two are the same */ ucName = (ucNewName!=NULL?ucNewName:ucName); ucNewName = ucName; } #ifdef __BT_GOEP_V2__ /// if connection type is 1 (l2cap), turn on srm mode if( act_client_cntx_p && (1 == act_client_cntx_p->ftpc_conntype) ){ srm_enable = TRUE; }else{ srm_enable = FALSE; } OS_Report("[AUTO] turn srm_enable to %d", srm_enable); #endif /// check state and push a push req switch (act_client_cntx_p->ftpc_state) { case BT_FTPC_STATE_CONNECTED: /* copy ucName to ftpc_obj_name */ memset( act_client_cntx_p->ftpc_filepath, 0, sizeof(act_client_cntx_p->ftpc_filepath)); bt_ftp_compose_path(local_folderpath, ucNewName, (U8 *) act_client_cntx_p->ftpc_filepath, sizeof(act_client_cntx_p->ftpc_filepath)/2); ext_ucs2ncpy( (S8 *) act_client_cntx_p->ftpc_obj_name, (const S8 *) ucName, sizeof(act_client_cntx_p->ftpc_obj_name) ); /* send get obj req */ req = (bt_ftpc_pullfile_req_struct*) CONSTRUCT_LOCAL_PARAM(sizeof(bt_ftpc_pullfile_req_struct),TD_CTRL); GOEP_MEMSET( req, 0, sizeof(bt_ftpc_pullfile_req_struct)); req->goep_conn_id = ftpc_cntx_p->goep_conn_id[0]; ext_ucs2ncpy((S8 *) req->obj_name, (S8 *) act_client_cntx_p->ftpc_obj_name, sizeof(req->obj_name)/2 ); bt_ftp_ucs2_htons( (U8 *)req->obj_name, (U8 *)req->obj_name ); ext_ucs2ncpy((S8 *) req->filepath, (S8 *)act_client_cntx_p->ftpc_filepath, sizeof(act_client_cntx_p->ftpc_filepath)/2); req->filepath_len = ext_ucs2strlen( (const S8 *)req->filepath)*2; req->srm_enable = srm_enable; req->srm_waitcount = waitCount; /* switch state */ BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_GETTING_OBJ); bt_ftp_send_msg(MSG_ID_BT_FTPC_PULLFILE_REQ, req,sizeof(bt_ftpc_pullfile_req_struct)); return TRUE; break; default: break; } return FALSE; }
/* * OPP Server receives a file */ U16 * bt_goep_make_tmpfile_prefix(U16 *name, U16 size, U16 *old_name, U16 num) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ static U16 prefix[10]; U16 l1, l2; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ //TODO ascii to unicode sprintf( (S8 *)prefix, (const S8 *)"Dup(%d)", num); l1 = ext_ucs2strlen((const S8*)prefix); l2 = ext_ucs2strlen((const S8*)old_name); size = size -1; if (l1 + l2 > size) { return NULL; } ext_ucs2ncpy((S8 *)name, (S8 *)prefix, OPPS_TMP_BUFF_SIZE); ext_ucs2ncat((S8 *)name, (S8 *)old_name, OPPS_TMP_BUFF_SIZE); return name; }
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; }
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; }
void static_convert_DirEntry_to_file_info( FS_DOSDirEntry *dir_entry, bt_ftp_obj_info_struct *ftp_file_info, U8 *filename) { memset(ftp_file_info, 0, sizeof(bt_ftp_obj_info_struct) ); ext_ucs2ncpy((S8 *) ftp_file_info->file_name, filename, (BTMTK_EP_MAX_FILENAME_LEN/2)-1 ); ftp_file_info->year = dir_entry->DateTime.Year1980 + 1980; ftp_file_info->month = dir_entry->DateTime.Month; ftp_file_info->day = dir_entry->DateTime.Day; ftp_file_info->hour = dir_entry->DateTime.Hour; ftp_file_info->min = dir_entry->DateTime.Minute; ftp_file_info->sec = dir_entry->DateTime.Second2; ftp_file_info->file_size = dir_entry->FileSize; if( dir_entry->Attributes & FS_ATTR_DIR ) { ftp_file_info->isFile = FALSE; } else { ftp_file_info->isFile = TRUE; } }
/** * @brief Compose Folder and Filename to Filepath * @param Folder ucs2 folder path ex. L"\\est" * @param Filename ucs2 filename ex. L"Text1.txt" * @param Filepath Output filepath ex. L"\\est\\Text1.txt" * @param u4MaxSize the size of FilePath in bytes * */ U32 btmtk_goep_compose_filepath(const U8 *Folder1, const U8 *Folder2, U8 *FilePath, U32 u4MaxSize){ S32 index; ext_ucs2ncpy((S8 *)FilePath, (const S8 *)Folder1, u4MaxSize); index = ext_ucs2strlen((const S8*) FilePath ); if( index > 0){ index--; if( (FilePath[index*2] == '\\' ||FilePath[index*2] == '/' ) && FilePath[index*2+1] == 0 ){ FilePath[index*2] = FilePath[index*2+1] = 0; }else if( (Folder1[index*2] == '\\' ||Folder1[index*2] == '/' ) && Folder1[index*2+1] == 0 ) { FilePath[index*2] = FilePath[index*2+1] = 0; } } ext_ucs2ncat( (S8 *)FilePath, (const S8*) "/", u4MaxSize); // FS_FOLDER_DELIMITOR index = ext_ucs2strlen((const S8*) Folder2 ); if( index > 0){ if( (Folder2[0] == '\\' || Folder2[0] == '/') && Folder2[1] == 0 ){ Folder2 +=2; }else if( (Folder2[1] == '\\' || Folder2[1] == '/' )&& Folder2[0] == 0 ){ Folder2 +=2; }else{ } ext_ucs2ncat((S8 *)FilePath, (const S8 *)Folder2, u4MaxSize); } index = ext_ucs2strlen((const S8*) FilePath ); if( index >= 0){ index--; if( (FilePath[index*2] == '\\' ||FilePath[index*2] == '/' ) && FilePath[index*2+1] == 0 ){ FilePath[index*2] = FilePath[index*2+1] = 0; }else if( (FilePath[index*2] == '\\' ||FilePath[index*2] == '/' ) && FilePath[index*2+1] == 0 ) { FilePath[index*2] = FilePath[index*2+1] = 0; } } return ext_ucs2strlen((const S8*)FilePath); }
/** * @brief This function is to truncate object name if exceeds max buffer size * PARAMETERS * new_name [OUT] * old_name [IN] * max_len [IN] **/ void bt_goep_truncate_ntoh_filename(U16 *dst_name, const U16 *src_netname, U16 max_dst_len) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ U32 src_name_len; U16 *p_ext, *p1; U32 ext_len; U16 copy_len; S8 l_wave[8]; if( 0 == max_dst_len ){ GOEP_ASSERT(0); } /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ src_name_len = ext_ucs2strlen((const S8*)src_netname); // max_dst_len /= ENCODING_LENGTH; max_dst_len /= 2; //TODO unicode is 2 byte if (src_name_len < max_dst_len) { /* need not truncate */ ext_ucs2ncpy((S8 *)dst_name, (S8 *) src_netname, max_dst_len); p1 = dst_name; for(; *p1; p1++) { *p1 = bt_goep_ntohs(*p1); } *p1 = (U16)'\0'; } else { /* need truncate */ GOEP_MEMSET( (U8*) dst_name, 0, max_dst_len * 2 ); //* ENCODING_LENGTH); /* find filename ext */ p_ext = (U16 *)ext_ucs2rchr((const S8 *)(S8 *)src_netname, (U16)(L'.')); if(p_ext) { ext_len = ext_ucs2strlen((const S8*)p_ext); } else { ext_len = 0; } /* 1 char for '~'; 1 char for \0 */ copy_len = (U16) (max_dst_len - ext_len - 1 - 1 ); ext_ucs2ncpy((S8 *) l_wave, (const S8*) L"-", 8); p1 = (U16 *)l_wave; for(; *p1; p1++) { *p1 = bt_goep_ntohs(*p1); } ext_ucs2ncpy((S8 *)dst_name, (const S8 *)src_netname, copy_len); ext_ucs2ncat((S8 *)dst_name, (const S8 *)l_wave, max_dst_len); if (p_ext) { ext_ucs2ncat((S8 *)dst_name, (const S8 *)p_ext, max_dst_len); } p1 = dst_name; for(; *p1; p1++) { *p1 = bt_goep_ntohs(*p1); } *p1 = (U16)'\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; }
/** * @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; }
/* * @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; }
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; }
/***************************************************************************** * FUNCTION * bt_goep_rename_temp_obj * DESCRIPTION * This function is to rename temp object. * PARAMETERS: * void * RETURNS: * S32 *****************************************************************************/ static S32 bt_goep_rename_temp_obj(void) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ U16 new_name[OPP_MAX_PATH_LENGTH+1] ; U16 *old_name = GOPP(recv_path); //U16 *tname = g_opps_tmp_buff; U16 tname[OPPS_TMP_BUFF_SIZE]; S32 retval = EXT_FS_OK; U16 cnt = 0; S8 *file_name; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ //new_name = kal_memalloc(sizeof(GOPP(recv_path))); /*check name whether include "/" */ file_name = bt_goep_get_file_name_ext((S8 *)GOPP(ops_obj_name), OPP_FILE_GET_NAME_VALID); bt_goep_make_folderpath(new_name, 0, NULL, old_name); //bt_opps_update_path(new_name, 0, (U16 *)file_name); //TODO BT_OPP_LOG_PATH(old_name); //TODO BT_OPP_LOG_PATH(new_name); while (cnt++ < BT_OBEX_DUP_FILENAME_MAX_NUM) { retval = btmtk_goep_rename_file(old_name, new_name); //X: retval = FS_Rename(old_name, new_name); //TODO BT_OPP_LOG_PATH(new_name); //TODO BT_OPP_LOG1(BT_OPP_OPPS_RENAME_TEMP_OBJ,retval); if ( EXT_FS_OK != retval ) { break; } if (bt_goep_make_tmpfile_prefix( tname, OPPS_TMP_BUFF_SIZE, (U16 *)file_name, cnt)) { //bt_opps_update_path(new_name, 0, tname); } else { break; } } if ( EXT_FS_OK != retval ) { btmtk_goep_delete_file(old_name); //X : FS_Delete(old_name); } else { ext_ucs2ncpy((S8 *)old_name, (S8 *)new_name, OPPS_TMP_BUFF_SIZE); } // kal_memfree(new_name); return retval; }