/** * @param ucfolder */ BT_BOOL btmtk_ftpc_get_folder_content_ex(const U8 *ucFolderpath, const U8 *ucFilename) { bt_ftpc_pullfile_req_struct * req; if( NULL == act_client_cntx_p ) { return FALSE; } // copy it to folder_obj if ( BT_FTPC_STATE_CONNECTED== act_client_cntx_p->ftpc_state ) { if( NULL != ucFolderpath && NULL != 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 ); } BT_FTPC_STATE_TRANS(0, BT_FTPC_STATE_GETTING_FOLDER); /* send get current folder req */ /* construct get folder req ilm */ 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_strncpy((S8 *) req->obj_mime_type, "x-obex/folder-listing", GOEP_MAX_MIME_TYPE); GOEP_MEMCPY( req->filepath, act_client_cntx_p->folder_obj, ext_ucs2strlen( (const S8 *)act_client_cntx_p->folder_obj) *2); req->filepath_len = ext_ucs2strlen( (const S8 *)act_client_cntx_p->folder_obj) *2; /* send get folder req */ bt_ftp_send_msg(MSG_ID_BT_FTPC_PULLFILE_REQ, req ,sizeof(bt_ftpc_pullfile_req_struct)); return TRUE; } return FALSE; }
/** * @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); }
/* * 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; }
/** * @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; }
/***************************************************************************** * FUNCTION * bt_goep_make_folderpath * DESCRIPTION * This function is to make full path of receive file * PARAMETERS * path [OUT] * drive [IN] * folder [IN] * file [IN] * RETURNS * S32 *****************************************************************************/ U16 * bt_goep_make_folderpath(U16 *path, U8 drive, U16 *folder, U16 *file) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ U16 l1 = 0, l2 = 0; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ BT_OPP_ASSERT(path); path[l1] = L'\0'; if (drive) { sprintf( (S8*) path, (const S8 *) "%c:\\", drive); l1 = ext_ucs2strlen((const S8*)path); path[l1] = L'\0'; } if (folder) { //TODO check path length ext_ucs2ncat((S8 *)path, (S8 *)folder, OPPS_TMP_BUFF_SIZE); l2 = ext_ucs2strlen((const S8*)folder); l1 += l2; if (folder[l2-1] != L'\\' && file) { path[l1] = L'\\'; l1++; } path[l1] = L'\0'; } if (file) { ext_ucs2ncat((S8 *)path, (S8 *)file, OPPS_TMP_BUFF_SIZE); } return path; }
/** * @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; }
/** * @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); }
/***************************************************************************** * FUNCTION * mmi_bt_goep_get_file_name_ext * DESCRIPTION * This function is to abstract file name. * PARAMETERS * name [IN] The input file path * type [IN] Get file name or extension name * RETURNS * void *****************************************************************************/ S8 * bt_goep_get_file_name_ext(S8 *name,U32 type) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ U16 len = (U16)ext_ucs2strlen((const S8*)name); U16 *tname = (U16*)name; U16 deter; BT_OPP_GET_FILE_ENUM eType = (BT_OPP_GET_FILE_ENUM) type; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ switch (eType) { case OPP_FILE_GET_NAME: deter = '\\'; break; case OPP_FILE_GET_EXT: deter = '.'; break; case OPP_FILE_GET_NAME_VALID: deter = '/'; break; default: BT_OPP_ASSERT(0); return NULL; } while (len > 0) { len--; /* This is a Byte Order dependency algorithm need to guarantee name is Little Endian */ if (tname[len] == deter) { break; } } if (len == 0) { return name; } return (S8*)(&tname[len+1]); }
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; }
/***************************************************************************** * FUNCTION * bt_goep_clean_tempfile * DESCRIPTION * This function is to clean unfinished receive file * PARAMETERS * close_only [IN] * RETURNS * S32 error code *****************************************************************************/ FS_STATUS bt_goep_clean_tempfile(FHANDLE fh ,U8 *FilePath, BT_BOOL close_only) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ S32 retval; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ //BT_OPP_LOG2(BT_OPP_OPPS_CLEAN_TEMP_OBJ_1, close_only, GOPP(h_recv)); retval = EXT_FS_OK; if( FHANDLE_INVALID_VALUE != fh ) { btmtk_goep_close_rstream(fh); if( FALSE == close_only && 0 < ext_ucs2strlen((const S8*)FilePath)) { btmtk_goep_delete_file( (const U16*) FilePath); } } //BT_OPP_LOG2(BT_OPP_OPPS_CLEAN_TEMP_OBJ, close_only, retval); return retval; }
/** * @brief Request to delete a subfolder in FTP server's current folder * FTP Client Delete Folder * @return TRUE send request successful. Wait for BT_FTPCUI_FOLDER_DELETED evebt */ BT_BOOL btmtk_ftpc_delete_folder(const U8 *foldername){ if( NULL == act_client_cntx_p ){ //TODO fault error return FALSE; } if( 0 == ext_ucs2strlen( (const S8 *) foldername) ){ return FALSE; } /// check state and push a push delete switch (act_client_cntx_p->ftpc_state) { case BT_FTPC_STATE_CONNECTED: return bt_ftpc_delete_folder_routine( (const U16 *) foldername ); break; default: GOEP_TRACE( (BT_FTP_TRC_CLASS, BT_FTPC_STATE_ERROR, act_client_cntx_p->ftpc_state)); break; } return FALSE; }
/** * @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; }