auth.h 3.06 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
    AUTH_USERADDED,
    AUTH_USEREXISTS,
38
    AUTH_USERDELETED
Michael Smith's avatar
Michael Smith committed
39
40
} auth_result;

41
42
43
44
typedef struct auth_client_tag
{
    char        *mount;
    client_t    *client;
45
    void        (*process)(struct auth_tag *auth, struct auth_client_tag *auth_user);
46
47
48
49
    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
    auth_result (*authenticate)(auth_client *aclient);
56
    auth_result (*release_listener)(auth_client *auth_user);
57

58
59
60
    /* auth handler for authenicating a connecting source client */
    void (*stream_auth)(auth_client *auth_user);

61
    /* auth handler for source startup, no client passed as it may disappear */
62
    void (*stream_start)(auth_client *auth_user);
63
64

    /* auth handler for source exit, no client passed as it may disappear */
65
66
    void (*stream_end)(auth_client *auth_user);

67
    /* auth state-specific free call */
Michael Smith's avatar
Michael Smith committed
68
    void (*free)(struct auth_tag *self);
69

70
71
72
73
    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);

74
    mutex_t lock;
75
    int running;
76
77
78
    int refcount;
    int allow_duplicate_users;

79
80
81
82
83
84
    thread_type *thread;

    /* per-auth queue for clients */
    auth_client *head, **tailp;
    int pending_count;

Michael Smith's avatar
Michael Smith committed
85
    void *state;
86
    char *type;
Michael Smith's avatar
Michael Smith committed
87
88
} auth_t;

89
90
void auth_add_listener (const char *mount, client_t *client);
int  auth_release_listener (client_t *client);
91

92
93
void auth_initialise (void);
void auth_shutdown (void);
94

95
96
97
auth_t  *auth_get_authenticator (xmlNodePtr node);
void    auth_release (auth_t *authenticator);

98
/* call to trigger an event when a stream starts */
99
100
void auth_stream_start (struct _mount_proxy *mountinfo, const char *mount);

101
/* call to trigger an event when a stream ends */
102
void auth_stream_end (struct _mount_proxy *mountinfo, const char *mount);
Michael Smith's avatar
Michael Smith committed
103

104
105
106
/* call to trigger an event to authenticate a source client */
int auth_stream_authenticate (client_t *client, const char *mount, struct _mount_proxy *mountinfo);

107
108
/* called from auth thread, after the client has successfully authenticated
 * and requires adding to source or fserve. */
109
int auth_postprocess_listener (auth_client *auth_user);
Michael Smith's avatar
Michael Smith committed
110
111
112
113

#endif