📄 gwinhttpfile.c
字号:
child->url.lpszUserName = g_memdup (winhttp_file->url.lpszUserName, winhttp_file->url.dwUserNameLength*2); child->url.lpszPassword = g_memdup (winhttp_file->url.lpszPassword, winhttp_file->url.dwPasswordLength*2); child->url.lpszUrlPath = wnew_path; child->url.dwUrlPathLength = 2*(wcslen (wnew_path)+1); child->url.lpszExtraInfo = NULL; child->url.dwExtraInfoLength = 0; return (GFile *) child;}static GFile *g_winhttp_file_get_child_for_display_name (GFile *file, const char *display_name, GError **error){ GFile *new_file; char *basename; basename = g_locale_from_utf8 (display_name, -1, NULL, NULL, NULL); if (basename == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME, _("Invalid filename %s"), display_name); return NULL; } new_file = g_file_get_child (file, basename); g_free (basename); return new_file;}static GFile *g_winhttp_file_set_display_name (GFile *file, const char *display_name, GCancellable *cancellable, GError **error){ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("Operation not supported")); return NULL;}static time_tmktime_utc (SYSTEMTIME *t){ time_t retval; static const gint days_before[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; if (t->wMonth < 1 || t->wMonth > 12) return (time_t) -1; retval = (t->wYear - 1970) * 365; retval += (t->wYear - 1968) / 4; retval += days_before[t->wMonth-1] + t->wDay - 1; if (t->wYear % 4 == 0 && t->wMonth < 3) retval -= 1; retval = ((((retval * 24) + t->wHour) * 60) + t->wMinute) * 60 + t->wSecond; return retval;}static GFileInfo *g_winhttp_file_query_info (GFile *file, const char *attributes, GFileQueryInfoFlags flags, GCancellable *cancellable, GError **error){ GWinHttpFile *winhttp_file = G_WINHTTP_FILE (file); HINTERNET connection, request; const wchar_t *accept_types[] = { L"*/*", NULL, }; GFileInfo *info; GFileAttributeMatcher *matcher; char *basename; wchar_t *content_length; wchar_t *content_type; SYSTEMTIME last_modified; DWORD last_modified_len; connection = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpConnect (G_WINHTTP_VFS (winhttp_file->vfs)->session, winhttp_file->url.lpszHostName, winhttp_file->url.nPort, 0); if (connection == NULL) { _g_winhttp_set_error (error, GetLastError (), "HTTP connection"); return NULL; } request = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpOpenRequest (connection, L"HEAD", winhttp_file->url.lpszUrlPath, NULL, WINHTTP_NO_REFERER, accept_types, winhttp_file->url.nScheme == INTERNET_SCHEME_HTTPS ? WINHTTP_FLAG_SECURE : 0); if (request == NULL) { _g_winhttp_set_error (error, GetLastError (), "HEAD request"); return NULL; } if (!G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpSendRequest (request, NULL, 0, NULL, 0, 0, 0)) { _g_winhttp_set_error (error, GetLastError (), "HEAD request"); return NULL; } if (!_g_winhttp_response (winhttp_file->vfs, request, error, "HEAD request")) return NULL; matcher = g_file_attribute_matcher_new (attributes); info = g_file_info_new (); g_file_info_set_attribute_mask (info, matcher); basename = g_winhttp_file_get_basename (file); g_file_info_set_name (info, basename); g_free (basename); content_length = NULL; if (_g_winhttp_query_header (winhttp_file->vfs, request, "HEAD request", WINHTTP_QUERY_CONTENT_LENGTH, &content_length, NULL)) { gint64 cl; int n; if (swscanf (content_length, L"%I64d%n", &cl, &n) == 1 && n == wcslen (content_length)) g_file_info_set_size (info, cl); g_free (content_length); } if (matcher == NULL) return info; content_type = NULL; if (_g_winhttp_query_header (winhttp_file->vfs, request, "HEAD request", WINHTTP_QUERY_CONTENT_TYPE, &content_type, NULL)) { char *ct = g_utf16_to_utf8 (content_type, -1, NULL, NULL, NULL); if (ct != NULL) { char *p = strchr (ct, ';'); if (p != NULL) { char *tmp = g_strndup (ct, p - ct); g_file_info_set_content_type (info, tmp); g_free (tmp); } else g_file_info_set_content_type (info, ct); } g_free (ct); } last_modified_len = sizeof (last_modified); if (G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpQueryHeaders (request, WINHTTP_QUERY_LAST_MODIFIED | WINHTTP_QUERY_FLAG_SYSTEMTIME, NULL, &last_modified, &last_modified_len, NULL) && last_modified_len == sizeof (last_modified) && /* Don't bother comparing to the exact Y2038 moment */ last_modified.wYear >= 1970 && last_modified.wYear < 2038) { GTimeVal tv; tv.tv_sec = mktime_utc (&last_modified); tv.tv_usec = last_modified.wMilliseconds * 1000; g_file_info_set_modification_time (info, &tv); } g_file_attribute_matcher_unref (matcher); return info;}static GFileInputStream *g_winhttp_file_read (GFile *file, GCancellable *cancellable, GError **error){ GWinHttpFile *winhttp_file = G_WINHTTP_FILE (file); HINTERNET connection, request; const wchar_t *accept_types[] = { L"*/*", NULL, }; connection = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpConnect (G_WINHTTP_VFS (winhttp_file->vfs)->session, winhttp_file->url.lpszHostName, winhttp_file->url.nPort, 0); if (connection == NULL) { _g_winhttp_set_error (error, GetLastError (), "HTTP connection"); return NULL; } request = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpOpenRequest (connection, L"GET", winhttp_file->url.lpszUrlPath, NULL, WINHTTP_NO_REFERER, accept_types, winhttp_file->url.nScheme == INTERNET_SCHEME_HTTPS ? WINHTTP_FLAG_SECURE : 0); if (request == NULL) { _g_winhttp_set_error (error, GetLastError (), "GET request"); return NULL; } return _g_winhttp_file_input_stream_new (winhttp_file, connection, request);}static GFileOutputStream *g_winhttp_file_create (GFile *file, GFileCreateFlags flags, GCancellable *cancellable, GError **error){ GWinHttpFile *winhttp_file = G_WINHTTP_FILE (file); HINTERNET connection; connection = G_WINHTTP_VFS_GET_CLASS (winhttp_file->vfs)->funcs->pWinHttpConnect (G_WINHTTP_VFS (winhttp_file->vfs)->session, winhttp_file->url.lpszHostName, winhttp_file->url.nPort, 0); if (connection == NULL) { _g_winhttp_set_error (error, GetLastError (), "HTTP connection"); return NULL; } return _g_winhttp_file_output_stream_new (winhttp_file, connection);}#if 0static GFileOutputStream *g_winhttp_file_replace (GFile *file, const char *etag, gboolean make_backup, GFileCreateFlags flags, GCancellable *cancellable, GError **error){ /* FIXME: Implement */ return NULL;}static gbooleang_winhttp_file_delete (GFile *file, GCancellable *cancellable, GError **error){ /* FIXME: Implement */ return FALSE;}static gbooleang_winhttp_file_make_directory (GFile *file, GCancellable *cancellable, GError **error){ /* FIXME: Implement */ return FALSE;}static gbooleang_winhttp_file_copy (GFile *source, GFile *destination, GFileCopyFlags flags, GCancellable *cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GError **error){ /* Fall back to default copy?? */ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Copy not supported"); return FALSE;}static gbooleang_winhttp_file_move (GFile *source, GFile *destination, GFileCopyFlags flags, GCancellable *cancellable, GFileProgressCallback progress_callback, gpointer progress_callback_data, GError **error){ /* FIXME: Implement */ return FALSE;}#endifstatic voidg_winhttp_file_file_iface_init (GFileIface *iface){ iface->dup = g_winhttp_file_dup; iface->hash = g_winhttp_file_hash; iface->equal = g_winhttp_file_equal; iface->is_native = g_winhttp_file_is_native; iface->has_uri_scheme = g_winhttp_file_has_uri_scheme; iface->get_uri_scheme = g_winhttp_file_get_uri_scheme; iface->get_basename = g_winhttp_file_get_basename; iface->get_path = g_winhttp_file_get_path; iface->get_uri = g_winhttp_file_get_uri; iface->get_parse_name = g_winhttp_file_get_parse_name; iface->get_parent = g_winhttp_file_get_parent; iface->prefix_matches = g_winhttp_file_prefix_matches; iface->get_relative_path = g_winhttp_file_get_relative_path; iface->resolve_relative_path = g_winhttp_file_resolve_relative_path; iface->get_child_for_display_name = g_winhttp_file_get_child_for_display_name; iface->set_display_name = g_winhttp_file_set_display_name; iface->query_info = g_winhttp_file_query_info; iface->read_fn = g_winhttp_file_read; iface->create = g_winhttp_file_create;#if 0 iface->replace = g_winhttp_file_replace; iface->delete_file = g_winhttp_file_delete; iface->make_directory = g_winhttp_file_make_directory; iface->copy = g_winhttp_file_copy; iface->move = g_winhttp_file_move;#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -