HANDLE _CeOpenDatabase(/*{{{*/ RapiContext *context, PCEOID poid, LPWSTR lpszName, CEPROPID propid, DWORD dwFlags, HWND hwndNotify SYNCE_UNUSED) { HANDLE handle = INVALID_HANDLE_VALUE; rapi_database_trace("begin"); rapi_context_begin_command(context, 0x0e); if (!poid) { context->last_error = ERROR_INVALID_PARAMETER; goto exit; } rapi_buffer_write_uint32(context->send_buffer, *poid); rapi_buffer_write_uint32(context->send_buffer, propid); rapi_buffer_write_uint32(context->send_buffer, dwFlags); if (*poid == 0) { rapi_buffer_write_string(context->send_buffer, lpszName); } if ( !rapi_context_call(context) ) goto exit; if ( !rapi_buffer_read_uint32(context->recv_buffer, &context->last_error) ) goto exit; rapi_database_trace("context->last_error=0x%08x", context->last_error); if ( !rapi_buffer_read_uint32(context->recv_buffer, &handle) ) goto exit; if (*poid == 0) { if ( !rapi_buffer_read_uint32(context->recv_buffer, poid) ) goto exit; } exit: return handle; }/*}}}*/
DWORD _CeGetFileAttributes( LPCWSTR lpFileName) { RapiContext* context = rapi_context_current(); DWORD return_value = 0xFFFFFFFF; rapi_context_begin_command(context, 0x03); rapi_buffer_write_string(context->send_buffer, lpFileName); if ( !rapi_context_call(context) ) goto exit; rapi_buffer_read_uint32(context->recv_buffer, &context->last_error); rapi_buffer_read_uint32(context->recv_buffer, &return_value); exit: return return_value; }
CEOID _CeCreateDatabase( RapiContext *context, LPWSTR lpszName, DWORD dwDbaseType, WORD wNumSortOrder, SORTORDERSPEC *rgSortSpecs) { CEOID return_value = 0; int i; rapi_database_trace("begin"); rapi_context_begin_command(context, 0x0d); /* NOTE: strange marshalling order for parameters */ rapi_buffer_write_uint32(context->send_buffer, dwDbaseType); rapi_buffer_write_uint16(context->send_buffer, wNumSortOrder); /* NOTE: We can't write whole rgSortSpecs buffer directly because we need to * think about the byte order */ for (i = 0; i < wNumSortOrder; i++) { rapi_buffer_write_uint32(context->send_buffer, rgSortSpecs[i].propid); rapi_buffer_write_uint32(context->send_buffer, rgSortSpecs[i].dwFlags); } rapi_buffer_write_string(context->send_buffer, lpszName); if ( !rapi_context_call(context) ) goto fail; if ( !rapi_buffer_read_uint32(context->recv_buffer, &context->last_error) ) goto fail; rapi_database_trace("context->last_error=0x%08x", context->last_error); if ( !rapi_buffer_read_uint32(context->recv_buffer, &return_value) ) goto fail; return return_value; fail: return 0; }
HANDLE _CeFindFirstFile( LPCWSTR lpFileName, LPCE_FIND_DATA lpFindFileData) { RapiContext* context = rapi_context_current(); HANDLE handle = INVALID_HANDLE_VALUE; rapi_context_begin_command(context, 0x00); rapi_buffer_write_string(context->send_buffer, lpFileName); if ( !rapi_context_call(context) ) return INVALID_HANDLE_VALUE; rapi_buffer_read_uint32(context->recv_buffer, &context->last_error); rapi_buffer_read_uint32(context->recv_buffer, &handle); if (!rapi_buffer_read_find_data(context->recv_buffer, lpFindFileData) ) return INVALID_HANDLE_VALUE; return handle; }
BOOL _CeSetFileAttributes( LPCWSTR lpFileName, DWORD dwFileAttributes) { RapiContext* context = rapi_context_current(); BOOL return_value = false; synce_trace("Setting attributes %08x", dwFileAttributes); rapi_context_begin_command(context, 0x04); rapi_buffer_write_uint32(context->send_buffer, dwFileAttributes); rapi_buffer_write_string(context->send_buffer, lpFileName); if ( !rapi_context_call(context) ) goto exit; rapi_buffer_read_uint32(context->recv_buffer, &context->last_error); rapi_buffer_read_uint32(context->recv_buffer, &return_value); exit: return return_value; }
BOOL _CeFindAllFiles( LPCWSTR szPath, DWORD dwFlags, LPDWORD lpdwFoundCount, LPLPCE_FIND_DATA ppFindDataArray) { RapiContext* context = rapi_context_current(); uint32_t count = 0; rapi_context_begin_command(context, 0x09); rapi_buffer_write_string(context->send_buffer, szPath); rapi_buffer_write_uint32(context->send_buffer, dwFlags); if ( !rapi_context_call(context) ) return false; rapi_buffer_read_uint32(context->recv_buffer, &count); synce_trace("found %i files", count); if (count) { unsigned i; uint32_t name_size; CE_FIND_DATA* array = calloc(count, sizeof(CE_FIND_DATA)); if (!array) return false; for (i = 0; i < count; i++) { if (dwFlags & FAF_NAME) rapi_buffer_read_uint32(context->recv_buffer, &name_size); if (dwFlags & FAF_ATTRIBUTES) rapi_buffer_read_uint32(context->recv_buffer, &array[i].dwFileAttributes); if (dwFlags & FAF_CREATION_TIME) { rapi_buffer_read_uint32(context->recv_buffer, &array[i].ftCreationTime.dwLowDateTime); rapi_buffer_read_uint32(context->recv_buffer, &array[i].ftCreationTime.dwHighDateTime); } if (dwFlags & FAF_LASTACCESS_TIME) { rapi_buffer_read_uint32(context->recv_buffer, &array[i].ftLastAccessTime.dwLowDateTime); rapi_buffer_read_uint32(context->recv_buffer, &array[i].ftLastAccessTime.dwHighDateTime); } if (dwFlags & FAF_LASTWRITE_TIME) { rapi_buffer_read_uint32(context->recv_buffer, &array[i].ftLastWriteTime.dwLowDateTime); rapi_buffer_read_uint32(context->recv_buffer, &array[i].ftLastWriteTime.dwHighDateTime); } if (dwFlags & FAF_SIZE_HIGH) rapi_buffer_read_uint32(context->recv_buffer, &array[i].nFileSizeHigh); if (dwFlags & FAF_SIZE_LOW) rapi_buffer_read_uint32(context->recv_buffer, &array[i].nFileSizeLow); if (dwFlags & FAF_OID) rapi_buffer_read_uint32(context->recv_buffer, &array[i].dwOID); if (dwFlags & FAF_NAME) { rapi_buffer_read_data(context->recv_buffer, array[i].cFileName, name_size * sizeof(WCHAR) ); synce_trace_wstr(array[i].cFileName); } } if (ppFindDataArray) *ppFindDataArray = array; } if (lpdwFoundCount) *lpdwFoundCount = count; return true; }