static void filebox_uploader_handle_handler (GObject *source_object, GAsyncResult *res, gpointer user_data) { g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__); hev_filebox_uploader_handle_finish (HEV_FILEBOX_UPLOADER (source_object), res, NULL); }
static void hev_scgi_handler_filebox_handle_upload (HevSCGIHandler *self, GObject *scgi_task) { HevSCGIHandlerFileboxPrivate *priv = HEV_SCGI_HANDLER_FILEBOX_GET_PRIVATE(self); g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__); hev_filebox_uploader_handle_async (HEV_FILEBOX_UPLOADER (priv->uploader), scgi_task, filebox_uploader_handle_handler, NULL); }
static void hev_filebox_uploader_dispose (GObject *obj) { HevFileboxUploader *self = HEV_FILEBOX_UPLOADER (obj); HevFileboxUploaderPrivate *priv = HEV_FILEBOX_UPLOADER_GET_PRIVATE (self); g_debug ("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__); G_OBJECT_CLASS (hev_filebox_uploader_parent_class)->dispose (obj); }
static void hev_filebox_uploader_finalize (GObject *obj) { HevFileboxUploader *self = HEV_FILEBOX_UPLOADER (obj); HevFileboxUploaderPrivate *priv = HEV_FILEBOX_UPLOADER_GET_PRIVATE (self); g_debug ("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__); if(priv->config) { g_key_file_unref (priv->config); priv->config = NULL; } G_OBJECT_CLASS (hev_filebox_uploader_parent_class)->finalize (obj); }
static void hev_filebox_uploader_set_property(GObject *obj, guint prop_id, const GValue *value, GParamSpec *pspec) { HevFileboxUploader *self = HEV_FILEBOX_UPLOADER(obj); HevFileboxUploaderPrivate *priv = HEV_FILEBOX_UPLOADER_GET_PRIVATE(self); g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__); switch(prop_id) { case PROP_CONFIG: priv->config = g_key_file_ref (g_value_get_pointer(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop_id, pspec); break; } }
static void filebox_uploader_handle_task_handler (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable) { HevFileboxUploader *self = HEV_FILEBOX_UPLOADER (source_object); HevFileboxUploaderPrivate *priv = HEV_FILEBOX_UPLOADER_GET_PRIVATE (self); GObject *scgi_task = task_data; gboolean status = TRUE; GObject *request = NULL; GInputStream *req_stream = NULL; GHashTable *req_htb = NULL; GObject *response = NULL; GOutputStream *res_stream = NULL; GHashTable *res_htb = NULL; const gchar *content_type = NULL, *content_length = NULL; GRegex *regex = NULL; GMatchInfo *match_info = NULL; gchar rand_pass[16], *boundary = NULL, *fp_path = NULL, *fm_path = NULL, *ft_path = NULL; gint rand_pass_len; guint64 length = 0; GFile *file_tmp = NULL; g_debug ("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__); request = hev_scgi_task_get_request (HEV_SCGI_TASK (scgi_task)); req_stream = hev_scgi_request_get_input_stream (HEV_SCGI_REQUEST (request)); req_htb = hev_scgi_request_get_header_hash_table (HEV_SCGI_REQUEST (request)); response = hev_scgi_task_get_response (HEV_SCGI_TASK (scgi_task)); res_stream = hev_scgi_response_get_output_stream (HEV_SCGI_RESPONSE (response)); res_htb = hev_scgi_response_get_header_hash_table (HEV_SCGI_RESPONSE (response)); content_type = g_hash_table_lookup (req_htb, "CONTENT_TYPE"); content_length = g_hash_table_lookup (req_htb, "CONTENT_LENGTH"); /* get boundary string from content type */ regex = g_regex_new ("^multipart/form-data;\\s*boundary=(.+)$", 0, 0, NULL); if (!g_regex_match (regex, content_type, 0, &match_info)) { g_hash_table_insert (res_htb, g_strdup ("Status"), g_strdup ("400 Bad Request")); hev_scgi_response_write_header (HEV_SCGI_RESPONSE (response), NULL); g_regex_unref (regex); g_task_return_boolean (task, FALSE); return; } boundary = g_match_info_fetch (match_info, 1); g_match_info_unref (match_info); g_regex_unref (regex); fp_path = g_key_file_get_string (priv->config, "Module", "FilePoolPath", NULL); fm_path = g_key_file_get_string (priv->config, "Module", "FileMetaPath", NULL); ft_path = g_key_file_get_string (priv->config, "Module", "FileTempPath", NULL); length = g_ascii_strtoull (content_length, NULL, 10); rand_pass_len = g_snprintf (rand_pass, 16, "%u", g_random_int_range (99999, 999999)); g_object_set_data (scgi_task, "rand-pass", rand_pass); /* create tmp file */ file_tmp = filebox_uploader_handle_task_create_tmp (self, scgi_task, req_stream, req_htb, res_htb, ft_path, length); if (file_tmp) { gchar *path = NULL; GMappedFile *mapped_file = NULL; path = g_file_get_path (file_tmp); mapped_file = g_mapped_file_new (path, FALSE, NULL); g_free (path); if (mapped_file) { GPtrArray *files = NULL; gchar *duration = NULL, *one_off = NULL; /* split files from tmp file */ files = filebox_uploader_handle_task_split_tmp (self, scgi_task, mapped_file, res_htb, fp_path, fm_path, boundary, &duration, &one_off); if (files) { /* write meta files */ g_object_set_data (scgi_task, "duration", duration); g_object_set_data (scgi_task, "one-off", one_off); g_ptr_array_foreach (files, file_ptr_array_foreach_write_meta_handler, scgi_task); g_ptr_array_unref (files); } g_free (duration); g_free (one_off); g_mapped_file_unref (mapped_file); } g_file_delete (file_tmp, NULL, NULL); g_object_unref (file_tmp); } g_free (boundary); g_free (fp_path); g_free (fm_path); g_free (ft_path); if (!g_hash_table_contains (res_htb, "Status")) g_hash_table_insert (res_htb, g_strdup ("Status"), g_strdup ("200 OK")); hev_scgi_response_write_header (HEV_SCGI_RESPONSE (response), NULL); g_output_stream_write_all (res_stream, rand_pass, rand_pass_len, NULL, NULL, NULL); g_task_return_boolean (task, status); }