Example #1
0
/* SD-ID format:
 *	name@<private enterprise number>, e.g., "ourSDID@32473"
 */
static int valid_structured_data_id(const char *str)
{
	char *at = strchr(str, '@');
	const char *p;

	/* standardized IDs without @<digits> */
	if (!at && (strcmp(str, "timeQuality") == 0 ||
		    strcmp(str, "origin") == 0 ||
		    strcmp(str, "meta") == 0))
		return 1;

	if (!at || at == str || !*(at + 1))
		return 0;
	if (!isdigit_string(at + 1))
		return 0;

	/* check for forbidden chars in the <name> */
	for (p = str; p < at; p++) {
		if (*p == '[' || *p == '=' || *p == '"' || *p == '@')
			return 0;
		if (isblank((unsigned char) *p) || iscntrl((unsigned char) *p))
			return 0;
	}
	return 1;
}
Example #2
0
static int ask_number(struct fdisk_context *cxt,
		      struct fdisk_ask *ask,
		      char *buf, size_t bufsz)
{
	char prompt[128] = { '\0' };
	const char *q = fdisk_ask_get_query(ask);
	const char *range = fdisk_ask_number_get_range(ask);

	uint64_t dflt = fdisk_ask_number_get_default(ask),
		 low = fdisk_ask_number_get_low(ask),
		 high = fdisk_ask_number_get_high(ask);

	assert(q);

	DBG(ASK, dbgprint("asking for number ['%s', <%jd,%jd>, default=%jd, range: %s]",
				q, low, high, dflt, range));
	if (range && dflt >= low && dflt <= high)
		snprintf(prompt, sizeof(prompt), _("%s (%s, default %jd): "), q, range, dflt);
	else if (dflt >= low && dflt <= high)
		snprintf(prompt, sizeof(prompt), _("%s (%jd-%jd, default %jd): "), q, low, high, dflt);
	else
		snprintf(prompt, sizeof(prompt), _("%s (%jd-%jd): "), q, low, high);

	do {
		int rc = get_user_reply(cxt, prompt, buf, bufsz);

		if (rc)
			return rc;
		if (!*buf && dflt >= low && dflt <= high)
			return fdisk_ask_number_set_result(ask, dflt);
		else if (isdigit_string(buf)) {
			char *end;
			uint64_t num;

			errno = 0;
			num = strtoumax(buf, &end, 10);
			if (errno || buf == end || (end && *end))
				continue;
			if (num >= low && num <= high)
				return fdisk_ask_number_set_result(ask, num);
			printf(_("Value out of range.\n"));
		}
	} while (1);

	return -1;
}
Example #3
0
/* HTS_Label_load_from_strings: load label from strings */
void HTS_Label_load_from_strings(HTS_Label * label, size_t sampling_rate, size_t fperiod, char **lines, size_t num_lines)
{
   char buff[HTS_MAXBUFLEN];
   HTS_LabelString *lstring = NULL;
   size_t i;
   size_t data_index;
   double start, end;
   const double rate = (double) sampling_rate / ((double) fperiod * 1e+7);

   if (label->head || label->size != 0) {
      HTS_error(1, "HTS_Label_load_from_fp: label list is not initialized.\n");
      return;
   }
   /* copy label */
   for (i = 0; i < num_lines; i++) {
      if (!isgraph((int) lines[i][0]))
         break;
      label->size++;

      if (lstring) {
         lstring->next = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         lstring = lstring->next;
      } else {                  /* first time */
         lstring = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         label->head = lstring;
      }
      data_index = 0;
      if (isdigit_string(lines[i])) {   /* has frame infomation */
         HTS_get_token_from_string(lines[i], &data_index, buff);
         start = atof(buff);
         HTS_get_token_from_string(lines[i], &data_index, buff);
         end = atof(buff);
         HTS_get_token_from_string(lines[i], &data_index, buff);
         lstring->name = HTS_strdup(buff);
         lstring->start = rate * start;
         lstring->end = rate * end;
      } else {
         lstring->start = -1.0;
         lstring->end = -1.0;
         lstring->name = HTS_strdup(lines[i]);
      }
      lstring->next = NULL;
   }
   HTS_Label_check_time(label);
}
Example #4
0
/* HTS_Label_load: load label */
static void HTS_Label_load(HTS_Label * label, size_t sampling_rate, size_t fperiod, HTS_File * fp)
{
   char buff[HTS_MAXBUFLEN];
   HTS_LabelString *lstring = NULL;
   double start, end;
   const double rate = (double) sampling_rate / ((double) fperiod * 1e+7);

   if (label->head || label->size != 0) {
      HTS_error(1, "HTS_Label_load_from_fp: label is not initialized.\n");
      return;
   }

   /* parse label file */
   while (HTS_get_token_from_fp(fp, buff)) {
      if (!isgraph((int) buff[0]))
         break;
      label->size++;

      if (lstring) {
         lstring->next = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         lstring = lstring->next;
      } else {                  /* first time */
         lstring = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         label->head = lstring;
      }
      if (isdigit_string(buff)) {       /* has frame infomation */
         start = atof(buff);
         HTS_get_token_from_fp(fp, buff);
         end = atof(buff);
         HTS_get_token_from_fp(fp, buff);
         lstring->start = rate * start;
         lstring->end = rate * end;
      } else {
         lstring->start = -1.0;
         lstring->end = -1.0;
      }
      lstring->next = NULL;
      lstring->name = HTS_strdup(buff);
   }
   HTS_Label_check_time(label);
}
/* HTS_Label_load_from_string: load label from string */
void HTS_Label_load_from_string(HTS_Label * label, int sampling_rate,
                                int fperiod, char *data)
{
   char buff[HTS_MAXBUFLEN];
   HTS_LabelString *lstring = NULL;
   int data_index = 0;          /* data index */
   double start, end;
   const double rate = (double) sampling_rate / ((double) fperiod * 1e+7);

   if (label->head || label->size != 0)
      HTS_error(1, "HTS_Label_load_from_fp: label list is not initialized.\n");
   /* copy label */
   while (HTS_get_token_from_string(data, &data_index, buff)) {
      if (!isgraph(buff[0]))
         break;
      label->size++;

      if (lstring) {
         lstring->next =
             (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         lstring = lstring->next;
      } else {                  /* first time */
         lstring = (HTS_LabelString *) HTS_calloc(1, sizeof(HTS_LabelString));
         label->head = lstring;
      }
      if (isdigit_string(buff)) {       /* has frame infomation */
         start = atof(buff);
         HTS_get_token_from_string(data, &data_index, buff);
         end = atof(buff);
         HTS_get_token_from_string(data, &data_index, buff);
         lstring->start = rate * start;
         lstring->end = rate * end;
      } else {
         lstring->start = -1.0;
         lstring->end = -1.0;
      }
      lstring->next = NULL;
      lstring->name = HTS_strdup(buff);
   }
   HTS_Label_check_time(label);
}
Example #6
0
static int ask_number(struct fdisk_context *cxt,
		      struct fdisk_ask *ask,
		      char *buf, size_t bufsz)
{
	char prompt[128] = { '\0' };
	const char *q = fdisk_ask_get_query(ask);
	const char *range = fdisk_ask_number_get_range(ask);

	uint64_t dflt = fdisk_ask_number_get_default(ask),
		 low = fdisk_ask_number_get_low(ask),
		 high = fdisk_ask_number_get_high(ask);
	int inchar = fdisk_ask_number_inchars(ask);

	assert(q);

	DBG(ASK, ul_debug("asking for number "
			"['%s', <%ju,%ju>, default=%ju, range: %s]",
			q, low, high, dflt, range));

	if (range && dflt >= low && dflt <= high) {
		if (inchar)
			snprintf(prompt, sizeof(prompt), _("%s (%s, default %c): "),
					q, range, tochar(dflt));
		else
			snprintf(prompt, sizeof(prompt), _("%s (%s, default %ju): "),
					q, range, dflt);

	} else if (dflt >= low && dflt <= high) {
		if (inchar)
			snprintf(prompt, sizeof(prompt), _("%s (%c-%c, default %c): "),
					q, tochar(low), tochar(high), tochar(dflt));
		else
			snprintf(prompt, sizeof(prompt), _("%s (%ju-%ju, default %ju): "),
					q, low, high, dflt);
	} else if (inchar)
		snprintf(prompt, sizeof(prompt), _("%s (%c-%c): "),
				q, tochar(low), tochar(high));
	else
		snprintf(prompt, sizeof(prompt), _("%s (%ju-%ju): "),
				q, low, high);

	do {
		int rc = get_user_reply(cxt, prompt, buf, bufsz);
		uint64_t num;

		if (rc)
			return rc;
		if (!*buf && dflt >= low && dflt <= high)
			return fdisk_ask_number_set_result(ask, dflt);

		if (isdigit_string(buf)) {
			char *end;

			errno = 0;
			num = strtoumax(buf, &end, 10);
			if (errno || buf == end || (end && *end))
				continue;
		} else if (inchar && isalpha(*buf)) {
			num = tolower(*buf) - 'a' + 1;
		} else
			rc = -EINVAL;

		if (rc == 0 && num >= low && num <= high)
			return fdisk_ask_number_set_result(ask, num);

		fdisk_warnx(cxt, _("Value out of range."));
	} while (1);

	return -1;
}
Example #7
0
static void
dissect_rsh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	/* Set up structures needed to add the protocol subtree and manage it */
	proto_item *ti;
	proto_tree *rsh_tree=NULL;

	/* Variables for extracting and displaying data from the packet */
	guchar *field_stringz; /* Temporary storage for each field we extract */

	gint length;
	guint offset = 0;
	conversation_t *conversation;
	rsh_hash_entry_t *hash_info;

	conversation = find_or_create_conversation(pinfo);

	/* Retrieve information from conversation
	 * or add it if it isn't there yet
	 */
	hash_info = conversation_get_proto_data(conversation, proto_rsh);
	if(!hash_info){
		hash_info = se_alloc(sizeof(rsh_hash_entry_t));

		hash_info->first_packet_number = pinfo->fd->num;
		hash_info->second_packet_number = 0;
		hash_info->third_packet_number  = 0;
		hash_info->fourth_packet_number  = 0;

		hash_info->state = WAIT_FOR_STDERR_PORT; /* The first field we'll see */

		/* Start with empty username and command strings */
		hash_info->client_username=NULL;
		hash_info->server_username=NULL;
		hash_info->command=NULL;

		/* These will be set on the first pass by the first
		 * four packets of the conversation
		 */
		hash_info->first_packet_state  = NONE;
		hash_info->second_packet_state = NONE;
		hash_info->third_packet_state  = NONE;
		hash_info->fourth_packet_state  = NONE;

		conversation_add_proto_data(conversation, proto_rsh, hash_info);
	}

	/* Store the number of the first three packets of this conversation
	 * as we reach them the first time */

	if(!hash_info->second_packet_number
	&& pinfo->fd->num > hash_info->first_packet_number){
		/* We're on the second packet of the conversation */
		hash_info->second_packet_number = pinfo->fd->num;
	} else if(hash_info->second_packet_number
	 && !hash_info->third_packet_number
	 && pinfo->fd->num > hash_info->second_packet_number) {
		/* We're on the third packet of the conversation */
		hash_info->third_packet_number = pinfo->fd->num;
	} else if(hash_info->third_packet_number
	 && !hash_info->fourth_packet_number
	 && pinfo->fd->num > hash_info->third_packet_number) {
		/* We're on the fourth packet of the conversation */
		hash_info->fourth_packet_number = pinfo->fd->num;
	}

	/* Save this packet's state so we can retrieve it if this packet
	 * is selected again later.  If the packet's state was already stored,
	 * then retrieve it */
	if(pinfo->fd->num == hash_info->first_packet_number){
		if(hash_info->first_packet_state == NONE){
			hash_info->first_packet_state = hash_info->state;
		} else {
			hash_info->state = hash_info->first_packet_state;
		}
	}

	if(pinfo->fd->num == hash_info->second_packet_number){
		if(hash_info->second_packet_state == NONE){
			hash_info->second_packet_state = hash_info->state;
		} else {
			hash_info->state = hash_info->second_packet_state;
		}
	}

	if(pinfo->fd->num == hash_info->third_packet_number){
		if(hash_info->third_packet_state == NONE){
			hash_info->third_packet_state = hash_info->state;
		} else {
			hash_info->state = hash_info->third_packet_state;
		}
	}

	if(pinfo->fd->num == hash_info->fourth_packet_number){
		if(hash_info->fourth_packet_state == NONE){
			hash_info->fourth_packet_state = hash_info->state;
		} else {
			hash_info->state = hash_info->fourth_packet_state;
		}
	}

	col_set_str(pinfo->cinfo, COL_PROTOCOL, "RSH");

	if(check_col(pinfo->cinfo, COL_INFO)){
		/* First, clear the info column */
		col_clear(pinfo->cinfo, COL_INFO);

		/* Client username */
		if(hash_info->client_username && preference_info_show_client_username == TRUE){
			col_append_fstr(pinfo->cinfo, COL_INFO, "Client username:%s ", hash_info->client_username);
		}

		/* Server username */
		if(hash_info->server_username && preference_info_show_server_username == TRUE){
			col_append_fstr(pinfo->cinfo, COL_INFO, "Server username:%s ", hash_info->server_username);
		}

		/* Command */
		if(hash_info->command && preference_info_show_command == TRUE){
			col_append_fstr(pinfo->cinfo, COL_INFO, "Command:%s ", hash_info->command);
		}
	}

	/* create display subtree for the protocol */
	ti = proto_tree_add_item(tree, proto_rsh, tvb, 0, -1, ENC_NA);
	rsh_tree = proto_item_add_subtree(ti, ett_rsh);

	/* If this packet doesn't end with a null terminated string,
	 * then it must be session data only and we can skip looking
	 * for the other fields.
	 */
	if(tvb_find_guint8(tvb, tvb_length(tvb)-1, 1, '\0') == -1){
		hash_info->state = WAIT_FOR_DATA;
	}

	if(hash_info->state == WAIT_FOR_STDERR_PORT
	&& tvb_length_remaining(tvb, offset)){
		field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);

		/* Check if this looks like the stderr_port field.
		 * It is optional, so it may only be 1 character long
		 * (the NULL)
		 */
		if(length == 1 || (isdigit_string(field_stringz)
		&& length <= RSH_STDERR_PORT_LEN)){
			proto_tree_add_string(rsh_tree, hf_rsh_stderr_port, tvb, offset, length, (gchar*)field_stringz);
			 /* Next field we need */
			hash_info->state = WAIT_FOR_CLIENT_USERNAME;
		} else {
			/* Since the data doesn't match this field, it must be data only */
			hash_info->state = WAIT_FOR_DATA;
		}

		/* Used if the next field is in the same packet */
		offset += length;
	}


	if(hash_info->state == WAIT_FOR_CLIENT_USERNAME
	&& tvb_length_remaining(tvb, offset)){
		field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);

		/* Check if this looks like the username field */
		if(length != 1 && length <= RSH_CLIENT_USERNAME_LEN
		&& isprint_string(field_stringz)){
			proto_tree_add_string(rsh_tree, hf_rsh_client_username, tvb, offset, length, (gchar*)field_stringz);

			/* Store the client username so we can display it in the
			 * info column of the entire conversation
			 */
			if(!hash_info->client_username){
				hash_info->client_username=se_strdup((gchar*)field_stringz);
			}

			 /* Next field we need */
			hash_info->state = WAIT_FOR_SERVER_USERNAME;
		} else {
			/* Since the data doesn't match this field, it must be data only */
			hash_info->state = WAIT_FOR_DATA;
		}

		/* Used if the next field is in the same packet */
		offset += length;
	}


	if(hash_info->state == WAIT_FOR_SERVER_USERNAME
	&& tvb_length_remaining(tvb, offset)){
		field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);

		/* Check if this looks like the password field */
		if(length != 1 && length <= RSH_SERVER_USERNAME_LEN
		&& isprint_string(field_stringz)){
			proto_tree_add_string(rsh_tree, hf_rsh_server_username, tvb, offset, length, (gchar*)field_stringz);

			/* Store the server username so we can display it in the
			 * info column of the entire conversation
			 */
			if(!hash_info->server_username){
				hash_info->server_username=se_strdup((gchar*)field_stringz);
			}

			/* Next field we need */
			hash_info->state = WAIT_FOR_COMMAND;
		} else {
			/* Since the data doesn't match this field, it must be data only */
			hash_info->state = WAIT_FOR_DATA;
		}

		/* Used if the next field is in the same packet */
		offset += length;
		 /* Next field we are looking for */
		hash_info->state = WAIT_FOR_COMMAND;
	}


	if(hash_info->state == WAIT_FOR_COMMAND
	&& tvb_length_remaining(tvb, offset)){
		field_stringz = tvb_get_ephemeral_stringz(tvb, offset, &length);

		/* Check if this looks like the command field */
		if(length != 1 && length <= RSH_COMMAND_LEN
		&& isprint_string(field_stringz)){
			proto_tree_add_string(rsh_tree, hf_rsh_command, tvb, offset, length, (gchar*)field_stringz);

			/* Store the command so we can display it in the
			 * info column of the entire conversation
			 */
			if(!hash_info->command){
				hash_info->command=se_strdup((gchar*)field_stringz);
			}

		} else {
			/* Since the data doesn't match this field, it must be data only */
			hash_info->state = WAIT_FOR_DATA;
		}
	}


	if(hash_info->state == WAIT_FOR_DATA
	&& tvb_length_remaining(tvb, offset)){
		if(pinfo->destport == RSH_PORT){
			/* Packet going to the server */
			/* offset = 0 since the whole packet is data */
			proto_tree_add_text(rsh_tree, tvb, 0, -1, "Client -> Server Data");

			col_append_str(pinfo->cinfo, COL_INFO, "Client -> Server data");
		} else {
			/* This packet must be going back to the client */
			/* offset = 0 since the whole packet is data */
			proto_tree_add_text(rsh_tree, tvb, 0, -1, "Server -> Client Data");

			col_append_str(pinfo->cinfo, COL_INFO, "Server -> Client Data");
		}
	}

	/* We haven't seen all of the fields yet */
	if(hash_info->state < WAIT_FOR_DATA){
		col_set_str(pinfo->cinfo, COL_INFO, "Session Establishment");
	}
}
Example #8
0
int main(int argc, const char **argv)
{
	int input_size;
	bool use_complex_inputs;
	bool print = false;
	bool check = false;

	int cl_platform_index = 0;
	int cl_device_index = 0;

	// Parsing degli eventuali ultimi due argomenti numerici, da destra verso
	// sinistra
	if (argc >= 4 && isdigit_string(argv[argc - 1]))
		cl_platform_index = atoi(argv[--argc]);
	if (argc >= 4 && isdigit_string(argv[argc - 1]))
	{
		cl_device_index = cl_platform_index;
		cl_platform_index = atoi(argv[--argc]);
	}

	if (
		!(argc == 3
			|| (argc == 4 && (print = !strcmp(argv[3], "print")))
			|| (argc == 4 && (check = !strcmp(argv[3], "check")))
		)
		|| (use_complex_inputs = !!strcmp(argv[1], "real")) == !!strcmp(argv[1], "complex")
		|| (input_size = atoi(argv[2])) <= 0)
	{
#ifdef ALLOW_NPOT
		const char *pot_text = "";
#else
		const char *pot_text = " (potenza di due)";
#endif

		cerr << "Uso: " << argv[0] << " <real | complex> input-size [print | check] [cl-platform-num [cl-device-num]]" << endl << endl;
		cerr << " real             Usa input di tipo reale" << endl;
		cerr << " complex          Usa input di tipo complesso" << endl;
		cerr << " input-size       Numero di samples da passare in input" << pot_text << endl;
		cerr << " print            Mostra output" << endl;
#ifdef ALLOW_NPOT
		cerr << " check            Confronta output con serial naive DFT" << endl;
#else
		cerr << " check            Confronta output con serial non-recursive FFT" << endl;
#endif
		cerr << " cl-platform-num  Indice della piattaforma OpenCL da utilizzare (default: 0)" << endl;
		cerr << " cl-device-num    Indice del dispositivo OpenCL da utilizzare (default: 0)" << endl;
		cerr << endl;

		cerr << "Piattaforme e dispositivi OpenCL disponibili:" << endl;
		vector<string> platforms = clhAvailablePlatformNames();
		if (platforms.size() == 0)
		{
			cerr << "(nessuna piattaforma)" << endl;
		}
		else
		{
			for (unsigned i = 0; i < platforms.size(); i++)
			{
				cerr << "#" << i << " " << platforms[i] << endl;

				vector<string> devices = clhAvailableDeviceNames(clhSelectPlatform(i));
				if (devices.size() == 0)
				{
					cerr << "   (nessun dispositivo)" << endl;
				}
				else
				{
					for (unsigned j = 0; j < devices.size(); j++)
						cerr << "  -> " << i << " " << j << " - " << devices[j] << endl;
				}
			}
		}

		cerr << endl;
		return EXIT_FAILURE;
	}

#ifndef ALLOW_NPOT
	if (input_size & (input_size-1))
	{
		cerr << "input-size deve essere una potenza di 2" << endl;
		return EXIT_FAILURE;
	}
#endif

	cl_platform_id platform = clhSelectPlatform(cl_platform_index);
	cerr << "CL platform: " << clhGetPlatformFriendlyName(platform) << endl;

	cl_device_id device = clhSelectDevice(platform, cl_device_index);
	cerr << "CL device: " << clhGetDeviceFriendlyName(device) << endl;

	cl_context context = clhCreateContextSingleDevice(platform, device);
	cl_command_queue command_queue = clhCreateCommandQueue(context, device, true /* profiling abilitato */);

	clhEmptyNvidiaCache();

	if (use_complex_inputs)
	{
		ALGOCLASS<cpx> instance(platform, device, context, command_queue, input_size);
		cerr << "sleep(1)" << endl;
		sleep(1);
		runTest<cpx>(context, command_queue, &instance, input_size, print, check);
	}
	else
	{
		ALGOCLASS<float> instance(platform, device, context, command_queue, input_size);
		cerr << "sleep(1)" << endl;
		sleep(1);
		runTest<float>(context, command_queue, &instance, input_size, print, check);
	}

	CL_CHECK_ERR("clReleaseCommandQueue", clReleaseCommandQueue(command_queue));
	CL_CHECK_ERR("clReleaseContext", clReleaseContext(context));
}