From: Ramon G. F. <ra...@pd...> - 2004-03-07 13:36:42
|
CVS Root: /cvs/gstreamer Module: gst-sandbox Changes by: ramon Date: Sun Mar 07 2004 05:28:46 PST Log message: weekend work Modified files: rtpdec : address.c address.h socket_fns.c socket_fns.h Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/rtpdec/address.c.diff?r1=1.1&r2=1.2 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/rtpdec/address.h.diff?r1=1.4&r2=1.5 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/rtpdec/socket_fns.c.diff?r1=1.2&r2=1.3 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/rtpdec/socket_fns.h.diff?r1=1.2&r2=1.3 ====Begin Diffs==== Index: address.c =================================================================== RCS file: /cvs/gstreamer/gst-sandbox/rtpdec/address.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- a/address.c 27 Feb 2004 04:47:28 -0000 1.1 +++ b/address.c 7 Mar 2004 13:28:34 -0000 1.2 @@ -5,18 +5,6 @@ static void gst_address_free(gpointer); -static gpointer gst_address_list_copy(gpointer); - -static void gst_address_list_free(gpointer); -static gpointer gst_addr_port_copy(gpointer); -static void gst_addr_port_free(gpointer); -static gpointer gst_addr_port_list_copy(gpointer); -static void gst_addr_port_list_free(gpointer); static void resolve_name(const gchar* name, GstNumAddress* result); GType @@ -53,117 +41,16 @@ g_free(ptr); } -GType -gst_address_list_get_type(void) { - static GType type = 0; - if (type == 0) { - type = g_boxed_type_register_static("GstAddressList", - gst_address_list_copy, - gst_address_list_free); - } - return type; -} -static gpointer -gst_address_list_copy(gpointer src) -{ - GList* src_list = (GList*) src; - GList* dest_list = NULL; - GList* list_node = src_list; - while (list_node != NULL) { - dest_list = g_list_append(dest_list, gst_address_copy(list_node->data)); - list_node = g_list_next(list_node); - return (gpointer) dest_list; -static void -gst_address_list_free(gpointer ptr) - GList* ptr_list = (GList*) ptr; - GList* list_node = ptr_list; - gst_address_free(list_node->data); - list_node = g_list_remove_link(list_node, list_node); -static gpointer -gst_addr_port_copy(gpointer src) - GstAddrPort* addr_src = (GstAddrPort*) src; - GstAddrPort* addr_result; - addr_result = g_new0(GstAddrPort, 1); - *addr_result = *addr_src; - if (addr_src->addr.type == NAME) { - addr_result->addr.addr.name = g_strdup(addr_src->addr.addr.name); - return (gpointer) addr_result; -static void -gst_addr_port_free(gpointer ptr) - GstAddrPort* addr_ptr = (GstAddrPort*) ptr; - if (addr_ptr->addr.type == NAME) { - g_free(addr_ptr->addr.addr.name); - g_free(ptr); -gst_addr_port_get_type(void) - type = g_boxed_type_register_static("GstAddrPort", - gst_addr_port_copy, - gst_addr_port_free); -GType -gst_addr_port_list_get_type(void) - type = g_boxed_type_register_static("GstAddrPortList", - gst_addr_port_list_copy, - gst_addr_port_list_free); -gst_addr_port_list_copy(gpointer src) - dest_list = g_list_append(dest_list, gst_addr_port_copy(list_node->data)); -gst_addr_port_list_free(gpointer ptr) +void +gst_addr_free_num_address(GstNumAddress* addr) { - gst_addr_port_free(list_node->data); + if (addr->alternatives) { + g_free(addr->alternatives); } void -resolve_address(const GstAddress* address, GstNumAddress* result) +gst_addr_resolve_address(const GstAddress* address, GstNumAddress* result) if (result->alternatives != NULL) { g_free(result->alternatives); @@ -186,7 +73,6 @@ static void resolve_name(const gchar* name, GstNumAddress* result) @@ -252,3 +138,28 @@ break; + +gboolean +gst_addr_allowed(GstAuthorizedAddrs* acls, struct sockaddr_in6* peer) +{ + GstAuthorizedAddr* acl_entry; + GstNumAddr* addr; + struct in6_addr* addr_alt; + unsigned int i, j; + for (i = 0; i < acls->authorized_addrs->len; i ++) { + acl_entry = ((GstAuthorizedAddr *) acls->authorized_addrs->data)[i]; + if (peer->sin6_port < acl_entry->low || + peer->sin6_port > acl_entry->high) + continue; + addr = &acl_entry->addr; + for (j = 0; j < addr->alternatives->len; j++) { + addr_alt = ((struct in6_addr*) + addr->alternatives->data)[j]; + if (memcpy(addr_alt, peer->sin6_addr, sizeof(struct sockaddr_in6))) { + return TRUE; + } + } + } + return FALSE; +} Index: address.h RCS file: /cvs/gstreamer/gst-sandbox/rtpdec/address.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- a/address.h 5 Mar 2004 01:08:00 -0000 1.4 +++ b/address.h 7 Mar 2004 13:28:34 -0000 1.5 @@ -46,9 +46,12 @@ typedef struct _GstAuthorizedAddrs GstAuthorizedAddrs; +void gst_addr_free_num_address(GstNumAddress* addr); void gst_addr_resolve_address(const GstAddress* address, GstNumAddress* result); +gboolean gst_addr_in_list(const GstAddress* address, struct in6_addr addr); -gboolean gst_addr_try_bind(int socket, const GstNumAddress* address, int port); +gboolean gst_addr_try_bind(int socket, const GstNumAddress* address, in_port_t port); void gst_addr_try_send(int socket, GstNumAddress* remote, in_port_t port, const char* data, guint size); Index: socket_fns.c RCS file: /cvs/gstreamer/gst-sandbox/rtpdec/socket_fns.c,v retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- a/socket_fns.c 5 Mar 2004 01:08:00 -0000 1.2 +++ b/socket_fns.c 7 Mar 2004 13:28:34 -0000 1.3 @@ -84,3 +84,85 @@ element->mtu = mtu; write(element->report_thread_pipe[1], &m, 1); +authorized_packet(GstRtpdec* element, struct sockaddr_in6* addr, packet_type* type) + if (element->default_authorized) { + if (element->multicast_mode) { + return TRUE; + } else { + return gst_addr_in_list(element->remote_address); + } else { + return gst_addr_allowed(element->authorized_senders, addr); +gst_rtpdec_open_conn(GstElement* element) + int error; + gboolean bound; + bound = FALSE; + if (element->data_port < 0 && element->control_port < 0) { + bound = try_bind(element, 5004, &element->data_socket); + if (bound) { + bound = try_bind(element, 5005, &element->control_socket); + if (!bound) { + close(element->data_socket); + } + if (!bound) { + bound = try_bind_both_random(element); + if (!bound) + goto error; + } else if (element->data_port > 0 && element->control_port < 0) { + bound = try_bind(element, element->data_port, &element->data_socket); + bound = try_bind(element, element->data_port + 1, &element->control_socket); + bound = try_bind_random(element, &element->control_socket); + } else { + bound = try_bind_both_random(element); + } + error: + if (element->control_socket >= 0) { + close(element->control_socket); + if (element->data_socket >= 0) { + close(element->data_socket); + return FALSE; +gboolen +try_bind_one(GstRtpdec* element, in_port_t port, int* socket) + struct sockaddr_in6 addr; + int i; + gboolean result; + *socket = socket(AF_INET6, SOCK_DGRAM, 0); + result = gst_addr_try_bind(*socket, element->local_address, port); + if (!result) { + close(*socket); + *socket = -1; + return result; +static gboolean +try_bind_random(GstRtpdec* element, int* socket) + result = gst_addr_try_bind(*socket, element->local_address, ); Index: socket_fns.h RCS file: /cvs/gstreamer/gst-sandbox/rtpdec/socket_fns.h,v --- a/socket_fns.h 2 Mar 2004 06:31:12 -0000 1.2 +++ b/socket_fns.h 7 Mar 2004 13:28:34 -0000 1.3 @@ -9,20 +9,6 @@ gboolean authorized_packet(GstRtpdec* element, struct sockaddr_in6* addr, packet_type* type); -void gst_rtpdec_set_data_port(guint port); -void gst_rtpdec_set_ctl_port(guint port); -void gst_rtpdec_set_local_addr(GstAddress* addr); -void gst_rtpdec_set_remote_addr(GstAddress* addr); -void gst_rtpdec_set_remote_data_port(guint port); -void gst_rtpdec_set_remote_ctl_port(guint port); -void gst_rtpdec_set_multicast_addr(GstAddress* addr); gboolean gst_rtpdec_open_conn(GstElement* element); void gst_rtpdec_close_conn(GstElement* element); |