int process_header_end(request * req) { if (!req->logline) { send_r_error(req); return 0; } /* Percent-decode request */ if (unescape_uri(req->request_uri, &(req->query_string)) == 0) { log_error_doc(req); fputs("Problem unescaping uri\n", stderr); send_r_bad_request(req); return 0; } /* clean pathname */ clean_pathname(req->request_uri); if (req->request_uri[0] != '/') { send_r_bad_request(req); return 0; } if (translate_uri(req) == 0) { /* unescape, parse uri */ SQUASH_KA(req); return 0; /* failure, close down */ } if (req->method == M_POST) { req->post_data_fd = create_temporary_file(1, NULL, 0); if (req->post_data_fd == 0) return(0); return(1); /* success */ } if (req->is_cgi) { return init_cgi(req); } req->status = WRITE; return init_get(req); /* get and head */ }
int process_header_end(request * req) { if (!req->logline) { log_error_doc(req); fputs("No logline in process_header_end\n", stderr); send_r_error(req); return 0; } /* Percent-decode request */ if (unescape_uri(req->request_uri, &(req->query_string)) == 0) { log_error_doc(req); fputs("URI contains bogus characters\n", stderr); send_r_bad_request(req); return 0; } /* clean pathname */ clean_pathname(req->request_uri); if (req->request_uri[0] != '/') { log_error("URI does not begin with '/'\n"); send_r_bad_request(req); return 0; } if (vhost_root) { char *c; if (!req->header_host) { req->host = strdup(default_vhost); } else { req->host = strdup(req->header_host); } if (!req->host) { log_error_doc(req); fputs("unable to strdup default_vhost/req->header_host\n", stderr); send_r_error(req); return 0; } strlower(req->host); /* check for port, and remove * we essentially ignore the port, because we cannot * as yet report a different port than the one we are * listening on */ c = strchr(req->host, ':'); if (c) *c = '\0'; if (check_host(req->host) < 1) { log_error_doc(req); fputs("host invalid!\n", stderr); send_r_bad_request(req); return 0; } } if (translate_uri(req) == 0) { /* unescape, parse uri */ /* errors already logged */ SQUASH_KA(req); return 0; /* failure, close down */ } if (req->method == M_POST) { req->post_data_fd = create_temporary_file(1, NULL, 0); if (req->post_data_fd == 0) { /* errors already logged */ send_r_error(req); return 0; } if (fcntl(req->post_data_fd, F_SETFD, 1) == -1) { log_error_doc(req); fputs("unable to set close-on-exec for req->post_data_fd!\n", stderr); close(req->post_data_fd); req->post_data_fd = 0; send_r_error(req); return 0; } return 1; /* success */ } if (req->cgi_type) { return init_cgi(req); } req->status = WRITE; // return complete_response(req); return init_control(req); // return init_get(req); /* get and head */ }
static gboolean tracker_writeback_file_update_metadata (TrackerWriteback *writeback, GPtrArray *values, TrackerSparqlConnection *connection, GCancellable *cancellable, GError **error) { TrackerWritebackFileClass *writeback_file_class; gboolean retval; GFile *file, *tmp_file; GFileInfo *file_info; GStrv row; const gchar * const *content_types; const gchar *mime_type; guint n; GError *n_error = NULL; writeback_file_class = TRACKER_WRITEBACK_FILE_GET_CLASS (writeback); if (!writeback_file_class->update_file_metadata) { g_critical ("%s doesn't implement update_file_metadata()", G_OBJECT_TYPE_NAME (writeback)); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s doesn't implement update_file_metadata()", G_OBJECT_TYPE_NAME (writeback)); return FALSE; } if (!writeback_file_class->content_types) { g_critical ("%s doesn't implement content_types()", G_OBJECT_TYPE_NAME (writeback)); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s doesn't implement content_types()", G_OBJECT_TYPE_NAME (writeback)); return FALSE; } /* Get the file from the row */ row = g_ptr_array_index (values, 0); file = g_file_new_for_uri (row[0]); file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_UNIX_MODE "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (!file_info) { g_object_unref (file); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s doesn't exist", row[0]); return FALSE; } if (!g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) { g_object_unref (file_info); g_object_unref (file); g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "%s not writable", row[0]); return FALSE; } mime_type = g_file_info_get_content_type (file_info); content_types = (writeback_file_class->content_types) (TRACKER_WRITEBACK_FILE (writeback)); retval = FALSE; for (n = 0; content_types[n] != NULL; n++) { if (g_strcmp0 (mime_type, content_types[n]) == 0) { retval = TRUE; break; } } if (!retval) { /* module does not support writeback for this file */ g_object_unref (file_info); g_object_unref (file); g_set_error_literal (error, TRACKER_DBUS_ERROR, TRACKER_DBUS_ERROR_UNSUPPORTED, "Module does not support writeback for this file"); return FALSE; } /* Copy to a temporary file so we can perform an atomic write on move */ tmp_file = create_temporary_file (file, file_info, &n_error); if (!tmp_file) { g_object_unref (file); g_propagate_error (error, n_error); g_object_unref (file_info); return FALSE; } retval = (writeback_file_class->update_file_metadata) (TRACKER_WRITEBACK_FILE (writeback), tmp_file, values, connection, cancellable, &n_error); if (!retval) { /* Delete the temporary file and preserve original */ g_file_delete (tmp_file, NULL, NULL); } else { GError *m_error = NULL; /* Move back the modified file to the original location */ g_file_move (tmp_file, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL); /* Set file attributes on tmp_file using file_info of original file */ g_file_set_attributes_from_info (tmp_file, file_info, 0, NULL, &m_error); if (m_error) { g_warning ("Can't restore permissions of original file for %s", row[0]); g_error_free (m_error); } } g_object_unref (file_info); g_object_unref (tmp_file); g_object_unref (file); if (n_error) { g_propagate_error (error, n_error); } return retval; }
int process_header_end(request * req) { if (!req->logline) { log_error_doc(req); fputs("No logline in process_header_end\n", stderr); send_r_error(req); return 0; } /* Percent-decode request */ if (unescape_uri(req->request_uri, &(req->query_string)) == 0) { log_error_doc(req); fputs("URI contains bogus characters\n", stderr); send_r_bad_request(req); return 0; } /* clean pathname */ clean_pathname(req->request_uri); if (req->request_uri[0] != '/') { log_error("URI does not begin with '/'\n"); send_r_bad_request(req); return 0; } if (use_caudium_hack) { /* We check whether the path is of the form "/(ll)/foo/..." which is used by the Caudium webserver for caching purposes and people have bookmarked it. To cope with this we simply strip it of. */ if (req->request_uri[0] == '/' && req->request_uri[1] == '(' && req->request_uri[2] >= 'a' && req->request_uri[2] <= 'z' && req->request_uri[3] >= 'a' && req->request_uri[3] <= 'z' && req->request_uri[4] == ')' && req->request_uri[5] == '/' && req->request_uri[6] ) { unsigned int len = strlen(req->request_uri); memmove (req->request_uri, req->request_uri+5, len - 5 + 1); } } if (vhost_root) { char *c; if (!req->header_host) { req->host = strdup(default_vhost); } else { req->host = strdup(req->header_host); } if (!req->host) { log_error_doc(req); fputs("unable to strdup default_vhost/req->header_host\n", stderr); send_r_error(req); return 0; } strlower(req->host); /* check for port, and remove * we essentially ignore the port, because we cannot * as yet report a different port than the one we are * listening on */ c = strchr(req->host, ':'); if (c) *c = '\0'; if (check_host(req->host) < 1) { log_error_doc(req); fputs("host invalid!\n", stderr); send_r_bad_request(req); return 0; } } if (translate_uri(req) == 0) { /* unescape, parse uri */ /* errors already logged */ SQUASH_KA(req); return 0; /* failure, close down */ } if (req->method == M_POST) { req->post_data_fd = create_temporary_file(1, NULL, 0); if (req->post_data_fd == 0) { /* errors already logged */ send_r_error(req); return 0; } if (fcntl(req->post_data_fd, F_SETFD, 1) == -1) { boa_perror(req, "unable to set close-on-exec for req->post_data_fd!"); close(req->post_data_fd); req->post_data_fd = 0; return 0; } return 1; /* success */ } if (req->cgi_type) { return init_cgi(req); } req->status = WRITE; return init_get(req); /* get and head */ }