[sr-dev] [kamailio/kamailio] slack: new module, send message to slack channel (#2838)

Henning Westerholt notifications at github.com
Tue Aug 31 09:16:01 CEST 2021


@henningw commented on this pull request.



> + */
+static int _curl_send(const char* uri, str *post_data)
+{
+	int datasz;
+	char* send_data;
+	CURL *curl_handle;
+	CURLcode res;
+	// LM_DBG("sending to[%s]\n", uri);
+
+	datasz = snprintf(NULL, 0, BODY_FMT, slack_channel, slack_username, post_data->s, slack_icon);
+	send_data = (char*)pkg_malloc((datasz+1)*sizeof(char));
+	if(send_data==NULL) {
+        LM_ERR("Error: can not allocate pkg memory [%d] bytes\n", datasz);
+        return -1;
+    }
+    snprintf(send_data, datasz+1, BODY_FMT, slack_channel, slack_username, post_data->s, slack_icon);

This of course depends on the working of snprintf, the docs unfortunately do not give much more details. But generally it is good "defensive" programming practice to check for errors on outside library calls that you do not control/own.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/pull/2838#discussion_r699048847
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20210831/45ea9b77/attachment-0001.htm>


More information about the sr-dev mailing list