spif_cmp_t spif_eterm_action_comp(spif_eterm_action_t self, spif_eterm_action_t other) { spif_cmp_t c; SPIF_OBJ_COMP_CHECK_NULL(self, other); c = SPIF_CMP_FROM_INT((int) (self->type) - (int) (other->type)); if (!SPIF_CMP_IS_EQUAL(c)) { return c; } c = SPIF_CMP_FROM_INT((int) (self->button) - (int) (other->button)); if (!SPIF_CMP_IS_EQUAL(c)) { return c; } c = SPIF_CMP_FROM_INT((int) (self->keysym) - (int) (other->keysym)); if (!SPIF_CMP_IS_EQUAL(c)) { return c; } return SPIF_CMP_FROM_INT((int) (self->modifiers) - (int) (other->modifiers)); }
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; ASSERT_RVAL(!SPIF_URL_ISNULL(self), FALSE); /* If we have a remote URL, use it. Otherwise, use the local one. */ url = ((SPIF_URL_ISNULL(self->remote_url)) ? (self->local_url) : (self->remote_url)); REQUIRE_RVAL(!SPIF_URL_ISNULL(url), FALSE); 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, SPIF_CHARPTR("raw")))) { spif_str_t target; /* Raw socket. Could be raw UNIX or raw IP. */ SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_TYPE_RAW); /* If we have a hostname, it's IP. If we have a path only, it's UNIX. */ 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 if (SPIF_CMP_IS_EQUAL(spif_str_cmp_with_ptr(proto_str, SPIF_CHARPTR("unix")))) { /* UNIX socket. Assume stream-based. */ SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_UNIX); SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_TYPE_STREAM); } else { /* IP socket. See if they gave us a protocol name. */ SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_INET); proto = getprotobyname((char *) SPIF_STR_STR(proto_str)); if (!proto) { /* If it's not a protocol, it's probably a service. */ serv = getservbyname((char *) SPIF_STR_STR(proto_str), "tcp"); if (!serv) { serv = getservbyname((char *) SPIF_STR_STR(proto_str), "udp"); } if (serv) { /* If we found one, get the protocol info too. */ proto = getprotobyname(serv->s_proto); REQUIRE_RVAL(proto != NULL, FALSE); } } if (proto) { /* Bingo. Set the flags appropriately. */ self->proto = proto->p_proto; if (!strcmp(proto->p_name, "tcp")) { SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_TYPE_STREAM); } else if (!strcmp(proto->p_name, "udp")) { SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_TYPE_DGRAM); } } } } else { /* No protocol? Assume a UNIX socket. */ SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_FAMILY_UNIX); SPIF_SOCKET_FLAGS_SET(self, SPIF_SOCKET_FLAGS_TYPE_STREAM); } return TRUE; }
spif_cmp_t spiftool_version_compare(spif_charptr_t v1, spif_charptr_t v2) { spif_char_t buff1[128], buff2[128]; D_CONF(("Comparing version strings \"%s\" and \"%s\"\n", NONULL(v1), NONULL(v2))); SPIF_COMP_CHECK_NULL(v1, v2); for (; *v1 && *v2; ) { D_CONF((" -> Looking at \"%s\" and \"%s\"\n", v1, v2)); if (isalpha(*v1) && isalpha(*v2)) { spif_charptr_t p1 = buff1, p2 = buff2; spif_int8_t ival1 = 6, ival2 = 6; /* Compare words. First, copy each word into buffers. */ for (; *v1 && isalpha(*v1); v1++, p1++) *p1 = *v1; for (; *v2 && isalpha(*v2); v2++, p2++) *p2 = *v2; *p1 = *p2 = 0; /* Change the buffered strings to lowercase for easier comparison. */ spiftool_downcase_str(buff1); spiftool_downcase_str(buff2); D_CONF((" -> Comparing as words \"%s\" vs. \"%s\"\n", buff1, buff2)); /* Some strings require special handling. */ if (!strcmp((char *) buff1, "snap")) { ival1 = 1; } else if (!strcmp((char *) buff1, "pre")) { ival1 = 2; } else if (!strcmp((char *) buff1, "alpha")) { ival1 = 3; } else if (!strcmp((char *) buff1, "beta")) { ival1 = 4; } else if (!strcmp((char *) buff1, "rc")) { ival1 = 5; } if (!strcmp((char *) buff2, "snap")) { ival2 = 1; } else if (!strcmp((char *) buff2, "pre")) { ival2 = 2; } else if (!strcmp((char *) buff2, "alpha")) { ival2 = 3; } else if (!strcmp((char *) buff2, "beta")) { ival2 = 4; } else if (!strcmp((char *) buff2, "rc")) { ival2 = 5; } if (ival1 != ival2) { /* If the values are different, compare them. */ D_CONF((" -> %d\n", (int) SPIF_CMP_FROM_INT(ival1 - ival2))); return SPIF_CMP_FROM_INT(ival1 - ival2); } else if (ival1 == 6) { int c; /* Two arbitrary strings. Compare them too. */ if ((c = strcmp((char *) buff1, (char *) buff2)) != 0) { D_CONF((" -> %d\n", (int) SPIF_CMP_FROM_INT(c))); return SPIF_CMP_FROM_INT(c); } } } else if (isdigit(*v1) && isdigit(*v2)) { spif_charptr_t p1 = buff1, p2 = buff2; spif_int32_t ival1, ival2; spif_cmp_t c; /* Compare numbers. First, copy each number into buffers. */ for (; *v1 && isdigit(*v1); v1++, p1++) *p1 = *v1; for (; *v2 && isdigit(*v2); v2++, p2++) *p2 = *v2; *p1 = *p2 = 0; /* Convert the strings into actual integers. */ ival1 = (spif_int32_t) strtol((char *) buff1, (char **) NULL, 10); ival2 = (spif_int32_t) strtol((char *) buff2, (char **) NULL, 10); D_CONF((" -> Comparing as integers %d vs. %d\n", (int) ival1, (int) ival2)); /* Compare the integers and return if not equal. */ c = SPIF_CMP_FROM_INT(ival1 - ival2); if (!SPIF_CMP_IS_EQUAL(c)) { D_CONF((" -> %d\n", (int) c)); return c; } } else if (!isalnum(*v1) && !isalnum(*v2)) { spif_charptr_t p1 = buff1, p2 = buff2; spif_cmp_t c; /* Compare non-alphanumeric strings. */ for (; *v1 && !isalnum(*v1); v1++, p1++) *p1 = *v1; for (; *v2 && !isalnum(*v2); v2++, p2++) *p2 = *v2; *p1 = *p2 = 0; D_CONF((" -> Comparing as non-alphanumeric strings \"%s\" vs. \"%s\"\n", buff1, buff2)); c = SPIF_CMP_FROM_INT(strcasecmp((char *) buff1, (char *) buff2)); if (!SPIF_CMP_IS_EQUAL(c)) { D_CONF((" -> %d\n", (int) c)); return c; } } else { D_CONF((" -> Comparing as alphanumeric strings \"%s\" vs. \"%s\"\n", buff1, buff2)); D_CONF((" -> %d\n", (int) SPIF_CMP_FROM_INT(strcasecmp((char *) buff1, (char *) buff2)))); return SPIF_CMP_FROM_INT(strcasecmp((char *) buff1, (char *) buff2)); } } /* We've reached the end of one of the strings. */ if (*v1) { if (!BEG_STRCASECMP((char *) v1, "snap") || !BEG_STRCASECMP((char *) v1, "pre") || !BEG_STRCASECMP((char *) v1, "alpha") || !BEG_STRCASECMP((char *) v1, "beta")) { D_CONF((" -> <\n")); return SPIF_CMP_LESS; } else { D_CONF((" -> >\n")); return SPIF_CMP_GREATER; } } else if (*v2) { if (!BEG_STRCASECMP((char *) v2, "snap") || !BEG_STRCASECMP((char *) v2, "pre") || !BEG_STRCASECMP((char *) v2, "alpha") || !BEG_STRCASECMP((char *) v2, "beta")) { D_CONF((" -> >\n")); return SPIF_CMP_GREATER; } else { D_CONF((" -> <\n")); return SPIF_CMP_LESS; } } D_CONF((" -> ==\n")); return SPIF_CMP_EQUAL; }