aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-05-24 19:01:14 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2022-06-14 03:07:25 +0200
commitd0e711e5b090d01efa35a151ad9dfdf0a2911067 (patch)
treeeb4bd9c1f2e4069e150dc7d5b5f55630427d74b5 /tools
parent397cb23c6cd7e0cf941fd8292dc97c7b612756fd (diff)
downloadhardware_replicant_libsamsung-ipc-d0e711e5b090d01efa35a151ad9dfdf0a2911067.tar.gz
hardware_replicant_libsamsung-ipc-d0e711e5b090d01efa35a151ad9dfdf0a2911067.tar.bz2
hardware_replicant_libsamsung-ipc-d0e711e5b090d01efa35a151ad9dfdf0a2911067.zip
tools: https-send-sms: don't depend on CURLU_ALLOW_SPACE
CURLU_ALLOW_SPACE is available since curl 7.78.0, and not using it could enable us to be compatible with curl 7.62.0. Since Replicant 11 has curl 7.67.0, this should enable to run https-send-sms on Replicant 11. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/https-send-sms.c56
1 files changed, 35 insertions, 21 deletions
diff --git a/tools/https-send-sms.c b/tools/https-send-sms.c
index 75442dc..1cb4e03 100644
--- a/tools/https-send-sms.c
+++ b/tools/https-send-sms.c
@@ -24,12 +24,17 @@
#include <curl/curl.h>
-int send_https(char *url, __attribute__((unused)) char *post_data)
+/* CURL documentation for curl_easy_escape[1] mentions that "This
+ * function does not accept input strings longer than
+ * CURL_MAX_INPUT_LENGTH (8 MB)." but CURL_MAX_INPUT_LENGTH is not
+ * exported in the curl public headers (in /usr/include/curl).
+ */
+#define CURL_MAX_INPUT_LENGTH 8000000
+
+int send_https(CURL *hnd, char *url, __attribute__((unused)) char *post_data)
{
CURLcode ret;
- CURL *hnd;
- hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
curl_easy_setopt(hnd, CURLOPT_URL, url);
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
@@ -41,9 +46,6 @@ int send_https(char *url, __attribute__((unused)) char *post_data)
ret = curl_easy_perform(hnd);
- curl_easy_cleanup(hnd);
- hnd = NULL;
-
/*
* TODO: HTTP(s) return codes:
* 200: SMS sent
@@ -58,13 +60,19 @@ int send_https(char *url, __attribute__((unused)) char *post_data)
return (int)ret;
}
-int create_parameter(char **out, const char *parameter, const char *value)
+int create_parameter(CURL *hnd,
+ char **out, const char *parameter, const char *value)
{
char *result = NULL;
+ char *encoded_value;
size_t size = 0;
size_t rc;
- rc = snprintf(result, size, "%s=%s", parameter, value);
+ assert(strlen(value) < CURL_MAX_INPUT_LENGTH);
+ encoded_value = curl_easy_escape(hnd, value, 0);
+ assert(encoded_value != NULL);
+
+ rc = snprintf(result, size, "%s=%s", parameter, encoded_value);
assert(rc > 0);
size = rc;
@@ -76,52 +84,58 @@ int create_parameter(char **out, const char *parameter, const char *value)
return rc;
}
- rc = snprintf(result, size + 1, "%s=%s", parameter, value);
+ rc = snprintf(result, size + 1, "%s=%s", parameter, encoded_value);
assert(rc == size);
+ assert(rc < CURL_MAX_INPUT_LENGTH);
+
*out = result;
+ curl_free(encoded_value);
+
return 0;
}
int send_sms_get(const char *username, const char *password,
const char *message)
{
- int rc;
+ CURL *hnd;
char *parameter = NULL;
- CURLU *url = curl_url();
+ int rc;
+ CURLU *url;
char *url_string;
+ url = curl_url();
+ hnd = curl_easy_init();
+
rc = curl_url_set(url, CURLUPART_URL,
"https://smsapi.free-mobile.fr/sendmsg", 0);
assert(rc == 0);
- rc = create_parameter(&parameter, "user", username);
+ rc = create_parameter(hnd, &parameter, "user", username);
assert(rc == 0);
- rc = curl_url_set(url, CURLUPART_QUERY, parameter,
- CURLU_URLENCODE|CURLU_APPENDQUERY);
+ rc = curl_url_set(url, CURLUPART_QUERY, parameter, CURLU_APPENDQUERY);
assert(rc == 0);
free(parameter);
- rc = create_parameter(&parameter, "pass", password);
- rc = curl_url_set(url, CURLUPART_QUERY, parameter,
- CURLU_URLENCODE|CURLU_APPENDQUERY);
+ rc = create_parameter(hnd, &parameter, "pass", password);
+ rc = curl_url_set(url, CURLUPART_QUERY, parameter, CURLU_APPENDQUERY);
assert(rc == 0);
free(parameter);
- rc = create_parameter(&parameter, "msg", message);
- rc = curl_url_set(url, CURLUPART_QUERY, parameter,
- CURLU_URLENCODE|CURLU_APPENDQUERY|CURLU_ALLOW_SPACE);
+ rc = create_parameter(hnd, &parameter, "msg", message);
+ rc = curl_url_set(url, CURLUPART_QUERY, parameter, CURLU_APPENDQUERY);
assert(rc == 0);
free(parameter);
rc = curl_url_get(url, CURLUPART_URL, &url_string, 0);
assert(rc == 0);
- rc = send_https(url_string, NULL);
+ rc = send_https(hnd, url_string, NULL);
assert(rc == CURLE_OK);
+ curl_easy_cleanup(hnd);
curl_url_cleanup(url);
return 0;