expose struct ast_ha so external code can do things such as printing it
[asterisk/asterisk.git] / include / asterisk / acl.h
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2006, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  * \brief Access Control of various sorts
21  */
22
23 #ifndef _ASTERISK_ACL_H
24 #define _ASTERISK_ACL_H
25
26
27 #if defined(__cplusplus) || defined(c_plusplus)
28 extern "C" {
29 #endif
30
31 #include <netinet/in.h>
32 #include "asterisk/io.h"
33
34 #define AST_SENSE_DENY                  0
35 #define AST_SENSE_ALLOW                 1
36
37 /* Host based access control */
38
39 /*! \brief internal representation of acl entries
40  * In principle user applications would have no need for this,
41  * but there is sometimes a need to extract individual items,
42  * e.g. to print them, and rather than defining iterators to
43  * navigate the list, and an externally visible 'struct ast_ha_entry',
44  * at least in the short term it is more convenient to make the whole
45  * thing public and let users play with them.
46  */
47 struct ast_ha {
48         /* Host access rule */
49         struct in_addr netaddr;  
50         struct in_addr netmask;
51         int sense;
52         struct ast_ha *next;
53 };
54
55 /*! \brief Free host access list */
56 void ast_free_ha(struct ast_ha *ha);
57
58 /*! \brief Append ACL entry to host access list. */
59 struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path, int *error);
60
61 /*! \brief Check IP address with host access list */
62 int ast_apply_ha(struct ast_ha *ha, struct sockaddr_in *sin);
63
64 /*! \brief Copy host access list */
65 struct ast_ha *ast_duplicate_ha_list(struct ast_ha *original);
66
67 int ast_get_ip(struct sockaddr_in *sin, const char *value);
68
69 int ast_get_ip_or_srv(struct sockaddr_in *sin, const char *value, const char *service);
70
71 int ast_ouraddrfor(struct in_addr *them, struct in_addr *us);
72
73 int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr);
74
75 int ast_str2cos(const char *value, unsigned int *cos);
76
77 int ast_str2tos(const char *value, unsigned int *tos);
78 const char *ast_tos2str(unsigned int tos);
79
80 #if defined(__cplusplus) || defined(c_plusplus)
81 }
82 #endif
83
84 #endif /* _ASTERISK_ACL_H */