/* * D O F I L E */ void dofile(FILE *fp) { register int c; while ( (c = getc(fp)) != EOF ) { switch ( c ) { /* One of a kind functions */ case 'e': case 'F': putchar( c ); break; case 'f': case 't': putchar( c ); copy_string( fp ); break; case 'C': putchar( c ); COPY(3); break; case 'c': /* map x, y? */ putchar( c ); COPY(6); break; case 'a': /* map points? */ putchar( c ); COPY(12); break; case 'p': case 'm': case 'n': /* Two coordinates in, three out. Change command. */ putchar( UPPER_CASE(c) ); two_coord_out( fp, rmat ); break; case 'l': putchar( 'L' ); two_coord_out( fp, rmat ); two_coord_out( fp, rmat ); break; case 'P': case 'M': case 'N': putchar( c ); three_coord_out( fp, rmat ); break; case 'L': putchar( c ); three_coord_out( fp, rmat ); three_coord_out( fp, rmat ); break; case 's': { /* 2-D integer SPACE command. * This is the only AT&T compatible space * command; be certain to only output * with pl_space(), to ensure that output * file is AT&T style if input was. */ long minx, miny, maxx, maxy; point_t min, max; minx = getshort(fp); miny = getshort(fp); maxx = getshort(fp); maxy = getshort(fp); VSET( min, minx, miny, -1 ); VSET( max, maxx, maxy, -1 ); model_rpp( min, max ); minx = (long)floor( space_min[X] ); miny = (long)floor( space_min[Y] ); maxx = (long)ceil( space_max[X] ); maxy = (long)ceil( space_max[Y] ); if ( minx < -32768 ) minx = -32768; if ( miny < -32768 ) miny = -32768; if ( maxx > 32767 ) maxx = 32767; if ( maxy > 32767 ) maxy = 32767; pl_space( stdout, minx, miny, maxx, maxy ); } break; case 'S': { /* BRL-extended 3-D integer SPACE command */ point_t min, max; min[X] = getshort(fp); min[Y] = getshort(fp); min[Z] = getshort(fp); max[X] = getshort(fp); max[Y] = getshort(fp); max[Z] = getshort(fp); model_rpp( min, max ); pdv_3space( stdout, space_min, space_max ); } break; /* 2D and 3D IEEE */ case 'w': { /* BRL 2-D floating point SPACE command */ point_t min, max; min[X] = getdouble(fp); min[Y] = getdouble(fp); min[Z] = -1.0; max[X] = getdouble(fp); max[Y] = getdouble(fp); max[Z] = 1.0; model_rpp( min, max ); pdv_3space( stdout, space_min, space_max ); } break; case 'W': { /* BRL 3-D floating point SPACE command */ point_t min, max; min[X] = getdouble(fp); min[Y] = getdouble(fp); min[Z] = getdouble(fp); max[X] = getdouble(fp); max[Y] = getdouble(fp); max[Z] = getdouble(fp); model_rpp( min, max ); pdv_3space( stdout, space_min, space_max ); } break; case 'i': putchar(c); COPY(3*8); break; case 'r': putchar(c); COPY(6*8); break; case 'x': case 'o': case 'q': /* Two coordinates in, three out. Change command. */ putchar( UPPER_CASE(c) ); two_dcoord_out( fp, rmat ); break; case 'v': /* Two coordinates in, three out. Change command. */ putchar( 'V' ); two_dcoord_out( fp, rmat ); two_dcoord_out( fp, rmat ); break; case 'X': case 'O': case 'Q': putchar( c ); three_dcoord_out( fp, rmat ); break; case 'V': putchar( c ); three_dcoord_out( fp, rmat ); three_dcoord_out( fp, rmat ); break; default: fprintf( stderr, "plrot: unrecognized command '%c' (0x%x)\n", (isascii(c) && isprint(c)) ? c : '?', c ); fprintf( stderr, "plrot: ftell = %ld\n", ftell(fp) ); putchar( c ); break; } } }
int tag_parser(char* tag, int len, char* back_tag) { int i = 0; if (tag[0] == '/') { *back_tag = 1; i++; } else *back_tag = 0; switch (tag[i]) { case 'b': case 'B': case 'i': case 'I': if (!isascii(tag[i+1])) return 0; if (!isspace(tag[i+1])) return 0; if ((tag[i] == 'b') || (tag[i] == 'B')) return PTAG_B; return PTAG_I; case 'e': case 'E': i++; if (!isascii(tag[i+1])) return 0; if (((tag[i]=='m')||(tag[i]=='M')) && (isspace(tag[i+1]))) return PTAG_I; return 0; case 'h': case 'H': i++; if (!isascii(tag[i+1])) return 0; if (((tag[i]>='1')&&(tag[i]<='6')) && (isspace(tag[i+1]))) return PTAG_H; return 0; case 't': case 'T': i++; if (!isascii(tag[i+4])) return 0; if ((0==strnicmp(tag+i, "itle", 4)) && (isspace(tag[i+4]))) return PTAG_TITLE; return 0; case 's': case 'S': i++; if (!isascii(tag[i+5])) return 0; if ((0==strnicmp(tag+i, "trong", 5)) && (isspace(tag[i+5]))) return PTAG_B; if ((0==strnicmp(tag+i, "cript", 5)) && (isspace(tag[i+5]))) return PTAG_SCRIPT; return 0; default: break; } return 0; }
ssize_t print_string(char *s, ssize_t len, int dl, const uint8_t *data) { uint8_t c; const uint8_t *e, *p; ssize_t bytes = 0; ssize_t r; e = data + dl; while (data < e) { c = *data++; if (c == '\0') { /* If rest is all NULL, skip it. */ for (p = data; p < e; p++) if (*p != '\0') break; if (p == e) break; } if (!isascii(c) || !isprint(c)) { if (s) { if (len < 5) { errno = ENOBUFS; return -1; } r = snprintf(s, len, "\\%03o", c); len -= r; bytes += r; s += r; } else bytes += 4; continue; } switch (c) { case '"': /* FALLTHROUGH */ case '\'': /* FALLTHROUGH */ case '$': /* FALLTHROUGH */ case '`': /* FALLTHROUGH */ case '\\': /* FALLTHROUGH */ case '|': /* FALLTHROUGH */ case '&': if (s) { if (len < 3) { errno = ENOBUFS; return -1; } *s++ = '\\'; len--; } bytes++; break; } if (s) { *s++ = c; len--; } bytes++; } /* NULL */ if (s) *s = '\0'; bytes++; return bytes; }
unsigned long printResource(const char *image, unsigned long id) { unsigned long result = 0; ELF_SPEC_HEADER *res = NULL; MELF *melf = melf_open(image); Elf32_Res current; char *type = NULL; do { if (!melf) { fprintf(stderr, "elfres: could not open elf image. (%s)\n", image); break; } if (!(res = melf_resOpen(melf))) { fprintf(stderr, "elfres: could not find resources in image.\n"); break; } if (!melf_resGetId(melf, res, id, ¤t)) { fprintf(stderr, "elfres: could not find resource %lu in image.\n", id); break; } switch (current.header.type) { case ELF_RES_TYPE_STRING: type = "string"; break; case ELF_RES_TYPE_BINARY: type = "binary"; break; default: type = "unknown"; break; } fprintf(stdout, "Resource #%.4lu:\n" " Type : %s\n" " Length: %lu\n" " Id : %lu\n" "-- Start data --\n", current.index, type, current.header.length, current.header.identifier); switch (current.header.type) { case ELF_RES_TYPE_STRING: fprintf(stdout, "%s", (char *)current.data); break; case ELF_RES_TYPE_BINARY: default: { unsigned char *data = (unsigned char *)current.data; unsigned long x = 0, y = 0; for (x = 0; x < current.header.length; x++) { fprintf(stdout, "%.2x ", data[x]); if ((x+1) % 10 == 0 || x+1 == current.header.length) { fprintf(stdout, "\t"); for (; y <= x; y++) { if (isascii(data[y])) fprintf(stdout, "%c", data[y]); else fprintf(stdout, "."); } fprintf(stdout, "\n"); y = x + 1; } } } break; } fprintf(stdout, "\n-- End data --\n"); result = 1; } while (0); if (res) melf_resClose(melf, res); if (melf) melf_destroy(melf); return result; }
static int ipcharok(int c) { return c == '.' || c == ':' || isascii(c) && isxdigit(c); }
static void rfc1048_print(u_char *bp, int length) { u_char tag; u_char *ep; int len; u_int32 ul; u_short us; struct in_addr ia; char *optstr; printf("-rfc1395"); /* Step over magic cookie */ bp += sizeof(int32); /* Setup end pointer */ ep = bp + length; while (bp < ep) { tag = *bp++; /* Check for tags with no data first. */ if (tag == TAG_PAD) continue; if (tag == TAG_END) return; if (tag < KNOWN_OPTIONS) { optstr = rfc1048_opts[tag]; printf(" %s:", optstr + 1); } else { printf(" T%d:", tag); optstr = "?"; } /* Now scan the length byte. */ len = *bp++; if (bp + len > ep) { /* truncated option */ printf(" |(%d>%d)", len, ep - bp); return; } /* Print the option value(s). */ switch (optstr[0]) { case 'a': /* ASCII string */ printfn(bp, bp + len); bp += len; len = 0; break; case 's': /* Word formats */ while (len >= 2) { bcopy((char *) bp, (char *) &us, 2); printf("%d", ntohs(us)); bp += 2; len -= 2; if (len) printf(","); } if (len) printf("(junk=%d)", len); break; case 'l': /* Long words */ while (len >= 4) { bcopy((char *) bp, (char *) &ul, 4); printf("%ld", (long)ntohl(ul)); bp += 4; len -= 4; if (len) printf(","); } if (len) printf("(junk=%d)", len); break; case 'i': /* INET addresses */ while (len >= 4) { bcopy((char *) bp, (char *) &ia, 4); printf("%s", ipaddr_string(&ia)); bp += 4; len -= 4; if (len) printf(","); } if (len) printf("(junk=%d)", len); break; case 'b': default: break; } /* switch */ /* Print as characters, if appropriate. */ if (len) { dump_hex(bp, len); if (isascii(*bp) && isprint(*bp)) { printf("("); printfn(bp, bp + len); printf(")"); } bp += len; len = 0; } } /* while bp < ep */ }
/*% This function has to be reachable by res_data.c but not publically. */ int __res_vinit(res_state statp, int preinit) { FILE *fp; char *cp, **pp; int n; char buf[BUFSIZ]; int nserv = 0; /*%< number of nameserver records read from file */ int haveenv = 0; int havesearch = 0; #ifdef RESOLVSORT int nsort = 0; char *net; #endif int dots; union res_sockaddr_union u[2]; int maxns = MAXNS; RES_SET_H_ERRNO(statp, 0); if (statp->_u._ext.ext != NULL) res_ndestroy(statp); if (!preinit) { statp->retrans = RES_TIMEOUT; statp->retry = RES_DFLRETRY; statp->options = RES_DEFAULT; } statp->_rnd = malloc(16); res_rndinit(statp); statp->id = res_nrandomid(statp); memset(u, 0, sizeof(u)); #ifdef USELOOPBACK u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); #else u[nserv].sin.sin_addr.s_addr = INADDR_ANY; #endif u[nserv].sin.sin_family = AF_INET; u[nserv].sin.sin_port = htons(NAMESERVER_PORT); #ifdef HAVE_SA_LEN u[nserv].sin.sin_len = sizeof(struct sockaddr_in); #endif nserv++; #ifdef HAS_INET6_STRUCTS #ifdef USELOOPBACK u[nserv].sin6.sin6_addr = in6addr_loopback; #else u[nserv].sin6.sin6_addr = in6addr_any; #endif u[nserv].sin6.sin6_family = AF_INET6; u[nserv].sin6.sin6_port = htons(NAMESERVER_PORT); #ifdef HAVE_SA_LEN u[nserv].sin6.sin6_len = sizeof(struct sockaddr_in6); #endif nserv++; #endif statp->nscount = 0; statp->ndots = 1; statp->pfcode = 0; statp->_vcsock = -1; statp->_flags = 0; statp->qhook = NULL; statp->rhook = NULL; statp->_u._ext.nscount = 0; statp->_u._ext.ext = malloc(sizeof(*statp->_u._ext.ext)); if (statp->_u._ext.ext != NULL) { memset(statp->_u._ext.ext, 0, sizeof(*statp->_u._ext.ext)); statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr; strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa"); strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int"); statp->_u._ext.ext->reload_period = 2; } else { /* * Historically res_init() rarely, if at all, failed. * Examples and applications exist which do not check * our return code. Furthermore several applications * simply call us to get the systems domainname. So * rather then immediately fail here we store the * failure, which is returned later, in h_errno. And * prevent the collection of 'nameserver' information * by setting maxns to 0. Thus applications that fail * to check our return code wont be able to make * queries anyhow. */ RES_SET_H_ERRNO(statp, NETDB_INTERNAL); maxns = 0; } #ifdef RESOLVSORT statp->nsort = 0; #endif res_setservers(statp, u, nserv); #ifdef SOLARIS2 /* * The old libresolv derived the defaultdomain from NIS/NIS+. * We want to keep this behaviour */ { char buf[sizeof(statp->defdname)], *cp; int ret; if ((ret = sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf))) > 0 && (unsigned int)ret <= sizeof(buf)) { if (buf[0] == '+') buf[0] = '.'; cp = strchr(buf, '.'); cp = (cp == NULL) ? buf : (cp + 1); strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); statp->defdname[sizeof(statp->defdname) - 1] = '\0'; } } #endif /* SOLARIS2 */ /* Allow user to override the local domain definition */ if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) { (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); statp->defdname[sizeof(statp->defdname) - 1] = '\0'; haveenv++; /* * Set search list to be blank-separated strings * from rest of env value. Permits users of LOCALDOMAIN * to still have a search list, and anyone to set the * one that they want to use as an individual (even more * important now that the rfc1535 stuff restricts searches) */ cp = statp->defdname; pp = statp->dnsrch; *pp++ = cp; for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) { if (*cp == '\n') /*%< silly backwards compat */ break; else if (*cp == ' ' || *cp == '\t') { *cp = 0; n = 1; } else if (n) { *pp++ = cp; n = 0; havesearch = 1; } } /* null terminate last domain if there are excess */ while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n') cp++; *cp = '\0'; *pp++ = 0; } #define MATCH(line, name) \ (!strncmp(line, name, sizeof(name) - 1) && \ (line[sizeof(name) - 1] == ' ' || \ line[sizeof(name) - 1] == '\t')) nserv = 0; if ((fp = fopen(_PATH_RESCONF, "re")) != NULL) { struct stat sb; struct timespec now; if (statp->_u._ext.ext != NULL) { if (_fstat(fileno(fp), &sb) == 0) { statp->_u._ext.ext->conf_mtim = sb.st_mtim; if (clock_gettime(CLOCK_MONOTONIC_FAST, &now) == 0) { statp->_u._ext.ext->conf_stat = now.tv_sec; } } } /* read the config file */ while (fgets(buf, sizeof(buf), fp) != NULL) { /* skip comments */ if (*buf == ';' || *buf == '#') continue; /* read default domain name */ if (MATCH(buf, "domain")) { if (haveenv) /*%< skip if have from environ */ continue; cp = buf + sizeof("domain") - 1; while (*cp == ' ' || *cp == '\t') cp++; if ((*cp == '\0') || (*cp == '\n')) continue; strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); statp->defdname[sizeof(statp->defdname) - 1] = '\0'; if ((cp = strpbrk(statp->defdname, " \t\n")) != NULL) *cp = '\0'; havesearch = 0; continue; } /* set search list */ if (MATCH(buf, "search")) { if (haveenv) /*%< skip if have from environ */ continue; cp = buf + sizeof("search") - 1; while (*cp == ' ' || *cp == '\t') cp++; if ((*cp == '\0') || (*cp == '\n')) continue; strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); statp->defdname[sizeof(statp->defdname) - 1] = '\0'; if ((cp = strchr(statp->defdname, '\n')) != NULL) *cp = '\0'; /* * Set search list to be blank-separated strings * on rest of line. */ cp = statp->defdname; pp = statp->dnsrch; *pp++ = cp; for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) { if (*cp == ' ' || *cp == '\t') { *cp = 0; n = 1; } else if (n) { *pp++ = cp; n = 0; } } /* null terminate last domain if there are excess */ while (*cp != '\0' && *cp != ' ' && *cp != '\t') cp++; *cp = '\0'; *pp++ = 0; havesearch = 1; continue; } /* read nameservers to query */ if (MATCH(buf, "nameserver") && nserv < maxns) { struct addrinfo hints, *ai; char sbuf[NI_MAXSERV]; const size_t minsiz = sizeof(statp->_u._ext.ext->nsaddrs[0]); cp = buf + sizeof("nameserver") - 1; while (*cp == ' ' || *cp == '\t') cp++; cp[strcspn(cp, ";# \t\n")] = '\0'; if ((*cp != '\0') && (*cp != '\n')) { memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; /*dummy*/ hints.ai_flags = AI_NUMERICHOST; sprintf(sbuf, "%u", NAMESERVER_PORT); if (getaddrinfo(cp, sbuf, &hints, &ai) == 0 && ai->ai_addrlen <= minsiz) { if (statp->_u._ext.ext != NULL) { memcpy(&statp->_u._ext.ext->nsaddrs[nserv], ai->ai_addr, ai->ai_addrlen); } if (ai->ai_addrlen <= sizeof(statp->nsaddr_list[nserv])) { memcpy(&statp->nsaddr_list[nserv], ai->ai_addr, ai->ai_addrlen); } else statp->nsaddr_list[nserv].sin_family = 0; freeaddrinfo(ai); nserv++; } } continue; } #ifdef RESOLVSORT if (MATCH(buf, "sortlist")) { struct in_addr a; struct in6_addr a6; int m, i; u_char *u; struct __res_state_ext *ext = statp->_u._ext.ext; cp = buf + sizeof("sortlist") - 1; while (nsort < MAXRESOLVSORT) { while (*cp == ' ' || *cp == '\t') cp++; if (*cp == '\0' || *cp == '\n' || *cp == ';') break; net = cp; while (*cp && !ISSORTMASK(*cp) && *cp != ';' && isascii(*cp) && !isspace((unsigned char)*cp)) cp++; n = *cp; *cp = 0; if (inet_aton(net, &a)) { statp->sort_list[nsort].addr = a; if (ISSORTMASK(n)) { *cp++ = n; net = cp; while (*cp && *cp != ';' && isascii(*cp) && !isspace((unsigned char)*cp)) cp++; n = *cp; *cp = 0; if (inet_aton(net, &a)) { statp->sort_list[nsort].mask = a.s_addr; } else { statp->sort_list[nsort].mask = net_mask(statp->sort_list[nsort].addr); } } else { statp->sort_list[nsort].mask = net_mask(statp->sort_list[nsort].addr); } ext->sort_list[nsort].af = AF_INET; ext->sort_list[nsort].addr.ina = statp->sort_list[nsort].addr; ext->sort_list[nsort].mask.ina.s_addr = statp->sort_list[nsort].mask; nsort++; } else if (inet_pton(AF_INET6, net, &a6) == 1) { ext->sort_list[nsort].af = AF_INET6; ext->sort_list[nsort].addr.in6a = a6; u = (u_char *)&ext->sort_list[nsort].mask.in6a; *cp++ = n; net = cp; while (*cp && *cp != ';' && isascii(*cp) && !isspace(*cp)) cp++; m = n; n = *cp; *cp = 0; switch (m) { case '/': m = atoi(net); break; case '&': if (inet_pton(AF_INET6, net, u) == 1) { m = -1; break; } /*FALLTHROUGH*/ default: m = sizeof(struct in6_addr) * CHAR_BIT; break; } if (m >= 0) { for (i = 0; i < sizeof(struct in6_addr); i++) { if (m <= 0) { *u = 0; } else { m -= CHAR_BIT; *u = (u_char)~0; if (m < 0) *u <<= -m; } u++; } } statp->sort_list[nsort].addr.s_addr = (u_int32_t)0xffffffff; statp->sort_list[nsort].mask = (u_int32_t)0xffffffff; nsort++; } *cp = n; } continue; } #endif if (MATCH(buf, "options")) { res_setoptions(statp, buf + sizeof("options") - 1, "conf"); continue; } } if (nserv > 0) statp->nscount = nserv; #ifdef RESOLVSORT statp->nsort = nsort; #endif (void) fclose(fp); } /* * Last chance to get a nameserver. This should not normally * be necessary */ #ifdef NO_RESOLV_CONF if(nserv == 0) nserv = get_nameservers(statp); #endif if (statp->defdname[0] == 0 && gethostname(buf, sizeof(statp->defdname) - 1) == 0 && (cp = strchr(buf, '.')) != NULL) strcpy(statp->defdname, cp + 1); /* find components of local domain that might be searched */ if (havesearch == 0) { pp = statp->dnsrch; *pp++ = statp->defdname; *pp = NULL; dots = 0; for (cp = statp->defdname; *cp; cp++) dots += (*cp == '.'); cp = statp->defdname; while (pp < statp->dnsrch + MAXDFLSRCH) { if (dots < LOCALDOMAINPARTS) break; cp = strchr(cp, '.') + 1; /*%< we know there is one */ *pp++ = cp; dots--; } *pp = NULL; #ifdef DEBUG if (statp->options & RES_DEBUG) { printf(";; res_init()... default dnsrch list:\n"); for (pp = statp->dnsrch; *pp; pp++) printf(";;\t%s\n", *pp); printf(";;\t..END..\n"); } #endif } if (issetugid()) statp->options |= RES_NOALIASES; else if ((cp = getenv("RES_OPTIONS")) != NULL) res_setoptions(statp, cp, "env"); statp->options |= RES_INIT; return (statp->res_h_errno); }
/* ev_err -- reports error (err_num) in file "file" at line "line_num" and returns to user error handler; list_num is an error list number (0 is the basic list pointed by err_mesg, 1 is the basic list of warnings) */ int ev_err(char *file,int err_num,int line_num,char *fn_name,int list_num) { int num; if ( err_num < 0 ) err_num = 0; #ifndef USING_R if (list_num < 0 || list_num >= err_list_end || err_list[list_num].listp == (char **)NULL) { fprintf(stderr, "\n Not (properly) attached list of errors: list_num = %d\n", list_num); fprintf(stderr," Call \"err_list_attach\" in your program\n"); if ( ! isatty(fileno(stdout)) ) { fprintf(stderr, "\n Not (properly) attached list of errors: list_num = %d\n", list_num); fprintf(stderr," Call \"err_list_attach\" in your program\n"); } printf("\nExiting program\n"); exit(0); } #endif num = err_num; if ( num >= err_list[list_num].len ) num = 0; #ifndef USING_R if ( cnt_errs && ++num_errs >= MAX_ERRS ) /* too many errors */ { fprintf(stderr,"\n\"%s\", line %d: %s in function %s()\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); if ( ! isatty(fileno(stdout)) ) fprintf(stdout,"\n\"%s\", line %d: %s in function %s()\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); printf("Sorry, too many errors: %d\n",num_errs); printf("Exiting program\n"); exit(0); } #endif if ( err_list[list_num].warn ) switch ( err_flag ) { case EF_SILENT: break; default: #ifdef USING_R Rprintf("\n\"%s\", line %d: %s in function %s()\n\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); #else fprintf(stderr,"\n\"%s\", line %d: %s in function %s()\n\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); if ( ! isatty(fileno(stdout)) ) fprintf(stdout,"\n\"%s\", line %d: %s in function %s()\n\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); #endif break; } else switch ( err_flag ) { case EF_SILENT: longjmp(restart,(err_num==0)? -1 : err_num); break; case EF_ABORT: #ifdef USING_R Rprintf("\n\"%s\", line %d: %s in function %s()\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); #else fprintf(stderr,"\n\"%s\", line %d: %s in function %s()\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); if ( ! isatty(fileno(stdout)) ) fprintf(stdout,"\n\"%s\", line %d: %s in function %s()\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); #endif #ifdef USING_R Rf_error(""); #else abort(); #endif break; case EF_JUMP: #ifdef USING_R Rprintf("\n\"%s\", line %d: %s in function %s()\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); #else fprintf(stderr,"\n\"%s\", line %d: %s in function %s()\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); if ( ! isatty(fileno(stdout)) ) fprintf(stdout,"\n\"%s\", line %d: %s in function %s()\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); #endif longjmp(restart,(err_num==0)? -1 : err_num); break; case EF_R_ERROR: #ifdef USING_R /* EJP */ Rprintf("\n\"%s\", line %d: %s in function %s()\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); s_gstat_error(isascii(*fn_name) ? fn_name : "???", 0); #endif break; default: #ifdef USING_R Rprintf("\n\"%s\", line %d: %s in function %s()\n\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); #else fprintf(stderr,"\n\"%s\", line %d: %s in function %s()\n\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); if ( ! isatty(fileno(stdout)) ) fprintf(stdout,"\n\"%s\", line %d: %s in function %s()\n\n", file,line_num,err_list[list_num].listp[num], isascii(*fn_name) ? fn_name : "???"); #endif break; } /* ensure exit if fall through */ if ( ! err_list[list_num].warn ) #ifdef USING_R /* EJP */ s_gstat_error("err.c", 0); #else exit(0); #endif return 0; }
static void doit (FILE *fp, const char *filename, const char *chars, int xhot, int yhot, const char *name) { int i, j; int last_character; char buf[BUFSIZ]; char *cp, *newline; int width = 0, height = 0; int len; int removespace = (((isascii(chars[0]) && isspace(chars[0])) || (isascii(chars[1]) && isspace(chars[1]))) ? 0 : 1); int lineno = 0; int bytes_per_scanline = 0; struct _scan_list { int allocated; int used; unsigned char *scanlines; struct _scan_list *next; } *head = NULL, *slist = NULL; static unsigned char masktable[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; int padded = 0; #define NTOALLOC 16 #define NewSList() \ slist = (struct _scan_list *) calloc (1, sizeof *slist); \ if (!slist) { \ fprintf (stderr, "%s: unable to allocate scan list\n", \ ProgramName); \ return; \ } \ slist->allocated = NTOALLOC * bytes_per_scanline; \ slist->scanlines = (unsigned char *) calloc(slist->allocated, 1); \ if (!slist->scanlines) { \ fprintf (stderr, "%s: unable to allocate char array\n", \ ProgramName); \ return; \ } \ slist->used = 0; \ slist->next = NULL; while (1) { buf[0] = '\0'; lineno++; if (fgets (buf, sizeof buf, fp) == NULL) break; cp = buf; if (removespace) { for (cp = buf; *cp && isascii(*cp) && isspace(*cp); cp++) ; } if (*cp == '\n' || !*cp) continue; /* empty line */ newline = strchr(cp, '\n'); if (!newline) { fprintf (stderr, "%s: line %d too long.\n", ProgramName, lineno); return; } if (removespace) { for (; --newline > cp && isascii(*newline) && isspace(*newline); ); newline++; } if (newline == cp + 1) continue; *newline = '\0'; len = strlen (cp); if (width == 0) { width = len; padded = ((width & 7) != 0); bytes_per_scanline = (len + 7) / 8; NewSList (); head = slist; } else if (width != len) { fprintf (stderr, "%s: line %d is %d characters wide instead of %d\n", ProgramName, lineno, len, width); return; } if (slist->used + 1 >= slist->allocated) { struct _scan_list *old = slist; NewSList (); old->next = slist; } /* okay, parse the line and stick values into the scanline array */ for (i = 0; i < width; i++) { int ind = (i & 7); int on = 0; if (cp[i] == chars[1]) { on = 1; } else if (cp[i] != chars[0]) { fprintf (stderr, "%s: bad character '%c' on line %d\n", ProgramName, cp[i], lineno); } if (on) slist->scanlines[slist->used] |= masktable[ind]; if (ind == 7) slist->used++; } if (padded) slist->used++; height++; } printf ("#define %s_width %d\n", name, width); printf ("#define %s_height %d\n", name, height); if (xhot >= 0) printf ("#define %s_x_hot %d\n", name, xhot); if (yhot >= 0) printf ("#define %s_y_hot %d\n", name, yhot); printf ("\n"); printf ("static unsigned char %s_bits[] = {\n", name); j = 0; last_character = height * bytes_per_scanline - 1; for (slist = head; slist; slist = slist->next) { for (i = 0; i < slist->used; i++) { printf (" 0x%02x", slist->scanlines[i]); if (j != last_character) putchar (','); if ((j % 12) == 11) putchar ('\n'); j++; } } printf (" };\n"); return; }
/* * Check whether "cp" is a valid ascii representation of an Internet address * and convert to a binary address. Returns 1 if the address is valid, 0 if * not. This replaces inet_addr, the return value from which cannot * distinguish between failure and a local broadcast address. * * This implementation of the standard inet_aton() function was copied * (with trivial modifications) from the OpenBSD project. */ int win32_inet_aton(const char *cp, struct in_addr *addr) { register unsigned int val; register int base, n; register char c; unsigned int parts[4]; register unsigned int *pp = parts; assert(sizeof(val) == 4); c = *cp; while(1) { /* * Collect number up to ``.''. * Values are specified as for C: * 0x=hex, 0=octal, isdigit=decimal. */ if(!isdigit(c)) return (0); val = 0; base = 10; if(c == '0') { c = *++cp; if(c == 'x' || c == 'X') base = 16, c = *++cp; else base = 8; } while(1) { if(isascii(c) && isdigit(c)) { val = (val * base) + (c - '0'); c = *++cp; } else if(base == 16 && isascii(c) && isxdigit(c)) { val = (val << 4) | (c + 10 - (islower(c) ? 'a' : 'A')); c = *++cp; } else break; } if(c == '.') { /* * Internet format: * a.b.c.d * a.b.c (with c treated as 16 bits) * a.b (with b treated as 24 bits) */ if(pp >= parts + 3) return (0); *pp++ = val; c = *++cp; } else break; } /* * Check for trailing characters. */ if(c != '\0' && (!isascii(c) || !isspace(c))) return (0); /* * Concoct the address according to * the number of parts specified. */ n = pp - parts + 1; switch(n) { case 0: return (0); /* initial nondigit */ case 1: /* a -- 32 bits */ break; case 2: /* a.b -- 8.24 bits */ if((val > 0xffffff) || (parts[0] > 0xff)) return (0); val |= parts[0] << 24; break; case 3: /* a.b.c -- 8.8.16 bits */ if((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff)) return (0); val |= (parts[0] << 24) | (parts[1] << 16); break; case 4: /* a.b.c.d -- 8.8.8.8 bits */ if((val > 0xff) || (parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff)) return (0); val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); break; } if(addr) addr->s_addr = htonl(val); return (1); }
/* * Do format conversion placing the output in buffer */ static int format_converter(register buffy * odp, const char *fmt, va_list ap) { register char *sp; register char *bep; register int cc = 0; register int i; register char *s = NULL; char *q; int s_len; register int min_width = 0; int precision = 0; enum { LEFT, RIGHT } adjust; char pad_char; char prefix_char; double fp_num; wide_int i_num = (wide_int) 0; u_wide_int ui_num; char num_buf[NUM_BUF_SIZE]; char char_buf[2]; /* for printing %% and %<unknown> */ /* * Flag variables */ boolean_e is_long; boolean_e alternate_form; boolean_e print_sign; boolean_e print_blank; boolean_e adjust_precision; boolean_e adjust_width; bool_int is_negative; s_len=0; /* warning fix */ sp = odp->nextb; bep = odp->buf_end; while (*fmt) { if (*fmt != '%') { INS_CHAR(*fmt, sp, bep, cc); } else { /* * Default variable settings */ adjust = RIGHT; alternate_form = print_sign = print_blank = NO; pad_char = ' '; prefix_char = NUL; fmt++; /* * Try to avoid checking for flags, width or precision */ if (isascii((int)*fmt) && !islower((int)*fmt)) { /* * Recognize flags: -, #, BLANK, + */ for (;; fmt++) { if (*fmt == '-') adjust = LEFT; else if (*fmt == '+') print_sign = YES; else if (*fmt == '#') alternate_form = YES; else if (*fmt == ' ') print_blank = YES; else if (*fmt == '0') pad_char = '0'; else break; } /* * Check if a width was specified */ if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, min_width); adjust_width = YES; } else if (*fmt == '*') { min_width = va_arg(ap, int); fmt++; adjust_width = YES; if (min_width < 0) { adjust = LEFT; min_width = -min_width; } } else adjust_width = NO; /* * Check if a precision was specified * * XXX: an unreasonable amount of precision may be specified * resulting in overflow of num_buf. Currently we * ignore this possibility. */ if (*fmt == '.') { adjust_precision = YES; fmt++; if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, precision); } else if (*fmt == '*') { precision = va_arg(ap, int); fmt++; if (precision < 0) precision = 0; } else
/*% * Check whether "cp" is a valid ascii representation * of an Internet address and convert to a binary address. * Returns 1 if the address is valid, 0 if not. * This replaces inet_addr, the return value from which * cannot distinguish between failure and a local broadcast address. */ int inet_aton(const char *cp, struct in_addr *addr) { u_long val; int base, n; char c; u_int8_t parts[4]; u_int8_t *pp = parts; int digit; c = *cp; for (;;) { /* * Collect number up to ``.''. * Values are specified as for C: * 0x=hex, 0=octal, isdigit=decimal. */ if (!isdigit((unsigned char)c)) return (0); val = 0; base = 10; digit = 0; if (c == '0') { c = *++cp; if (c == 'x' || c == 'X') base = 16, c = *++cp; else { base = 8; digit = 1 ; } } for (;;) { if (isascii(c) && isdigit((unsigned char)c)) { if (base == 8 && (c == '8' || c == '9')) return (0); val = (val * base) + (c - '0'); c = *++cp; digit = 1; } else if (base == 16 && isascii(c) && isxdigit((unsigned char)c)) { val = (val << 4) | (c + 10 - (islower((unsigned char)c) ? 'a' : 'A')); c = *++cp; digit = 1; } else break; } if (c == '.') { /* * Internet format: * a.b.c.d * a.b.c (with c treated as 16 bits) * a.b (with b treated as 24 bits) */ if (pp >= parts + 3 || val > 0xffU) return (0); *pp++ = val; c = *++cp; } else break; } /* * Check for trailing characters. */ if (c != '\0' && (!isascii(c) || !isspace((unsigned char)c))) return (0); /* * Did we get a valid digit? */ if (!digit) return (0); /* * Concoct the address according to * the number of parts specified. */ n = pp - parts + 1; switch (n) { case 1: /*%< a -- 32 bits */ break; case 2: /*%< a.b -- 8.24 bits */ if (val > 0xffffffU) return (0); val |= parts[0] << 24; break; case 3: /*%< a.b.c -- 8.8.16 bits */ if (val > 0xffffU) return (0); val |= (parts[0] << 24) | (parts[1] << 16); break; case 4: /*%< a.b.c.d -- 8.8.8.8 bits */ if (val > 0xffU) return (0); val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); break; } if (addr != NULL) addr->s_addr = htonl(val); return (1); }
/* This function will convert an attribute value, specified by the OID, * to a string. The result will be a null terminated string. * * res may be null. This will just return the res_size, needed to * hold the string. */ int _gnutls_x509_oid_data2string (const char *oid, void *value, int value_size, char *res, size_t * res_size) { char str[MAX_STRING_LEN], tmpname[128]; const char *ANAME = NULL; int CHOICE = -1, len = -1, result; ASN1_TYPE tmpasn = ASN1_TYPE_EMPTY; if (value == NULL || value_size <= 0 || res_size == NULL) { gnutls_assert (); return GNUTLS_E_INVALID_REQUEST; } if (_gnutls_x509_oid_data_printable (oid) == 0) { gnutls_assert (); return GNUTLS_E_INTERNAL_ERROR; } ANAME = asn1_find_structure_from_oid (_gnutls_get_pkix (), oid); CHOICE = _gnutls_x509_oid_data_choice (oid); if (ANAME == NULL) { gnutls_assert (); return GNUTLS_E_INTERNAL_ERROR; } _gnutls_str_cpy (str, sizeof (str), "PKIX1."); _gnutls_str_cat (str, sizeof (str), ANAME); if ((result = asn1_create_element (_gnutls_get_pkix (), str, &tmpasn)) != ASN1_SUCCESS) { gnutls_assert (); return _gnutls_asn2err (result); } if ((result = asn1_der_decoding (&tmpasn, value, value_size, NULL)) != ASN1_SUCCESS) { gnutls_assert (); asn1_delete_structure (&tmpasn); return _gnutls_asn2err (result); } /* If this is a choice then we read the choice. Otherwise it * is the value; */ len = sizeof (str) - 1; if ((result = asn1_read_value (tmpasn, "", str, &len)) != ASN1_SUCCESS) { /* CHOICE */ gnutls_assert (); asn1_delete_structure (&tmpasn); return _gnutls_asn2err (result); } if (CHOICE == 0) { str[len] = 0; if (res) _gnutls_str_cpy (res, *res_size, str); *res_size = len; asn1_delete_structure (&tmpasn); } else { /* CHOICE */ int non_printable = 0, teletex = 0; str[len] = 0; /* Note that we do not support strings other than * UTF-8 (thus ASCII as well). */ if (strcmp (str, "printableString") != 0 && strcmp (str, "utf8String") != 0) { non_printable = 1; } if (strcmp (str, "teletexString") == 0) teletex = 1; _gnutls_str_cpy (tmpname, sizeof (tmpname), str); len = sizeof (str) - 1; if ((result = asn1_read_value (tmpasn, tmpname, str, &len)) != ASN1_SUCCESS) { asn1_delete_structure (&tmpasn); return _gnutls_asn2err (result); } asn1_delete_structure (&tmpasn); if (teletex != 0) { int ascii = 0, i; /* HACK: if the teletex string contains only ascii * characters then treat it as printable. */ for (i = 0; i < len; i++) if (!isascii (str[i])) ascii = 1; if (ascii == 0) non_printable = 0; } if (res) { if (non_printable == 0) { str[len] = 0; _gnutls_str_cpy (res, *res_size, str); *res_size = len; } else { result = _gnutls_x509_data2hex (str, len, res, res_size); if (result < 0) { gnutls_assert (); return result; } } } } return 0; }
int res_vinit_from_file(res_state statp, int preinit, char *resconf_file) { register FILE *fp; register char *cp, **pp; register int n; char buf[BUFSIZ]; int nserv = 0; /* number of nameserver records read from file */ int haveenv = 0; int havesearch = 0; int isresdefault = 0; unsigned short port; /* HOST BYTE ORDER */ unsigned int i, total_timeout; #ifdef RESOLVSORT int nsort = 0; char *net; #endif int dots; port = NS_DEFAULTPORT; total_timeout = 0; if (!preinit) { statp->retrans = RES_TIMEOUT; statp->retry = RES_DFLRETRY; statp->options = RES_DEFAULT; statp->id = res_randomid(); } if ((statp->options & RES_INIT) != 0) res_ndestroy(statp); /* N.B. we allocate a new statp->_u._ext.ext below */ /* make sure version is set */ statp->_pad = 9; statp->nscount = 0; if ((resconf_file == NULL) || (!strcmp(resconf_file, _PATH_RESCONF))) { isresdefault = 1; #ifdef USELOOPBACK statp->nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); #else statp->nsaddr.sin_addr.s_addr = INADDR_ANY; #endif statp->nsaddr.sin_family = AF_INET; statp->nsaddr.sin_port = htons(NS_DEFAULTPORT); #ifdef HAVE_SA_LEN statp->nsaddr.sin_len = sizeof(struct sockaddr_in); #endif statp->nscount = 1; /* * Force loopback queries to use TCP * so we don't take a timeout if named isn't running. */ statp->options |= RES_USEVC; } statp->ndots = 1; statp->pfcode = 0; statp->_vcsock = -1; statp->_flags = 0; statp->qhook = NULL; statp->rhook = NULL; statp->_u._ext.nscount = 0; statp->_u._ext.ext = (struct __res_state_ext *)calloc(1, sizeof(struct __res_state_ext)); if (statp->_u._ext.ext != NULL) { memset(statp->_u._ext.ext, 0, sizeof(*statp->_u._ext.ext)); statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr; strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa"); strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int"); strcpy(statp->_u._ext.ext->bsuffix, "ip6.arpa"); } #ifdef RESOLVSORT statp->nsort = 0; #endif /* Allow user to override the local domain definition */ cp = getenv("LOCALDOMAIN"); if ((cp != NULL) && (isresdefault != 0)) { (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); statp->defdname[sizeof(statp->defdname) - 1] = '\0'; haveenv++; /* * Set search list to be blank-separated strings * from rest of env value. Permits users of LOCALDOMAIN * to still have a search list, and anyone to set the * one that they want to use as an individual (even more * important now that the rfc1535 stuff restricts searches) */ cp = statp->defdname; pp = statp->dnsrch; *pp++ = cp; for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) { if (*cp == '\n') break; else if (*cp == ' ' || *cp == '\t') { *cp = 0; n = 1; } else if (n != 0) { *pp++ = cp; n = 0; havesearch = 1; } } /* null terminate last domain if there are excess */ while ((*cp != '\0') && (*cp != ' ') && (*cp != '\t') && (*cp != '\n')) cp++; *cp = '\0'; *pp++ = 0; } #define MATCH(line, name) \ (!strncmp(line, name, sizeof(name) - 1) && \ (line[sizeof(name) - 1] == ' ' || \ line[sizeof(name) - 1] == '\t')) if (resconf_file == NULL) resconf_file = _PATH_RESCONF; if ((fp = fopen(resconf_file, "r")) != NULL) { /* look for port number */ while (fgets(buf, sizeof(buf), fp) != NULL) { /* skip comments */ if (*buf == ';' || *buf == '#') continue; /* read default domain name */ if (MATCH(buf, "port")) { cp = buf + sizeof("port") - 1; while (*cp == ' ' || *cp == '\t') cp++; if ((*cp == '\0') || (*cp == '\n')) continue; port = atoi(cp); break; } } fclose(fp); } if ((fp = fopen(resconf_file, "r")) != NULL) { /* read the config file */ while (fgets(buf, sizeof(buf), fp) != NULL) { /* skip comments */ if ((*buf == ';') || (*buf == '#')) continue; /* read default domain name */ if (MATCH(buf, "domain")) { /* skip if have from environ */ if (haveenv) continue; cp = buf + sizeof("domain") - 1; while ((*cp == ' ') || (*cp == '\t')) cp++; if ((*cp == '\0') || (*cp == '\n')) continue; strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); statp->defdname[sizeof(statp->defdname) - 1] = '\0'; cp = strpbrk(statp->defdname, " \t\n"); if (cp != NULL) *cp = '\0'; havesearch = 0; continue; } /* set search list */ if (MATCH(buf, "search")) { /* skip if have from environ */ if (haveenv) continue; cp = buf + sizeof("search") - 1; while ((*cp == ' ') || (*cp == '\t')) cp++; if ((*cp == '\0') || (*cp == '\n')) continue; strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); statp->defdname[sizeof(statp->defdname) - 1] = '\0'; cp = strchr(statp->defdname, '\n'); if (cp != NULL) *cp = '\0'; /* * Set search list to be blank-separated strings * on rest of line. */ cp = statp->defdname; pp = statp->dnsrch; *pp++ = cp; for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) { if ((*cp == ' ') || (*cp == '\t')) { *cp = 0; n = 1; } else if (n != 0) { *pp++ = cp; n = 0; } } /* null terminate last domain if there are excess */ while ((*cp != '\0') && (*cp != ' ') && (*cp != '\t')) cp++; *cp = '\0'; *pp++ = 0; havesearch = 1; continue; } /* read nameservers to query */ if (MATCH(buf, "nameserver") && (nserv < MAXNS)) { #ifndef __APPLE__ struct addrinfo hints, *ai; #endif int dotcount, semicount, status; struct in_addr addr4; struct sockaddr_in sin4; struct in6_addr addr6; struct sockaddr_in6 sin6; unsigned short aport; /* HOST BYTE ORDER */ char *lastdot, *checkp; char sbuf[NI_MAXSERV]; #ifndef __APPLE__ const size_t minsiz = sizeof(statp->_u._ext.ext->nsaddrs[0]); #endif cp = buf + sizeof("nameserver") - 1; while ((*cp == ' ') || (*cp == '\t')) cp++; cp[strcspn(cp, ";# \t\n")] = '\0'; if ((*cp != '\0') && (*cp != '\n')) { #ifndef __APPLE__ memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; /*dummy*/ hints.ai_flags = AI_NUMERICHOST; #endif dotcount = 0; semicount = 0; lastdot = NULL; aport = port; for (checkp = cp; *checkp != '\0'; checkp++) { if (*checkp == ':') semicount++; else if (*checkp == '.') { dotcount++; lastdot = checkp; } } if ((dotcount == 4) || ((semicount > 0) && (lastdot != NULL))) { aport = atoi(lastdot + 1); if (aport == 0) aport = port; *lastdot = '\0'; } sprintf(sbuf, "%u", aport); #ifdef __APPLE__ memset(&addr4, 0, sizeof(struct in_addr)); memset(&sin4, 0, sizeof(struct sockaddr_in)); memset(&addr6, 0, sizeof(struct in6_addr)); memset(&sin6, 0, sizeof(struct sockaddr_in6)); status = inet_pton(AF_INET6, cp, &addr6); if (status == 1) { sin6.sin6_addr = addr6; sin6.sin6_family = AF_INET6; sin6.sin6_port = htons(aport); sin6.sin6_len = sizeof(struct sockaddr_in6); if (statp->_u._ext.ext != NULL) { memcpy(&statp->_u._ext.ext->nsaddrs[nserv], &sin6, sizeof(struct sockaddr_in6)); } statp->nsaddr_list[nserv].sin_family = 0; nserv++; } else { status = inet_pton(AF_INET, cp, &addr4); if (status == 1) { sin4.sin_addr = addr4; sin4.sin_family = AF_INET; sin4.sin_port = htons(port); sin4.sin_len = sizeof(struct sockaddr_in); if (statp->_u._ext.ext != NULL) { memcpy(&statp->_u._ext.ext->nsaddrs[nserv], &sin4, sizeof(struct sockaddr_in)); } memcpy(&statp->nsaddr_list[nserv], &sin4, sizeof(struct sockaddr_in)); nserv++; } } #else if (getaddrinfo(cp, sbuf, &hints, &ai) == 0 && ai->ai_addrlen <= minsiz) { if (statp->_u._ext.ext != NULL) { memcpy(&statp->_u._ext.ext->nsaddrs[nserv], ai->ai_addr, ai->ai_addrlen); } if (ai->ai_addrlen <= sizeof(statp->nsaddr_list[nserv])) { memcpy(&statp->nsaddr_list[nserv], ai->ai_addr, ai->ai_addrlen); } else { statp->nsaddr_list[nserv].sin_family = 0; } freeaddrinfo(ai); nserv++; } #endif } continue; } #ifdef RESOLVSORT if (MATCH(buf, "sortlist")) { struct in_addr a; cp = buf + sizeof("sortlist") - 1; while (nsort < MAXRESOLVSORT) { while ((*cp == ' ') || (*cp == '\t')) cp++; if ((*cp == '\0') || (*cp == '\n') || (*cp == ';')) break; net = cp; while (*cp && !ISSORTMASK(*cp) && (*cp != ';') && isascii(*cp) && !isspace((unsigned char)*cp)) cp++; n = *cp; *cp = 0; if (inet_aton(net, &a)) { statp->sort_list[nsort].addr = a; if (ISSORTMASK(n)) { *cp++ = n; net = cp; while (*cp && (*cp != ';') && isascii(*cp) && !isspace((unsigned char)*cp)) cp++; n = *cp; *cp = 0; if (inet_aton(net, &a)) { statp->sort_list[nsort].mask = a.s_addr; } else { statp->sort_list[nsort].mask = net_mask(statp->sort_list[nsort].addr); } } else { statp->sort_list[nsort].mask = net_mask(statp->sort_list[nsort].addr); } nsort++; } *cp = n; } continue; } #endif if (MATCH(buf, "options")) { res_setoptions(statp, buf + sizeof("options") - 1, "conf"); continue; } if (MATCH(buf, "timeout")) { cp = buf + sizeof("timeout") - 1; while (*cp == ' ' || *cp == '\t') cp++; if ((*cp == '\0') || (*cp == '\n')) continue; i = atoi(cp); if (i > RES_MAXRETRANS) i = RES_MAXRETRANS; total_timeout = i; continue; } } if (nserv > 1) statp->nscount = nserv; #ifdef RESOLVSORT statp->nsort = nsort; #endif fclose(fp); } /* * Last chance to get a nameserver. This should not normally * be necessary */ #ifdef NO_RESOLV_CONF if(nserv == 0) nserv = get_nameservers(statp); #endif if (isresdefault != 0) { if ((statp->defdname[0] == 0) && (gethostname(buf, sizeof(statp->defdname) - 1) == 0) && ((cp = strchr(buf, '.')) != NULL)) { strcpy(statp->defdname, cp + 1); } } /* find components of local domain that might be searched */ if (havesearch == 0) { pp = statp->dnsrch; *pp++ = statp->defdname; *pp = NULL; dots = 0; for (cp = statp->defdname; *cp; cp++) { if (*cp == '.') dots++; } /* Back up over any trailing dots and cut them out of the name */ for (cp--; (cp >= statp->defdname) && (*cp == '.'); cp--) { *cp = '\0'; dots--; } cp = statp->defdname; while (pp < statp->dnsrch + MAXDFLSRCH) { if (dots < LOCALDOMAINPARTS) break; /* we know there is a dot */ cp = strchr(cp, '.') + 1; *pp++ = cp; dots--; } *pp = NULL; #ifdef DEBUG if (statp->options & RES_DEBUG) { printf(";; res_init()... default dnsrch list:\n"); for (pp = statp->dnsrch; *pp; pp++) printf(";;\t%s\n", *pp); printf(";;\t..END..\n"); } #endif } cp = getenv("RES_OPTIONS"); if ((cp != NULL) && (isresdefault != 0)) { res_setoptions(statp, cp, "env"); } #ifdef __APPLE__ /* * Post processing to set the timeout value. */ if (total_timeout != 0) { /* Timeout was set with a "timeout" line in the file */ statp->retrans = total_timeout; } else { /* * Timeout is default, or was set with "options timeout:" * This is a per-select timeout value. Calculate total timeout * and set statp->restrans which we (Apple) use to indicate * total time allowed for a query to be resolved. */ total_timeout = statp->retrans * (statp->retry + 1) * statp->nscount; statp->retrans = total_timeout; } #endif statp->options |= RES_INIT; return (0); }
static int interp_header (uint8_t *header, int header_len) { int i; int packet_length=-1; /* * parse header */ i = 30; while (i<header_len) { uint64_t guid_1, guid_2, length; guid_2 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); i += 8; guid_1 = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); i += 8; // mp_msg(MSGT_NETWORK,MSGL_INFO,"guid found: %016llx%016llx\n", guid_1, guid_2); length = (uint64_t)header[i] | ((uint64_t)header[i+1]<<8) | ((uint64_t)header[i+2]<<16) | ((uint64_t)header[i+3]<<24) | ((uint64_t)header[i+4]<<32) | ((uint64_t)header[i+5]<<40) | ((uint64_t)header[i+6]<<48) | ((uint64_t)header[i+7]<<56); i += 8; if ( (guid_1 == 0x6cce6200aa00d9a6ULL) && (guid_2 == 0x11cf668e75b22630ULL) ) { mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_MMST_HeaderObject); } else if ((guid_1 == 0x6cce6200aa00d9a6ULL) && (guid_2 == 0x11cf668e75b22636ULL)) { mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_MMST_DataObject); } else if ((guid_1 == 0x6553200cc000e48eULL) && (guid_2 == 0x11cfa9478cabdca1ULL)) { packet_length = get_32(header, i+92-24); mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_MMST_FileObjectPacketLen, packet_length, get_32(header, i+96-24)); } else if ((guid_1 == 0x6553200cc000e68eULL) && (guid_2 == 0x11cfa9b7b7dc0791ULL)) { int stream_id = header[i+48] | header[i+49] << 8; mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_MMST_StreamObjectStreamID, stream_id); if (num_stream_ids < MAX_STREAMS) { stream_ids[num_stream_ids] = stream_id; num_stream_ids++; } else { mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_MMST_2ManyStreamID); } } else { #if 0 int b = i; printf ("unknown object (guid: %016llx, %016llx, len: %lld)\n", guid_1, guid_2, length); for (; b < length; b++) { if (isascii(header[b]) || isalpha(header[b])) printf("%c ", header[b]); else printf("%x ", header[b]); } printf("\n"); #else mp_msg(MSGT_NETWORK,MSGL_WARN,MSGTR_MPDEMUX_MMST_UnknownObject); #endif } // mp_msg(MSGT_NETWORK,MSGL_INFO,"length : %lld\n", length); i += length-24; } return packet_length; }
/** Convert the given input string "scaled" into numeric in "result". * Return 0 on success, -1 and errno set on error. */ scan_scaled(char *scaled, long long *result) { char *p = scaled; int sign = 0; unsigned int i, ndigits = 0, fract_digits = 0; long long scale_fact = 1, whole = 0, fpart = 0; /* Skip leading whitespace */ while (isascii((unsigned char)*p) && isspace((unsigned char)*p)) ++p; /* Then at most one leading + or - */ while (*p == '-' || *p == '+') { if (*p == '-') { if (sign) { errno = EINVAL; return -1; } sign = -1; ++p; } else if (*p == '+') { if (sign) { errno = EINVAL; return -1; } sign = +1; ++p; } } /* Main loop: Scan digits, find decimal point, if present. * We don't allow exponentials, so no scientific notation * (but note that E for Exa might look like e to some!). * Advance 'p' to end, to get scale factor. */ for (; isascii((unsigned char)*p) && (isdigit((unsigned char)*p) || *p=='.'); ++p) { if (*p == '.') { if (fract_digits > 0) { /* oops, more than one '.' */ errno = EINVAL; return -1; } fract_digits = 1; continue; } i = (*p) - '0'; /* whew! finally a digit we can use */ if (fract_digits > 0) { if (fract_digits >= MAX_DIGITS-1) /* ignore extra fractional digits */ continue; fract_digits++; /* for later scaling */ fpart *= 10; fpart += i; } else { /* normal digit */ if (++ndigits >= MAX_DIGITS) { errno = ERANGE; return -1; } whole *= 10; whole += i; } } if (sign) { whole *= sign; fpart *= sign; } /* If no scale factor given, we're done. fraction is discarded. */ if (!*p) { *result = whole; return 0; } /* Validate scale factor, and scale whole and fraction by it. */ for (i = 0; i < SCALE_LENGTH; i++) { /** Are we there yet? */ if (*p == scale_chars[i] || *p == tolower((unsigned char)scale_chars[i])) { /* If it ends with alphanumerics after the scale char, bad. */ if (isalnum((unsigned char)*(p+1))) { errno = EINVAL; return -1; } scale_fact = scale_factors[i]; /* scale whole part */ whole *= scale_fact; /* truncate fpart so it does't overflow. * then scale fractional part. */ while (fpart >= LLONG_MAX / scale_fact) { fpart /= 10; fract_digits--; } fpart *= scale_fact; if (fract_digits > 0) { for (i = 0; i < fract_digits -1; i++) fpart /= 10; } whole += fpart; *result = whole; return 0; } } errno = ERANGE; return -1; }
static bool_t modify_urls (blockmail_t *blockmail, receiver_t *rec, block_t *block) /*{{{*/ { int n; int len; const xmlChar *cont; int lstore; int state; char initial; char ch; int start, end; int mask; int clen; bool_t changed; xmlBufferEmpty (block -> out); len = xmlBufferLength (block -> in); cont = xmlBufferContent (block -> in); lstore = 0; state = ST_INITIAL; if (block -> nr == 1) initial = 'h'; else if (block -> nr == 2) initial = '<'; else initial = '\0'; start = -1; end = -1; mask = 1 << (block -> nr - 1); changed = false; for (n = 0; n <= len; ) { if (n < len) { clen = xmlCharLength (cont[n]); if ((clen == 1) && isascii ((char) cont[n])) { ch = (char) cont[n]; switch (state) { case ST_INITIAL: if (tolower (ch) == initial) { if (block -> nr == 1) { state = 1; start = n; } else if (block -> nr == 2) state = 100; } break; # define CHK(ccc) do { if ((ccc) == ch) ++state; else state = ST_INITIAL; } while (0) # define CCHK(ccc) do { if ((ccc) == tolower (ch)) ++state; else state = ST_INITIAL; } while (0) case 1: CCHK ('t'); break; case 2: CCHK ('t'); break; case 3: CCHK ('p'); break; case 4: ++state; if (tolower (ch) == 's') break; /* Fall through . . . */ case 5: CHK (':'); break; case 6: CHK ('/'); break; case 7: if (ch == '/') state = ST_START_FOUND; else state = ST_INITIAL; break; case 100: CCHK ('a'); break; # define HCHK(ccc) do { if ((ccc) == tolower (ch)) ++state; else if ('>' == ch) state = ST_INITIAL; else state = 101; } while (0) case 101: HCHK ('h'); break; case 102: HCHK ('r'); break; case 103: HCHK ('e'); break; case 104: HCHK ('f'); break; # undef HCHK case 105: CHK ('='); break; case 106: ++state; if (ch == '"') break; /* Fall through . . */ case 107: if (tolower (ch) == 'h') { state = 1; start = n; } else state = ST_INITIAL; break; case ST_START_FOUND: if (isspace ((int) ((unsigned char) ch)) || (ch == '"') || (ch == '>')) { end = n; state = ST_END_FOUND; } break; } # undef CHK # undef CCHK } else { if (state == ST_START_FOUND) { end = n; state = ST_END_FOUND; } else state = ST_INITIAL; } n += clen; } else { if (state == ST_START_FOUND) { end = n; state = ST_END_FOUND; } ++n; } if (state == ST_END_FOUND) { int ulen, m, o; ulen = end - start; for (m = 0; m < blockmail -> url_count; ++m) if ((blockmail -> url[m] -> usage & mask) && (blockmail -> url[m] -> dlen == ulen) && (! xmlStrncmp (blockmail -> url[m] -> dptr, cont + start, ulen))) break; if (m < blockmail -> url_count) { if (lstore < start) xmlBufferAdd (block -> out, cont + lstore, start - lstore); for (o = 0; o < rec -> url_count; ++o) if (rec -> url[o] -> uid == blockmail -> url[m] -> uid) break; if (o < rec -> url_count) xmlBufferAdd (block -> out, rec -> url[o] -> dptr, rec -> url[o] -> dlen); lstore = end; changed = true; } state = ST_INITIAL; } } if (changed) { if (lstore < len) xmlBufferAdd (block -> out, cont + lstore, len - lstore); SWAP (block); } return true; }/*}}}*/
/* * Main parse routine for an opened file. This is called for each * opened file and simply loops around the full input file, possibly * nesting (i.e., with `so'). */ static void mparse_buf_r(struct mparse *curp, struct buf blk, int start) { const struct tbl_span *span; struct buf ln; enum rofferr rr; int i, of, rc; int pos; /* byte number in the ln buffer */ int lnn; /* line number in the real file */ unsigned char c; memset(&ln, 0, sizeof(struct buf)); lnn = curp->line; pos = 0; for (i = 0; i < (int)blk.sz; ) { if (0 == pos && '\0' == blk.buf[i]) break; if (start) { curp->line = lnn; curp->reparse_count = 0; } while (i < (int)blk.sz && (start || '\0' != blk.buf[i])) { /* * When finding an unescaped newline character, * leave the character loop to process the line. * Skip a preceding carriage return, if any. */ if ('\r' == blk.buf[i] && i + 1 < (int)blk.sz && '\n' == blk.buf[i + 1]) ++i; if ('\n' == blk.buf[i]) { ++i; ++lnn; break; } /* * Warn about bogus characters. If you're using * non-ASCII encoding, you're screwing your * readers. Since I'd rather this not happen, * I'll be helpful and replace these characters * with "?", so we don't display gibberish. * Note to manual writers: use special characters. */ c = (unsigned char) blk.buf[i]; if ( ! (isascii(c) && (isgraph(c) || isblank(c)))) { mandoc_msg(MANDOCERR_BADCHAR, curp, curp->line, pos, NULL); i++; if (pos >= (int)ln.sz) resize_buf(&ln, 256); ln.buf[pos++] = '?'; continue; } /* Trailing backslash = a plain char. */ if ('\\' != blk.buf[i] || i + 1 == (int)blk.sz) { if (pos >= (int)ln.sz) resize_buf(&ln, 256); ln.buf[pos++] = blk.buf[i++]; continue; } /* * Found escape and at least one other character. * When it's a newline character, skip it. * When there is a carriage return in between, * skip that one as well. */ if ('\r' == blk.buf[i + 1] && i + 2 < (int)blk.sz && '\n' == blk.buf[i + 2]) ++i; if ('\n' == blk.buf[i + 1]) { i += 2; ++lnn; continue; } if ('"' == blk.buf[i + 1] || '#' == blk.buf[i + 1]) { i += 2; /* Comment, skip to end of line */ for (; i < (int)blk.sz; ++i) { if ('\n' == blk.buf[i]) { ++i; ++lnn; break; } } /* Backout trailing whitespaces */ for (; pos > 0; --pos) { if (ln.buf[pos - 1] != ' ') break; if (pos > 2 && ln.buf[pos - 2] == '\\') break; } break; } /* Some other escape sequence, copy & cont. */ if (pos + 1 >= (int)ln.sz) resize_buf(&ln, 256); ln.buf[pos++] = blk.buf[i++]; ln.buf[pos++] = blk.buf[i++]; } if (pos >= (int)ln.sz) resize_buf(&ln, 256); ln.buf[pos] = '\0'; /* * A significant amount of complexity is contained by * the roff preprocessor. It's line-oriented but can be * expressed on one line, so we need at times to * readjust our starting point and re-run it. The roff * preprocessor can also readjust the buffers with new * data, so we pass them in wholesale. */ of = 0; /* * Maintain a lookaside buffer of all parsed lines. We * only do this if mparse_keep() has been invoked (the * buffer may be accessed with mparse_getkeep()). */ if (curp->secondary) { curp->secondary->buf = mandoc_realloc (curp->secondary->buf, curp->secondary->sz + pos + 2); memcpy(curp->secondary->buf + curp->secondary->sz, ln.buf, pos); curp->secondary->sz += pos; curp->secondary->buf [curp->secondary->sz] = '\n'; curp->secondary->sz++; curp->secondary->buf [curp->secondary->sz] = '\0'; } rerun: rr = roff_parseln (curp->roff, curp->line, &ln.buf, &ln.sz, of, &of); switch (rr) { case (ROFF_REPARSE): if (REPARSE_LIMIT >= ++curp->reparse_count) mparse_buf_r(curp, ln, 0); else mandoc_msg(MANDOCERR_ROFFLOOP, curp, curp->line, pos, NULL); pos = 0; continue; case (ROFF_APPEND): pos = (int)strlen(ln.buf); continue; case (ROFF_RERUN): goto rerun; case (ROFF_IGN): pos = 0; continue; case (ROFF_ERR): assert(MANDOCLEVEL_FATAL <= curp->file_status); break; case (ROFF_SO): /* * We remove `so' clauses from our lookaside * buffer because we're going to descend into * the file recursively. */ if (curp->secondary) curp->secondary->sz -= pos + 1; mparse_readfd_r(curp, -1, ln.buf + of, 1); if (MANDOCLEVEL_FATAL <= curp->file_status) break; pos = 0; continue; default: break; } /* * If we encounter errors in the recursive parse, make * sure we don't continue parsing. */ if (MANDOCLEVEL_FATAL <= curp->file_status) break; /* * If input parsers have not been allocated, do so now. * We keep these instanced between parsers, but set them * locally per parse routine since we can use different * parsers with each one. */ if ( ! (curp->man || curp->mdoc)) pset(ln.buf + of, pos - of, curp); /* * Lastly, push down into the parsers themselves. One * of these will have already been set in the pset() * routine. * If libroff returns ROFF_TBL, then add it to the * currently open parse. Since we only get here if * there does exist data (see tbl_data.c), we're * guaranteed that something's been allocated. * Do the same for ROFF_EQN. */ rc = -1; if (ROFF_TBL == rr) while (NULL != (span = roff_span(curp->roff))) { rc = curp->man ? man_addspan(curp->man, span) : mdoc_addspan(curp->mdoc, span); if (0 == rc) break; } else if (ROFF_EQN == rr) rc = curp->mdoc ? mdoc_addeqn(curp->mdoc, roff_eqn(curp->roff)) : man_addeqn(curp->man, roff_eqn(curp->roff)); else if (curp->man || curp->mdoc) rc = curp->man ? man_parseln(curp->man, curp->line, ln.buf, of) : mdoc_parseln(curp->mdoc, curp->line, ln.buf, of); if (0 == rc) { assert(MANDOCLEVEL_FATAL <= curp->file_status); break; } /* Temporary buffers typically are not full. */ if (0 == start && '\0' == blk.buf[i]) break; /* Start the next input line. */ pos = 0; } free(ln.buf); }
extern char * escape_chars(char const * in, unsigned int len) { char * out; unsigned int inpos; unsigned int outpos; if (!in) return NULL; out = (char*)xmalloc(len*4+1); /* if all turn into \xxx */ for (inpos=0,outpos=0; inpos<len; inpos++) { if (in[inpos]=='\\') { out[outpos++] = '\\'; out[outpos++] = '\\'; } else if (in[inpos]=='"') { out[outpos++] = '\\'; out[outpos++] = '"'; } else if (isascii((int)in[inpos]) && isprint((int)in[inpos])) out[outpos++] = in[inpos]; else if (in[inpos]=='\a') { out[outpos++] = '\\'; out[outpos++] = 'a'; } else if (in[inpos]=='\b') { out[outpos++] = '\\'; out[outpos++] = 'b'; } else if (in[inpos]=='\t') { out[outpos++] = '\\'; out[outpos++] = 't'; } else if (in[inpos]=='\n') { out[outpos++] = '\\'; out[outpos++] = 'n'; } else if (in[inpos]=='\v') { out[outpos++] = '\\'; out[outpos++] = 'v'; } else if (in[inpos]=='\f') { out[outpos++] = '\\'; out[outpos++] = 'f'; } else if (in[inpos]=='\r') { out[outpos++] = '\\'; out[outpos++] = 'r'; } else { out[outpos++] = '\\'; /* always 001 through 377 octal */ sprintf(&out[outpos],"%03o",(unsigned int)(unsigned char)in[inpos]); outpos += 3; } } /* if outpos >= len*4+1 then the buffer was overflowed */ out[outpos] = '\0'; return out; }
static wmEvent *rna_Window_event_add_simulate(wmWindow *win, ReportList *reports, int type, int value, const char *unicode, int x, int y, bool shift, bool ctrl, bool alt, bool oskey) { if ((G.f & G_FLAG_EVENT_SIMULATE) == 0) { BKE_report(reports, RPT_ERROR, "Not running with '--enable-event-simulate' enabled"); return NULL; } if (!ELEM(value, KM_PRESS, KM_RELEASE, KM_NOTHING)) { BKE_report(reports, RPT_ERROR, "value: only 'PRESS/RELEASE/NOTHING' are supported"); return NULL; } if (ISKEYBOARD(type) || ISMOUSE_BUTTON(type)) { if (!ELEM(value, KM_PRESS, KM_RELEASE)) { BKE_report(reports, RPT_ERROR, "value: must be 'PRESS/RELEASE' for keyboard/buttons"); return NULL; } } if (ELEM(type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { if (value != KM_NOTHING) { BKE_report(reports, RPT_ERROR, "value: must be 'NOTHING' for motion"); return NULL; } } if (unicode != NULL) { if (value != KM_PRESS) { BKE_report(reports, RPT_ERROR, "value: must be 'PRESS' when unicode is set"); return NULL; } } /* TODO: validate NDOF. */ char ascii = 0; if (unicode != NULL) { int len = BLI_str_utf8_size(unicode); if (len == -1 || unicode[len] != '\0') { BKE_report(reports, RPT_ERROR, "Only a single character supported"); return NULL; } if (len == 1 && isascii(unicode[0])) { ascii = unicode[0]; } } wmEvent e = *win->eventstate; e.type = type; e.val = value; e.x = x; e.y = y; /* Note: KM_MOD_FIRST, KM_MOD_SECOND aren't used anywhere, set as bools */ e.shift = shift; e.ctrl = ctrl; e.alt = alt; e.oskey = oskey; e.prevx = win->eventstate->x; e.prevy = win->eventstate->y; e.prevval = win->eventstate->val; e.prevtype = win->eventstate->type; e.ascii = '\0'; e.utf8_buf[0] = '\0'; if (unicode != NULL) { e.ascii = ascii; STRNCPY(e.utf8_buf, unicode); } return WM_event_add_simulate(win, &e); }
static void dissect_icap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { proto_tree *icap_tree = NULL; proto_item *ti = NULL; proto_item *hidden_item; gint offset = 0; const guchar *line; gint next_offset; const guchar *linep, *lineend; int linelen; guchar c; icap_type_t icap_type; int datalen; col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICAP"); if (check_col(pinfo->cinfo, COL_INFO)) { /* * Put the first line from the buffer into the summary * if it's an ICAP header (but leave out the * line terminator). * Otherwise, just call it a continuation. * * Note that "tvb_find_line_end()" will return a value that * is not longer than what's in the buffer, so the * "tvb_get_ptr()" call won't throw an exception. */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); line = tvb_get_ptr(tvb, offset, linelen); icap_type = ICAP_OTHER; /* type not known yet */ if (is_icap_message(line, linelen, &icap_type)) col_add_str(pinfo->cinfo, COL_INFO, format_text(line, linelen)); else col_set_str(pinfo->cinfo, COL_INFO, "Continuation"); } if (tree) { ti = proto_tree_add_item(tree, proto_icap, tvb, offset, -1, ENC_NA); icap_tree = proto_item_add_subtree(ti, ett_icap); } /* * Process the packet data, a line at a time. */ icap_type = ICAP_OTHER; /* type not known yet */ while (tvb_offset_exists(tvb, offset)) { gboolean is_icap = FALSE; gboolean loop_done = FALSE; /* * Find the end of the line. */ linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE); /* * Get a buffer that refers to the line. */ line = tvb_get_ptr(tvb, offset, linelen); lineend = line + linelen; /* * find header format */ if (is_icap_message(line, linelen, &icap_type)) { goto is_icap_header; } /* * if it looks like a blank line, end of header perhaps? */ if (linelen == 0) { goto is_icap_header; } /* * No. Does it look like a header? */ linep = line; loop_done = FALSE; while (linep < lineend && (!loop_done)) { c = *linep++; /* * This must be a CHAR to be part of a token; that * means it must be ASCII. */ if (!isascii(c)) { is_icap = FALSE; break; /* not ASCII, thus not a CHAR */ } /* * This mustn't be a CTL to be part of a token. * * XXX - what about leading LWS on continuation * lines of a header? */ if (iscntrl(c)) { is_icap = FALSE; break; /* CTL, not part of a header */ } switch (c) { case '(': case ')': case '<': case '>': case '@': case ',': case ';': case '\\': case '"': case '/': case '[': case ']': case '?': case '=': case '{': case '}': /* * It's a separator, so it's not part of a * token, so it's not a field name for the * beginning of a header. * * (We don't have to check for HT; that's * already been ruled out by "iscntrl()".) * * XXX - what about ' '? HTTP's checks * check for that. */ is_icap = FALSE; loop_done = TRUE; break; case ':': /* * This ends the token; we consider this * to be a header. */ goto is_icap_header; } } /* * We don't consider this part of an ICAP message, * so we don't display it. * (Yeah, that means we don't display, say, a text/icap * page, but you can get that from the data pane.) */ if (!is_icap) break; is_icap_header: if (tree) { proto_tree_add_text(icap_tree, tvb, offset, next_offset - offset, "%s", tvb_format_text(tvb, offset, next_offset - offset) ); } offset = next_offset; } if (tree) { switch (icap_type) { case ICAP_OPTIONS: hidden_item = proto_tree_add_boolean(icap_tree, hf_icap_options, tvb, 0, 0, 1); PROTO_ITEM_SET_HIDDEN(hidden_item); break; case ICAP_REQMOD: hidden_item = proto_tree_add_boolean(icap_tree, hf_icap_reqmod, tvb, 0, 0, 1); PROTO_ITEM_SET_HIDDEN(hidden_item); break; case ICAP_RESPMOD: hidden_item = proto_tree_add_boolean(icap_tree, hf_icap_respmod, tvb, 0, 0, 1); PROTO_ITEM_SET_HIDDEN(hidden_item); break; case ICAP_RESPONSE: hidden_item = proto_tree_add_boolean(icap_tree, hf_icap_response, tvb, 0, 0, 1); PROTO_ITEM_SET_HIDDEN(hidden_item); break; case ICAP_OTHER: default: break; } } datalen = tvb_length_remaining(tvb, offset); if (datalen > 0) { call_dissector(data_handle, tvb_new_subset_remaining(tvb, offset), pinfo, icap_tree); } }
// Insert a string into the message text. Will insert into any field // description. Except for an ArgId of zero (message number), if the ArgId // is not found, the routine adds a line with the parameter so information // will not be lost. void DjVuMessageLite::InsertArg( GUTF8String &message, const int ArgId, const GUTF8String &arg ) const { // argument target string const GUTF8String target= "%"+GUTF8String(ArgId)+"!"; // location of target string int format_start = message.search( (const char *)target ); if( format_start >= 0 ) { do { const int n=format_start+target.length()+1; const int format_end=message.search((unsigned long)'!',n); if(format_end > format_start) { const int len=1+format_end-n; if(len && isascii(message[n-1])) { GUTF8String narg; GUTF8String format="%"+message.substr(n-1,len); switch(format[len]) { case 'd': case 'i': narg.format((const char *)format,arg.toInt()); break; case 'u': case 'o': case 'x': case 'X': narg.format((const char *)format,(unsigned int)arg.toInt()); break; case 'f': case 'g': case 'e': { int endpos; narg.format((const char *)format, arg.toDouble(0,endpos)); if( endpos < 0 ) narg = arg; } break; default: narg.format((const char *)format,(const char *)arg); break; } message = message.substr( 0, format_start )+narg +message.substr( format_end+1, -1 ); }else { message = message.substr( 0, format_start )+arg +message.substr( format_end+1, -1 ); } } format_start=message.search((const char*)target, format_start+arg.length()); } while(format_start >= 0); } else { // Not found, fake it if( ArgId != 0 ) { message += "\n"+LookUpSingle(uparameter+("\t"+arg)); } } }
/* * static int * inet_net_pton_ipv4(src, dst, size) * convert IPv4 network number from presentation to network format. * accepts hex octets, hex strings, decimal octets, and /CIDR. * "size" is in bytes and describes "dst". * return: * number of bits, either imputed classfully or specified with /CIDR, * or -1 if some failure occurred (check errno). ENOENT means it was * not an IPv4 network specification. * note: * network byte order assumed. this means 192.5.5.240/28 has * 0b11110000 in its fourth octet. * author: * Paul Vixie (ISC), June 1996 */ static int inet_net_pton_ipv4( const char *src, unsigned char *dst, size_t size) { static const char xdigits[] = "0123456789abcdef"; static const char digits[] = "0123456789"; int n, ch, tmp = 0, dirty, bits; const unsigned char *odst = dst; ch = *src++; if (ch == '0' && (src[0] == 'x' || src[0] == 'X') && isascii((unsigned char)(src[1])) && isxdigit((unsigned char)(src[1]))) { /* Hexadecimal: Eat nybble string. */ if (size == 0) goto emsgsize; dirty = 0; src++; /* skip x or X. */ while ((ch = *src++) != '\0' && isascii((unsigned char)ch) && isxdigit((unsigned char)ch)) { if (isupper((unsigned char)ch)) ch = tolower((unsigned char)ch); n = strchr(xdigits, ch) - xdigits; if (dirty == 0) tmp = n; else tmp = (tmp << 4) | n; if (++dirty == 2) { if (size-- == 0) goto emsgsize; *dst++ = (unsigned char) tmp; dirty = 0; } } if (dirty) { /* Odd trailing nybble? */ if (size-- == 0) goto emsgsize; *dst++ = (unsigned char) (tmp << 4); } } else if (isascii((unsigned char)ch) && isdigit((unsigned char)ch)) { /* Decimal: eat dotted digit string. */ for (;;) { tmp = 0; do { n = strchr(digits, ch) - digits; tmp *= 10; tmp += n; if (tmp > 255) goto enoent; } while ((ch = *src++) != '\0' && isascii((unsigned char)ch) && isdigit((unsigned char)ch)); if (size-- == 0) goto emsgsize; *dst++ = (unsigned char) tmp; if (ch == '\0' || ch == '/') break; if (ch != '.') goto enoent; ch = *src++; if (!isascii((unsigned char)ch) || !isdigit((unsigned char)ch)) goto enoent; } } else goto enoent; bits = -1; if (ch == '/' && isascii((unsigned char)(src[0])) && isdigit((unsigned char)(src[0])) && dst > odst) { /* CIDR width specifier. Nothing can follow it. */ ch = *src++; /* Skip over the /. */ bits = 0; do { n = strchr(digits, ch) - digits; bits *= 10; bits += n; } while ((ch = *src++) != '\0' && isascii((unsigned char)ch) && isdigit((unsigned char)ch)); if (ch != '\0') goto enoent; if (bits > 32) goto emsgsize; } /* Firey death and destruction unless we prefetched EOS. */ if (ch != '\0') goto enoent; /* If nothing was written to the destination, we found no address. */ if (dst == odst) goto enoent; /* If no CIDR spec was given, infer width from net class. */ if (bits == -1) { if (*odst >= 240) /* Class E */ bits = 32; else if (*odst >= 224) /* Class D */ bits = 4; else if (*odst >= 192) /* Class C */ bits = 24; else if (*odst >= 128) /* Class B */ bits = 16; else /* Class A */ bits = 8; /* If imputed mask is narrower than specified octets, widen. */ if (bits >= 8 && bits < ((dst - odst) * 8)) bits = (dst - odst) * 8; } /* Extend network to cover the actual mask. */ while (bits > ((dst - odst) * 8)) { if (size-- == 0) goto emsgsize; *dst++ = '\0'; } return (bits); enoent: errno = ENOENT; return (-1); emsgsize: errno = EMSGSIZE; return (-1); }
/** * New sprintf implementation for PHP. * * Modifiers: * * " " pad integers with spaces * "-" left adjusted field * n field size * "."n precision (floats only) * "+" Always place a sign (+ or -) in front of a number * * Type specifiers: * * "%" literal "%", modifiers are ignored. * "b" integer argument is printed as binary * "c" integer argument is printed as a single character * "d" argument is an integer * "f" the argument is a float * "o" integer argument is printed as octal * "s" argument is a string * "x" integer argument is printed as lowercase hexadecimal * "X" integer argument is printed as uppercase hexadecimal */ char *string_printf(const char *format, int len, CArrRef args, int *outlen) { Array vargs = args; if (!vargs.isNull() && !vargs->isVectorData()) { vargs = Array::Create(); for (ArrayIter iter(args); iter; ++iter) { vargs.append(iter.second()); } } if (len == 0) { return strdup(""); } int size = 240; char *result = (char *)malloc(size); int outpos = 0; int argnum = 0, currarg = 1; for (int inpos = 0; inpos < len; ++inpos) { char ch = format[inpos]; int expprec = 0; if (ch != '%') { appendchar(&result, &outpos, &size, ch); continue; } if (format[inpos + 1] == '%') { appendchar(&result, &outpos, &size, '%'); inpos++; continue; } /* starting a new format specifier, reset variables */ int alignment = ALIGN_RIGHT; int adjusting = 0; char padding = ' '; int always_sign = 0; int width, precision; inpos++; /* skip the '%' */ ch = format[inpos]; if (isascii(ch) && !isalpha(ch)) { /* first look for argnum */ int temppos = inpos; while (isdigit((int)format[temppos])) temppos++; if (format[temppos] == '$') { argnum = getnumber(format, &inpos); if (argnum <= 0) { free(result); throw_invalid_argument("argnum: must be greater than zero"); return nullptr; } inpos++; /* skip the '$' */ } else { argnum = currarg++; } /* after argnum comes modifiers */ for (;; inpos++) { ch = format[inpos]; if (ch == ' ' || ch == '0') { padding = ch; } else if (ch == '-') { alignment = ALIGN_LEFT; /* space padding, the default */ } else if (ch == '+') { always_sign = 1; } else if (ch == '\'') { padding = format[++inpos]; } else { break; } } ch = format[inpos]; /* after modifiers comes width */ if (isdigit(ch)) { if ((width = getnumber(format, &inpos)) < 0) { free(result); throw_invalid_argument("width: must be greater than zero " "and less than %d", INT_MAX); return nullptr; } adjusting |= ADJ_WIDTH; } else { width = 0; } ch = format[inpos]; /* after width and argnum comes precision */ if (ch == '.') { ch = format[++inpos]; if (isdigit((int)ch)) { if ((precision = getnumber(format, &inpos)) < 0) { free(result); throw_invalid_argument("precision: must be greater than zero " "and less than %d", INT_MAX); return nullptr; } ch = format[inpos]; adjusting |= ADJ_PRECISION; expprec = 1; } else { precision = 0; } } else { precision = 0; } } else { width = precision = 0; argnum = currarg++; } if (argnum > vargs.size()) { free(result); throw_invalid_argument("arguments: (too few)"); return nullptr; } if (ch == 'l') { ch = format[++inpos]; } /* now we expect to find a type specifier */ Variant tmp = vargs[argnum-1]; switch (ch) { case 's': { String s = tmp.toString(); appendstring(&result, &outpos, &size, s, width, precision, padding, alignment, s.size(), 0, expprec, 0); break; } case 'd': appendint(&result, &outpos, &size, tmp.toInt64(), width, padding, alignment, always_sign); break; case 'u': appenduint(&result, &outpos, &size, tmp.toInt64(), width, padding, alignment); break; case 'g': case 'G': case 'e': case 'E': case 'f': case 'F': appenddouble(&result, &outpos, &size, tmp.toDouble(), width, padding, alignment, precision, adjusting, ch, always_sign); break; case 'c': appendchar(&result, &outpos, &size, tmp.toByte()); break; case 'o': append2n(&result, &outpos, &size, tmp.toInt64(), width, padding, alignment, 3, hexchars, expprec); break; case 'x': append2n(&result, &outpos, &size, tmp.toInt64(), width, padding, alignment, 4, hexchars, expprec); break; case 'X': append2n(&result, &outpos, &size, tmp.toInt64(), width, padding, alignment, 4, HEXCHARS, expprec); break; case 'b': append2n(&result, &outpos, &size, tmp.toInt64(), width, padding, alignment, 1, hexchars, expprec); break; case '%': appendchar(&result, &outpos, &size, '%'); break; default: break; } } /* possibly, we have to make sure we have room for the terminating null? */ result[outpos]=0; if (outlen) *outlen = outpos; return result; }
/* High bit set, or ISO-2022-INT */ static int non_ascii(int ch) { return !isascii(ch) || ch == '\033'; }
/* * Do format conversion placing the output in buffer */ static int xbuf_format_converter(char **outbuf, const char *fmt, va_list ap) { register char *s = nullptr; char *q; int s_len; register int min_width = 0; int precision = 0; enum { LEFT, RIGHT } adjust; char pad_char; char prefix_char; double fp_num; wide_int i_num = (wide_int) 0; u_wide_int ui_num; char num_buf[NUM_BUF_SIZE]; char char_buf[2]; /* for printing %% and %<unknown> */ #ifdef HAVE_LOCALE_H struct lconv *lconv = nullptr; #endif /* * Flag variables */ length_modifier_e modifier; boolean_e alternate_form; boolean_e print_sign; boolean_e print_blank; boolean_e adjust_precision; boolean_e adjust_width; int is_negative; int size = 240; char *result = (char *)malloc(size); int outpos = 0; while (*fmt) { if (*fmt != '%') { appendchar(&result, &outpos, &size, *fmt); } else { /* * Default variable settings */ adjust = RIGHT; alternate_form = print_sign = print_blank = NO; pad_char = ' '; prefix_char = NUL; fmt++; /* * Try to avoid checking for flags, width or precision */ if (isascii((int)*fmt) && !islower((int)*fmt)) { /* * Recognize flags: -, #, BLANK, + */ for (;; fmt++) { if (*fmt == '-') adjust = LEFT; else if (*fmt == '+') print_sign = YES; else if (*fmt == '#') alternate_form = YES; else if (*fmt == ' ') print_blank = YES; else if (*fmt == '0') pad_char = '0'; else break; } /* * Check if a width was specified */ if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, min_width); adjust_width = YES; } else if (*fmt == '*') { min_width = va_arg(ap, int); fmt++; adjust_width = YES; if (min_width < 0) { adjust = LEFT; min_width = -min_width; } } else adjust_width = NO; /* * Check if a precision was specified * * XXX: an unreasonable amount of precision may be specified * resulting in overflow of num_buf. Currently we * ignore this possibility. */ if (*fmt == '.') { adjust_precision = YES; fmt++; if (isdigit((int)*fmt)) { STR_TO_DEC(fmt, precision); } else if (*fmt == '*') { precision = va_arg(ap, int); fmt++; if (precision < 0) precision = 0; } else
/* This will encode and write the AttributeTypeAndValue field. * 'multi' must be zero if writing an AttributeTypeAndValue, and 1 if Attribute. * In all cases only one value is written. */ int _gnutls_x509_encode_and_write_attribute (const char *given_oid, ASN1_TYPE asn1_struct, const char *where, const void *_data, int sizeof_data, int multi) { const char *val_name; const opaque *data = _data; char tmp[128]; ASN1_TYPE c2; int result; /* Find how to encode the data. */ val_name = asn1_find_structure_from_oid (_gnutls_get_pkix (), given_oid); if (val_name == NULL) { gnutls_assert (); return GNUTLS_E_X509_UNSUPPORTED_OID; } _gnutls_str_cpy (tmp, sizeof (tmp), "PKIX1."); _gnutls_str_cat (tmp, sizeof (tmp), val_name); result = asn1_create_element (_gnutls_get_pkix (), tmp, &c2); if (result != ASN1_SUCCESS) { gnutls_assert (); return _gnutls_asn2err (result); } tmp[0] = 0; if ((result = _gnutls_x509_oid_data_choice (given_oid)) > 0) { char *string_type; int i; string_type = "printableString"; /* Check if the data is plain ascii, and use * the UTF8 string type if not. */ for (i = 0; i < sizeof_data; i++) { if (!isascii (data[i])) { string_type = "utf8String"; break; } } /* if the type is a CHOICE then write the * type we'll use. */ result = asn1_write_value (c2, "", string_type, 1); if (result != ASN1_SUCCESS) { gnutls_assert (); asn1_delete_structure (&c2); return _gnutls_asn2err (result); } _gnutls_str_cpy (tmp, sizeof (tmp), string_type); } result = asn1_write_value (c2, tmp, data, sizeof_data); if (result != ASN1_SUCCESS) { gnutls_assert (); asn1_delete_structure (&c2); return _gnutls_asn2err (result); } /* write the data (value) */ _gnutls_str_cpy (tmp, sizeof (tmp), where); _gnutls_str_cat (tmp, sizeof (tmp), ".value"); if (multi != 0) { /* if not writing an AttributeTypeAndValue, but an Attribute */ _gnutls_str_cat (tmp, sizeof (tmp), "s"); /* values */ result = asn1_write_value (asn1_struct, tmp, "NEW", 1); if (result != ASN1_SUCCESS) { gnutls_assert (); return _gnutls_asn2err (result); } _gnutls_str_cat (tmp, sizeof (tmp), ".?LAST"); } result = _gnutls_x509_der_encode_and_copy (c2, "", asn1_struct, tmp, 0); if (result < 0) { gnutls_assert (); return result; } /* write the type */ _gnutls_str_cpy (tmp, sizeof (tmp), where); _gnutls_str_cat (tmp, sizeof (tmp), ".type"); result = asn1_write_value (asn1_struct, tmp, given_oid, 1); if (result != ASN1_SUCCESS) { gnutls_assert (); return _gnutls_asn2err (result); } return 0; }
void cook_buf(FILE *fp) { int ch, gobble, line, prev; line = gobble = 0; for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) { if (prev == '\n') { if (ch == '\n') { if (sflag) { if (!gobble && nflag && !bflag) (void)fprintf(stdout, "%6d\t\n", ++line); else if (!gobble && putchar(ch) == EOF) break; gobble = 1; continue; } if (nflag) { if (!bflag) { (void)fprintf(stdout, "%6d\t", ++line); if (ferror(stdout)) break; } else if (eflag) { (void)fprintf(stdout, "%6s\t", ""); if (ferror(stdout)) break; } } } else if (nflag) { (void)fprintf(stdout, "%6d\t", ++line); if (ferror(stdout)) break; } } gobble = 0; if (ch == '\n') { if (eflag) if (putchar('$') == EOF) break; } else if (ch == '\t') { if (tflag) { if (putchar('^') == EOF || putchar('I') == EOF) break; continue; } } else if (vflag) { if (!isascii(ch)) { if (putchar('M') == EOF || putchar('-') == EOF) break; ch = toascii(ch); } if (iscntrl(ch)) { if (putchar('^') == EOF || putchar(ch == '\177' ? '?' : ch | 0100) == EOF) break; continue; } } if (putchar(ch) == EOF) break; } if (ferror(fp)) { warn("%s", filename); rval = EXIT_FAILURE; clearerr(fp); } if (ferror(stdout)) err(EXIT_FAILURE, "stdout"); }
//================================================================ int EDI_CB__ (MemObj *mo, void **data) { //================================================================ /// ED_CB__ editor-callback of GUI_edi__ int i1; long l1; char *p1; // printf("EDI_CB__ ev=%d\n",GUI_DATA_EVENT); // printf(" EDI_CB__: ED_lnr_act=%d\n",ED_lnr_act); //---------------------------------------------------------------- if(GUI_DATA_EVENT == TYP_EventEnter) { // 400 // caused by mouseclick into editor .. l1 = GUI_DATA_L2; // printf(" enter line %ld\n",l1); // ED_newPos ED_update ED_update (0L); // editor -> memory if Filesize has changed .. // von der zuletzt bearbeiteten Zeile bis zu lNr anzeigen/abarbeiten ED_work_CurSet (l1); // GUI_edi_Focus (&winED); return 0; //---------------------------------------------------------------- } else if (GUI_DATA_EVENT == TYP_EventPress) { // 402 // key-press /* kommt nicht ! if(GUI_DATA_I1 == GUI_KeyReturn) { // UI_key_return (); l1 = ED_get_lnr_act(); --l1; ED_lnr_act = l1; // l1 -= 2; // ED_work_CurSet (l1); // UI_EdKeyCR (1); goto AllDone; } */ // test if it is a special-char if(isascii(GUI_DATA_I1)) goto AllDone; i1 = UI_key_view__ (GUI_DATA_EVENT, GUI_DATA_I1); if(i1) goto AllDone; if(GUI_DATA_I1 == GUI_KeyEsc) { UI_key_escape (); } else if(GUI_DATA_I1 == GUI_KeyF1) { // HELP-key // test if process is active if(PRC_IS_ACTIVE) { APP_Help (APP_act_proc, ""); } else { APP_Help ("gCAD3D_startMAN", ""); } } else if(GUI_DATA_I1 == GUI_KeyF3) { UI_men__ ("Edit"); ED_update (0L); } else if(GUI_DATA_I1 == GUI_KeyF4) { AP_APT_clean (); } goto AllDone; //---------------------------------------------------------------- } else { // 403 = TYP_EventRelease = key-release // printf(" key=%c (%x) mod=%d\n",GUI_DATA_I1,GUI_DATA_I1,GUI_DATA_I2); // skip all not printable keys if(!isascii(GUI_DATA_I1)) { // necessary; keyDown is not activated (in last line) ? if((GUI_DATA_I1 == GUI_KeyDel) || (GUI_DATA_I1 == GUI_KeyReturn)) { // printf(" release-CR..\n"); // bei CR am end of file kommt kein TYP_EventEnter new-Line !!!!! // UI_EdKeyCR (); geht nicht - liefert zusätzliches CR ! ED_update (0L); l1 = GUI_edi_getLnr (mo); if(ED_lnr_act >= l1) ED_lnr_act = l1 - 1; // l1 = ED_lnr_act; --ED_lnr_act; // printf(" ED_lnr_act=%d l1=%ld\n",ED_lnr_act,l1); UI_AP (UI_FuncSet, UID_ouf_lNr, (void*)l1); GL_temp_del_all (); // remove circle WC_set_obj_stat (0); // 0=perm ED_work_CurSet (l1); l1 = ED_get_lnr_act() - 1; // get lNr AP_ED_lNr // printf(" lastLn %d |%s|\n",l1,mem_cbuf1); // filled by ED_Run if(GUI_DATA_I1 == GUI_KeyReturn) { // no undo for delete -operations UNDO_grp_add (l1, 0); // add new codeline to undo-list UNDO_upd__ (); } } else { // modify view (move/pan/zoom) UI_key_view__ (GUI_DATA_EVENT, GUI_DATA_I1); } goto AllDone; } // Shift + Alt if((GUI_DATA_I2 & GUI_Modif_shift) && (GUI_DATA_I2 & GUI_Modif_alt)) { UI_key_spcShAlt (GUI_DATA_I1); goto AllDone; } // check modifier Ctrl if(GUI_DATA_I2 & GUI_Modif_ctrl) { // test if group-creation is active // KeyStatCtrl = OFF; UI_key_spcCtrl (GUI_DATA_I1); goto AllDone; } // check modifier ALT if(GUI_DATA_I2 & GUI_Modif_alt) { // printf(" ALT IS ON\n"); i1 = toupper(GUI_DATA_I1); p1 = strchr("PLCSABDTVRINM",i1); if(p1) { i1 = AP_typ_typChar (i1); // printf(" i1=%d |%c|\n",i1,i1); // i1 = UI_creObjHdr (NULL, PTR_INT(i1)); l1 = AP_cre_defHdr (i1, 20); // if(i1 > 0) goto AllDone; } else { if(i1 == 'F') {ED_add_Def ("FROM "); goto AllDone;} if(i1 == 'W') {ED_add_Def ("WORK "); goto AllDone;} } goto Finish; } } //---------------------------------------------------------------- Finish: AllDone: return 0; }
static int ssh_print_version(netdissect_options *ndo, const u_char *pptr, u_int len) { u_int idx = 0; const char *pnp; if ( GET_U_1(pptr+idx) != 'S' ) return 0; idx++; if ( GET_U_1(pptr+idx) != 'S' ) return 0; idx++; if ( GET_U_1(pptr+idx) != 'H' ) return 0; idx++; if ( GET_U_1(pptr+idx) != '-' ) return 0; idx++; while (idx < len) { if (GET_U_1(pptr + idx) == '\n') { /* * LF without CR; end of line. * Skip the LF and print the line, with the * exception of the LF. */ goto print; } else if (GET_U_1(pptr + idx) == '\r') { /* CR - any LF? */ if ((idx+1) >= len) { /* not in this packet */ goto trunc; } if (GET_U_1(pptr + idx + 1) == '\n') { /* * CR-LF; end of line. * Skip the CR-LF and print the line, with * the exception of the CR-LF. */ goto print; } /* * CR followed by something else; treat this as * if it were binary data and don't print it. */ goto trunc; } else if (!isascii(GET_U_1(pptr + idx)) || !isprint(GET_U_1(pptr + idx)) ) { /* * Not a printable ASCII character; treat this * as if it were binary data and don't print it. */ goto trunc; } idx++; } trunc: return -1; print: ND_PRINT(": "); /* Capitalize the protocol name */ for (pnp = ndo->ndo_protocol; *pnp != '\0'; pnp++) ND_PRINT("%c", ND_TOUPPER((u_char)*pnp)); ND_PRINT(": %.*s", (int)idx, pptr); return idx; }