Update to new rjp api

This commit is contained in:
rexy712 2020-04-05 10:54:27 -07:00
parent 52d9818f6d
commit a27e2c06ba
6 changed files with 21 additions and 27 deletions

View File

@ -67,7 +67,7 @@ namespace matrix{
if(!reply) if(!reply)
return _create_netreturn(reply, http_status()); return _create_netreturn(reply, http_status());
raii::rjp_ptr root(rjp_parse(reply)); raii::rjp_ptr root(rjp_parse(reply, RJP_PARSE_ALL_EXT));
netreturn<std::vector<raii::rjp_string>> retval = _create_netreturn(root, http_status()); netreturn<std::vector<raii::rjp_string>> retval = _create_netreturn(root, http_status());
if(!root) if(!root)
return retval; return retval;
@ -180,7 +180,7 @@ namespace matrix{
if(!reply) if(!reply)
return netreturn<sync::client_response>(rexy::string(), rexy::string(), http_status(), {nullptr}); return netreturn<sync::client_response>(rexy::string(), rexy::string(), http_status(), {nullptr});
raii::rjp_ptr root(rjp_parse(reply)); raii::rjp_ptr root(rjp_parse(reply, RJP_PARSE_ALL_EXT));
netreturn<sync::client_response> retval = _create_netreturn(root, http_status()); netreturn<sync::client_response> retval = _create_netreturn(root, http_status());
if(!root) if(!root)
return retval; return retval;
@ -227,7 +227,7 @@ namespace matrix{
if(!succ || !fileurl) if(!succ || !fileurl)
return _create_netreturn(fileurl, http_status()); return _create_netreturn(fileurl, http_status());
raii::rjp_ptr root(rjp_parse(fileurl)); raii::rjp_ptr root(rjp_parse(fileurl, RJP_PARSE_ALL_EXT));
netreturn<uploaded_file> retval = _create_netreturn(root, http_status()); netreturn<uploaded_file> retval = _create_netreturn(root, http_status());
if(!root) if(!root)
return retval; return retval;

View File

@ -161,7 +161,7 @@ namespace matrix{
rexy::string reply = _post_curl(data, url, header); rexy::string reply = _post_curl(data, url, header);
if(!reply) if(!reply)
return _create_netreturn(reply, http_status()); return _create_netreturn(reply, http_status());
raii::rjp_ptr root(rjp_parse(reply)); raii::rjp_ptr root(rjp_parse(reply, RJP_PARSE_ALL_EXT));
netreturn<raii::rjp_string> retval = _create_netreturn(root, http_status()); netreturn<raii::rjp_string> retval = _create_netreturn(root, http_status());
retval.value() = _curl_reply_search(reply, target); retval.value() = _curl_reply_search(reply, target);
return retval; return retval;
@ -172,7 +172,7 @@ namespace matrix{
rexy::string reply = _put_curl(data, url, header); rexy::string reply = _put_curl(data, url, header);
if(!reply) if(!reply)
return _create_netreturn(reply, http_status()); return _create_netreturn(reply, http_status());
raii::rjp_ptr root(rjp_parse(reply)); raii::rjp_ptr root(rjp_parse(reply, RJP_PARSE_ALL_EXT));
netreturn<raii::rjp_string> retval = _create_netreturn(root, http_status()); netreturn<raii::rjp_string> retval = _create_netreturn(root, http_status());
retval.value() = _curl_reply_search(reply, target); retval.value() = _curl_reply_search(reply, target);
return retval; return retval;
@ -181,13 +181,13 @@ namespace matrix{
rexy::string reply = _get_curl(url); rexy::string reply = _get_curl(url);
if(!reply) if(!reply)
return _create_netreturn(reply, http_status()); return _create_netreturn(reply, http_status());
raii::rjp_ptr root(rjp_parse(reply)); raii::rjp_ptr root(rjp_parse(reply, RJP_PARSE_ALL_EXT));
netreturn<raii::rjp_string> retval = _create_netreturn(root, http_status()); netreturn<raii::rjp_string> retval = _create_netreturn(root, http_status());
retval.value() = _curl_reply_search(reply, target); retval.value() = _curl_reply_search(reply, target);
return retval; return retval;
} }
raii::rjp_string connection::_curl_reply_search(const rexy::string_base& reply, const rexy::string_base& target)const{ raii::rjp_string connection::_curl_reply_search(const rexy::string_base& reply, const rexy::string_base& target)const{
raii::rjp_ptr root(rjp_parse(reply)); raii::rjp_ptr root(rjp_parse(reply, RJP_PARSE_ALL_EXT));
return _curl_reply_search(root, target); return _curl_reply_search(root, target);
} }
raii::rjp_string connection::_curl_reply_search(const raii::rjp_ptr& root, const rexy::string_base& target)const{ raii::rjp_string connection::_curl_reply_search(const raii::rjp_ptr& root, const rexy::string_base& target)const{
@ -218,7 +218,7 @@ namespace matrix{
netreturn_base connection::_create_netreturn(const rexy::string_base& mxjson, int httpstatus){ netreturn_base connection::_create_netreturn(const rexy::string_base& mxjson, int httpstatus){
if(!mxjson) if(!mxjson)
return netreturn_base(""_ss, ""_ss, httpstatus); return netreturn_base(""_ss, ""_ss, httpstatus);
raii::rjp_ptr root(rjp_parse(mxjson.get())); raii::rjp_ptr root(rjp_parse(mxjson.get(), RJP_PARSE_ALL_EXT));
return _create_netreturn(root, httpstatus); return _create_netreturn(root, httpstatus);
} }
netreturn_base connection::_create_netreturn(const raii::rjp_ptr& root, int httpstatus){ netreturn_base connection::_create_netreturn(const raii::rjp_ptr& root, int httpstatus){

View File

@ -57,7 +57,7 @@ namespace matrix{
rexy::string resp = _get_curl(m_urls.room_members()); rexy::string resp = _get_curl(m_urls.room_members());
if(!resp) return _create_netreturn(resp, http_status()); if(!resp) return _create_netreturn(resp, http_status());
raii::rjp_ptr root(rjp_parse(resp.get())); raii::rjp_ptr root(rjp_parse(resp.get(), RJP_PARSE_ALL_EXT));
if(!root) return _create_netreturn(root, http_status()); if(!root) return _create_netreturn(root, http_status());
RJP_value* res = rjp_search_member(root.get(), json::keys::joined()); RJP_value* res = rjp_search_member(root.get(), json::keys::joined());
if(!res) return _create_netreturn(root, http_status()); if(!res) return _create_netreturn(root, http_status());
@ -107,7 +107,7 @@ namespace matrix{
if(!reply) if(!reply)
return _create_netreturn(reply, http_status()); return _create_netreturn(reply, http_status());
raii::rjp_ptr root(rjp_parse(reply)); raii::rjp_ptr root(rjp_parse(reply, RJP_PARSE_ALL_EXT));
netreturn<raii::rjp_string> retval = _create_netreturn(root, http_status()); netreturn<raii::rjp_string> retval = _create_netreturn(root, http_status());
retval.value() = _curl_reply_search(root, json::keys::event::eventid()); retval.value() = _curl_reply_search(root, json::keys::event::eventid());
return retval; return retval;
@ -144,7 +144,7 @@ namespace matrix{
netreturn<sync::roomcxn_message_event_list> roomcxn::get_event(const rexy::string_base& eventid)const{ netreturn<sync::roomcxn_message_event_list> roomcxn::get_event(const rexy::string_base& eventid)const{
rexy::string reply = _get_curl(m_urls.event(*m_ses, m_curl.encode(m_roomid), eventid)); rexy::string reply = _get_curl(m_urls.event(*m_ses, m_curl.encode(m_roomid), eventid));
if(!reply) return _create_netreturn(reply, http_status()); if(!reply) return _create_netreturn(reply, http_status());
raii::rjp_ptr root(rjp_parse(reply.get())); raii::rjp_ptr root(rjp_parse(reply.get(), RJP_PARSE_ALL_EXT));
if(!root.get()) _create_netreturn(root, http_status()); if(!root.get()) _create_netreturn(root, http_status());
netreturn<sync::roomcxn_message_event_list> retval = _create_netreturn(root, http_status()); netreturn<sync::roomcxn_message_event_list> retval = _create_netreturn(root, http_status());
@ -160,7 +160,7 @@ namespace matrix{
netreturn<sync::roomcxn_message_event_list> roomcxn::_get_events(int amount, rexy::static_string direction, const rexy::string_base& from, const rexy::string_base& to){ netreturn<sync::roomcxn_message_event_list> roomcxn::_get_events(int amount, rexy::static_string direction, const rexy::string_base& from, const rexy::string_base& to){
rexy::string reply = _get_curl(m_urls.messages(*m_ses, m_curl.encode(m_roomid), from, to, direction, amount)); rexy::string reply = _get_curl(m_urls.messages(*m_ses, m_curl.encode(m_roomid), from, to, direction, amount));
if(!reply) return _create_netreturn(reply, http_status()); if(!reply) return _create_netreturn(reply, http_status());
raii::rjp_ptr root(rjp_parse(reply.get())); raii::rjp_ptr root(rjp_parse(reply.get(), RJP_PARSE_ALL_EXT));
if(!root.get()) _create_netreturn(root, http_status()); if(!root.get()) _create_netreturn(root, http_status());
netreturn<sync::roomcxn_message_event_list> retval = _create_netreturn(root, http_status()); netreturn<sync::roomcxn_message_event_list> retval = _create_netreturn(root, http_status());

View File

@ -82,7 +82,7 @@ namespace matrix{
rexy::string reply = _post_curl(json::_empty(), rest::session_urls::password(*m_ses), raii::curl_llist()); rexy::string reply = _post_curl(json::_empty(), rest::session_urls::password(*m_ses), raii::curl_llist());
if(!reply) if(!reply)
return _create_netreturn(reply, http_status()); return _create_netreturn(reply, http_status());
raii::rjp_ptr root(rjp_parse(reply)); raii::rjp_ptr root(rjp_parse(reply, RJP_PARSE_ALL_EXT));
netreturn<void> retval = _create_netreturn(root, http_status()); netreturn<void> retval = _create_netreturn(root, http_status());
if(!root) if(!root)
return retval; return retval;
@ -155,7 +155,7 @@ namespace matrix{
rexy::string reply = _request_access_token(name, pass, loginurl); rexy::string reply = _request_access_token(name, pass, loginurl);
if(!reply) if(!reply)
return _create_netreturn(reply, http_status()); return _create_netreturn(reply, http_status());
raii::rjp_ptr root(rjp_parse(reply)); raii::rjp_ptr root(rjp_parse(reply, RJP_PARSE_ALL_EXT));
netreturn<std::pair<raii::rjp_string,raii::rjp_string>> retval = _create_netreturn(root, http_status()); netreturn<std::pair<raii::rjp_string,raii::rjp_string>> retval = _create_netreturn(root, http_status());
if(!root) if(!root)
return retval; return retval;

View File

@ -51,7 +51,7 @@ namespace matrix::sync{
//Sync response //Sync response
client_response::client_response(const rexy::string_base& s): client_response::client_response(const rexy::string_base& s):
m_root(rjp_parse(s)){} m_root(rjp_parse(s, RJP_PARSE_ALL_EXT)){}
client_response::client_response(RJP_value* root): client_response::client_response(RJP_value* root):
m_root(root){} m_root(root){}
room_list client_response::room_join_events(void)const{ room_list client_response::room_join_events(void)const{

View File

@ -37,7 +37,7 @@ matrix::auth_data read_auth_file(const char* filename){
if(!fp){ if(!fp){
return {}; return {};
} }
raii::rjp_ptr root(rjp_parse(fp.read(fp.length()))); raii::rjp_ptr root(rjp_parse(fp.read(fp.length()), RJP_PARSE_ALL_EXT));
if(!root.get()) if(!root.get())
return {}; return {};
@ -54,11 +54,11 @@ void write_to_auth_file(const char* filename, const matrix::auth_data& auth){
if(!root.get()) if(!root.get())
return; return;
rjp_move_value(rjp_add_member_key_copy(root.get(), "user", 4), rjp_new_string_copy(auth.name, 0)); rjp_move_value(rjp_new_member(root.get(), "user", 4), rjp_new_string(auth.name, 0));
rjp_move_value(rjp_add_member_key_copy(root.get(), "pass", 4), rjp_new_string_copy(auth.pass, 0)); rjp_move_value(rjp_new_member(root.get(), "pass", 4), rjp_new_string(auth.pass, 0));
rjp_move_value(rjp_add_member_key_copy(root.get(), "server", 6), rjp_new_string_copy(auth.homeserver, 0)); rjp_move_value(rjp_new_member(root.get(), "server", 6), rjp_new_string(auth.homeserver, 0));
rjp_move_value(rjp_add_member_key_copy(root.get(), "token", 5), rjp_new_string_copy(auth.access_token, 0)); rjp_move_value(rjp_new_member(root.get(), "token", 5), rjp_new_string(auth.access_token, 0));
rjp_move_value(rjp_add_member_key_copy(root.get(), "useragent", 9), rjp_new_string_copy(auth.useragent, 0)); rjp_move_value(rjp_new_member(root.get(), "useragent", 9), rjp_new_string(auth.useragent, 0));
raii::rjp_string output; raii::rjp_string output;
output.reset(rjp_to_json(root.get(), RJP_FORMAT_NONE)); output.reset(rjp_to_json(root.get(), RJP_FORMAT_NONE));
@ -345,22 +345,16 @@ int main(){
while(true){ while(true){
auto sync_status = client.sync(30000, sync_res); auto sync_status = client.sync(30000, sync_res);
sync_res = std::move(sync_status.value()); sync_res = std::move(sync_status.value());
printf("here 1\n");
if(!sync_status.ok()){ if(!sync_status.ok()){
printf("here 2\n");
fprintf(stderr, "Sync error, attempting to continue\n");
continue; continue;
} }
printf("here 3\n");
for(auto room : sync_res.room_join_events()){ for(auto room : sync_res.room_join_events()){
printf("here 4\n");
auto r = client.spawn_room(room.roomid()); auto r = client.spawn_room(room.roomid());
auto&& range = room.timeline_events(); auto&& range = room.timeline_events();
auto begin = range.begin(); auto begin = range.begin();
auto end = range.end(); auto end = range.end();
for(;begin != end;++begin){ for(;begin != end;++begin){
auto event = *begin; auto event = *begin;
printf("here 5\n");
if(event.sender() == client.userid()) if(event.sender() == client.userid())
continue; continue;
printf("%s : %s : %s\n", room.roomid().get(), event.type().get(), event.sender().get()); printf("%s : %s : %s\n", room.roomid().get(), event.type().get(), event.sender().get());