More temporary string cleanup.

This commit is contained in:
2025-04-19 02:25:08 -04:00
parent aaead901ae
commit 414c1d287e

View File

@ -1318,15 +1318,14 @@ static void Cookies_add_matching_cookies(const char *domain,
/* /*
* Return a string that contains all relevant cookies as headers. * Return a string that contains all relevant cookies as headers.
*/ */
static char *Cookies_get(char *url_host, char *url_path, static std::string Cookies_get(char *url_host, char *url_path,
char *url_scheme) char *url_scheme)
{ {
char *domain_str, *str; char *domain_str;
CookieData_t *cookie; CookieData_t *cookie;
Dlist *matching_cookies; Dlist *matching_cookies;
bool_t is_tls, is_ip_addr, host_only_val; bool_t is_tls, is_ip_addr, host_only_val;
Dstr *cookie_dstring;
int i; int i;
if (disabled) if (disabled)
@ -1380,27 +1379,27 @@ static char *Cookies_get(char *url_host, char *url_path,
} }
/* Found the cookies, now make the string */ /* Found the cookies, now make the string */
cookie_dstring = dStr_new(""); std::string cookie_dstring;
using namespace std::literals::string_literals;
if (dList_length(matching_cookies) > 0) { if (dList_length(matching_cookies) > 0) {
dStr_sprintfa(cookie_dstring, "Cookie: "); cookie_dstring+= "Cookie: ";
for (i = 0; (cookie = reinterpret_cast< CookieData_t * >( dList_nth_data(matching_cookies, i) )); ++i) { for (i = 0; (cookie = reinterpret_cast< CookieData_t * >( dList_nth_data(matching_cookies, i) )); ++i) {
dStr_sprintfa(cookie_dstring, "%s=%s", cookie->name, cookie->value); cookie_dstring+= cookie->name + "="s + cookie->value;
dStr_append(cookie_dstring, cookie_dstring+=
dList_length(matching_cookies) > i + 1 ? "; " : "\r\n"); dList_length(matching_cookies) > i + 1 ? "; " : "\r\n";
} }
} }
dList_free(matching_cookies); dList_free(matching_cookies);
str = cookie_dstring->str;
dStr_free(cookie_dstring, FALSE);
if (*str) { if (not cookie_dstring.empty()) {
MSG("%s GETTING: %s", url_host, str); MSG("%s GETTING: %s", url_host, cookie_dstring.c_str());
cookies_use_counter++; cookies_use_counter++;
} }
return str; return cookie_dstring;
} }
/* ------------------------------------------------------------- /* -------------------------------------------------------------
@ -1544,7 +1543,7 @@ static CookieControlAction Cookies_control_check_domain(const char *domain)
*/ */
static int srv_parse_tok(Dsh *sh, ClientInfo *client, char *Buf) static int srv_parse_tok(Dsh *sh, ClientInfo *client, char *Buf)
{ {
char *cmd, *cookie, *host, *path; char *cmd, *host, *path;
int ret = 1; int ret = 1;
size_t BufSize = strlen(Buf); size_t BufSize = strlen(Buf);
@ -1567,7 +1566,7 @@ static int srv_parse_tok(Dsh *sh, ClientInfo *client, char *Buf)
int st; int st;
char *date; char *date;
cookie = a_Dpip_get_attr_l(Buf, BufSize, "cookie"); char *cookie = a_Dpip_get_attr_l(Buf, BufSize, "cookie");
host = a_Dpip_get_attr_l(Buf, BufSize, "host"); host = a_Dpip_get_attr_l(Buf, BufSize, "host");
path = a_Dpip_get_attr_l(Buf, BufSize, "path"); path = a_Dpip_get_attr_l(Buf, BufSize, "path");
date = a_Dpip_get_attr_l(Buf, BufSize, "date"); date = a_Dpip_get_attr_l(Buf, BufSize, "date");
@ -1591,13 +1590,13 @@ static int srv_parse_tok(Dsh *sh, ClientInfo *client, char *Buf)
host = a_Dpip_get_attr_l(Buf, BufSize, "host"); host = a_Dpip_get_attr_l(Buf, BufSize, "host");
path = a_Dpip_get_attr_l(Buf, BufSize, "path"); path = a_Dpip_get_attr_l(Buf, BufSize, "path");
cookie = Cookies_get(host, path, scheme); std::string cookie = Cookies_get(host, path, scheme);
dFree(scheme); dFree(scheme);
dFree(path); dFree(path);
dFree(host); dFree(host);
dFree(cmd); dFree(cmd);
cmd = a_Dpip_build_cmd("cmd=%s cookie=%s", "get_cookie_answer", cookie); cmd = a_Dpip_build_cmd("cmd=%s cookie=%s", "get_cookie_answer", cookie.c_str());
if (a_Dpip_dsh_write_str(sh, 1, cmd)) { if (a_Dpip_dsh_write_str(sh, 1, cmd)) {
ret = 1; ret = 1;
@ -1605,7 +1604,6 @@ static int srv_parse_tok(Dsh *sh, ClientInfo *client, char *Buf)
_MSG("a_Dpip_dsh_write_str: SUCCESS cmd={%s}\n", cmd); _MSG("a_Dpip_dsh_write_str: SUCCESS cmd={%s}\n", cmd);
ret = 2; ret = 2;
} }
dFree(cookie);
} }
dFree(cmd); dFree(cmd);