Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2577722
main.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
main.cpp
View Options
/*
* This file is part of libkazv.
* SPDX-FileCopyrightText: 2020-2021 Tusooa Zhu <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include
<libkazv-config.hpp>
#include
<string>
#include
<iostream>
#include
<fstream>
#include
<lager/store.hpp>
#include
<lager/event_loop/boost_asio.hpp>
#include
<lager/resources_path.hpp>
#include
<boost/asio.hpp>
#ifndef NDEBUG
//#include <lager/debug/http_server.hpp>
#endif
#include
<asio-promise-handler.hpp>
#include
<cprjobhandler.hpp>
#include
<lagerstoreeventemitter.hpp>
#include
<sdk.hpp>
#include
"commands.hpp"
using
namespace
std
::
string_literals
;
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<=
1
)
{
std
::
cerr
<<
"Usage: basicexample <auth-file-name>
\n\n
"
<<
"auth file is a text file with these lines:
\n
"
<<
"mode(pw or token)
\n
"
<<
"homeserver address
\n
"
<<
"username (if pw) or userid (if token)
\n
"
<<
"password (if pw) or token (if token)
\n
"
<<
"deviceId (if token) or blank (if pw)
\n\n
"
<<
"For example:
\n
"
<<
"pw
\n
"
<<
"https://some.server.org
\n
"
<<
"someUserName
\n
"
<<
"somePa$$w0rd
\n
"
;
return
1
;
}
boost
::
asio
::
io_context
ioContext
;
auto
eventEmitter
=
Kazv
::
LagerStoreEventEmitter
(
lager
::
with_boost_asio_event_loop
{
ioContext
.
get_executor
()});
Kazv
::
CprJobHandler
jobHandler
{
ioContext
.
get_executor
()};
auto
sdk
=
Kazv
::
makeDefaultSdkWithCryptoRandom
(
Kazv
::
genRandomData
(
Kazv
::
makeDefaultSdkWithCryptoRandomSize
()),
static_cast
<
Kazv
::
CprJobHandler
&>
(
jobHandler
),
static_cast
<
Kazv
::
EventInterface
&>
(
eventEmitter
),
Kazv
::
AsioPromiseHandler
{
ioContext
.
get_executor
()},
zug
::
identity
);
auto
store
=
sdk
.
context
();
auto
c
=
sdk
.
client
();
auto
watchable
=
eventEmitter
.
watchable
();
watchable
.
after
<
Kazv
::
ReceivingRoomTimelineEvent
>
(
[](
auto
e
)
{
auto
[
event
,
roomId
]
=
e
;
std
::
cout
<<
"
\033
[1;32mreceiving event "
<<
event
.
id
()
<<
" in "
<<
roomId
<<
" from "
<<
event
.
sender
()
<<
": "
<<
event
.
content
().
get
().
dump
()
<<
"
\033
[0m"
<<
std
::
endl
;
});
watchable
.
after
<
Kazv
::
ReceivingToDeviceMessage
>
(
[](
auto
e
)
{
auto
[
event
]
=
e
;
std
::
cout
<<
"
\033
[1;32mreceiving to-device event "
<<
event
.
originalJson
().
get
().
dump
()
<<
"
\033
[0m"
<<
std
::
endl
;
});
{
std
::
ifstream
auth
(
argv
[
1
]);
if
(
!
auth
)
{
std
::
cerr
<<
"Cannot open auth file "
<<
argv
[
1
]
<<
"
\n
"
;
return
1
;
}
std
::
string
mode
;
std
::
string
homeserver
;
std
::
string
username
;
std
::
getline
(
auth
,
mode
);
std
::
getline
(
auth
,
homeserver
);
std
::
getline
(
auth
,
username
);
if
(
mode
==
"token"
)
{
std
::
string
token
;
std
::
string
deviceId
;
std
::
getline
(
auth
,
token
);
std
::
getline
(
auth
,
deviceId
);
c
.
tokenLogin
(
homeserver
,
username
,
token
,
deviceId
);
}
else
{
std
::
string
password
;
std
::
getline
(
auth
,
password
);
c
.
passwordLogin
(
homeserver
,
username
,
password
,
"libkazv basic example"
);
std
::
cout
<<
"password login action sent"
<<
std
::
endl
;
}
}
std
::
cout
<<
"starting event loop"
<<
std
::
endl
;
std
::
thread
([
&
]
{
ioContext
.
run
();
}).
detach
();
std
::
size_t
command
=
1
;
while
(
true
)
{
std
::
cout
<<
"
\033
[1;33mCommand["
<<
command
<<
"]:
\033
[0m
\n
"
;
std
::
string
l
;
if
(
!
std
::
getline
(
std
::
cin
,
l
))
{
break
;
}
parse
(
l
,
c
);
++
command
;
}
jobHandler
.
stop
();
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Tue, Jun 24, 12:48 PM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
234866
Default Alt Text
main.cpp (3 KB)
Attached To
Mode
rL libkazv
Attached
Detach File
Event Timeline
Log In to Comment