Make ACL be what SIP is going to need (bug #2358, just first part)
[asterisk/asterisk.git] / include / asterisk / acl.h
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Access Control of various sorts
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #ifndef _ASTERISK_ACL_H
15 #define _ASTERISK_ACL_H
16
17
18 #if defined(__cplusplus) || defined(c_plusplus)
19 extern "C" {
20 #endif
21
22 #include <netinet/in.h>
23 #include <asterisk/io.h>
24 #include <asterisk/astobj.h>
25
26 #define AST_SENSE_DENY                  0
27 #define AST_SENSE_ALLOW                 1
28
29 /* Host based access control */
30
31 struct ast_ha;
32 struct ast_netsock;
33
34 struct ast_netsock_list {
35         ASTOBJ_CONTAINER_COMPONENTS(struct ast_netsock);
36         struct io_context *ioc;
37 };
38
39 extern void ast_free_ha(struct ast_ha *ha);
40 extern struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path);
41 extern int ast_apply_ha(struct ast_ha *ha, struct sockaddr_in *sin);
42 extern int ast_get_ip(struct sockaddr_in *sin, const char *value);
43 extern int ast_get_ip_or_srv(struct sockaddr_in *sin, const char *value, const char *service);
44 extern int ast_ouraddrfor(struct in_addr *them, struct in_addr *us);
45 extern int ast_lookup_iface(char *iface, struct in_addr *address);
46 extern struct ast_ha *ast_duplicate_ha_list(struct ast_ha *original);
47 extern int ast_netsock_init(struct ast_netsock_list *list);
48 extern struct ast_netsock *ast_netsock_bind(struct ast_netsock_list *list, struct io_context *ioc, const char *bindinfo, int defaultport, int tos, ast_io_cb callback, void *data);
49 extern struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, struct io_context *ioc, struct sockaddr_in *bindaddr, int tos, ast_io_cb callback, void *data);
50 extern int ast_netsock_free(struct ast_netsock_list *list, struct ast_netsock *netsock);
51 extern int ast_netsock_release(struct ast_netsock_list *list);
52 extern int ast_netsock_sockfd(struct ast_netsock *ns);
53 extern const struct sockaddr_in *ast_netsock_boundaddr(struct ast_netsock *ns);
54 extern void *ast_netsock_data(struct ast_netsock *ns);
55 extern int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr);
56
57 /*! Compares the source address and port of two sockaddr_in */
58 static inline int inaddrcmp(struct sockaddr_in *sin1, struct sockaddr_in *sin2)
59 {
60         return ((sin1->sin_addr.s_addr != sin2->sin_addr.s_addr ) 
61                 || (sin1->sin_port != sin2->sin_port));
62 }
63
64 #if defined(__cplusplus) || defined(c_plusplus)
65 }
66 #endif
67
68 #endif