auth.h 2.51 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
/* Icecast
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright 2000-2004, Jack Moffitt <jack@xiph.org, 
 *                      Michael Smith <msmith@xiph.org>,
 *                      oddsock <oddsock@xiph.org>,
 *                      Karl Heyes <karl@xiph.org>
 *                      and others (see AUTHORS for details).
 */

Michael Smith's avatar
Michael Smith committed
13
14
15
#ifndef __AUTH_H__
#define __AUTH_H__

Karl Heyes's avatar
Karl Heyes committed
16
17
18
19
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

20
21
22
struct source_tag;
struct auth_tag;

23
24
25
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
26
#include "cfgfile.h"
Karl Heyes's avatar
Karl Heyes committed
27
#include "client.h"
28
#include "thread/thread.h"
Michael Smith's avatar
Michael Smith committed
29
30
31

typedef enum
{
32
    AUTH_UNDEFINED,
Michael Smith's avatar
Michael Smith committed
33
34
    AUTH_OK,
    AUTH_FAILED,
35
    AUTH_FORBIDDEN,
36
37
38
    AUTH_USERADDED,
    AUTH_USEREXISTS,
    AUTH_USERDELETED,
Michael Smith's avatar
Michael Smith committed
39
40
} auth_result;

41
42
43
44
45
46
47
48
49
typedef struct auth_client_tag
{
    char        *mount;
    client_t    *client;
    void        (*process)(struct auth_client_tag *auth_user);
    struct auth_client_tag *next;
} auth_client;


Michael Smith's avatar
Michael Smith committed
50
51
typedef struct auth_tag
{
52
53
    char *mount;

Michael Smith's avatar
Michael Smith committed
54
    /* Authenticate using the given username and password */
55
56
57
58
59
60
61
62
63
    auth_result (*authenticate)(auth_client *aclient);
    auth_result (*release_client)(auth_client *auth_user);

    /* callbacks to specific auth for notifying auth server on source
     * startup or shutdown
     */
    void (*stream_start)(auth_client *auth_user);
    void (*stream_end)(auth_client *auth_user);

Michael Smith's avatar
Michael Smith committed
64
    void (*free)(struct auth_tag *self);
65
66
67
68
    auth_result (*adduser)(struct auth_tag *auth, const char *username, const char *password);
    auth_result (*deleteuser)(struct auth_tag *auth, const char *username);
    auth_result (*listuser)(struct auth_tag *auth, xmlNodePtr srcnode);

69
    mutex_t lock;
70
71
72
    int refcount;
    int allow_duplicate_users;

Michael Smith's avatar
Michael Smith committed
73
    void *state;
74
    char *type;
Michael Smith's avatar
Michael Smith committed
75
76
} auth_t;

77
78
79
80
void add_client (const char *mount, client_t *client);
int  release_client (client_t *client);

void auth_initialise ();
81
82
void auth_shutdown ();

83
84
85
86
87
88
89
90
auth_t  *auth_get_authenticator (xmlNodePtr node);
void    auth_release (auth_t *authenticator);

/* call to send a url request when source starts */
void auth_stream_start (struct _mount_proxy *mountinfo, const char *mount);

/* call to send a url request when source ends */
void auth_stream_end (struct _mount_proxy *mountinfo, const char *mount);
Michael Smith's avatar
Michael Smith committed
91

92
93
94
/* called from auth thread, after the client has successfully authenticated
 * and requires adding to source or fserve. */
int auth_postprocess_client (auth_client *auth_user);
Michael Smith's avatar
Michael Smith committed
95
96
97
98

#endif