spif_tok_t spif_tok_new_from_fd(int fd) { spif_tok_t self; self = SPIF_ALLOC(tok); if (!spif_tok_init_from_fd(self, fd)) { SPIF_DEALLOC(self); self = (spif_tok_t) NULL; } return self; }
spif_str_t spif_str_new_from_buff(spif_charptr_t buff, spif_stridx_t size) { spif_str_t self; self = SPIF_ALLOC(str); if (!spif_str_init_from_buff(self, buff, size)) { SPIF_DEALLOC(self); self = (spif_str_t) NULL; } return self; }
static spif_url_t spif_url_new_from_unixaddr(spif_unixsockaddr_t unixaddr) { spif_url_t self; self = SPIF_ALLOC(url); if (!spif_url_init_from_unixaddr(self, unixaddr)) { SPIF_DEALLOC(self); self = (spif_url_t) NULL; } return self; }
spif_socket_t spif_socket_new(void) { spif_socket_t self; self = SPIF_ALLOC(socket); if (!spif_socket_init(self)) { SPIF_DEALLOC(self); self = (spif_socket_t) NULL; } return self; }
spif_socket_t spif_socket_new_from_urls(spif_url_t surl, spif_url_t durl) { spif_socket_t self; self = SPIF_ALLOC(socket); if (!spif_socket_init_from_urls(self, surl, durl)) { SPIF_DEALLOC(self); self = (spif_socket_t) NULL; } return self; }
spif_str_t spif_str_new_from_num(long num) { spif_str_t self; self = SPIF_ALLOC(str); if (!spif_str_init_from_num(self, num)) { SPIF_DEALLOC(self); self = (spif_str_t) NULL; } return self; }
spif_eterm_action_t spif_eterm_action_new(void) { spif_eterm_action_t self; self = SPIF_ALLOC(eterm_action); if (!spif_eterm_action_init(self)) { SPIF_DEALLOC(self); self = (spif_eterm_action_t) NULL; } return self; }
spif_tok_t spif_tok_new_from_ptr(spif_charptr_t old) { spif_tok_t self; self = SPIF_ALLOC(tok); if (!spif_tok_init_from_ptr(self, old)) { SPIF_DEALLOC(self); self = (spif_tok_t) NULL; } return self; }
spif_tok_t spif_tok_new_from_fp(FILE * fp) { spif_tok_t self; self = SPIF_ALLOC(tok); if (!spif_tok_init_from_fp(self, fp)) { SPIF_DEALLOC(self); self = (spif_tok_t) NULL; } return self; }
spif_tok_t spif_tok_new(void) { spif_tok_t self; self = SPIF_ALLOC(tok); if (!spif_tok_init(self)) { SPIF_DEALLOC(self); self = (spif_tok_t) NULL; } return self; }
spif_url_t spif_url_new_from_ptr(spif_charptr_t other) { spif_url_t self; self = SPIF_ALLOC(url); if (!spif_url_init_from_ptr(self, other)) { SPIF_DEALLOC(self); self = (spif_url_t) NULL; } return self; }
spif_url_t spif_url_new(void) { spif_url_t self; self = SPIF_ALLOC(url); if (!spif_url_init(self)) { SPIF_DEALLOC(self); self = (spif_url_t) NULL; } return self; }
spif_str_t spif_str_new(void) { spif_str_t self; self = SPIF_ALLOC(str); if (!spif_str_init(self)) { SPIF_DEALLOC(self); self = (spif_str_t) NULL; } return self; }
spif_eterm_action_t spif_eterm_action_new_from_data(spif_eterm_action_type_t type, spif_ushort_t modifiers, spif_uchar_t button, KeySym keysym, spif_ptr_t param) { spif_eterm_action_t self; self = SPIF_ALLOC(eterm_action); if (!spif_eterm_action_init_from_data(self, type, modifiers, button, keysym, param)) { SPIF_DEALLOC(self); self = (spif_eterm_action_t) NULL; } return self; }
spif_str_t spif_str_dup(spif_str_t self) { spif_str_t tmp; ASSERT_RVAL(!SPIF_STR_ISNULL(self), (spif_str_t) NULL); tmp = SPIF_ALLOC(str); memcpy(tmp, self, SPIF_SIZEOF_TYPE(str)); tmp->s = (spif_charptr_t) STRDUP((const char *) SPIF_STR_STR(self)); tmp->len = self->len; tmp->size = self->size; return tmp; }
static spif_unixsockaddr_t spif_url_get_unixaddr(spif_url_t self) { spif_unixsockaddr_t addr; ASSERT_RVAL(!SPIF_URL_ISNULL(self), (spif_unixsockaddr_t) NULL); /* No address to look up, just a file path. */ addr = SPIF_ALLOC(unixsockaddr); addr->sun_family = AF_UNIX; addr->sun_path[0] = 0; strncat(addr->sun_path, (char *) SPIF_STR_STR(spif_url_get_path(self)), sizeof(addr->sun_path) - 1); return addr; }
static spif_ipsockaddr_t spif_url_get_ipaddr(spif_url_t self) { spif_uint8_t tries; spif_hostinfo_t hinfo; spif_ipsockaddr_t addr; spif_str_t hostname; ASSERT_RVAL(!SPIF_URL_ISNULL(self), (spif_ipsockaddr_t) NULL); /* We need a hostname of some type to connect to. */ hostname = SPIF_STR(spif_url_get_host(self)); REQUIRE_RVAL(!SPIF_STR_ISNULL(hostname), (spif_ipsockaddr_t) NULL); /* Try up to 3 times to resolve the hostname. */ h_errno = 0; tries = 0; do { tries++; hinfo = gethostbyname((char *) SPIF_STR_STR(hostname)); } while ((tries <= 3) && (!hinfo) && (h_errno == TRY_AGAIN)); if (!hinfo) { libast_print_error("Unable to resolve hostname \"%s\" -- %s\n", SPIF_STR_STR(hostname), hstrerror(h_errno)); return (spif_ipsockaddr_t) NULL; } if (!hinfo->h_addr_list) { libast_print_error("Invalid address list returned by gethostbyname()\n"); return (spif_ipsockaddr_t) NULL; } /* Grab the host IP address and port number, both in network byte order. */ addr = SPIF_ALLOC(ipsockaddr); addr->sin_family = AF_INET; addr->sin_port = htons(spif_url_get_portnum(self)); memcpy(&(addr->sin_addr), (void *) (hinfo->h_addr_list[0]), sizeof(addr->sin_addr)); D_OBJ(("Got address 0x%08x and port %d for name \"%s\"\n", (long) ntohl(*((int *) (&addr->sin_addr))), (int) ntohs(addr->sin_port), SPIF_STR_STR(hostname))); return addr; }
spif_socket_t spif_socket_accept(spif_socket_t self) { spif_sockaddr_t addr; spif_sockaddr_len_t len; int newfd; spif_socket_t tmp; ASSERT_RVAL(!SPIF_SOCKET_ISNULL(self), (spif_socket_t) NULL); addr = SPIF_ALLOC(sockaddr); len = SPIF_SIZEOF_TYPE(sockaddr); do { newfd = accept(self->fd, addr, &len); } while ((newfd < 0) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))); if (newfd < 0) { libast_print_error("Unable to accept() connection on %d -- %s\n", self->fd, strerror(errno)); return (spif_socket_t) NULL; } /* We got one. Create and return a new socket object for the accepted connection. */ tmp = spif_socket_dup(self); tmp->fd = newfd; SPIF_SOCKET_FLAGS_CLEAR(tmp, (SPIF_SOCKET_FLAGS_LISTEN | SPIF_SOCKET_FLAGS_HAVE_INPUT | SPIF_SOCKET_FLAGS_CAN_OUTPUT)); if (SPIF_SOCKET_FLAGS_IS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_INET)) { tmp->remote_url = spif_url_new_from_ipaddr((spif_ipsockaddr_t) addr); } else if (SPIF_SOCKET_FLAGS_IS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_UNIX)) { tmp->remote_url = spif_url_new_from_unixaddr((spif_unixsockaddr_t) addr); } SPIF_DEALLOC(addr); if (SPIF_SOCKET_FLAGS_IS_SET(self, SPIF_SOCKET_FLAGS_NBIO)) { spif_socket_set_nbio(tmp); } return tmp; }