void pars_newtopic(void) { if (config->packet_qchat) { strncpy(status->chnl[0].topic, packet, STR_SIZE); snprintf(message, MSG_SIZE, PARS_QTOPIC, time_get()); #ifdef TCP write_tcp(status->room->name); #endif /* TCP */ if (config->verbose) { write_log(config->log_main); write_str(status->room->name, COL_SYSTEM); } /* SERGEJ */ validate_string(status->chnl[0].topic); snprintf(message, MSG_SIZE, "%s\n", status->chnl[0].topic); #ifdef TCP write_tcp(status->room->name); #endif /* TCP */ if (config->verbose) { write_log(config->log_main); write_str(status->room->name, COL_SYSTEM); } } else { strncpy(status->channel, packet, CHANNEL_MAXLEN); if (strncmp(status->chnl[0].name, status->channel, CHANNEL_MAXLEN) && !chnl_getnum()) return; strncpy(status->chnl[chnl_getnum()].topic, pars_word(), STR_SIZE); snprintf(message, MSG_SIZE, PARS_TOPIC, time_get(), status->channel); #ifdef TCP write_tcp(status->channel); #endif /* TCP */ if (config->verbose) { write_log(config->log_main); write_str(status->channel, COL_SYSTEM); } /* SERGEJ */ validate_string(status->chnl[chnl_getnum()].topic); snprintf(message, MSG_SIZE, "%s\n", status->chnl[chnl_getnum()].topic); #ifdef TCP write_tcp(status->channel); #endif /* TCP */ if (config->verbose) { write_log(config->log_main); write_str(status->channel, COL_SYSTEM); } } refresh_room(); screen_show(); refresh_input(); string_show(); if ((!config->my_only || !strncmp(status->room->name, status->channel, CHANNEL_MAXLEN)) && (config->mode == MOD_NORMAL)) beep_system(); }
/* * Validate the obtained NN host and ports */ static void validate_result(NNHAConf *conf) { for (int i = 0; i < conf->numn; i++) { validate_string(conf->nodes[i], "HA Namenode host number %d is NULL value", i + 1); validate_port(conf->rpcports[i], "HA Namenode RPC port number %d is NULL value", i + 1); validate_port(conf->restports[i], "HA Namenode REST port number %d is NULL value", i + 1); } }
int main(void) { int ch, hyphen_count = 0, first_is_valid=0, second_is_valid=0, third_is_valid=0; printf("Enter the serial number: \n"); while ((ch=getchar()) != '\n') { if (ch == SEPARATOR) hyphen_count++; switch (hyphen_count) { case 0: first_is_valid += validate_string(ch); break; case 1: if (first_is_valid != 12) // then we don't have enough letters { printf ("\nFirst part of the key is invalid! First part should contain 12 letters\n"); return 0; } second_is_valid += validate_num(ch); break; case 2: third_is_valid += validate_string(ch); if (second_is_valid != 9) { printf ("\nSecond part of the key is invalid! Second part should contain 9 numbers\n"); return 0; } break; } } // Presumably the user has hit "Enter" after entering the third part of the serial number. if (third_is_valid == 9) { // If the user typed exactly 9 letters: printf("Key is in a valid format. Your copy of Adobe Photoshop has been unlocked!\n"); } else { printf ("\nThird part of the key is invalid! Third part should contain 9 letters\n"); } return 0; }
void pars_topic(void) { if (strncmp(config->nick, packet, NICK_MAXLEN)) return; if (config->packet_qchat) { if (!strncmp(status->chnl[0].topic, pars_word(), STR_SIZE)) return; strncpy(status->chnl[0].topic, packet, STR_SIZE); snprintf(message, MSG_SIZE, PARS_QTOPICC, time_get()); #ifdef TCP write_tcp(status->room->name); #endif /* TCP */ write_log(config->log_main); write_str(status->room->name, COL_SYSTEM); /* SERGEJ */ validate_string(status->chnl[0].topic); snprintf(message, MSG_SIZE, "%s\n", status->chnl[0].topic); #ifdef TCP write_tcp(status->room->name); #endif /* TCP */ write_log(config->log_main); write_str(status->room->name, COL_SYSTEM); } else { strncpy(status->channel, pars_word(), CHANNEL_MAXLEN); if (!strncmp(status->room->topic, pars_word(), STR_SIZE)) return; strncpy(status->chnl[chnl_getnum()].topic, packet, STR_SIZE); snprintf(message, MSG_SIZE, PARS_TOPICC, time_get(), status->channel); #ifdef TCP write_tcp(status->channel); #endif /* TCP */ write_log(config->log_main); write_str(status->channel, COL_SYSTEM); /* SERGEJ */ validate_string(status->chnl[chnl_getnum()].topic); snprintf(message, MSG_SIZE, "%s\n", status->chnl[chnl_getnum()].topic); #ifdef TCP write_tcp(status->channel); #endif /* TCP */ write_log(config->log_main); write_str(status->channel, COL_SYSTEM); } refresh_room(); screen_show(); refresh_input(); string_show(); }
/* * make sure port is in the valid numbers range for a port */ static void validate_port(char *port, const char *m1, int num) { const long max_port_number = 65535; long numport; char *tail = NULL; validate_string(port, m1, num); /*now validate number */ numport = strtol(port, &tail, 10); /* atol and atoi will not catch 100abc. They will return 100 */ if (numport == 0 || (tail && strlen(tail) > 0) /* port had a non-numeric part*/ || numport > max_port_number) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("Invalid port <%s> detected in nameservice configuration", port))); }
/* * pg_atouX: convert string to unsigned integer * * allows any number of leading or trailing whitespace characters. * * c, if not 0, is a terminator character that may appear after the * integer (plus whitespace). If 0, the string must end after the integer. * * Unlike plain atoi(), this will throw ereport() upon bad input format or * overflow. */ uint8 pg_atou1(char *s, int c) { unsigned long int l; char *badp; validate_string(s); errno = 0; l = strtoul(s, &badp, 10); if (s == badp) report_invalid(s); if (errno == ERANGE || l > UCHAR_MAX) report_range_error(s, "uint1"); skip_trailing_whitespace(s, badp, c); return (uint8)l; }
uint64 pg_atou8(char *s, int c) { uint8 l; char *badp; validate_string(s); errno = 0; l = strtoull(s, &badp, 10); if (s == badp) report_invalid(s); if (errno == ERANGE) report_range_error(s, "uint8"); skip_trailing_whitespace(s, badp, c); return l; }
uint32 pg_atou4(char *s, int c) { unsigned long int l; char *badp; validate_string(s); errno = 0; l = strtoul(s, &badp, 10); if (s == badp) report_invalid(s); if (errno == ERANGE) report_range_error(s, "uint4"); skip_trailing_whitespace(s, badp, c); return l; }
int openddl::detail::ParserContext::build_literal(Command::LiteralPayload::encoding_t encoding, Token const * ts, Token const * te, Command::LiteralPayload & payload) { payload.encoding = encoding; if (encoding == Command::LiteralPayload::kReference) { Token const * i = ts; std::vector<std::string> * reference = new std::vector<std::string>(); while (i <= te && (i->token_type == Token::kNull || i->token_type == Token::kGlobalName || i->token_type == Token::kLocalName)) { reference->emplace_back(i->payload); i++; } payload.value.reference_ = reference; return i - ts; } else if (encoding == Command::LiteralPayload::kString) { Token const * i = ts; std::string * string = new std::string(); while (i <= te && (i->token_type == Token::kStringLiteral)) { validate_string(errors, *string, i->payload); i++; } payload.value.string_ = string; return i - ts; } else { int code; if ((code=decode_literal(*ts, payload))!=0) { if(code == 1) push_error("parse.literal.out_of_range"); else if (code == -1) push_error("parse.literal.type_mismatch"); } return 1; } }
/* * Translates the Namenode structure to a NNHAConf structure * Input Namenode: * rpc_addr: mdw:9000 * http_addr: mdw:50070 */ static void set_one_namenode(NNHAConf *conf, int idx, Namenode *source) { char *portstart; int hostlen; validate_string(source->rpc_addr, "In configuration Namenode.rpc_address number %d is null or empty", idx + 1); portstart = strchr(source->rpc_addr, ':'); if (!portstart) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("dfs.namenode.rpc-address was set incorrectly in the configuration. ':' missing"))); hostlen = portstart - source->rpc_addr; portstart++; conf->nodes[idx] = pnstrdup(source->rpc_addr, hostlen); conf->rpcports[idx] = pstrdup(portstart); /* * we override the ha rest post from hdfs-site.xml, with pxf_service_port */ port_to_str(&(conf->restports[idx]), pxf_service_port); }
int main( int argc, char **argv ) { int retval, i, j; const PAPI_hw_info_t *hwinfo = NULL; const PAPI_mh_info_t *mh; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); retval = papi_print_header ( "Test case hwinfo.c: Check output of PAPI_get_hardware_info.\n", &hwinfo ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); mh = &hwinfo->mem_hierarchy; validate_string( ( char * ) hwinfo->vendor_string, "vendor_string" ); validate_string( ( char * ) hwinfo->model_string, "model_string" ); if ( hwinfo->vendor == PAPI_VENDOR_UNKNOWN ) test_fail( __FILE__, __LINE__, "Vendor unknown", 0 ); if ( hwinfo->cpu_max_mhz == 0.0 ) test_fail( __FILE__, __LINE__, "Mhz unknown", 0 ); if ( hwinfo->ncpu < 1 ) test_fail( __FILE__, __LINE__, "ncpu < 1", 0 ); if ( hwinfo->totalcpus < 1 ) test_fail( __FILE__, __LINE__, "totalcpus < 1", 0 ); /* if ( PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ) < 1 ) test_fail( __FILE__, __LINE__, "get_opt(MAX_HWCTRS) < 1", 0 ); if ( PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ) < 1 ) test_fail( __FILE__, __LINE__, "get_opt(MAX_MPX_CTRS) < 1", 0 );*/ if ( mh->levels < 0 ) test_fail( __FILE__, __LINE__, "max mh level < 0", 0 ); printf( "Max level of TLB or Cache: %d\n", mh->levels ); for ( i = 0; i < mh->levels; i++ ) { for ( j = 0; j < PAPI_MH_MAX_LEVELS; j++ ) { const PAPI_mh_cache_info_t *c = &mh->level[i].cache[j]; const PAPI_mh_tlb_info_t *t = &mh->level[i].tlb[j]; printf( "Level %d, TLB %d: %d, %d, %d\n", i, j, t->type, t->num_entries, t->associativity ); printf( "Level %d, Cache %d: %d, %d, %d, %d, %d\n", i, j, c->type, c->size, c->line_size, c->num_lines, c->associativity ); } } test_pass( __FILE__, 0, 0 ); exit( 1 ); }