Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vernemq_dev_api: add has_session/1 function #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/vernemq_dev_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ <h3 class="typedecl"><a name="type-topic">topic()</a></h3>

<h2><a name="index">Function Index</a></h2>
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#disconnect_by_subscriber_id-2">disconnect_by_subscriber_id/2</a></td><td>Disconnect a client by <a href="#type-subscriber_id"><code>subscriber_id()</code></a></td></tr>
<tr><td valign="top"><a href="#has_session-1">has_session/1</a></td><td>Check if a <a href="#type-subscriber_id"><code>subscriber_id()</code></a> has an existing session.</td></tr>
<tr><td valign="top"><a href="#unword_topic-1">unword_topic/1</a></td><td>Convert a <a href="#type-topic"><code>topic()</code></a> list into an <a href="#type-iolist"><code>iolist()</code></a>
which can be flattened into a binary.</td></tr>
</table>
Expand All @@ -52,6 +53,15 @@ <h3 class="function"><a name="disconnect_by_subscriber_id-2">disconnect_by_subsc
Given a subscriber_id the client is looked up in the cluster and
disconnected.</p>

<h3 class="function"><a name="has_session-1">has_session/1</a></h3>
<div class="spec">
<p><tt>has_session(SId) -&gt; true | false</tt>
<ul class="definitions"><li><tt>SId = <a href="#type-subscriber_id">subscriber_id()</a></tt></li>></ul></p>
</div><p><p>Check if a <a href="#type-subscriber_id"><code>subscriber_id()</code> has an existing session</a></p>

Given a subscriber_id, this function checks if it has an existing
session.</p>

<h3 class="function"><a name="unword_topic-1">unword_topic/1</a></h3>
<div class="spec">
<p><tt>unword_topic(Topic) -&gt; iolist()</tt>
Expand Down
15 changes: 15 additions & 0 deletions src/vernemq_dev_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

-export([unword_topic/1,
disconnect_by_subscriber_id/2,
has_session/1,
reauthorize_subscriptions/3]).

-type disconnect_flag() :: do_cleanup.
Expand All @@ -36,6 +37,20 @@ disconnect_by_subscriber_id(SubscriberId, Opts) ->
vmq_queue:force_disconnect(QueuePid, normal, proplists:get_bool(do_cleanup, Opts))
end.

%% @doc Check if a {@link subscriber_id().} has an existing session
%%
%% Given a subscriber_id, this function checks if it has an existing
%% session.
-spec has_session(SId) -> true | false when
SId :: subscriber_id().
has_session(SubscriberId) ->
case vmq_subscriber_db:read(SubscriberId) of
undefined ->
false;
_Subs ->
true
end.

%% @doc Reauthorize subscriptions by username and subscriber_id
%%
%% Given a username and subscriber_id all subscriptions
Expand Down