Ejemplo n.º 1
0
int mark_pids_add(int sid, int aid, char *pids)
{
	int i, la;
	adapter *ad;
	char *arg[MAX_PIDS + 2];
	int pid;

	ad = get_adapter(aid);
	if (!ad)
		return -1;

	if (!pids)
		return -1;
	LOG("adding pids to adapter %d, sid %d, pids=%s", aid, sid,
			pids ? pids : "NULL");

	la = split(arg, pids, MAX_PIDS, ',');
	for (i = 0; i < la; i++)
	{
		pid = map_intd(arg[i], NULL, -1);
		if (pid == -1)
			continue;
		if (mark_pid_add(sid, aid, pid) < 0)
			return -1;
	}
	dump_pids(aid);
	return 0;
}
Ejemplo n.º 2
0
int var_eval(char *orig, int len, char *dest, int max_len)
{
	int nb = 0, i, j, off;
	char var[VAR_LENGTH + 1];
	memset(var, 0, sizeof(var));
	strncpy(var, orig + 1, len - 1);
	for (i = 0; sym[i] != NULL; i++)
		for (j = 0; sym[i][j].name; j++)
			if (!strncmp(sym[i][j].name, var, strlen(sym[i][j].name)))
			{
				switch (sym[i][j].type)
				{
				case VAR_UINT8:
					nb = snprintf(dest, max_len, "%d",
							(int) ((*(uint8_t *) sym[i][j].addr)
									* sym[i][j].multiplier));
					break;
				case VAR_INT8:
					nb = snprintf(dest, max_len, "%d",
							(int) ((*(int8_t *) sym[i][j].addr)
									* sym[i][j].multiplier));
					break;
				case VAR_UINT16:
					nb = snprintf(dest, max_len, "%d",
							(int) ((*(uint16_t *) sym[i][j].addr)
									* sym[i][j].multiplier));
					break;
				case VAR_INT16:
					nb = snprintf(dest, max_len, "%d",
							(int) ((*(int16_t *) sym[i][j].addr)
									* sym[i][j].multiplier));
					break;
				case VAR_INT:
					nb = snprintf(dest, max_len, "%d",
							(int) ((*(int *) sym[i][j].addr)
									* sym[i][j].multiplier));
					break;

				case VAR_STRING:
					nb = snprintf(dest, max_len, "%s", (char *) sym[i][j].addr);
					break;

				case VAR_PSTRING:
					nb = snprintf(dest, max_len, "%s",
							*(char **) sym[i][j].addr);
					break;

				case VAR_FLOAT:
					nb = snprintf(dest, max_len, "%f",
							(*(float *) sym[i][j].addr) * sym[i][j].multiplier);
					break;

				case VAR_HEX:
					nb = snprintf(dest, max_len, "0x%x",
							*(int *) sym[i][j].addr);
					break;

				case VAR_ARRAY_INT:
				case VAR_ARRAY_FLOAT:
				case VAR_ARRAY_HEX:
				case VAR_ARRAY_UINT16:
				case VAR_ARRAY_INT16:
				case VAR_ARRAY_UINT8:
				case VAR_ARRAY_INT8:
				case VAR_ARRAY_STRING:
				case VAR_ARRAY_PSTRING:
					off = map_intd(var + strlen(sym[i][j].name), NULL, 0);
					if (off >= 0 && off < sym[i][j].len)
					{
						char *p = (((char *) sym[i][j].addr)
								+ off * sym[i][j].skip);
						switch (sym[i][j].type)
						{
						case VAR_ARRAY_UINT8:
							nb =
									snprintf(dest, max_len, "%d",
											(int) (*(uint8_t *) p
													* sym[i][j].multiplier));
							break;
						case VAR_ARRAY_INT8:
							nb =
									snprintf(dest, max_len, "%d",
											(int) (*(int8_t *) p
													* sym[i][j].multiplier));
							break;
						case VAR_ARRAY_UINT16:
							nb = snprintf(dest, max_len, "%d",
									(int) (*(uint16_t *) p
											* sym[i][j].multiplier));
							break;
						case VAR_ARRAY_INT16:
							nb =
									snprintf(dest, max_len, "%d",
											(int) (*(int16_t *) p
													* sym[i][j].multiplier));
							break;
						case VAR_ARRAY_INT:
							nb = snprintf(dest, max_len, "%d",
									(int) (*(int *) p * sym[i][j].multiplier));
							break;
						case VAR_ARRAY_FLOAT:
							nb =
									snprintf(dest, max_len, "%f",
											(float) (*(float *) p
													* sym[i][j].multiplier));
							break;
						case VAR_ARRAY_HEX:
							nb = snprintf(dest, max_len, "0x%x",
									(int) (*(int *) p * sym[i][j].multiplier));
							break;
						case VAR_ARRAY_STRING:
							nb = snprintf(dest, max_len, "%s", p);
							break;
						case VAR_ARRAY_PSTRING:
							nb = snprintf(dest, max_len, "%s", *(char **) p);
							break;
						}
					}
					break;

				case VAR_FUNCTION_INT:
					off = map_intd(var + strlen(sym[i][j].name), NULL, 0);
					get_data_int funi = (get_data_int) sym[i][j].addr;
					nb = snprintf(dest, max_len, "%d", funi(off));
					break;

				case VAR_FUNCTION_STRING:
					off = map_intd(var + strlen(sym[i][j].name), NULL, 0);
					get_data_string funs = (get_data_string) sym[i][j].addr;
					funs(off, dest, max_len);
					nb = strlen(dest);
					if (nb > max_len)
						nb = max_len;
					break;

				}
				return nb;
			}
	return 0;
}
Ejemplo n.º 3
0
int map_int(char *s, char ** v)
{
	return map_intd(s, v, 0);
}