diff --git a/.gitignore b/.gitignore
index a8dbf81..42fa14c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,5 +7,7 @@ data
testout
audio
video
-result*.json
-dissection_result*.txt
+doc/syncres/*
+lib*.so
+lib*.a
+matrix-send
diff --git a/include/raii/rjp_iterator.hpp b/include/raii/rjp_iterator.hpp
index 152fde5..ed49eb9 100644
--- a/include/raii/rjp_iterator.hpp
+++ b/include/raii/rjp_iterator.hpp
@@ -1,3 +1,21 @@
+/**
+ This file is a part of r0nk, atlas_moon, and rexy's matrix client
+ Copyright (C) 2019 rexy712
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
#ifndef RJP_ITERATOR_HPP
#define RJP_ITERATOR_HPP
@@ -25,10 +43,7 @@ namespace raii{
constexpr bool operator!=(const rjp_object_iterator& e)const{
return m_value != e.m_value;
}
- rjp_object_iterator& operator++(void){
- m_value = rjp_next_member(m_value);
- return *this;
- }
+ rjp_object_iterator& operator++(void);
constexpr RJP_value* operator*(void){
return m_value;
}
@@ -62,10 +77,7 @@ namespace raii{
constexpr bool operator!=(const rjp_array_iterator& e)const{
return m_value != e.m_value;
}
- rjp_array_iterator& operator++(void){
- m_value = rjp_next_element(m_value);
- return *this;
- }
+ rjp_array_iterator& operator++(void);
constexpr RJP_value* operator*(void){
return m_value;
}
diff --git a/include/raii/rjp_ptr.hpp b/include/raii/rjp_ptr.hpp
index e40e247..ab34698 100644
--- a/include/raii/rjp_ptr.hpp
+++ b/include/raii/rjp_ptr.hpp
@@ -29,8 +29,10 @@ namespace raii{
{
template
void operator()(T* ptr){
- rjp_free_value(ptr);
+ internal_free_value(ptr);
}
+ private:
+ void internal_free_value(RJP_value*);
};
}
diff --git a/include/raii/rjp_string.hpp b/include/raii/rjp_string.hpp
index eddecce..7d71af6 100644
--- a/include/raii/rjp_string.hpp
+++ b/include/raii/rjp_string.hpp
@@ -31,18 +31,9 @@ namespace raii{
class rjp_allocator
{
public:
- static void free(void* data){
- rjp_free(data);
- }
- static void* allocate(size_t size){
- return rjp_alloc(size);
- }
- static void* copy(const void* data, size_t len){
- char* tmp = reinterpret_cast(allocate(len));
- memcpy(tmp, data, len-1);
- tmp[len-1] = 0;
- return tmp;
- }
+ static void free(void* data);
+ static void* allocate(size_t size);
+ static void* copy(const void* data, size_t len);
};
}
@@ -69,7 +60,6 @@ namespace raii{
}
};
rjp_string rjp_string_from_key(RJP_value* val);
-
}
#endif
diff --git a/makefile b/makefile
index 65b182d..7addc03 100644
--- a/makefile
+++ b/makefile
@@ -14,20 +14,36 @@
#Copyright 2018-2019 rexy712
-SOURCE_DIRS:=src src/raii src/matrix
+ifeq ($(OS),Windows_NT)
+ WINDOWS=1
+endif
+
+SOURCE_DIRS:=src/raii src/matrix
OBJDIR:=obj
DEPDIR:=$(OBJDIR)/dep
INCLUDE_DIRS:=include
EXT:=cpp
-MAIN_EXECUTABLE:=tester
+MAIN_LIBRARY:=librmatrix.so
-CXX:=g++
-CXXFLAGS:=-g -std=c++17 -Wall -pedantic -Wextra
+CXXFLAGS:=-g -std=c++17 -Wall -pedantic -Wextra -fPIC
+
+ifneq ($(WINDOWS),1)
+ CXX:=g++
+ AR:=ar
+ RANLIB:=ranlib
+ LDFLAGS:=-shared
+ LDLIBS:=-lcurl -lrjp -lavformat -lavcodec -lavutil -lswresample -lswscale -lfreeimageplus
+ STRIP:=strip
+else
+ CXX:=x86_64-w64-mingw32-g++
+ AR:=x86_64-w64-mingw32-ar
+ RANLIB:=x86_64-w64-mingw32-ranlib
+ LDFLAGS:=
+ LDLIBS:=-lcurl -lrjp -lavformat -lavcodec -lavutil -lswresample -lswscale -lfreeimageplus
+ STRIP:=x86_64-w64-mingw32-strip
+endif
all: CXXFLAGS+=-O0
release: CXXFLAGS+=-O2
-LDFLAGS=
-LDLIBS:=-lcurl -lrjp -lavformat -lavcodec -lavutil -lswresample -lswscale -lfreeimageplus -lpthread
-STRIP:=strip
memchk:LDFLAGS+=-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
memchk:CXXFLAGS+=-O0 -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
@@ -50,16 +66,21 @@ INTERNAL_CXXFLAGS=-c $(foreach dir,$(INCLUDE_DIRS),-I"$(dir)") -MMD -MP -MF"$(DE
SOURCES:=$(foreach source,$(SOURCE_DIRS),$(foreach ext,$(EXT),$(wildcard $(source)/*.$(ext))))
OBJECTS:=$(addprefix $(OBJDIR)/,$(subst \,.,$(subst /,.,$(addsuffix .o,$(SOURCES)))))
-all: $(MAIN_EXECUTABLE)
-memchk: $(MAIN_EXECUTABLE)
-
-$(MAIN_EXECUTABLE): $(OBJECTS)
- $(CXX) $(LDFLAGS) $^ -o "$(basename $@)" $(LDLIBS)
-
+all: $(MAIN_LIBRARY)
+.PHONY: memchk
+memchk: all
.PHONY: release
-release: $(OBJECTS)
- $(CXX) $(LDFLAGS) $^ -o "$(basename $(MAIN_EXECUTABLE))" $(LDLIBS)
- $(STRIP) --strip-all "$(MAIN_EXECUTABLE)"
+release: all
+.PHONY: utils
+utils: matrix-send
+tester: $(MAIN_LIBRARY) $(OBJDIR)/src.test.cpp.o
+ $(CXX) -L. -o "$@" $(OBJDIR)/src.test.cpp.o -lrmatrix -lpthread
+
+matrix-send: $(MAIN_LIBRARY) $(OBJDIR)/util.matrix-send.cpp.o
+ $(CXX) -L. -o "$@" $(OBJDIR)/util.matrix-send.cpp.o -lrmatrix
+
+$(MAIN_LIBRARY): $(OBJECTS)
+ $(CXX) -o "$@" $^ $(CXXFLAGS) $(LDFLAGS) $(LDLIBS)
define GENERATE_OBJECTS
@@ -69,6 +90,8 @@ $$(OBJDIR)/$(subst \,.,$(subst /,.,$(1))).%.o: $(1)/%
endef
$(foreach dir,$(SOURCE_DIRS),$(eval $(call GENERATE_OBJECTS,$(dir))))
+$(eval $(call GENERATE_OBJECTS,util))
+$(eval $(call GENERATE_OBJECTS,src))
$(OBJECTS): | $(OBJDIR) $(DEPDIR)
$(OBJDIR):
@@ -80,7 +103,11 @@ $(DEPDIR):
clean:
$(call rmdir,"$(DEPDIR)")
$(call rmdir,"$(OBJDIR)")
- $(call rm,"$(MAIN_EXECUTABLE)")
+ $(call rm,"$(MAIN_LIBRARY)")
+.PHONY: utilsclean
+fullclean: clean
+ $(call rm,"matrix-send")
+ $(call rm,"tester")
-include $(wildcard $(DEPDIR)/*.d)
diff --git a/src/raii/rjp_iterator.cpp b/src/raii/rjp_iterator.cpp
new file mode 100644
index 0000000..858dfff
--- /dev/null
+++ b/src/raii/rjp_iterator.cpp
@@ -0,0 +1,32 @@
+/**
+ This file is a part of r0nk, atlas_moon, and rexy's matrix client
+ Copyright (C) 2019 rexy712
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+#include "raii/rjp_iterator.hpp"
+
+namespace raii{
+
+ rjp_object_iterator& rjp_object_iterator::operator++(void){
+ m_value = rjp_next_member(m_value);
+ return *this;
+ }
+ rjp_array_iterator& rjp_array_iterator::operator++(void){
+ m_value = rjp_next_element(m_value);
+ return *this;
+ }
+
+}
diff --git a/src/raii/rjp_ptr.cpp b/src/raii/rjp_ptr.cpp
new file mode 100644
index 0000000..3529d86
--- /dev/null
+++ b/src/raii/rjp_ptr.cpp
@@ -0,0 +1,25 @@
+/**
+ This file is a part of r0nk, atlas_moon, and rexy's matrix client
+ Copyright (C) 2019 rexy712
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+#include "raii/rjp_ptr.hpp"
+
+namespace raii::detail{
+ void rjp_tree_deleter::internal_free_value(RJP_value* v){
+ rjp_free_value(v);
+ }
+}
diff --git a/src/raii/rjp_string.cpp b/src/raii/rjp_string.cpp
index 6944435..27e3b63 100644
--- a/src/raii/rjp_string.cpp
+++ b/src/raii/rjp_string.cpp
@@ -19,6 +19,20 @@
#include "raii/rjp_string.hpp"
namespace raii{
+ namespace detail{
+ void rjp_allocator::free(void* data){
+ rjp_free(data);
+ }
+ void* rjp_allocator::allocate(size_t size){
+ return rjp_alloc(size);
+ }
+ void* rjp_allocator::copy(const void* data, size_t len){
+ char* tmp = reinterpret_cast(allocate(len));
+ memcpy(tmp, data, len-1);
+ tmp[len-1] = 0;
+ return tmp;
+ }
+ }
rjp_string rjp_string_from_key(RJP_value* val){
char* key = rjp_member_name(val);
size_t len = rjp_member_name_length(val);
diff --git a/util/matrix-send.cpp b/util/matrix-send.cpp
new file mode 100644
index 0000000..bb3c954
--- /dev/null
+++ b/util/matrix-send.cpp
@@ -0,0 +1,50 @@
+/**
+ This file is a part of r0nk, atlas_moon, and rexy's matrix client
+ Copyright (C) 2019 rexy712
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+
+#include "matrix/matrix.hpp"
+#include "raii/static_string.hpp"
+
+#include //exit
+
+[[noreturn]] void usage(int status){
+ printf("Usage: matrix-send STRING\n");
+ printf("\tSends message to designated room as the designated user\n");
+ exit(status);
+}
+
+int main(int argc, char** argv){
+ const char* username = "username";
+ const char* password = "password";
+ const char* useragent = "rexy712s test bot";
+ const char* homeserver = "matrix.org";
+ const char* roomid = "!roomid:matrix.org";
+ matrix::auth_data auth{username, password, homeserver, useragent};
+
+ if(argc < 2)
+ usage(1);
+
+ matrix::session ses(auth);
+ if(!ses.valid()){
+ fprintf(stderr, "Failed to init matrix session!\n");
+ return 1;
+ }
+
+ auto client = ses.spawn_client();
+ auto room = client.spawn_room(raii::static_string(roomid));
+ room.send_message(raii::static_string(argv[1]));
+}