summary refs log tree commit diff stats
path: root/libchatprivacy/src/libchatprivacy.c
diff options
context:
space:
mode:
Diffstat (limited to 'libchatprivacy/src/libchatprivacy.c')
-rw-r--r--libchatprivacy/src/libchatprivacy.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/libchatprivacy/src/libchatprivacy.c b/libchatprivacy/src/libchatprivacy.c
new file mode 100644
index 0000000..e3cd59f
--- /dev/null
+++ b/libchatprivacy/src/libchatprivacy.c
@@ -0,0 +1,133 @@
+// LibChatPrivacy - C component of ChatPrivacy
+// Copyright (C) 2021  Soni L.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+
+/* libotr headers */
+#include <libotr/proto.h>
+#include <libotr/message.h>
+#include <libotr/privkey.h>
+
+#include "libchatprivacy.h"
+
+/* The protocol ID */
+static char const *const PROTOCOL = "minecraft";
+
+static OtrlUserState userstate = NULL;
+static int initialized = 0;
+static char *userat = NULL;
+
+static OtrlMessageAppOps msgappops = {0};
+
+#define LCP_CB_IMPL(name, nullable) \
+	static lcp_cb_##name *cb_##name = NULL; \
+	lcp_cb_##name *lcp_setup_cb_##name(lcp_cb_##name *const func) { \
+		nullable \
+		lcp_cb_##name *const oldfunc = cb_##name; \
+		cb_##name = func; \
+		return oldfunc; \
+	}
+
+#define LCP_CB_IMPL_OPT(name) LCP_CB_IMPL(name, )
+#define LCP_CB_IMPL_REQ(name) LCP_CB_IMPL(name, assert(func != NULL);)
+
+LCP_CB_IMPL_REQ(printmsg)
+LCP_CB_IMPL_REQ(sendmsg)
+LCP_CB_IMPL_REQ(dialogmsg)
+LCP_CB_IMPL_OPT(diagmsg)
+
+int lcp_init(char const *const uuid) {
+	if (!initialized) {
+		initialized = 1;
+		OTRL_INIT;
+	}
+
+	/* callback checks */
+	assert(cb_printmsg != NULL);
+	assert(cb_sendmsg != NULL);
+	assert(cb_dialogmsg != NULL);
+
+	/* library state checks */
+	if (userstate != NULL || userat != NULL) {
+		return 0;
+	}
+
+	/* arg checks */
+	if (uuid == NULL) {
+		return 0;
+	}
+
+	userstate = otrl_userstate_create();
+	assert(userstate != NULL);
+
+	/* read stuff */
+	otrl_privkey_read(userstate, "privkey");
+	otrl_instag_read(userstate, "instag");
+	otrl_privkey_read_fingerprints(userstate, "fingerprints", NULL, NULL);
+
+	/* copy uuid/userat */
+	size_t const uuidlen = strlen(uuid);
+	size_t const bufsize = uuidlen + 1;
+	char *const userat_buf = calloc(bufsize, 1);
+	if (userat_buf == NULL) {
+		return 0;
+	}
+	memcpy(userat_buf, uuid, uuidlen);
+	userat = userat_buf;
+
+	if (cb_diagmsg != NULL) {
+		cb_diagmsg(LCP_DIAG_INFO, "lcp initialized");
+	}
+
+	return 1;
+}
+
+int lcp_deinit(void) {
+	assert(userstate != NULL);
+	assert(userat != NULL);
+	otrl_userstate_free(userstate);
+	userstate = NULL;
+	free((void *)userat);
+	userat = NULL;
+	return 1;
+}
+
+void lcp_user_join(char const *const uuid, char const *const name) {
+	assert(0);
+}
+
+void lcp_user_part(char const *const uuid, char const *const name) {
+	assert(0);
+}
+
+void lcp_send(char const *const name, char const *const message) {
+	assert(0);
+}
+
+void lcp_recv(char const *const uuid, char const *const message) {
+	assert(0);
+}
+
+void lcp_cmd(char const *const cmd) {
+	assert(0);
+}
+
+void lcp_tick(void) {
+	assert(0);
+}