~ubuntu-branches/ubuntu/saucy/rabbitmq-server/saucy

« back to all changes in this revision

Viewing changes to plugins-src/rabbitmq-web-dispatch/src/rabbit_web_dispatch_util.erl

  • Committer: Package Import Robot
  • Author(s): Emile Joubert
  • Date: 2013-03-13 10:53:18 UTC
  • mfrom: (0.5.1) (0.1.36 sid)
  • Revision ID: package-import@ubuntu.com-20130313105318-8juqvm5209o27hbu
Tags: 3.0.4-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%% The contents of this file are subject to the Mozilla Public License
 
2
%% Version 1.1 (the "License"); you may not use this file except in
 
3
%% compliance with the License. You may obtain a copy of the License
 
4
%% at http://www.mozilla.org/MPL/
 
5
%%
 
6
%% Software distributed under the License is distributed on an "AS IS"
 
7
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
8
%% the License for the specific language governing rights and
 
9
%% limitations under the License.
 
10
%%
 
11
%% The Original Code is RabbitMQ.
 
12
%%
 
13
%% The Initial Developer of the Original Code is VMware, Inc.
 
14
%% Copyright (c) 2010-2013 VMware, Inc.  All rights reserved.
 
15
%%
 
16
 
 
17
-module(rabbit_web_dispatch_util).
 
18
 
 
19
-export([parse_auth_header/1]).
 
20
-export([relativise/2]).
 
21
 
 
22
parse_auth_header(Header) ->
 
23
    case Header of
 
24
        "Basic " ++ Base64 ->
 
25
            Str = base64:mime_decode_to_string(Base64),
 
26
            case string:chr(Str, $:) of
 
27
                0 -> invalid;
 
28
                N -> [list_to_binary(string:sub_string(Str, 1, N - 1)),
 
29
                      list_to_binary(string:sub_string(Str, N + 1))]
 
30
            end;
 
31
         _ ->
 
32
            invalid
 
33
    end.
 
34
 
 
35
relativise("/" ++ F, "/" ++ T) ->
 
36
    From = string:tokens(F, "/"),
 
37
    To = string:tokens(T, "/"),
 
38
    string:join(relativise0(From, To), "/").
 
39
 
 
40
relativise0([H], [H|_] = To) ->
 
41
    To;
 
42
relativise0([H|From], [H|To]) ->
 
43
    relativise0(From, To);
 
44
relativise0(From, []) ->
 
45
    lists:duplicate(length(From), "..");
 
46
relativise0([_|From], To) ->
 
47
    lists:duplicate(length(From), "..") ++ To;
 
48
relativise0([], To) ->
 
49
    To.