weechat-xmpp/util.cpp

51 lines
1.2 KiB
C++
Raw Normal View History

2021-07-13 03:03:34 +00:00
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
2021-07-25 08:15:12 +00:00
#include <stdio.h>
2021-07-13 03:03:34 +00:00
#include <stdlib.h>
2022-01-11 23:12:31 +00:00
#include <string.h>
2021-07-25 08:15:12 +00:00
#include <strophe.h>
2021-07-13 03:03:34 +00:00
#include <weechat/weechat-plugin.h>
2022-01-11 18:39:37 +00:00
#include "plugin.hh"
2022-01-11 23:12:31 +00:00
#include "util.hh"
2021-07-13 03:03:34 +00:00
int char_cmp(const void *p1, const void *p2)
{
return *(const char *)p1 == *(const char *)p2;
}
2021-07-25 08:15:12 +00:00
char *exec(const char *command)
{
// use hook_process instead!
2022-01-11 23:12:31 +00:00
char buffer[128];
char **result = weechat_string_dyn_alloc(256);
// Open pipe to file
FILE* pipe = popen(command, "r");
if (!pipe) {
return (char*)strdup("popen failed!");
}
// read till end of process:
while (!feof(pipe)) {
// use buffer to read and add to result
if (fgets(buffer, 128, pipe) != NULL)
weechat_string_dyn_concat(result, buffer, -1);
}
pclose(pipe);
weechat_string_dyn_free(result, 0);
return *result;
2021-07-25 08:15:12 +00:00
}
char *stanza_xml(xmpp_stanza_t *stanza)
{
char *result;
size_t len;
xmpp_stanza_to_text(stanza, &result, &len);
return result;
}