Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
Clean up a bit and make erl_openid more OTP compliant
Browse files Browse the repository at this point in the history
- add .app file
- use application and supervisor behaviours
- move header file to include/
- use erl -make to build
- request global name for openid_srv
  • Loading branch information
MarSik committed Jul 9, 2010
1 parent 88a9bed commit 224f488
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
*~
*.beam
*.pyc
Mnesia.*
sasl_err*
Expand Down
22 changes: 22 additions & 0 deletions Emakefile
@@ -0,0 +1,22 @@
{ './src/*', [
{ i, "./include" },
{ outdir, "./ebin" },
debug_info
]}.

{ './src/*/*', [
{ i, "./include" },
{ outdir, "./ebin" },
debug_info
]}.

{ './src/*/*/*', [
{ i, "./include" },
{ outdir, "./ebin" },
debug_info
]}.

{ '*', [
debug_info
]}.

24 changes: 4 additions & 20 deletions Makefile
@@ -1,34 +1,18 @@
SRC_DIR = src
EBIN_DIR = ebin
INCLUDE_DIR = include

SOURCES = $(wildcard $(SRC_DIR)/*.erl)
INCLUDES = $(wildcard $(INCLUDE_DIR)/*.hrl)
TARGETS = $(patsubst $(SRC_DIR)/%.erl, $(EBIN_DIR)/%.beam,$(SOURCES))
all: build

ERL_EBINS = -pa $(EBIN_DIR)

ERLC = erlc
ERLC_OPTS = -o $(EBIN_DIR) -Wall -v +debug_info

ERL_CMD=erl \
+W w \
$(ERL_EBINS)

all: $(TARGETS)
build:
erl -make

run_prereqs: all

test: run_prereqs
$(ERL_CMD) -noshell -pa ../mochiweb/ebin -s openid_srv test -s init stop

clean: cleanlog
rm -f $(TARGETS)
rm -f $(EBIN_DIR)/*.beam
rm -f ebin/*.beam

cleanlog:
rm -f auth.log report.log sasl_err.log
rm -f *.access

$(EBIN_DIR)/%.beam: $(SRC_DIR)/%.erl $(INCLUDES)
$(ERLC) $(ERLC_OPTS) $<
6 changes: 0 additions & 6 deletions ebin/.gitignore

This file was deleted.

13 changes: 13 additions & 0 deletions ebin/erl_openid.app
@@ -0,0 +1,13 @@
{application, erl_openid, [
{description, "Erlang OpenId Library"},
{vsn, "0.1"},
{registered, []},
{modules, [
openid,
openid_srv,
openid_utils,
yadis
]},
{mod, {openid, []}},
{applications, [kernel, stdlib, ssl]}
]}.
4 changes: 4 additions & 0 deletions src/openid.hrl → include/openid.hrl
Expand Up @@ -6,6 +6,10 @@
%%% Created : 18 Sep 2009 by Brendon Hogger <brendonh@dev.brendonh.org>
%%%-------------------------------------------------------------------

-define(GV(E, P), proplists:get_value(E, P)).
-define(GVD(E, P, D), proplists:get_value(E, P, D)).
-define(DBG(Term), io:format("~p: ~p~n", [self(), Term])).

-record(xrdService, {
types,
uris,
Expand Down
54 changes: 50 additions & 4 deletions src/openid.erl
Expand Up @@ -7,15 +7,61 @@
%%%-------------------------------------------------------------------
-module(openid).

-export([discover/1, associate/1, authentication_url/3, test/0]).
-export([
start/2, stop/1, init/1, start_link/1,
prepare/2, prepare/3, verify/3,
discover/1, associate/1, authentication_url/3, test/0]).

-behaviour(application).
-behaviour(supervisor).

-include("openid.hrl").

-define(GV(E, P), proplists:get_value(E, P)).
-define(GVD(E, P, D), proplists:get_value(E, P, D)).
-define(DBG(Term), io:format("~p: ~p~n", [self(), Term])).

%% ------------------------------------------------------------
%% Application
%% ------------------------------------------------------------

start(_, _) ->
start_link([]).

stop(_) ->
ok.


%% ------------------------------------------------------------
%% Main supervisor
%% ------------------------------------------------------------


start_link(Args) ->
supervisor:start_link({local, ?MODULE}, ?MODULE, Args).

init(_Args) ->
{ok, {{one_for_one, 10, 10},
[
{make_ref(),
{openid_srv, start_link, []},
permanent,
10000,
worker,
[openid_srv]
}
]
}}.

%%
%% Intf to openid server
%%

prepare(UUID, Identifier) ->
gen_server:call({global, openid_srv}, {prepare, UUID, Identifier}).

prepare(UUID, Identifier, Cache) ->
gen_server:call({global, openid_srv}, {prepare, UUID, Identifier, Cache}).

verify(UUID, ReturnTo, Fields) ->
gen_server:call({global, openid_srv}, {verify, UUID, ReturnTo, Fields}).

%% ------------------------------------------------------------
%% Discovery
Expand Down
11 changes: 5 additions & 6 deletions src/openid_srv.erl
Expand Up @@ -12,7 +12,7 @@
-include("openid.hrl").

%% API
-export([start_link/1, test/0]).
-export([start_link/0, start_link/1, test/0]).

%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
Expand All @@ -35,18 +35,17 @@
%%====================================================================
%% API
%%====================================================================
start_link() ->
start_link({global, ?MODULE}).

start_link(Name) ->
gen_server:start_link({local, Name}, ?MODULE, [], []).
gen_server:start_link(Name, ?MODULE, [], []).


%%====================================================================
%% gen_server callbacks
%%====================================================================

-define(GV(E, P), proplists:get_value(E, P)).
-define(GVD(E, P, D), proplists:get_value(E, P, D)).
-define(DBG(Term), io:format("~p: ~p~n", [self(), Term])).

init(_Args) ->
AuthReqs = ets:new(openid_authreqs, [set, private]),
Assocs = ets:new(openid_assocs, [set, private]),
Expand Down
2 changes: 0 additions & 2 deletions src/yadis.erl
Expand Up @@ -12,8 +12,6 @@
-include("openid.hrl").
-include_lib("xmerl/include/xmerl.hrl").

-define(GVD(E, P, D), proplists:get_value(E, P, D)).

-define(HTTP_HEADERS, [{"Accept", "application/xrds+xml"},
{"Connection", "close"},
{"User-Agent", "Erlang/openid"}]).
Expand Down

0 comments on commit 224f488

Please sign in to comment.