Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
98cbdd35
Commit
98cbdd35
authored
4 months ago
by
Adrien Béraud
Committed by
Adrien Béraud
3 months ago
Browse files
Options
Downloads
Patches
Plain Diff
server_account_manager: log cleanup
Change-Id: I1c8f8515998967c0e76173a8e65de3ef8e85343c
parent
1ff95cdb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/jamidht/server_account_manager.cpp
+18
-17
18 additions, 17 deletions
src/jamidht/server_account_manager.cpp
src/string_utils.cpp
+1
-1
1 addition, 1 deletion
src/string_utils.cpp
src/string_utils.h
+1
-1
1 addition, 1 deletion
src/string_utils.h
with
20 additions
and
19 deletions
src/jamidht/server_account_manager.cpp
+
18
−
17
View file @
98cbdd35
...
@@ -99,9 +99,9 @@ ServerAccountManager::initAuthentication(PrivateKey key,
...
@@ -99,9 +99,9 @@ ServerAccountManager::initAuthentication(PrivateKey key,
url
,
url
,
body
,
body
,
[
ctx
,
w
](
Json
::
Value
json
,
const
dht
::
http
::
Response
&
response
)
{
[
ctx
,
w
](
Json
::
Value
json
,
const
dht
::
http
::
Response
&
response
)
{
JAMI_DEBUG
(
"[Auth] Got request callback with status code={} {}"
,
response
.
status_code
,
response
.
body
);
auto
this_
=
std
::
static_pointer_cast
<
ServerAccountManager
>
(
w
.
lock
());
auto
this_
=
std
::
static_pointer_cast
<
ServerAccountManager
>
(
w
.
lock
());
JAMI_DEBUG
(
"[Auth] Got request callback with status code={}"
,
response
.
status_code
);
if
(
response
.
status_code
==
0
||
this_
==
nullptr
)
if
(
response
.
status_code
==
0
||
this_
==
nullptr
)
ctx
->
onFailure
(
AuthError
::
SERVER_ERROR
,
"Unable to connect to server"
);
ctx
->
onFailure
(
AuthError
::
SERVER_ERROR
,
"Unable to connect to server"
);
else
if
(
response
.
status_code
>=
400
&&
response
.
status_code
<
500
)
else
if
(
response
.
status_code
>=
400
&&
response
.
status_code
<
500
)
...
@@ -111,7 +111,7 @@ ServerAccountManager::initAuthentication(PrivateKey key,
...
@@ -111,7 +111,7 @@ ServerAccountManager::initAuthentication(PrivateKey key,
else
{
else
{
do
{
do
{
try
{
try
{
JAMI_WARNING
(
"[Auth] Got server response: {}
"
,
response
.
body
);
JAMI_WARNING
(
"
[Account {}]
[Auth] Got server response: {}
bytes"
,
this_
->
accountId_
,
response
.
body
.
size
()
);
auto
cert
=
std
::
make_shared
<
dht
::
crypto
::
Certificate
>
(
auto
cert
=
std
::
make_shared
<
dht
::
crypto
::
Certificate
>
(
json
[
"certificateChain"
].
asString
());
json
[
"certificateChain"
].
asString
());
auto
accountCert
=
cert
->
issuer
;
auto
accountCert
=
cert
->
issuer
;
...
@@ -193,7 +193,7 @@ ServerAccountManager::initAuthentication(PrivateKey key,
...
@@ -193,7 +193,7 @@ ServerAccountManager::initAuthentication(PrivateKey key,
std
::
move
(
receipt
),
std
::
move
(
receipt
),
std
::
move
(
receiptSignature
));
std
::
move
(
receiptSignature
));
}
catch
(
const
std
::
exception
&
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
JAMI_ERR
(
"
Error when loading account:
%s"
,
e
.
what
());
JAMI_ERR
OR
(
"[Account {}] [Auth]
Error when loading account:
{}"
,
this_
->
accountId_
,
e
.
what
());
ctx
->
onFailure
(
AuthError
::
NETWORK
,
""
);
ctx
->
onFailure
(
AuthError
::
NETWORK
,
""
);
}
}
}
while
(
false
);
}
while
(
false
);
...
@@ -220,10 +220,10 @@ ServerAccountManager::onAuthEnded(const Json::Value& json,
...
@@ -220,10 +220,10 @@ ServerAccountManager::onAuthEnded(const Json::Value& json,
:
(
scopeStr
==
"USER"
sv
?
TokenScope
::
User
:
TokenScope
::
None
);
:
(
scopeStr
==
"USER"
sv
?
TokenScope
::
User
:
TokenScope
::
None
);
auto
expires_in
=
json
[
"expires_in"
].
asLargestUInt
();
auto
expires_in
=
json
[
"expires_in"
].
asLargestUInt
();
auto
expiration
=
std
::
chrono
::
steady_clock
::
now
()
+
std
::
chrono
::
seconds
(
expires_in
);
auto
expiration
=
std
::
chrono
::
steady_clock
::
now
()
+
std
::
chrono
::
seconds
(
expires_in
);
JAMI_WARNING
(
"[Auth] Got server response: {} {}
"
,
response
.
status_code
,
response
.
body
);
JAMI_WARNING
(
"
[Account {}]
[Auth] Got server response: {}
(
{}
bytes)"
,
accountId_
,
response
.
status_code
,
response
.
body
.
size
()
);
setToken
(
json
[
"access_token"
].
asString
(),
scope
,
expiration
);
setToken
(
json
[
"access_token"
].
asString
(),
scope
,
expiration
);
}
else
{
}
else
{
JAMI_WARNING
(
"[Auth] Got server response: {} {}
"
,
response
.
status_code
,
response
.
body
);
JAMI_WARNING
(
"
[Account {}]
[Auth] Got server response: {}
(
{}
bytes)"
,
accountId_
,
response
.
status_code
,
response
.
body
.
size
()
);
authFailed
(
expectedScope
,
response
.
status_code
);
authFailed
(
expectedScope
,
response
.
status_code
);
}
}
clearRequest
(
response
.
request
);
clearRequest
(
response
.
request
);
...
@@ -236,7 +236,7 @@ ServerAccountManager::authenticateDevice()
...
@@ -236,7 +236,7 @@ ServerAccountManager::authenticateDevice()
authFailed
(
TokenScope
::
Device
,
0
);
authFailed
(
TokenScope
::
Device
,
0
);
}
}
const
std
::
string
url
=
managerHostname_
+
JAMI_PATH_LOGIN
;
const
std
::
string
url
=
managerHostname_
+
JAMI_PATH_LOGIN
;
JAMI_WARN
(
"
[Auth] Getting a device token:
%s
"
,
url
.
c_str
()
);
JAMI_WARN
ING
(
"[Account {}]
[Auth] Getting a device token:
{}
"
,
accountId_
,
url
);
auto
request
=
std
::
make_shared
<
Request
>
(
auto
request
=
std
::
make_shared
<
Request
>
(
*
Manager
::
instance
().
ioContext
(),
*
Manager
::
instance
().
ioContext
(),
url
,
url
,
...
@@ -255,7 +255,7 @@ void
...
@@ -255,7 +255,7 @@ void
ServerAccountManager
::
authenticateAccount
(
const
std
::
string
&
username
,
const
std
::
string
&
password
)
ServerAccountManager
::
authenticateAccount
(
const
std
::
string
&
username
,
const
std
::
string
&
password
)
{
{
const
std
::
string
url
=
managerHostname_
+
JAMI_PATH_LOGIN
;
const
std
::
string
url
=
managerHostname_
+
JAMI_PATH_LOGIN
;
JAMI_WARN
(
"[Auth] Getting a
device
token:
%s
"
,
url
.
c_str
()
);
JAMI_WARN
ING
(
"
[Account {}]
[Auth] Getting a
user
token:
{}
"
,
accountId_
,
url
);
auto
request
=
std
::
make_shared
<
Request
>
(
auto
request
=
std
::
make_shared
<
Request
>
(
*
Manager
::
instance
().
ioContext
(),
*
Manager
::
instance
().
ioContext
(),
url
,
url
,
...
@@ -272,7 +272,7 @@ ServerAccountManager::authenticateAccount(const std::string& username, const std
...
@@ -272,7 +272,7 @@ ServerAccountManager::authenticateAccount(const std::string& username, const std
void
void
ServerAccountManager
::
sendRequest
(
const
std
::
shared_ptr
<
dht
::
http
::
Request
>&
request
)
ServerAccountManager
::
sendRequest
(
const
std
::
shared_ptr
<
dht
::
http
::
Request
>&
request
)
{
{
request
->
set_header_field
(
restinio
::
http_field_t
::
user_agent
,
"Jami"
);
request
->
set_header_field
(
restinio
::
http_field_t
::
user_agent
,
userAgent
()
);
{
{
std
::
lock_guard
lock
(
requestLock_
);
std
::
lock_guard
lock
(
requestLock_
);
requests_
.
emplace
(
request
);
requests_
.
emplace
(
request
);
...
@@ -345,7 +345,8 @@ ServerAccountManager::setToken(std::string token,
...
@@ -345,7 +345,8 @@ ServerAccountManager::setToken(std::string token,
nameDir_
.
get
().
setToken
(
token_
);
nameDir_
.
get
().
setToken
(
token_
);
if
(
not
token_
.
empty
()
and
scope
!=
TokenScope
::
None
)
{
if
(
not
token_
.
empty
()
and
scope
!=
TokenScope
::
None
)
{
auto
&
reqQueue
=
getRequestQueue
(
scope
);
auto
&
reqQueue
=
getRequestQueue
(
scope
);
JAMI_DBG
(
"[Auth] Got token with scope %d, handling %zu pending requests"
,
JAMI_DEBUG
(
"[Account {}] [Auth] Got token with scope {}, handling {} pending requests"
,
accountId_
,
(
int
)
scope
,
(
int
)
scope
,
reqQueue
.
size
());
reqQueue
.
size
());
while
(
not
reqQueue
.
empty
())
{
while
(
not
reqQueue
.
empty
())
{
...
@@ -413,7 +414,7 @@ ServerAccountManager::syncDevices()
...
@@ -413,7 +414,7 @@ ServerAccountManager::syncDevices()
response
.
status_code
);
response
.
status_code
);
if
(
response
.
status_code
>=
200
&&
response
.
status_code
<
300
)
{
if
(
response
.
status_code
>=
200
&&
response
.
status_code
<
300
)
{
try
{
try
{
JAMI_WARNING
(
"[Account {}] [Auth] Got server response: {}"
,
this_
->
accountId_
,
response
.
body
);
JAMI_WARNING
(
"[Account {}] [Auth] Got server response: {}
bytes
"
,
this_
->
accountId_
,
response
.
body
.
size
()
);
if
(
not
json
.
isArray
())
{
if
(
not
json
.
isArray
())
{
JAMI_ERROR
(
"[Account {}] [Auth] Unable to parse server response: not an array"
,
this_
->
accountId_
);
JAMI_ERROR
(
"[Account {}] [Auth] Unable to parse server response: not an array"
,
this_
->
accountId_
);
}
else
{
}
else
{
...
@@ -494,13 +495,13 @@ ServerAccountManager::syncDevices()
...
@@ -494,13 +495,13 @@ ServerAccountManager::syncDevices()
urlContacts
,
urlContacts
,
jsonContacts
,
jsonContacts
,
[
w
=
weak_from_this
()](
Json
::
Value
json
,
const
dht
::
http
::
Response
&
response
)
{
[
w
=
weak_from_this
()](
Json
::
Value
json
,
const
dht
::
http
::
Response
&
response
)
{
JAMI_DEBUG
(
"[Auth] Got contact sync request callback with status code={}"
,
response
.
status_code
);
auto
this_
=
std
::
static_pointer_cast
<
ServerAccountManager
>
(
w
.
lock
());
auto
this_
=
std
::
static_pointer_cast
<
ServerAccountManager
>
(
w
.
lock
());
JAMI_DEBUG
(
"[Account {}] [Auth] Got contact sync request callback with status code={}"
,
this_
->
accountId_
,
response
.
status_code
);
if
(
!
this_
)
return
;
if
(
!
this_
)
return
;
if
(
response
.
status_code
>=
200
&&
response
.
status_code
<
300
)
{
if
(
response
.
status_code
>=
200
&&
response
.
status_code
<
300
)
{
try
{
try
{
JAMI_WARNING
(
"[Auth] Got server response: {}
"
,
response
.
body
);
JAMI_WARNING
(
"
[Account {}]
[Auth] Got server response: {}
bytes"
,
this_
->
accountId_
,
response
.
body
.
size
()
);
if
(
not
json
.
isArray
())
{
if
(
not
json
.
isArray
())
{
JAMI_ERROR
(
"[Auth] Unable to parse server response: not an array"
);
JAMI_ERROR
(
"[Auth] Unable to parse server response: not an array"
);
}
else
{
}
else
{
...
@@ -532,7 +533,7 @@ ServerAccountManager::syncDevices()
...
@@ -532,7 +533,7 @@ ServerAccountManager::syncDevices()
JAMI_DEBUG
(
"[Account {}] [Auth] Got request callback with status code={}"
,
this_
->
accountId_
,
response
.
status_code
);
JAMI_DEBUG
(
"[Account {}] [Auth] Got request callback with status code={}"
,
this_
->
accountId_
,
response
.
status_code
);
if
(
response
.
status_code
>=
200
&&
response
.
status_code
<
300
)
{
if
(
response
.
status_code
>=
200
&&
response
.
status_code
<
300
)
{
try
{
try
{
JAMI_
WARNING
(
"
[Auth] Got server response: {}
"
,
response
.
body
);
JAMI_
LOG
(
"[Account {}]
[Auth] Got server response: {}
bytes"
,
this_
->
accountId_
,
response
.
body
.
size
()
);
if
(
not
json
.
isArray
())
{
if
(
not
json
.
isArray
())
{
JAMI_ERROR
(
"[Auth] Unable to parse server response: not an array"
);
JAMI_ERROR
(
"[Auth] Unable to parse server response: not an array"
);
}
else
{
}
else
{
...
@@ -650,7 +651,7 @@ ServerAccountManager::searchUser(const std::string& query, SearchCallback cb)
...
@@ -650,7 +651,7 @@ ServerAccountManager::searchUser(const std::string& query, SearchCallback cb)
*
Manager
::
instance
().
ioContext
(),
*
Manager
::
instance
().
ioContext
(),
url
,
url
,
[
cb
,
w
=
weak_from_this
()](
Json
::
Value
json
,
const
dht
::
http
::
Response
&
response
)
{
[
cb
,
w
=
weak_from_this
()](
Json
::
Value
json
,
const
dht
::
http
::
Response
&
response
)
{
JAMI_D
B
G
(
"[Search] Got request callback with status code=
%u
"
,
response
.
status_code
);
JAMI_D
EBU
G
(
"[Search] Got request callback with status code=
{}
"
,
response
.
status_code
);
auto
this_
=
std
::
static_pointer_cast
<
ServerAccountManager
>
(
w
.
lock
());
auto
this_
=
std
::
static_pointer_cast
<
ServerAccountManager
>
(
w
.
lock
());
if
(
!
this_
)
return
;
if
(
!
this_
)
return
;
if
(
response
.
status_code
>=
200
&&
response
.
status_code
<
300
)
{
if
(
response
.
status_code
>=
200
&&
response
.
status_code
<
300
)
{
...
@@ -659,7 +660,7 @@ ServerAccountManager::searchUser(const std::string& query, SearchCallback cb)
...
@@ -659,7 +660,7 @@ ServerAccountManager::searchUser(const std::string& query, SearchCallback cb)
Json
::
Value
::
ArrayIndex
rcount
=
profiles
.
size
();
Json
::
Value
::
ArrayIndex
rcount
=
profiles
.
size
();
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>
results
;
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>
results
;
results
.
reserve
(
rcount
);
results
.
reserve
(
rcount
);
JAMI_WARNING
(
"[Search] Got server response: {}"
,
response
.
body
);
JAMI_WARNING
(
"[Search] Got server response: {}
bytes
"
,
response
.
body
.
size
()
);
for
(
Json
::
Value
::
ArrayIndex
i
=
0
;
i
<
rcount
;
i
++
)
{
for
(
Json
::
Value
::
ArrayIndex
i
=
0
;
i
<
rcount
;
i
++
)
{
const
auto
&
ruser
=
profiles
[
i
];
const
auto
&
ruser
=
profiles
[
i
];
std
::
map
<
std
::
string
,
std
::
string
>
user
;
std
::
map
<
std
::
string
,
std
::
string
>
user
;
...
...
This diff is collapsed.
Click to expand it.
src/string_utils.cpp
+
1
−
1
View file @
98cbdd35
...
@@ -63,7 +63,7 @@ const Json::CharReaderBuilder rbuilder = getJsonReaderBuilder();
...
@@ -63,7 +63,7 @@ const Json::CharReaderBuilder rbuilder = getJsonReaderBuilder();
const
Json
::
StreamWriterBuilder
wbuilder
=
getJsonWriterBuilder
();
const
Json
::
StreamWriterBuilder
wbuilder
=
getJsonWriterBuilder
();
}
}
std
::
string
_view
const
std
::
string
&
userAgent
()
userAgent
()
{
{
static
const
std
::
string
USER_AGENT
=
fmt
::
format
(
"{:s} ({:s}/{:s})"
,
PACKAGE_NAME
,
platform
(),
arch
());
static
const
std
::
string
USER_AGENT
=
fmt
::
format
(
"{:s} ({:s}/{:s})"
,
PACKAGE_NAME
,
platform
(),
arch
());
...
...
This diff is collapsed.
Click to expand it.
src/string_utils.h
+
1
−
1
View file @
98cbdd35
...
@@ -44,7 +44,7 @@ bool_to_str(bool b) noexcept
...
@@ -44,7 +44,7 @@ bool_to_str(bool b) noexcept
return
b
?
TRUE_STR
:
FALSE_STR
;
return
b
?
TRUE_STR
:
FALSE_STR
;
}
}
std
::
string
_view
userAgent
();
const
std
::
string
&
userAgent
();
constexpr
inline
std
::
string_view
constexpr
inline
std
::
string_view
platform
()
{
platform
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment