auth.h 2.79 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
    /* auth handler for source startup, no client passed as it may disappear */
59
    void (*stream_start)(auth_client *auth_user);
60
61

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

64
    /* auth state-specific free call */
Michael Smith's avatar
Michael Smith committed
65
    void (*free)(struct auth_tag *self);
66

67
68
69
70
    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);

71
    mutex_t lock;
72
    int running;
73
74
75
    int refcount;
    int allow_duplicate_users;

76
77
78
79
80
81
    thread_type *thread;

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

Michael Smith's avatar
Michael Smith committed
82
    void *state;
83
    char *type;
Michael Smith's avatar
Michael Smith committed
84
85
} auth_t;

86
87
void auth_add_listener (const char *mount, client_t *client);
int  auth_release_listener (client_t *client);
88

89
90
void auth_initialise (void);
void auth_shutdown (void);
91

92
93
94
95
96
97
98
99
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
100

101
102
/* called from auth thread, after the client has successfully authenticated
 * and requires adding to source or fserve. */
103
int auth_postprocess_listener (auth_client *auth_user);
Michael Smith's avatar
Michael Smith committed
104
105
106
107

#endif