diff --git a/dlib/dlib.cc b/dlib/dlib.cc index a6a2d3e..331b2d7 100644 --- a/dlib/dlib.cc +++ b/dlib/dlib.cc @@ -538,6 +538,23 @@ const char *dStr_printable(Dstr *in, int maxlen) return out->str; } +extern "C++" +{ +#include +} + +std::string +dStr_printable_std(const std::string &in, const int maxlen) +{ + const auto wrapped= Alepha::AutoRAII + { + [&]{ return dStr_new( in.c_str() ); }, + []( auto d ) { dStr_free( d, true ); } + }; + + return dStr_printable( wrapped, maxlen ); +} + /* *- dList --------------------------------------------------------------------- */ diff --git a/dlib/dlib.h b/dlib/dlib.h index 527bde0..1f71f99 100644 --- a/dlib/dlib.h +++ b/dlib/dlib.h @@ -124,6 +124,13 @@ void dStr_sprintfa (Dstr *ds, const char *format, ...); int dStr_cmp(Dstr *ds1, Dstr *ds2); char *dStr_memmem(Dstr *haystack, Dstr *needle); const char *dStr_printable(Dstr *in, int maxlen); +#ifdef __cplusplus +extern "C++" +{ +#include +} +std::string dStr_printable_std(const std::string &in, int maxlen); +#endif /* *-- dList -------------------------------------------------------------------- diff --git a/dpi/Makefile.am b/dpi/Makefile.am index 5ef740d..320b55b 100644 --- a/dpi/Makefile.am +++ b/dpi/Makefile.am @@ -45,12 +45,12 @@ datauri_filter_dpi_LDADD = \ downloads_dpi_CXXFLAGS = @LIBFLTK_CXXFLAGS@ -bookmarks_dpi_SOURCES = bookmarks.c dpiutil.c dpiutil.h -downloads_dpi_SOURCES = downloads.cc dpiutil.c dpiutil.h -ftp_filter_dpi_SOURCES = ftp.c dpiutil.c dpiutil.h -hello_filter_dpi_SOURCES = hello.c dpiutil.c dpiutil.h -vsource_filter_dpi_SOURCES = vsource.c dpiutil.c dpiutil.h -file_dpi_SOURCES = file.c dpiutil.c dpiutil.h -cookies_dpi_SOURCES = cookies.c dpiutil.c dpiutil.h -datauri_filter_dpi_SOURCES = datauri.c dpiutil.c dpiutil.h +bookmarks_dpi_SOURCES = bookmarks.c dpiutil.cc dpiutil.h +downloads_dpi_SOURCES = downloads.cc dpiutil.cc dpiutil.h +ftp_filter_dpi_SOURCES = ftp.c dpiutil.cc dpiutil.h +hello_filter_dpi_SOURCES = hello.c dpiutil.cc dpiutil.h +vsource_filter_dpi_SOURCES = vsource.c dpiutil.cc dpiutil.h +file_dpi_SOURCES = file.c dpiutil.cc dpiutil.h +cookies_dpi_SOURCES = cookies.c dpiutil.cc dpiutil.h +datauri_filter_dpi_SOURCES = datauri.c dpiutil.cc dpiutil.h diff --git a/dpi/dpiutil.c b/dpi/dpiutil.cc similarity index 98% rename from dpi/dpiutil.c rename to dpi/dpiutil.cc index da700a7..00ab9b8 100644 --- a/dpi/dpiutil.c +++ b/dpi/dpiutil.cc @@ -97,7 +97,7 @@ char *Escape_html_str(const char *str) Dstr *dstr = dStr_sized_new(64); for (i = 0; str[i]; ++i) { - if ((p = strchr(unsafe_chars, str[i]))) + if ((p = const_cast< char * >( strchr(unsafe_chars, str[i]) ))) dStr_append(dstr, unsafe_rep[p - unsafe_chars]); else dStr_append_c(dstr, str[i]); diff --git a/dpid/Makefile.am b/dpid/Makefile.am index 5ed1a19..465fa6c 100644 --- a/dpid/Makefile.am +++ b/dpid/Makefile.am @@ -19,14 +19,14 @@ dpid_SOURCES = \ dpid.h \ dpid_common.h \ misc_new.h \ - dpi.c \ + dpi.cc \ dpi_socket_dir.c \ - dpid.c \ + dpid.cc \ dpid_common.c \ main.c \ misc_new.c -dpidc_SOURCES = dpidc.c +dpidc_SOURCES = dpidc.cc sysconf_DATA = dpidrc CLEANFILES = $(sysconf_DATA) diff --git a/dpid/dpi.c b/dpid/dpi.cc similarity index 100% rename from dpid/dpi.c rename to dpid/dpi.cc diff --git a/dpid/dpi.h b/dpid/dpi.h index 03919f5..6fe0004 100644 --- a/dpid/dpi.h +++ b/dpid/dpi.h @@ -7,6 +7,12 @@ #ifndef DPI_H #define DPI_H +#ifdef __cplusplus +extern "C" +{ +#endif + + #include /* for socklen_t */ #include /* for socklen_t and AF_LOCAL */ @@ -42,4 +48,8 @@ char *a_Dpi_rd_dpi_socket_dir(char *dirname); char *a_Dpi_srs(void); +#ifdef __cplusplus +} +#endif + #endif diff --git a/dpid/dpid.c b/dpid/dpid.cc similarity index 99% rename from dpid/dpid.c rename to dpid/dpid.cc index 583551f..7503bb0 100644 --- a/dpid/dpid.c +++ b/dpid/dpid.cc @@ -98,7 +98,7 @@ void free_services_list(Dlist *s_list) struct service *s; for (i=0; i < dList_length(s_list) ; i++) { - s = dList_nth_data(s_list, i); + s = reinterpret_cast< service * >( dList_nth_data(s_list, i) ); dFree(s->name); } dList_free(s_list); @@ -888,7 +888,7 @@ void send_sockport(int sock_fd, char *dpi_tag, struct dp *dpi_attr_list) dReturn_if_fail((dpi_id = get_message(sock_fd, dpi_tag)) != NULL); - serv = dList_find_custom(services_list,dpi_id,(dCompareFunc)service_match); + serv = reinterpret_cast< service * >( dList_find_custom(services_list,dpi_id,(dCompareFunc)service_match) ); if (serv == NULL || (i = serv->dp_index) == -1) for (i = 0; i < numdpis; i++) diff --git a/dpid/dpid.h b/dpid/dpid.h index bd76946..b40ff9f 100644 --- a/dpid/dpid.h +++ b/dpid/dpid.h @@ -5,6 +5,11 @@ #ifndef DPID_H #define DPID_H +#ifdef __cplusplus +extern "C" +{ +#endif + #include #include /* for fd_set */ #include @@ -112,4 +117,8 @@ int service_match(const struct service *A, const char *B); void send_sockport(int sock_fd, char * dpi_tag, struct dp *dpi_attr_list); +#ifdef __cplusplus +} +#endif + #endif diff --git a/dpid/dpid_common.h b/dpid/dpid_common.h index 587c22d..cac9590 100644 --- a/dpid/dpid_common.h +++ b/dpid/dpid_common.h @@ -9,6 +9,11 @@ * the next patch */ +#ifdef __cplusplus +extern "C" +{ +#endif + #include #include /* size_t */ #include /* ssize_t */ @@ -51,4 +56,8 @@ void errmsg(char *caller, char *called, int errornum, char *file, int line); ssize_t ckd_write(int fd, char *msg, char *file, int line); ssize_t ckd_close(int fd, char *file, int line); +#ifdef __cplusplus +} +#endif + #endif diff --git a/dpid/dpidc.c b/dpid/dpidc.cc similarity index 100% rename from dpid/dpidc.c rename to dpid/dpidc.cc diff --git a/dpid/misc_new.h b/dpid/misc_new.h index c9ed85f..7ac0b30 100644 --- a/dpid/misc_new.h +++ b/dpid/misc_new.h @@ -1,10 +1,18 @@ #ifndef MISC_NEW_H #define MISC_NEW_H +#ifdef __cplusplus +extern "C" +{ +#endif + Dstr *a_Misc_rdtag(int socket); char *a_Misc_readtag(int sock); -char *a_Misc_mkdtemp(char *template); -char *a_Misc_mkfname(char *template); +char *a_Misc_mkdtemp(char *template_); +char *a_Misc_mkfname(char *template_); char *a_Misc_mksecret(int nchar); +#ifdef __cplusplus +} +#endif #endif diff --git a/src/IO/http.cc b/src/IO/http.cc index 14b5286..e1c88b3 100644 --- a/src/IO/http.cc +++ b/src/IO/http.cc @@ -360,9 +360,9 @@ static Dstr *Http_make_content_type(const DilloUrl *url) if (URL_FLAGS(url) & URL_MultipartEnc) { _MSG("submitting multipart/form-data!\n"); dstr = dStr_new("multipart/form-data; boundary=\""); - if (URL_DATA(url)->len > 2) { + if (URL_DATA(url).size() > 2) { /* boundary lines have "--" prepended. Skip that. */ - const char *start = URL_DATA(url)->str + 2; + const char *start = URL_DATA(url).c_str() + 2; const char *eol = strchr(start, '\r'); if (eol) dStr_append_l(dstr, start, eol - start); @@ -438,8 +438,8 @@ static Dstr *Http_make_query_str(DilloWeb *web, bool_t use_proxy, bool_t use_tls request_uri->str, URL_AUTHORITY(url), prefs.http_user_agent, accept_hdr_value, HTTP_Language_hdr, auth ? auth : "", proxy_auth->str, referer, connection_hdr_val, content_type->str, - (long)URL_DATA(url)->len, cookies); - dStr_append_l(query, URL_DATA(url)->str, URL_DATA(url)->len); + (long)URL_DATA(url).size(), cookies); + dStr_append_l(query, URL_DATA(url).c_str(), URL_DATA(url).size()); dStr_free(content_type, TRUE); } else { dStr_sprintfa( diff --git a/src/capi.cc b/src/capi.cc index 1b94d76..f26ad82 100644 --- a/src/capi.cc +++ b/src/capi.cc @@ -258,7 +258,7 @@ int a_Capi_dpi_verify_request(BrowserWindow *bw, DilloUrl *url) MSG("a_Capi_dpi_verify_request: Permission Denied!\n"); MSG(" URL_STR : %s\n", URL_STR(url)); if (URL_FLAGS(url) & URL_Post) { - MSG(" URL_DATA: %s\n", dStr_printable(URL_DATA(url), 1024)); + MSG(" URL_DATA: %s\n", dStr_printable_std(URL_DATA(url), 1024).c_str()); } } return allow; diff --git a/src/digest.cc b/src/digest.cc index a343fb4..f229939 100644 --- a/src/digest.cc +++ b/src/digest.cc @@ -15,11 +15,13 @@ #include "msg.hh" #include "../dlib/dlib.h" +#include + static const char *ALGORITHM2STR[] = { NULL, "MD5", "MD5-sess" }; static const char *QOP2STR[] = { NULL, "auth", "auth-int" }; static const char hexchars[] = "0123456789abcdef"; -static Dstr *md5hexdigest(const Dstr *data) +static Dstr *md5hexdigest(const std::string_view &data) { md5_state_t state; md5_byte_t digest[16]; @@ -27,7 +29,7 @@ static Dstr *md5hexdigest(const Dstr *data) int i; md5_init(&state); - md5_append(&state, (const md5_byte_t *)data->str, data->len); + md5_append(&state, (const md5_byte_t *)data.data(), data.size()); md5_finish(&state, digest); for (i = 0; i < 16; i++) @@ -68,7 +70,7 @@ int a_Digest_compute_digest(AuthRealm_t *realm, const char *username, */ Dstr *a0 = dStr_new(NULL); dStr_sprintf(a0, "%s:%s:%s", username, realm->name, passwd); - Dstr *ha0 = md5hexdigest(a0); + Dstr *ha0 = md5hexdigest(std::string_view{a0->str}); a1 = dStr_new(NULL); dStr_sprintf(a1, "%s:%s:%s", ha0, realm->nonce, realm->cnonce); dStr_free(a0, 1); @@ -78,7 +80,7 @@ int a_Digest_compute_digest(AuthRealm_t *realm, const char *username, return 0; } - digest = md5hexdigest(a1); + digest = md5hexdigest(a1->str); realm->authorization = digest->str; dStr_shred(a1); dStr_free(a1, 1); @@ -91,7 +93,7 @@ int a_Digest_compute_digest(AuthRealm_t *realm, const char *username, */ static Dstr *Digest_create_response(AuthRealm_t *realm, const char *method, const char *digest_uri, - const Dstr *entity_body) + const std::string &entity_body) { Dstr *ha2; Dstr *result; @@ -100,14 +102,14 @@ static Dstr *Digest_create_response(AuthRealm_t *realm, const char *method, /* A2 = Method ":" digest-uri-value */ Dstr *a2 = dStr_new(NULL); dStr_sprintf(a2, "%s:%s", method, digest_uri); - ha2 = md5hexdigest(a2); + ha2 = md5hexdigest(a2->str); dStr_free(a2, 1); } else if (realm->qop == AUTHINT) { /* A2 = Method ":" digest-uri-value ":" H(entity-body) */ Dstr *hentity = md5hexdigest(entity_body); Dstr *a2 = dStr_new(NULL); dStr_sprintf(a2, "%s:%s:%s", method, digest_uri, hentity->str); - ha2 = md5hexdigest(a2); + ha2 = md5hexdigest(a2->str); dStr_free(hentity, 1); dStr_free(a2, 1); } else { @@ -133,7 +135,7 @@ static Dstr *Digest_create_response(AuthRealm_t *realm, const char *method, ha2->str); } - Dstr *request_digest = md5hexdigest(result); + Dstr *request_digest = md5hexdigest(result->str); dStr_free(result, 1); dStr_free(ha2, 1); return request_digest; diff --git a/src/form.cc b/src/form.cc index 091364b..bf49168 100644 --- a/src/form.cc +++ b/src/form.cc @@ -29,6 +29,14 @@ #include #include +#include +#include + +#include + + +using namespace std::literals::string_literals; +using namespace std::literals::string_view_literals; using namespace lout; using namespace dw; @@ -84,19 +92,19 @@ class DilloHtmlForm { bool enabled; void eventHandler(Resource *resource, EventButton *event); DilloUrl *buildQueryUrl(DilloHtmlInput *active_input); - Dstr *buildQueryData(DilloHtmlInput *active_submit); + std::optional< std::string > buildQueryData(DilloHtmlInput *active_submit); char *makeMultipartBoundary(iconv_t char_encoder, DilloHtmlInput *active_submit); Dstr *encodeText(iconv_t char_encoder, Dstr **input); - void strUrlencodeAppend(Dstr *dstr, const char *str); - void inputUrlencodeAppend(Dstr *data, const char *name, const char *value); - void inputMultipartAppend(Dstr *data, const char *boundary, + void strUrlencodeAppend(std::string &dstr, const char *str); + void inputUrlencodeAppend(std::string &data, const char *name, const char *value); + void inputMultipartAppend(std::string &data, const char *boundary, const char *name, const char *value); - void filesInputMultipartAppend(Dstr* data, const char *boundary, + void filesInputMultipartAppend(std::string &data, const char *boundary, const char *name, Dstr *file, const char *filename); - void imageInputUrlencodeAppend(Dstr *data, Dstr *name, Dstr *x, Dstr *y); - void imageInputMultipartAppend(Dstr *data, const char *boundary, Dstr *name, + void imageInputUrlencodeAppend(std::string &data, Dstr *name, Dstr *x, Dstr *y); + void imageInputMultipartAppend(std::string &data, const char *boundary, Dstr *name, Dstr *x, Dstr *y); public: //BUG: for now everything is public @@ -1076,7 +1084,7 @@ DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *active_input) if ((method == DILLO_HTML_METHOD_GET) || (method == DILLO_HTML_METHOD_POST)) { - Dstr *DataStr; + std::string DataStr; DilloHtmlInput *active_submit = NULL; _MSG("DilloHtmlForm::buildQueryUrl: action=%s\n",URL_STR_(action)); @@ -1089,15 +1097,16 @@ DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *active_input) } } - DataStr = buildQueryData(active_submit); - if (DataStr) { + auto queryStr= buildQueryData(active_submit); + if (queryStr.has_value()) { + auto DataStr= queryStr.value(); /* action was previously resolved against base URL */ char *action_str = dStrdup(URL_STR(action)); if (method == DILLO_HTML_METHOD_POST) { new_url = a_Url_new(action_str, NULL); /* new_url keeps the dStr and sets DataStr to NULL */ - a_Url_set_data(new_url, &DataStr); + a_Url_set_data(new_url, DataStr); a_Url_set_flags(new_url, URL_FLAGS(new_url) | URL_Post); if (content_type == DILLO_HTML_ENC_MULTIPART) a_Url_set_flags(new_url, URL_FLAGS(new_url) | URL_MultipartEnc); @@ -1109,12 +1118,11 @@ DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *active_input) if ((p = strchr(action_str, '?'))) *p = 0; - url_str = dStrconcat(action_str, "?", DataStr->str, NULL); + url_str = dStrconcat(action_str, "?", DataStr.c_str(), NULL); new_url = a_Url_new(url_str, NULL); a_Url_set_flags(new_url, URL_FLAGS(new_url) | URL_Get); dFree(url_str); } - dStr_free(DataStr, 1); dFree(action_str); } } else { @@ -1127,10 +1135,10 @@ DilloUrl *DilloHtmlForm::buildQueryUrl(DilloHtmlInput *active_input) /** * Construct the data for a query URL */ -Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit) +std::optional< std::string > DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit) { - Dstr *DataStr = NULL; - char *boundary = NULL; + std::string DataStr; + char *boundary = nullptr; iconv_t char_encoder = (iconv_t) -1; if (submit_charset && dStrAsciiCasecmp(submit_charset, "UTF-8")) { @@ -1162,7 +1170,6 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit) if ((content_type == DILLO_HTML_ENC_URLENCODED) || (boundary != NULL)) { Dlist *values = dList_new(5); - DataStr = dStr_sized_new(4096); for (int i = 0; i < inputs.size(); i++) { auto input = inputs.at (i); Dstr *name = dStr_new(input->name); @@ -1230,12 +1237,12 @@ Dstr *DilloHtmlForm::buildQueryData(DilloHtmlInput *active_submit) } dStr_free(name, 1); } - if (DataStr->len > 0) { + if( not DataStr.empty() ) { if (content_type == DILLO_HTML_ENC_URLENCODED) { - if (DataStr->str[DataStr->len - 1] == '&') - dStr_truncate(DataStr, DataStr->len - 1); + if (DataStr.at( DataStr.size() - 1 ) == '&') + DataStr.pop_back(); } else if (content_type == DILLO_HTML_ENC_MULTIPART) { - dStr_append(DataStr, "--"); + DataStr+= "--"; } } dList_free(values); @@ -1393,24 +1400,27 @@ Dstr *DilloHtmlForm::encodeText(iconv_t char_encoder, Dstr **input) /** * Urlencode 'str' and append it to 'dstr' */ -void DilloHtmlForm::strUrlencodeAppend(Dstr *dstr, const char *str) +void DilloHtmlForm::strUrlencodeAppend(std::string &dstr, const char *str) { - char *encoded = a_Url_encode_hex_str(str); - dStr_append(dstr, encoded); - dFree(encoded); + auto encoded= Alepha::AutoRAII + { + [&]{ return a_Url_encode_hex_str(str); }, + dFree + }; + dstr+= encoded; } /** * Append a name-value pair to url data using url encoding. */ -void DilloHtmlForm::inputUrlencodeAppend(Dstr *data, const char *name, +void DilloHtmlForm::inputUrlencodeAppend(std::string &data, const char *name, const char *value) { if (name && name[0]) { strUrlencodeAppend(data, name); - dStr_append_c(data, '='); + data+= '='; strUrlencodeAppend(data, value); - dStr_append_c(data, '&'); + data+= '&'; } } @@ -1418,7 +1428,7 @@ void DilloHtmlForm::inputUrlencodeAppend(Dstr *data, const char *name, * Append files to URL data using multipart encoding. * Currently only accepts one file. */ -void DilloHtmlForm::filesInputMultipartAppend(Dstr* data, +void DilloHtmlForm::filesInputMultipartAppend(std::string &data, const char *boundary, const char *name, Dstr *file, @@ -1435,14 +1445,13 @@ void DilloHtmlForm::filesInputMultipartAppend(Dstr* data, ctype = "text/html"; } - if (data->len == 0) { - dStr_append(data, "--"); - dStr_append(data, boundary); + if (data.empty()) { + data+= "--"; + data+= boundary; } - dStr_sprintfa(data, - "\r\n" - "Content-Disposition: form-data; name=\"%s\"; " - "filename=\"", name); + data+= "\r\n"s + + "Content-Disposition: form-data; name=\"" + name +"\"; " + + "filename=\""; /* * Replace the characters that are the most likely to damage things. * For a while, there was some momentum to standardize on an encoding, @@ -1452,63 +1461,60 @@ void DilloHtmlForm::filesInputMultipartAppend(Dstr* data, for (int i = 0; char c = filename[i]; i++) { if (c == '\"' || c == '\r' || c == '\n') c = '_'; - dStr_append_c(data, c); + data+= c; } - dStr_sprintfa(data, - "\"\r\n" - "Content-Type: %s\r\n" - "\r\n", ctype); + data+= "\"\r\n"s + + "Content-Type: " + ctype + "\r\n" + + "\r\n"; - dStr_append_l(data, file->str, file->len); + data+= std::string_view{ file->str, file->str + file->len }; - dStr_sprintfa(data, - "\r\n" - "--%s", boundary); + data+= "\r\n--"s + boundary; } } /** * Append a name-value pair to url data using multipart encoding. */ -void DilloHtmlForm::inputMultipartAppend(Dstr *data, +void DilloHtmlForm::inputMultipartAppend(std::string &data, const char *boundary, const char *name, const char *value) { if (name && name[0]) { - if (data->len == 0) { - dStr_append(data, "--"); - dStr_append(data, boundary); + if (data.empty()) { + data+= "--"; + data+= boundary; } - dStr_sprintfa(data, - "\r\n" - "Content-Disposition: form-data; name=\"%s\"\r\n" - "\r\n" - "%s\r\n" - "--%s", - name, value, boundary); + data+= + "\r\n"s + + "Content-Disposition: form-data; name=\"" + name + "\"\r\n" + + "\r\n" + + value + "\r\n" + + "--" + + boundary; } } /** * Append an image button click position to url data using url encoding. */ -void DilloHtmlForm::imageInputUrlencodeAppend(Dstr *data, Dstr *name, Dstr *x, +void DilloHtmlForm::imageInputUrlencodeAppend(std::string &data, Dstr *name, Dstr *x, Dstr *y) { if (name->len) { strUrlencodeAppend(data, name->str); - dStr_sprintfa(data, ".x=%s&", x->str); + data+= ".x="s + x->str + "&"; strUrlencodeAppend(data, name->str); - dStr_sprintfa(data, ".y=%s&", y->str); + data+= ".y="s + y->str + "&"; } else - dStr_sprintfa(data, "x=%s&y=%s&", x->str, y->str); + data+= "x="s + x->str + "&y=" + y->str + "&"; } /** * Append an image button click position to url data using multipart encoding. */ -void DilloHtmlForm::imageInputMultipartAppend(Dstr *data, const char *boundary, +void DilloHtmlForm::imageInputMultipartAppend(std::string &data, const char *boundary, Dstr *name, Dstr *x, Dstr *y) { int orig_len = name->len; diff --git a/src/url.cc b/src/url.cc index 0feede9..a169691 100644 --- a/src/url.cc +++ b/src/url.cc @@ -143,7 +143,7 @@ static DilloUrl *Url_object_new(const char *uri_str) dReturn_val_if_fail (uri_str != NULL, NULL); - url = dNew0(DilloUrl, 1); + url = new DilloUrl{}; /* url->buffer is given a little extra room in case HSTS needs to transform * a URL string ending in ":80" to ":443". @@ -214,7 +214,6 @@ DilloUrl::~DilloUrl() if (this->hostname != this->authority) dFree((char *)this->hostname); dFree((char *)this->buffer); - dStr_free(this->data, 1); } /** @@ -424,7 +423,7 @@ DilloUrl* a_Url_new(const char *url_str, const char *base_url) /* Fill url data */ url = Url_object_new(SolvedUrl->str); - url->data = dStr_new(""); + url->data = ""; url->url_string = SolvedUrl; url->illegal_chars = n_ic; url->illegal_chars_spc = n_ic_spc; @@ -488,8 +487,7 @@ DilloUrl* a_Url_dup(const DilloUrl *ori) url->ismap_url_len = ori->ismap_url_len; url->illegal_chars = ori->illegal_chars; url->illegal_chars_spc = ori->illegal_chars_spc; - url->data = dStr_sized_new(URL_DATA(ori)->len); - dStr_append_l(url->data, URL_DATA(ori)->str, URL_DATA(ori)->len); + url->data = ori->data; return url; } @@ -516,7 +514,7 @@ int a_Url_cmp(const DilloUrl *A, const DilloUrl *B) B->path ? B->path + (*B->path == '/') : "")) == 0 && //(st = URL_STR_FIELD_CMP(A->path, B->path)) == 0 && (st = URL_STR_FIELD_CMP(A->query, B->query)) == 0 && - (st = dStr_cmp(A->data, B->data)) == 0 && + (st = strcmp(A->data.c_str(), B->data.c_str())) == 0 && (st = URL_STR_FIELD_I_CMP(A->scheme, B->scheme)) == 0)) return 0; return st; @@ -534,13 +532,9 @@ void a_Url_set_flags(DilloUrl *u, int flags) /** * Set DilloUrl data (like POST info, etc.) */ -void a_Url_set_data(DilloUrl *u, Dstr **data) +void a_Url_set_data(DilloUrl *u, std::string_view data) { - if (u) { - dStr_free(u->data, 1); - u->data = *data; - *data = NULL; - } + u->data= data; } /** diff --git a/src/url.hh b/src/url.hh index 0ca1ff0..0233461 100644 --- a/src/url.hh +++ b/src/url.hh @@ -15,6 +15,11 @@ #include "d_size.h" #include "../dlib/dlib.h" +extern "C++" +{ +#include +} + #define URL_HTTP_PORT 80 #define URL_HTTPS_PORT 443 @@ -98,7 +103,7 @@ struct DilloUrl { const char *hostname; /**/ int port; int flags; - Dstr *data; /**< POST */ + std::string data; /**< POST */ int ismap_url_len; /**< Used by server side image maps */ int illegal_chars; /**< number of illegal chars */ int illegal_chars_spc; /**< number of illegal space chars */ @@ -114,7 +119,7 @@ const char *a_Url_hostname(const DilloUrl *u); DilloUrl* a_Url_dup(const DilloUrl *u); int a_Url_cmp(const DilloUrl *A, const DilloUrl *B); void a_Url_set_flags(DilloUrl *u, int flags); -void a_Url_set_data(DilloUrl *u, Dstr **data); +void a_Url_set_data(DilloUrl *u, std::string_view data); void a_Url_set_ismap_coords(DilloUrl *u, char *coord_str); char *a_Url_decode_hex_str(const char *str); char *a_Url_encode_hex_str(const char *str);