omemo/pgp/util.c -> cpp

master
Tony Olagbaiye 3 years ago
parent 7fd3f4ac58
commit f2e711a54a
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -18,7 +18,7 @@ PACKAGES=(
make # Deps with makefiles make # Deps with makefiles
cmake # Deps with cmake cmake # Deps with cmake
doctest # Testing doctest # Testing
gcc-toolchain@10 # Compilation gcc-toolchain@11 # Compilation
pkg-config # Deps configuration and configuration of deps deps pkg-config # Deps configuration and configuration of deps deps
patchelf # Fix linkage (guix) patchelf # Fix linkage (guix)
bear # Generate compile_commands.json for language servers bear # Generate compile_commands.json for language servers

@ -15,7 +15,7 @@
#include "xmpp/stanza.hh" #include "xmpp/stanza.hh"
#include "config.hh" #include "config.hh"
#include "input.h" #include "input.h"
#include "omemo.h" #include "omemo.hh"
#include "account.hh" #include "account.hh"
#include "connection.h" #include "connection.h"
#include "user.hh" #include "user.hh"

@ -12,13 +12,13 @@
#include "plugin.hh" #include "plugin.hh"
#include "account.hh" #include "account.hh"
#include "omemo.h" #include "omemo.hh"
#include "user.hh" #include "user.hh"
#include "channel.hh" #include "channel.hh"
#include "input.h" #include "input.h"
#include "buffer.h" #include "buffer.h"
#include "pgp.h" #include "pgp.hh"
#include "util.h" #include "util.hh"
const char *channel__transport_name(enum t_channel_transport transport) const char *channel__transport_name(enum t_channel_transport transport)
{ {

@ -18,9 +18,9 @@
#include "user.hh" #include "user.hh"
#include "channel.hh" #include "channel.hh"
#include "connection.h" #include "connection.h"
#include "omemo.h" #include "omemo.hh"
#include "pgp.h" #include "pgp.hh"
#include "util.h" #include "util.hh"
#include "diff/diff.h" #include "diff/diff.h"
void connection__init() void connection__init()

@ -20,7 +20,7 @@ CFLAGS+=$(DBGCFLAGS) \
$(INCLUDES) $(INCLUDES)
CPPFLAGS+=$(DBGCFLAGS) \ CPPFLAGS+=$(DBGCFLAGS) \
-fno-omit-frame-pointer -fPIC \ -fno-omit-frame-pointer -fPIC \
-std=c++17 -gdwarf-4 \ -std=c++20 -gdwarf-4 \
-Wall -Wextra -pedantic \ -Wall -Wextra -pedantic \
-Wno-missing-field-initializers \ -Wno-missing-field-initializers \
$(INCLUDES) $(INCLUDES)
@ -49,10 +49,10 @@ HDRS=plugin.hh \
connection.h \ connection.h \
input.h \ input.h \
message.h \ message.h \
omemo.h \ omemo.hh \
pgp.h \ pgp.hh \
user.hh \ user.hh \
util.h \ util.hh \
xmpp/stanza.hh \ xmpp/stanza.hh \
SRCS=plugin.cpp \ SRCS=plugin.cpp \
@ -65,10 +65,10 @@ SRCS=plugin.cpp \
connection.c \ connection.c \
input.c \ input.c \
message.c \ message.c \
omemo.c \ omemo.cpp \
pgp.c \ pgp.cpp \
user.cpp \ user.cpp \
util.c \ util.cpp \
xmpp/presence.cpp \ xmpp/presence.cpp \
xmpp/iq.cpp \ xmpp/iq.cpp \

File diff suppressed because it is too large Load Diff

@ -10,7 +10,7 @@
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "plugin.hh" #include "plugin.hh"
#include "pgp.h" #include "pgp.hh"
#define RNP_SUCCESS 0 #define RNP_SUCCESS 0
@ -26,7 +26,7 @@ void pgp__init(struct t_pgp **pgp, const char *pub, const char *sec)
struct t_pgp *new_pgp; struct t_pgp *new_pgp;
rnp_input_t keyring; rnp_input_t keyring;
new_pgp = calloc(1, sizeof(**pgp)); new_pgp = (struct t_pgp*)calloc(1, sizeof(**pgp));
if (rnp_ffi_create(&new_pgp->context, if (rnp_ffi_create(&new_pgp->context,
RNP_KEYSTORE_GPG, RNP_KEYSTORE_GPG) != RNP_SUCCESS) { RNP_KEYSTORE_GPG, RNP_KEYSTORE_GPG) != RNP_SUCCESS) {
@ -164,7 +164,7 @@ char *pgp__decrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *c
rnp_result_t ret; rnp_result_t ret;
buf_len = strlen(PGP_MESSAGE_HEADER) + strlen(ciphertext) + strlen(PGP_MESSAGE_FOOTER) + 1; buf_len = strlen(PGP_MESSAGE_HEADER) + strlen(ciphertext) + strlen(PGP_MESSAGE_FOOTER) + 1;
buf = malloc(sizeof(char) * buf_len); buf = (uint8_t*)malloc(sizeof(char) * buf_len);
buf_len = snprintf((char *)buf, buf_len, PGP_MESSAGE_HEADER "%s" PGP_MESSAGE_FOOTER, ciphertext); buf_len = snprintf((char *)buf, buf_len, PGP_MESSAGE_HEADER "%s" PGP_MESSAGE_FOOTER, ciphertext);
/* create file input and memory output objects for the encrypted message and decrypted /* create file input and memory output objects for the encrypted message and decrypted
@ -213,7 +213,7 @@ char *pgp__verify(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *ce
rnp_result_t ret; rnp_result_t ret;
buf_len = strlen(PGP_SIGNATURE_HEADER) + strlen(certificate) + strlen(PGP_SIGNATURE_FOOTER) + 1; buf_len = strlen(PGP_SIGNATURE_HEADER) + strlen(certificate) + strlen(PGP_SIGNATURE_FOOTER) + 1;
buf = malloc(sizeof(char) * buf_len); buf = (uint8_t*)malloc(sizeof(char) * buf_len);
buf_len = snprintf((char *)buf, buf_len, PGP_SIGNATURE_HEADER "%s" PGP_SIGNATURE_FOOTER, certificate); buf_len = snprintf((char *)buf, buf_len, PGP_SIGNATURE_HEADER "%s" PGP_SIGNATURE_FOOTER, certificate);
/* create file input memory objects for the signed message and verified message */ /* create file input memory objects for the signed message and verified message */

Binary file not shown.

@ -4,11 +4,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <strophe.h> #include <strophe.h>
#include <weechat/weechat-plugin.h> #include <weechat/weechat-plugin.h>
#include "plugin.hh" #include "plugin.hh"
#include "util.h" #include "util.hh"
int char_cmp(const void *p1, const void *p2) int char_cmp(const void *p1, const void *p2)
{ {
@ -18,26 +19,26 @@ int char_cmp(const void *p1, const void *p2)
char *exec(const char *command) char *exec(const char *command)
{ {
// use hook_process instead! // use hook_process instead!
char buffer[128]; char buffer[128];
char **result = weechat_string_dyn_alloc(256); char **result = weechat_string_dyn_alloc(256);
// Open pipe to file // Open pipe to file
FILE* pipe = popen(command, "r"); FILE* pipe = popen(command, "r");
if (!pipe) { if (!pipe) {
return "popen failed!"; return (char*)strdup("popen failed!");
} }
// read till end of process: // read till end of process:
while (!feof(pipe)) { while (!feof(pipe)) {
// use buffer to read and add to result // use buffer to read and add to result
if (fgets(buffer, 128, pipe) != NULL) if (fgets(buffer, 128, pipe) != NULL)
weechat_string_dyn_concat(result, buffer, -1); weechat_string_dyn_concat(result, buffer, -1);
} }
pclose(pipe); pclose(pipe);
weechat_string_dyn_free(result, 0); weechat_string_dyn_free(result, 0);
return *result; return *result;
} }
char *stanza_xml(xmpp_stanza_t *stanza) char *stanza_xml(xmpp_stanza_t *stanza)

@ -2,13 +2,10 @@
// License, version 2.0. If a copy of the MPL was not distributed with this // 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/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef _WEECHAT_XMPP_UTIL_H_ #pragma once
#define _WEECHAT_XMPP_UTIL_H_
int char_cmp(const void *p1, const void *p2); int char_cmp(const void *p1, const void *p2);
char *exec(const char *command); char *exec(const char *command);
char *stanza_xml(struct _xmpp_stanza_t *stanza); char *stanza_xml(struct _xmpp_stanza_t *stanza);
#endif /*WEECHAT_XMPP_UTIL_H*/
Loading…
Cancel
Save