Some ownership towards dList removal in the file helper.

This commit is contained in:
2026-01-10 00:15:17 -05:00
parent d791913a7f
commit 1bc9cf7d92
+12 -16
View File
@@ -93,8 +93,8 @@ struct DilloDir {
struct ClientInfo { struct ClientInfo {
Dsh *sh; Dsh *sh;
char *orig_url; std::optional< std::string > orig_url;
char *filename; std::optional< std::string > filename;
int file_fd; int file_fd;
off_t file_sz; off_t file_sz;
DilloDir *d_dir; DilloDir *d_dir;
@@ -560,11 +560,11 @@ static const char *File_content_type(const char *filename)
* Send an error page * Send an error page
*/ */
static void File_prepare_send_error_page(ClientInfo *client, int res, static void File_prepare_send_error_page(ClientInfo *client, int res,
const char *orig_url) const std::string_view orig_url)
{ {
client->state = st_err; client->state = st_err;
client->err_code = res; client->err_code = res;
client->orig_url = dStrdup(orig_url); client->orig_url = orig_url;
client->flags &= ~FILE_READ; client->flags &= ~FILE_READ;
client->flags |= FILE_WRITE; client->flags |= FILE_WRITE;
} }
@@ -612,7 +612,7 @@ static void File_send_error_page(ClientInfo *client)
* Scan the directory, sort and prepare to send it enclosed in HTTP. * Scan the directory, sort and prepare to send it enclosed in HTTP.
*/ */
static int File_prepare_send_dir(ClientInfo *client, static int File_prepare_send_dir(ClientInfo *client,
const char *DirName, const char *orig_url) const char *DirName, const std::string_view orig_url)
{ {
std::string ds_dirname; std::string ds_dirname;
DilloDir *Ddir; DilloDir *Ddir;
@@ -626,7 +626,7 @@ static int File_prepare_send_dir(ClientInfo *client,
Ddir = File_dillodir_new(ds_dirname.c_str()).release(); Ddir = File_dillodir_new(ds_dirname.c_str()).release();
if (Ddir) { if (Ddir) {
/* looks ok, set things accordingly */ /* looks ok, set things accordingly */
client->orig_url = dStrdup(orig_url); client->orig_url = orig_url;
client->d_dir = Ddir; client->d_dir = Ddir;
client->state = st_start; client->state = st_start;
client->flags &= ~FILE_READ; client->flags &= ~FILE_READ;
@@ -641,7 +641,7 @@ static int File_prepare_send_dir(ClientInfo *client,
*/ */
static int File_prepare_send_file(ClientInfo *client, static int File_prepare_send_file(ClientInfo *client,
const char *filename, const char *filename,
const char *orig_url) const std::string_view orig_url)
{ {
int fd, res = -1; int fd, res = -1;
struct stat sb; struct stat sb;
@@ -658,8 +658,8 @@ static int File_prepare_send_file(ClientInfo *client,
client->file_sz = sb.st_size; client->file_sz = sb.st_size;
client->d_dir = NULL; client->d_dir = NULL;
client->state = st_start; client->state = st_start;
client->filename = dStrdup(filename); client->filename = filename;
client->orig_url = dStrdup(orig_url); client->orig_url = orig_url;
client->flags &= ~FILE_READ; client->flags &= ~FILE_READ;
client->flags |= FILE_WRITE; client->flags |= FILE_WRITE;
res = 0; res = 0;
@@ -717,9 +717,9 @@ static int File_send_file(ClientInfo *client)
/* send HTTP header */ /* send HTTP header */
/* Check for gzipped file */ /* Check for gzipped file */
namelen = strlen(client->filename); namelen = client->filename.value().size();
if (namelen > 3 && if (namelen > 3 &&
!dStrAsciiCasecmp(client->filename + namelen - 3, ".gz")) { !dStrAsciiCasecmp(client->filename.value().c_str() + namelen - 3, ".gz")) {
gzipped = true; gzipped = true;
namelen -= 3; namelen -= 3;
} }
@@ -727,7 +727,7 @@ static int File_send_file(ClientInfo *client)
* If there's no known extension, perform data sniffing. * If there's no known extension, perform data sniffing.
* If this doesn't lead to a conclusion, use "application/octet-stream". * If this doesn't lead to a conclusion, use "application/octet-stream".
*/ */
name = dStrndup(client->filename, namelen); name = dStrndup(client->filename.value().c_str(), namelen);
if (!(ct = File_content_type(name))) if (!(ct = File_content_type(name)))
ct = unknown_type; ct = unknown_type;
dFree(name); dFree(name);
@@ -894,8 +894,6 @@ static ClientInfo *File_add_client(int sock_fd)
{ {
auto new_client = std::make_unique< ClientInfo >(); auto new_client = std::make_unique< ClientInfo >();
new_client->sh = a_Dpip_dsh_new(sock_fd, sock_fd, 8*1024); new_client->sh = a_Dpip_dsh_new(sock_fd, sock_fd, 8*1024);
new_client->orig_url = NULL;
new_client->filename = NULL;
new_client->file_fd = -1; new_client->file_fd = -1;
new_client->file_sz = 0; new_client->file_sz = 0;
new_client->d_dir = NULL; new_client->d_dir = NULL;
@@ -920,8 +918,6 @@ static void File_remove_client(ClientInfo *client)
a_Dpip_dsh_close(client->sh); a_Dpip_dsh_close(client->sh);
a_Dpip_dsh_free(client->sh); a_Dpip_dsh_free(client->sh);
File_close(client->file_fd); File_close(client->file_fd);
dFree(client->orig_url);
dFree(client->filename);
File_dillodir_free(client->d_dir); File_dillodir_free(client->d_dir);
delete client; delete client;