mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-01 11:32:25 +00:00
Make ACL be what SIP is going to need (bug #2358, just first part)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5155 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
29
acl.c
29
acl.c
@@ -49,6 +49,7 @@ struct ast_netsock {
|
|||||||
int sockfd;
|
int sockfd;
|
||||||
int *ioref;
|
int *ioref;
|
||||||
struct io_context *ioc;
|
struct io_context *ioc;
|
||||||
|
void *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -317,25 +318,25 @@ struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, struct i
|
|||||||
if (setsockopt(netsocket, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))
|
if (setsockopt(netsocket, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))
|
||||||
ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
|
ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
|
||||||
|
|
||||||
/* Establish I/O callback for socket read */
|
|
||||||
ioref = ast_io_add(ioc, netsocket, callback, AST_IO_IN, data);
|
|
||||||
if (!ioref) {
|
|
||||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
|
||||||
close(netsocket);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ns = malloc(sizeof(struct ast_netsock));
|
ns = malloc(sizeof(struct ast_netsock));
|
||||||
if (ns) {
|
if (ns) {
|
||||||
|
/* Establish I/O callback for socket read */
|
||||||
|
ioref = ast_io_add(ioc, netsocket, callback, AST_IO_IN, ns);
|
||||||
|
if (!ioref) {
|
||||||
|
ast_log(LOG_WARNING, "Out of memory!\n");
|
||||||
|
close(netsocket);
|
||||||
|
free(ns);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
ASTOBJ_INIT(ns);
|
ASTOBJ_INIT(ns);
|
||||||
ns->ioref = ioref;
|
ns->ioref = ioref;
|
||||||
ns->ioc = ioc;
|
ns->ioc = ioc;
|
||||||
ns->sockfd = netsocket;
|
ns->sockfd = netsocket;
|
||||||
|
ns->data = data;
|
||||||
memcpy(&ns->bindaddr, bindaddr, sizeof(ns->bindaddr));
|
memcpy(&ns->bindaddr, bindaddr, sizeof(ns->bindaddr));
|
||||||
ASTOBJ_CONTAINER_LINK(list, ns);
|
ASTOBJ_CONTAINER_LINK(list, ns);
|
||||||
} else {
|
} else {
|
||||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
ast_log(LOG_WARNING, "Out of memory!\n");
|
||||||
ast_io_remove(ioc, ioref);
|
|
||||||
close(netsocket);
|
close(netsocket);
|
||||||
}
|
}
|
||||||
return ns;
|
return ns;
|
||||||
@@ -362,6 +363,16 @@ int ast_netsock_release(struct ast_netsock_list *list)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct sockaddr_in *ast_netsock_boundaddr(struct ast_netsock *ns)
|
||||||
|
{
|
||||||
|
return &(ns->bindaddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ast_netsock_data(struct ast_netsock *ns)
|
||||||
|
{
|
||||||
|
return ns->data;
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ extern struct ast_netsock *ast_netsock_bindaddr(struct ast_netsock_list *list, s
|
|||||||
extern int ast_netsock_free(struct ast_netsock_list *list, struct ast_netsock *netsock);
|
extern int ast_netsock_free(struct ast_netsock_list *list, struct ast_netsock *netsock);
|
||||||
extern int ast_netsock_release(struct ast_netsock_list *list);
|
extern int ast_netsock_release(struct ast_netsock_list *list);
|
||||||
extern int ast_netsock_sockfd(struct ast_netsock *ns);
|
extern int ast_netsock_sockfd(struct ast_netsock *ns);
|
||||||
|
extern const struct sockaddr_in *ast_netsock_boundaddr(struct ast_netsock *ns);
|
||||||
|
extern void *ast_netsock_data(struct ast_netsock *ns);
|
||||||
extern int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr);
|
extern int ast_find_ourip(struct in_addr *ourip, struct sockaddr_in bindaddr);
|
||||||
|
|
||||||
/*! Compares the source address and port of two sockaddr_in */
|
/*! Compares the source address and port of two sockaddr_in */
|
||||||
|
|||||||
Reference in New Issue
Block a user