Updated matrix-send utility to also use strings, binaries, and filerds from separate library
This commit is contained in:
parent
41b976bd6a
commit
52d9818f6d
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "matrix/matrix.hpp"
|
#include "matrix/matrix.hpp"
|
||||||
#include "raii/string_base.hpp"
|
#include <rexy/string_base.hpp>
|
||||||
|
|
||||||
#include <cstdlib> //exit
|
#include <cstdlib> //exit
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -26,7 +26,8 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "raii/rjp_ptr.hpp"
|
#include "raii/rjp_ptr.hpp"
|
||||||
#include "raii/string.hpp"
|
#include <rexy/string.hpp>
|
||||||
|
#include <rexy/filerd.hpp>
|
||||||
|
|
||||||
void check_netreturn_errors(const matrix::netreturn<raii::rjp_string>& n){
|
void check_netreturn_errors(const matrix::netreturn<raii::rjp_string>& n){
|
||||||
if(n.has_httperror()){
|
if(n.has_httperror()){
|
||||||
@ -45,12 +46,12 @@ void do_stdin(const matrix::roomcxn& room){
|
|||||||
data.push_back(in);
|
data.push_back(in);
|
||||||
}
|
}
|
||||||
data.push_back(0);
|
data.push_back(0);
|
||||||
auto reply = room.send_message(raii::static_string(data.data()));
|
auto reply = room.send_message(rexy::static_string(data.data()));
|
||||||
check_netreturn_errors(reply);
|
check_netreturn_errors(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
matrix::auth_data read_auth_file(const char* filename){
|
matrix::auth_data read_auth_file(const char* filename){
|
||||||
raii::filerd fp(filename, "r");
|
rexy::filerd fp(filename, "r");
|
||||||
if(!fp){
|
if(!fp){
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@ -74,11 +75,11 @@ int main(int argc, char** argv){
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char* roomid = argv[1];
|
const char* roomid = argv[1];
|
||||||
raii::string conf = "/etc/matrix-send.conf";
|
rexy::string conf = "/etc/matrix-send.conf";
|
||||||
const char* home = getenv("HOME");
|
const char* home = getenv("HOME");
|
||||||
|
|
||||||
if(home){
|
if(home){
|
||||||
raii::string home_conf = home + "/.config/matrix-send.conf"_ss;
|
rexy::string home_conf = home + "/.config/matrix-send.conf"_ss;
|
||||||
if(access(home_conf.get(), F_OK) != -1){
|
if(access(home_conf.get(), F_OK) != -1){
|
||||||
conf = std::move(home_conf);
|
conf = std::move(home_conf);
|
||||||
}
|
}
|
||||||
@ -92,7 +93,7 @@ int main(int argc, char** argv){
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto client = ses.spawn_client();
|
auto client = ses.spawn_client();
|
||||||
auto room = client.spawn_room(raii::static_string(roomid));
|
auto room = client.spawn_room(rexy::static_string(roomid));
|
||||||
|
|
||||||
if(argc < 3){
|
if(argc < 3){
|
||||||
do_stdin(room);
|
do_stdin(room);
|
||||||
@ -101,7 +102,7 @@ int main(int argc, char** argv){
|
|||||||
if(!strcmp(argv[i], "-")){
|
if(!strcmp(argv[i], "-")){
|
||||||
do_stdin(room);
|
do_stdin(room);
|
||||||
}else{
|
}else{
|
||||||
auto reply = room.send_message(raii::static_string(argv[i]));
|
auto reply = room.send_message(rexy::static_string(argv[i]));
|
||||||
check_netreturn_errors(reply);
|
check_netreturn_errors(reply);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user