From: <enl...@li...> - 2002-05-21 04:20:56
|
Enlightenment CVS committal Author : mej Project : eterm Module : libast Dir : eterm/libast/src Modified Files: array.c dlinked_list.c linked_list.c mem.c obj.c socket.c str.c strings.c tok.c url.c Log Message: Tue May 21 00:15:37 2002 Michael Jennings (mej) Fixed a number of memory leaks in both the testing code and the object classes themselves. Also rearranged some header stuff and created a few new helper macros for object declarations. =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/array.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- array.c 29 Apr 2002 19:26:51 -0000 1.3 +++ array.c 21 May 2002 04:20:25 -0000 1.4 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: array.c,v 1.3 2002/04/29 19:26:51 mej Exp $"; +static const char cvs_ident[] = "$Id: array.c,v 1.4 2002/05/21 04:20:25 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -56,29 +56,29 @@ static spif_const_listclass_t a_class = { { SPIF_DECL_CLASSNAME(array), - (spif_newfunc_t) spif_array_new, - (spif_memberfunc_t) spif_array_init, - (spif_memberfunc_t) spif_array_done, - (spif_memberfunc_t) spif_array_del, + (spif_func_t) spif_array_new, + (spif_func_t) spif_array_init, + (spif_func_t) spif_array_done, + (spif_func_t) spif_array_del, (spif_func_t) spif_array_show, (spif_func_t) spif_array_comp, (spif_func_t) spif_array_dup, (spif_func_t) spif_array_type }, - (spif_memberfunc_t) spif_array_append, - (spif_memberfunc_t) spif_array_contains, - (spif_memberfunc_t) spif_array_count, - (spif_memberfunc_t) spif_array_get, - (spif_memberfunc_t) spif_array_index, - (spif_memberfunc_t) spif_array_insert, - (spif_memberfunc_t) spif_array_insert_at, - (spif_memberfunc_t) spif_array_iterator, - (spif_memberfunc_t) spif_array_next, - (spif_memberfunc_t) spif_array_prepend, - (spif_memberfunc_t) spif_array_remove, - (spif_memberfunc_t) spif_array_remove_at, - (spif_memberfunc_t) spif_array_reverse, - (spif_memberfunc_t) spif_array_to_array + (spif_func_t) spif_array_append, + (spif_func_t) spif_array_contains, + (spif_func_t) spif_array_count, + (spif_func_t) spif_array_get, + (spif_func_t) spif_array_index, + (spif_func_t) spif_array_insert, + (spif_func_t) spif_array_insert_at, + (spif_func_t) spif_array_iterator, + (spif_func_t) spif_array_next, + (spif_func_t) spif_array_prepend, + (spif_func_t) spif_array_remove, + (spif_func_t) spif_array_remove_at, + (spif_func_t) spif_array_reverse, + (spif_func_t) spif_array_to_array }; spif_listclass_t SPIF_CLASS_VAR(array) = &a_class; /* *INDENT-ON* */ @@ -109,12 +109,12 @@ size_t i; for (i = 0; i < self->len; i++) { - if (self->items[i]) { + if (!SPIF_OBJ_ISNULL(self->items[i])) { SPIF_OBJ_DEL(self->items[i]); } } self->len = 0; - self->items = SPIF_NULL_CTYPE(spif_obj_t *); + FREE(self->items); return TRUE; } =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/dlinked_list.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- dlinked_list.c 29 Apr 2002 19:26:51 -0000 1.3 +++ dlinked_list.c 21 May 2002 04:20:25 -0000 1.4 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: dlinked_list.c,v 1.3 2002/04/29 19:26:51 mej Exp $"; +static const char cvs_ident[] = "$Id: dlinked_list.c,v 1.4 2002/05/21 04:20:25 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -66,10 +66,10 @@ /* *INDENT-OFF* */ static spif_const_class_t dli_class = { SPIF_DECL_CLASSNAME(dlinked_list_item), - (spif_newfunc_t) spif_dlinked_list_item_new, - (spif_memberfunc_t) spif_dlinked_list_item_init, - (spif_memberfunc_t) spif_dlinked_list_item_done, - (spif_memberfunc_t) spif_dlinked_list_item_del, + (spif_func_t) spif_dlinked_list_item_new, + (spif_func_t) spif_dlinked_list_item_init, + (spif_func_t) spif_dlinked_list_item_done, + (spif_func_t) spif_dlinked_list_item_del, (spif_func_t) spif_dlinked_list_item_show, (spif_func_t) spif_dlinked_list_item_comp, (spif_func_t) spif_dlinked_list_item_dup, @@ -80,29 +80,29 @@ static spif_const_listclass_t dl_class = { { SPIF_DECL_CLASSNAME(dlinked_list), - (spif_newfunc_t) spif_dlinked_list_new, - (spif_memberfunc_t) spif_dlinked_list_init, - (spif_memberfunc_t) spif_dlinked_list_done, - (spif_memberfunc_t) spif_dlinked_list_del, + (spif_func_t) spif_dlinked_list_new, + (spif_func_t) spif_dlinked_list_init, + (spif_func_t) spif_dlinked_list_done, + (spif_func_t) spif_dlinked_list_del, (spif_func_t) spif_dlinked_list_show, (spif_func_t) spif_dlinked_list_comp, (spif_func_t) spif_dlinked_list_dup, (spif_func_t) spif_dlinked_list_type }, - (spif_memberfunc_t) spif_dlinked_list_append, - (spif_memberfunc_t) spif_dlinked_list_contains, - (spif_memberfunc_t) spif_dlinked_list_count, - (spif_memberfunc_t) spif_dlinked_list_get, - (spif_memberfunc_t) spif_dlinked_list_index, - (spif_memberfunc_t) spif_dlinked_list_insert, - (spif_memberfunc_t) spif_dlinked_list_insert_at, - (spif_memberfunc_t) spif_dlinked_list_iterator, - (spif_memberfunc_t) spif_dlinked_list_next, - (spif_memberfunc_t) spif_dlinked_list_prepend, - (spif_memberfunc_t) spif_dlinked_list_remove, - (spif_memberfunc_t) spif_dlinked_list_remove_at, - (spif_memberfunc_t) spif_dlinked_list_reverse, - (spif_memberfunc_t) spif_dlinked_list_to_array + (spif_func_t) spif_dlinked_list_append, + (spif_func_t) spif_dlinked_list_contains, + (spif_func_t) spif_dlinked_list_count, + (spif_func_t) spif_dlinked_list_get, + (spif_func_t) spif_dlinked_list_index, + (spif_func_t) spif_dlinked_list_insert, + (spif_func_t) spif_dlinked_list_insert_at, + (spif_func_t) spif_dlinked_list_iterator, + (spif_func_t) spif_dlinked_list_next, + (spif_func_t) spif_dlinked_list_prepend, + (spif_func_t) spif_dlinked_list_remove, + (spif_func_t) spif_dlinked_list_remove_at, + (spif_func_t) spif_dlinked_list_reverse, + (spif_func_t) spif_dlinked_list_to_array }; spif_listclass_t SPIF_CLASS_VAR(dlinked_list) = &dl_class; /* *INDENT-ON* */ =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/linked_list.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- linked_list.c 29 Apr 2002 19:26:51 -0000 1.6 +++ linked_list.c 21 May 2002 04:20:25 -0000 1.7 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: linked_list.c,v 1.6 2002/04/29 19:26:51 mej Exp $"; +static const char cvs_ident[] = "$Id: linked_list.c,v 1.7 2002/05/21 04:20:25 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -66,10 +66,10 @@ /* *INDENT-OFF* */ static spif_const_class_t lli_class = { SPIF_DECL_CLASSNAME(linked_list_item), - (spif_newfunc_t) spif_linked_list_item_new, - (spif_memberfunc_t) spif_linked_list_item_init, - (spif_memberfunc_t) spif_linked_list_item_done, - (spif_memberfunc_t) spif_linked_list_item_del, + (spif_func_t) spif_linked_list_item_new, + (spif_func_t) spif_linked_list_item_init, + (spif_func_t) spif_linked_list_item_done, + (spif_func_t) spif_linked_list_item_del, (spif_func_t) spif_linked_list_item_show, (spif_func_t) spif_linked_list_item_comp, (spif_func_t) spif_linked_list_item_dup, @@ -80,29 +80,29 @@ static spif_const_listclass_t ll_class = { { SPIF_DECL_CLASSNAME(linked_list), - (spif_newfunc_t) spif_linked_list_new, - (spif_memberfunc_t) spif_linked_list_init, - (spif_memberfunc_t) spif_linked_list_done, - (spif_memberfunc_t) spif_linked_list_del, + (spif_func_t) spif_linked_list_new, + (spif_func_t) spif_linked_list_init, + (spif_func_t) spif_linked_list_done, + (spif_func_t) spif_linked_list_del, (spif_func_t) spif_linked_list_show, (spif_func_t) spif_linked_list_comp, (spif_func_t) spif_linked_list_dup, (spif_func_t) spif_linked_list_type }, - (spif_memberfunc_t) spif_linked_list_append, - (spif_memberfunc_t) spif_linked_list_contains, - (spif_memberfunc_t) spif_linked_list_count, - (spif_memberfunc_t) spif_linked_list_get, - (spif_memberfunc_t) spif_linked_list_index, - (spif_memberfunc_t) spif_linked_list_insert, - (spif_memberfunc_t) spif_linked_list_insert_at, - (spif_memberfunc_t) spif_linked_list_iterator, - (spif_memberfunc_t) spif_linked_list_next, - (spif_memberfunc_t) spif_linked_list_prepend, - (spif_memberfunc_t) spif_linked_list_remove, - (spif_memberfunc_t) spif_linked_list_remove_at, - (spif_memberfunc_t) spif_linked_list_reverse, - (spif_memberfunc_t) spif_linked_list_to_array + (spif_func_t) spif_linked_list_append, + (spif_func_t) spif_linked_list_contains, + (spif_func_t) spif_linked_list_count, + (spif_func_t) spif_linked_list_get, + (spif_func_t) spif_linked_list_index, + (spif_func_t) spif_linked_list_insert, + (spif_func_t) spif_linked_list_insert_at, + (spif_func_t) spif_linked_list_iterator, + (spif_func_t) spif_linked_list_next, + (spif_func_t) spif_linked_list_prepend, + (spif_func_t) spif_linked_list_remove, + (spif_func_t) spif_linked_list_remove_at, + (spif_func_t) spif_linked_list_reverse, + (spif_func_t) spif_linked_list_to_array }; spif_listclass_t SPIF_CLASS_VAR(linked_list) = &ll_class; /* *INDENT-ON* */ =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/mem.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- mem.c 5 Apr 2002 03:28:43 -0000 1.4 +++ mem.c 21 May 2002 04:20:25 -0000 1.5 @@ -22,7 +22,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: mem.c,v 1.4 2002/04/05 03:28:43 mej Exp $"; +static const char cvs_ident[] = "$Id: mem.c,v 1.5 2002/05/21 04:20:25 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -458,18 +458,18 @@ /* Convenience function for freeing a list. */ void -free_array(void **list, size_t count) +free_array(void *list, size_t count) { register size_t i; + void **l = (void **) list; REQUIRE(list != NULL); if (count == 0) { count = (size_t) (-1); } - for (i = 0; i < count && list[i]; i++) { - FREE(list[i]); - list[i] = NULL; + for (i = 0; i < count && l[i]; i++) { + FREE(l[i]); } FREE(list); } =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/obj.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- obj.c 11 Apr 2002 22:04:55 -0000 1.7 +++ obj.c 21 May 2002 04:20:25 -0000 1.8 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: obj.c,v 1.7 2002/04/11 22:04:55 mej Exp $"; +static const char cvs_ident[] = "$Id: obj.c,v 1.8 2002/05/21 04:20:25 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -32,10 +32,10 @@ /* *INDENT-OFF* */ static spif_const_class_t o_class = { SPIF_DECL_CLASSNAME(obj), - (spif_newfunc_t) spif_obj_new, - (spif_memberfunc_t) spif_obj_init, - (spif_memberfunc_t) spif_obj_done, - (spif_memberfunc_t) spif_obj_del, + (spif_func_t) spif_obj_new, + (spif_func_t) spif_obj_init, + (spif_func_t) spif_obj_done, + (spif_func_t) spif_obj_del, (spif_func_t) spif_obj_show, (spif_func_t) spif_obj_comp, (spif_func_t) spif_obj_dup, @@ -127,6 +127,11 @@ spif_obj_show(spif_obj_t self, spif_charptr_t name, spif_str_t buff, size_t indent) { char tmp[4096]; + + if (SPIF_OBJ_ISNULL(self)) { + SPIF_OBJ_SHOW_NULL("obj", name, buff, indent); + return buff; + } memset(tmp, ' ', indent); snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_obj_t) %s: (spif_obj_t) { \"%s\" }\n", name, SPIF_OBJ_CLASSNAME(self)); =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/socket.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- socket.c 7 May 2002 20:39:01 -0000 1.2 +++ socket.c 21 May 2002 04:20:25 -0000 1.3 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: socket.c,v 1.2 2002/05/07 20:39:01 mej Exp $"; +static const char cvs_ident[] = "$Id: socket.c,v 1.3 2002/05/21 04:20:25 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -29,15 +29,18 @@ #include <libast_internal.h> -static spif_uint32_t spif_socket_get_ipaddr(spif_socket_t); +static spif_ipsockaddr_t spif_url_get_ipaddr(spif_url_t); +static spif_unixsockaddr_t spif_url_get_unixaddr(spif_url_t); +static spif_sockport_t spif_url_get_portnum(spif_url_t); +static spif_bool_t spif_socket_get_proto(spif_socket_t); /* *INDENT-OFF* */ static spif_const_class_t o_class = { SPIF_DECL_CLASSNAME(socket), - (spif_newfunc_t) spif_socket_new, - (spif_memberfunc_t) spif_socket_init, - (spif_memberfunc_t) spif_socket_done, - (spif_memberfunc_t) spif_socket_del, + (spif_func_t) spif_socket_new, + (spif_func_t) spif_socket_init, + (spif_func_t) spif_socket_done, + (spif_func_t) spif_socket_del, (spif_func_t) spif_socket_show, (spif_func_t) spif_socket_comp, (spif_func_t) spif_socket_dup, @@ -102,6 +105,11 @@ { char tmp[4096]; + if (SPIF_SOCKET_ISNULL(self)) { + SPIF_OBJ_SHOW_NULL("socket", name, buff, indent); + return buff; + } + memset(tmp, ' ', indent); snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_socket_t) %s: {\n", name); if (SPIF_STR_ISNULL(buff)) { @@ -109,13 +117,34 @@ } else { spif_str_append_from_ptr(buff, tmp); } + + indent += 2; + memset(tmp, ' ', indent); + snprintf(tmp + indent, sizeof(tmp) - indent, "(int) fd: %d\n", self->fd); + spif_str_append_from_ptr(buff, tmp); + + snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_uint32_t) flags: %lu\n", (unsigned long) self->flags); + spif_str_append_from_ptr(buff, tmp); + + snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_sockaddr_t) addr: %8p\n", self->addr); + spif_str_append_from_ptr(buff, tmp); + + spif_url_show(self->src_url, "src_url", buff, indent); + spif_url_show(self->dest_url, "dest_url", buff, indent); + spif_str_show(self->input, "input", buff, indent); + spif_str_show(self->output, "output", buff, indent); + + indent -= 2; + snprintf(tmp + indent, sizeof(tmp) - indent, "}\n"); + spif_str_append_from_ptr(buff, tmp); + return buff; } spif_cmp_t spif_socket_comp(spif_socket_t self, spif_socket_t other) { - return (self == other); + return (self->fd == other->fd); } spif_socket_t @@ -137,21 +166,75 @@ spif_bool_t spif_socket_open(spif_socket_t self) { + REQUIRE_RVAL(!SPIF_SOCKET_ISNULL(self), 0); + if (!(self->addr)) { + spif_socket_get_proto(self); + + if (SPIF_SOCKET_FLAGS_IS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_INET)) { + self->fam = AF_INET; + self->addr = SPIF_CAST(sockaddr) spif_url_get_ipaddr(self->dest_url); + } else if (SPIF_SOCKET_FLAGS_IS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_UNIX)) { + self->fam = AF_UNIX; + self->addr = SPIF_CAST(sockaddr) spif_url_get_unixaddr(self->dest_url); + } else { + D_OBJ(("Unknown socket family 0x%08x!\n", SPIF_SOCKET_FLAGS_IS_SET(self, SPIF_SOCKET_FLAGS_FAMILY))); + ASSERT_NOTREACHED_RVAL(FALSE); + } + } + + if (self->fd < 0) { + if (SPIF_SOCKET_FLAGS_IS_SET(self, SPIF_SOCKET_FLAGS_TYPE_STREAM)) { + self->type = SOCK_STREAM; + } else if (SPIF_SOCKET_FLAGS_IS_SET(self, SPIF_SOCKET_FLAGS_TYPE_DGRAM)) { + self->type = SOCK_DGRAM; + } else if (SPIF_SOCKET_FLAGS_IS_SET(self, SPIF_SOCKET_FLAGS_TYPE_RAW)) { + self->type = SOCK_RAW; + } else { + D_OBJ(("Unknown socket type 0x%08x!\n", SPIF_SOCKET_FLAGS_IS_SET(self, SPIF_SOCKET_FLAGS_TYPE))); + ASSERT_NOTREACHED_RVAL(FALSE); + } + + self->fd = SPIF_CAST(sockfd) socket(self->fam, self->type, self->proto); + if (self->fd < 0) { + print_error("Unable to create socket(%d, %d, %d) -- %s\n", (int) self->fam, + (int) self->type, (int) self->proto, strerror(errno)); + return FALSE; + } + + if (!SPIF_URL_ISNULL(self->src_url)) { + if (SPIF_SOCKET_FLAGS_IS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_INET)) { + spif_ipsockaddr_t addr; + + addr = spif_url_get_ipaddr(self->src_url); + addr->sin_port = spif_url_get_portnum(self->src_url); + + if (bind(self->fd, SPIF_CAST(sockaddr) addr, SPIF_SIZEOF_TYPE(ipsockaddr))) { + print_error("Unable to bind socket %d to %s -- %s\n", (int) self->fd, + SPIF_STR_STR(self->src_url), strerror(errno)); + FREE(addr); + return FALSE; + } + FREE(addr); + } + } + } + + return TRUE; } -static spif_uint32_t -spif_socket_get_ipaddr(spif_socket_t self) +static spif_ipsockaddr_t +spif_url_get_ipaddr(spif_url_t self) { - struct hostent *hinfo; - struct in_addr *addr; char *ipaddr_str; - spif_str_t hostname; spif_uint8_t tries; + spif_hostinfo_t hinfo; + spif_ipsockaddr_t addr; + spif_str_t hostname; - REQUIRE_RVAL(!SPIF_SOCKET_ISNULL(self), 0); + REQUIRE_RVAL(!SPIF_URL_ISNULL(self), 0); - hostname = SPIF_STR(spif_url_get_host(SPIF_URL(self->dest_url))); + hostname = SPIF_STR(spif_url_get_host(self)); REQUIRE_RVAL(!SPIF_STR_ISNULL(hostname), 0); h_errno = 0; @@ -166,11 +249,94 @@ } ipaddr_str = hinfo->h_addr_list[0]; - addr = SPIF_CAST_C(struct in_addr *) MALLOC(sizeof(struct in_addr)); - if ((inet_aton(ipaddr_str, addr)) == 0) { + addr = SPIF_ALLOC(ipsockaddr); + addr->sin_family = AF_INET; + addr->sin_port = 0; + if ((inet_aton(ipaddr_str, &(addr->sin_addr))) == 0) { print_error("Invalid address \"%s\" returned by gethostbyname()\n", NONULL(ipaddr_str)); return 0; } + return addr; +} + +static spif_unixsockaddr_t +spif_url_get_unixaddr(spif_url_t self) +{ + spif_unixsockaddr_t addr; + + addr = SPIF_ALLOC(unixsockaddr); + addr->sun_family = AF_UNIX; + addr->sun_path[0] = 0; + strncat(addr->sun_path, SPIF_STR_STR(spif_url_get_path(self)), sizeof(addr->sun_path)); + return addr; +} + +static spif_sockport_t +spif_url_get_portnum(spif_url_t self) +{ + spif_str_t port_str; + + port_str = spif_url_get_port(self); + if (!SPIF_STR_ISNULL(port_str)) { + return SPIF_CAST(sockport) spif_str_to_num(port_str, 10); + } + + return SPIF_CAST(sockport) 0; +} + +static spif_bool_t +spif_socket_get_proto(spif_socket_t self) +{ + spif_url_t url; + spif_protoinfo_t proto; + spif_str_t proto_str; + spif_servinfo_t serv; + + url = ((SPIF_URL_ISNULL(self->dest_url)) ? (self->src_url) : (self->dest_url)); + + proto_str = spif_url_get_proto(url); + if (!SPIF_STR_ISNULL(proto_str)) { + if (SPIF_CMP_IS_EQUAL(spif_str_cmp_with_ptr(proto_str, "raw"))) { + spif_str_t target; + + SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_TYPE_RAW); + + target = spif_url_get_host(url); + if (SPIF_STR_ISNULL(target)) { + target = spif_url_get_path(url); + if (!SPIF_STR_ISNULL(target)) { + SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_UNIX); + } + } else { + SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_INET); + } + } else { + proto = getprotobyname(SPIF_STR_STR(proto_str)); + if (proto == NULL) { + /* If it's not a protocol, it's probably a service. */ + serv = getservbyname(SPIF_STR_STR(proto_str), "tcp"); + if (serv == NULL) { + serv = getservbyname(SPIF_STR_STR(proto_str), "udp"); + } + if (serv != NULL) { + proto = getprotobyname(serv->s_proto); + REQUIRE_RVAL(proto != NULL, FALSE); + self->port = serv->s_port; + } + } + self->proto = proto->p_proto; + if (!strcmp((char *) proto, "unix")) { + SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_UNIX); + } else { + SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_INET); + if (!strcmp((char *) proto, "tcp")) { + SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_TYPE_STREAM); + } else if (!strcmp((char *) proto, "udp")) { + SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_TYPE_DGRAM); + } + } + } + } - return *(SPIF_CAST_PTR(uint32) (addr)); + return TRUE; } =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/str.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -3 -r1.11 -r1.12 --- str.c 2 May 2002 03:22:26 -0000 1.11 +++ str.c 21 May 2002 04:20:25 -0000 1.12 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: str.c,v 1.11 2002/05/02 03:22:26 mej Exp $"; +static const char cvs_ident[] = "$Id: str.c,v 1.12 2002/05/21 04:20:25 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -32,10 +32,10 @@ /* *INDENT-OFF* */ static spif_const_class_t s_class = { SPIF_DECL_CLASSNAME(str), - (spif_newfunc_t) spif_str_new, - (spif_memberfunc_t) spif_str_init, - (spif_memberfunc_t) spif_str_done, - (spif_memberfunc_t) spif_str_del, + (spif_func_t) spif_str_new, + (spif_func_t) spif_str_init, + (spif_func_t) spif_str_done, + (spif_func_t) spif_str_del, (spif_func_t) spif_str_show, (spif_func_t) spif_str_cmp, (spif_func_t) spif_str_dup, @@ -411,6 +411,7 @@ } self->len = newsize - 1; memcpy(self->s, tmp, newsize); + FREE(tmp); return TRUE; } @@ -436,6 +437,7 @@ } self->len = newsize - 1; memcpy(self->s, tmp, newsize); + FREE(tmp); return TRUE; } @@ -496,13 +498,15 @@ { char tmp[4096]; - memset(tmp, ' ', indent); if (SPIF_STR_ISNULL(self)) { - snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_str_t) %s: " SPIF_NULLSTR_TYPE(str) "\n", NONULL(name)); - } else { - snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_str_t) %s: { \"%s\", len %lu, size %lu }\n", - name, self->s, (unsigned long) self->len, (unsigned long) self->mem); + SPIF_OBJ_SHOW_NULL("str", name, buff, indent); + return buff; } + + memset(tmp, ' ', indent); + snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_str_t) %s: { \"%s\", len %lu, size %lu }\n", + name, self->s, (unsigned long) self->len, (unsigned long) self->mem); + if (SPIF_STR_ISNULL(buff)) { buff = spif_str_new_from_ptr(tmp); } else { =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/strings.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- strings.c 2 May 2002 03:22:26 -0000 1.5 +++ strings.c 21 May 2002 04:20:25 -0000 1.6 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: strings.c,v 1.5 2002/05/02 03:22:26 mej Exp $"; +static const char cvs_ident[] = "$Id: strings.c,v 1.6 2002/05/21 04:20:25 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -149,11 +149,12 @@ register int result; char errbuf[256]; - if (!rexp) { + if (!str) { + FREE(rexp); + return FALSE; + } else if (!rexp) { rexp = (regex_t *) MALLOC(sizeof(regex_t)); } - - REQUIRE_RVAL(str != NULL, FALSE); if (pattern) { if ((result = regcomp(rexp, pattern, REG_EXTENDED)) != 0) { =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/tok.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -3 -r1.8 -r1.9 --- tok.c 19 Apr 2002 22:36:54 -0000 1.8 +++ tok.c 21 May 2002 04:20:25 -0000 1.9 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: tok.c,v 1.8 2002/04/19 22:36:54 mej Exp $"; +static const char cvs_ident[] = "$Id: tok.c,v 1.9 2002/05/21 04:20:25 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -32,10 +32,10 @@ /* *INDENT-OFF* */ static spif_const_class_t t_class = { SPIF_DECL_CLASSNAME(tok), - (spif_newfunc_t) spif_tok_new, - (spif_memberfunc_t) spif_tok_init, - (spif_memberfunc_t) spif_tok_done, - (spif_memberfunc_t) spif_tok_del, + (spif_func_t) spif_tok_new, + (spif_func_t) spif_tok_init, + (spif_func_t) spif_tok_done, + (spif_func_t) spif_tok_del, (spif_func_t) spif_tok_show, (spif_func_t) spif_tok_comp, (spif_func_t) spif_tok_dup, @@ -244,6 +244,11 @@ spif_tok_show(spif_tok_t self, spif_charptr_t name, spif_str_t buff, size_t indent) { char tmp[4096]; + + if (SPIF_TOK_ISNULL(self)) { + SPIF_OBJ_SHOW_NULL("tok", name, buff, indent); + return buff; + } memset(tmp, ' ', indent); snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_tok_t) %s: {\n", name); =================================================================== RCS file: /cvsroot/enlightenment/eterm/libast/src/url.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- url.c 2 May 2002 03:22:26 -0000 1.4 +++ url.c 21 May 2002 04:20:25 -0000 1.5 @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -static const char cvs_ident[] = "$Id: url.c,v 1.4 2002/05/02 03:22:26 mej Exp $"; +static const char cvs_ident[] = "$Id: url.c,v 1.5 2002/05/21 04:20:25 mej Exp $"; #ifdef HAVE_CONFIG_H # include <config.h> @@ -32,10 +32,10 @@ /* *INDENT-OFF* */ static spif_const_class_t u_class = { SPIF_DECL_CLASSNAME(url), - (spif_newfunc_t) spif_url_new, - (spif_memberfunc_t) spif_url_init, - (spif_memberfunc_t) spif_url_done, - (spif_memberfunc_t) spif_url_del, + (spif_func_t) spif_url_new, + (spif_func_t) spif_url_init, + (spif_func_t) spif_url_done, + (spif_func_t) spif_url_del, (spif_func_t) spif_url_show, (spif_func_t) spif_url_comp, (spif_func_t) spif_url_dup, @@ -135,31 +135,31 @@ spif_url_done(spif_url_t self) { if (!SPIF_STR_ISNULL(self->proto)) { - spif_str_done(self->proto); + spif_str_del(self->proto); self->proto = SPIF_NULL_TYPE(str); } if (!SPIF_STR_ISNULL(self->user)) { - spif_str_done(self->user); + spif_str_del(self->user); self->user = SPIF_NULL_TYPE(str); } if (!SPIF_STR_ISNULL(self->passwd)) { - spif_str_done(self->passwd); + spif_str_del(self->passwd); self->passwd = SPIF_NULL_TYPE(str); } if (!SPIF_STR_ISNULL(self->host)) { - spif_str_done(self->host); + spif_str_del(self->host); self->host = SPIF_NULL_TYPE(str); } if (!SPIF_STR_ISNULL(self->port)) { - spif_str_done(self->port); + spif_str_del(self->port); self->port = SPIF_NULL_TYPE(str); } if (!SPIF_STR_ISNULL(self->path)) { - spif_str_done(self->path); + spif_str_del(self->path); self->path = SPIF_NULL_TYPE(str); } if (!SPIF_STR_ISNULL(self->query)) { - spif_str_done(self->query); + spif_str_del(self->query); self->query = SPIF_NULL_TYPE(str); } spif_str_done(SPIF_STR(self)); @@ -170,6 +170,11 @@ spif_url_show(spif_url_t self, spif_charptr_t name, spif_str_t buff, size_t indent) { char tmp[4096]; + + if (SPIF_URL_ISNULL(self)) { + SPIF_OBJ_SHOW_NULL("url", name, buff, indent); + return buff; + } memset(tmp, ' ', indent); snprintf(tmp + indent, sizeof(tmp) - indent, "(spif_url_t) %s: {\n", name); |