Exemplo n.º 1
0
char *parse_lock(char *line, struct response *req)
{
	char *more;

	more = get_fpos(line, &req->r_fpos, REQUIRES_MORE);

	if (more == NULL)
		return more;

	more = get_lock_type(more, &req->r_lock_type);

	if (more == NULL)
		return more;

	if (req->r_lock_type != F_RDLCK && req->r_lock_type != F_WRLCK) {
		errno = EINVAL;
		strcpy(errdetail, "Invalid lock type");
		sprintf(badtoken, "%s", str_lock_type(req->r_lock_type));
	}

	more =
	    get_longlong(more, &req->r_start, REQUIRES_MORE,
			 "Invalid lock start");

	if (more == NULL)
		return more;

	return get_longlong(more, &req->r_length, REQUIRES_NO_MORE,
			    "Invalid lock len");
}
Exemplo n.º 2
0
static int
np_longlong(char *p, PyObject *v, const formatdef *f)
{
	PY_LONG_LONG x;
	if (get_longlong(v, &x) < 0)
		return -1;
	memcpy(p, (char *)&x, sizeof x);
	return 0;
}
Exemplo n.º 3
0
static PyObject *
q_set(void *ptr, PyObject *value, Py_ssize_t size)
{
    PY_LONG_LONG val;
    PY_LONG_LONG x;
    if (get_longlong(value, &val) < 0)
        return NULL;
    memcpy(&x, ptr, sizeof(x));
    x = SET(x, val, size);
    memcpy(ptr, &x, sizeof(x));
    _RET(value);
}
Exemplo n.º 4
0
char *parse_list(char *line, struct response *req)
{
	char *more;

	req->r_lock_type = F_WRLCK;

	more = get_fpos(line, &req->r_fpos, REQUIRES_MORE);

	if (more == NULL)
		return more;

	more =
	    get_longlong(more, &req->r_start, REQUIRES_MORE,
			 "Invalid lock start");

	if (more == NULL)
		return more;

	return get_longlong(more, &req->r_length, REQUIRES_NO_MORE,
			    "Invalid lock len");
}
Exemplo n.º 5
0
char *parse_seek(char *line, struct response *req)
{
	char *more;

	more = get_fpos(line, &req->r_fpos, REQUIRES_MORE);

	if (more == NULL)
		return more;

	return get_longlong(more, &req->r_start, REQUIRES_NO_MORE,
			    "Invalid pos");
}
Exemplo n.º 6
0
static PyObject *
q_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
{
    PY_LONG_LONG val;
    PY_LONG_LONG field;
    if (get_longlong(value, &val) < 0)
        return NULL;
    memcpy(&field, ptr, sizeof(field));
    field = SWAP_8(field);
    field = (PY_LONG_LONG)SET(field, val, size);
    field = SWAP_8(field);
    memcpy(ptr, &field, sizeof(field));
    _RET(value);
}
Exemplo n.º 7
0
char *parse_read(char *line, struct response *req)
{
	char *more;

	req->r_data[0] = '\0';

	more = get_fpos(line, &req->r_fpos, REQUIRES_MORE);

	if (more == NULL)
		return more;

	if (*more == '"')
		return get_str(more, req->r_data, &req->r_length,
			       REQUIRES_NO_MORE);
	else
		return get_longlong(more, &req->r_length, REQUIRES_NO_MORE,
				    "Invalid len");
}
Exemplo n.º 8
0
static void
get_server_info (GsqQuerier *querier, gchar *p)
{
	gchar *dir, *desc, *tags, tmp[256];
	gchar *server_os, *server_type;
	
	guint8 pver = gsq_get_uint8 (&p);							// Protocol version
	g_string_assign (querier->name, gsq_get_cstring (&p));		// Server name
	g_string_assign (querier->map, gsq_get_cstring (&p));		// Map name
	dir = gsq_get_cstring (&p);									// Game folder
	desc = gsq_get_cstring (&p);								// Game description
	guint16 appid = get_short (&p);								// Application ID
	querier->numplayers = gsq_get_uint8 (&p);					// Number of players
	querier->maxplayers = gsq_get_uint8 (&p);					// Maximum players
	gsq_get_uint8 (&p);											// Number of bots
	gchar dedicated = gsq_get_uint8 (&p);						// Dedicated
	gchar os = gsq_get_uint8 (&p);								// OS
	querier->password = gsq_get_uint8 (&p);						// Password
	gboolean secure = gsq_get_uint8 (&p);						// Secure
	g_string_assign (querier->version, gsq_get_cstring (&p));	// Game version
	guint8 edf = gsq_get_uint8 (&p);							// Extra data field
	if (edf & 0x80)
		get_short (&p);											// Server's game port
	if (edf & 0x10)
		get_longlong (&p);										// Server's SteamID
	if (edf & 0x40) {
		get_short (&p);											// Spectator port
		gsq_get_cstring (&p);									// Spectator name
	}
	if (edf & 0x20)
		tags = gsq_get_cstring (&p);							// Tags
	if (edf & 0x01)
		get_longlong (&p);										// Server's Game ID
	
	switch (os) {
		case 'l': server_os = "Linux"; break;
		case 'w': server_os = "Windows"; break;
		default:  server_os = "Unknown";
	}
	
	switch (dedicated) {
		case 'd': server_type = "Dedicated"; break;
		case 'l': server_type = "Listen"; break;
		case 'p': server_type = "SourceTV"; break;
		default:  server_type = "";
	}
	
	gsq_querier_set_extra (querier, "os", server_os);
	gsq_querier_set_extra (querier, "type", server_type);
	g_snprintf (tmp, 128, "%d", pver);
	gsq_querier_set_extra (querier, "protocol-version", tmp);
	g_snprintf (tmp, 128, "%d", appid);
	gsq_querier_set_extra (querier, "appid", tmp);
	gsq_querier_set_extra (querier, "secure", secure ? "true" : "false");
	
	const gchar *game_id = "", *game_name = desc, *game_mode = "";
	switch (appid) {
		case 10:
			if (strcmp (dir, "cstrike") == 0) {
				game_id = "cs";
				game_name = "Counter-Strike";
			} else {
				game_id = "hl";
				game_name = "Half-Life";
			}
			break;
		case 20:
			game_id = "tf";
			game_name = "Team Fortress";
			break;
		case 30:
			game_id = "dod";
			game_name = "Day of Defeat";
			break;
		case 80:
			game_id = "czero";
			game_name = "Counter-Strike: Condition Zero";
			break;
		case 240:
			game_id = "css";
			game_name = "Counter-Strike: Source";
			break;
		case 300:
			game_id = "dods";
			game_name = "Day of Defeat: Source";
			break;
		case 320:
			game_id = "hl2dm";
			game_name = "Half-Life 2: Deathmatch";
			break;
		case 440:
			game_id = "tf2";
			game_name = "Team Fortress 2";
			break;
		case 500:
			game_id = "l4d";
			game_name = "Left 4 Dead";
			game_mode = desc + 6;
			break;
		case 550:
			game_id = "l4d2";
			game_name = "Left 4 Dead 2";
			if (strstr (tags, "coop"))
				game_mode = "Co-op";
			else if (strstr (tags, "realism"))
				game_mode = "Realism";
			else if (strstr (tags, "survival"))
				game_mode = "Survival";
			else if (strstr (tags, "versus"))
				game_mode = "Versus";
			else if (strstr (tags, "scavenge"))
				game_mode = "Scavenge";
			break;
		case 630:
			game_id = "as";
			game_name = "Alien Swarm";
			break;
		case 730:
			game_id = "csgo";
			game_name = "Counter-Strike: Global Offensive";
			break;
		case 17500:
			game_id = "zp";
			game_name = "Zombie Panic!";
			break;
		case 17520:
			game_id = "syn";
			game_name = "Synergy";
			break;
		case 17700:
			game_id = "ins";
			game_name = "Insurgency";
			break;
		case 17710:
			game_id = "nd";
			game_name = "Nuclear dawn";
			break;
		case 41070:
			game_id = "ss3";
			game_name = "Serious Sam 3";
			break;
	}
	
	g_string_assign (querier->gameid, game_id);
	g_string_assign (querier->gamename, game_name);
	g_string_assign (querier->gamemode, game_mode);
	gsq_querier_emit_info_update (querier);
}
Exemplo n.º 9
0
char *parse_response(char *line, struct response *resp)
{
	char *rest;
	long long int dummy_len;

	if (resp->r_original == '\0')
		strcpy(resp->r_original, line);

	resp->r_cmd = NUM_COMMANDS;
	resp->r_tag = -1;

	rest = get_tag(line, resp, true, REQUIRES_MORE);

	if (rest == NULL)
		goto fail;

	rest = get_command(rest, &resp->r_cmd);

	if (rest == NULL)
		goto fail;

	rest = get_status(rest, resp);

	if (rest == NULL)
		goto fail;

	switch (resp->r_status) {
	case STATUS_OK:
		switch (resp->r_cmd) {
		case CMD_COMMENT:
		case CMD_HELLO:
			rest =
			    get_str(rest, resp->r_data, &resp->r_length,
				    REQUIRES_NO_MORE);
			break;

		case CMD_LOCKW:
		case CMD_LOCK:
		case CMD_UNLOCK:
		case CMD_TEST:
		case CMD_LIST:
		case CMD_HOP:
		case CMD_UNHOP:
		case NUM_COMMANDS:
			strcpy(errdetail, "Unexpected Status");
			errno = EINVAL;
			sprintf(badtoken, "%s", str_status(resp->r_status));
			goto fail;

		case CMD_ALARM:
			return get_long(rest, &resp->r_secs, REQUIRES_NO_MORE,
					"Invalid alarm time");

		case CMD_QUIT:
			return rest;

		case CMD_OPEN:
			rest = get_fpos(rest, &resp->r_fpos, REQUIRES_MORE);
			if (rest == NULL)
				goto fail;
			rest =
			    get_long(rest, &resp->r_fno, REQUIRES_NO_MORE,
				     "Invalid file number");
			break;

		case CMD_CLOSE:
		case CMD_SEEK:
			rest = get_fpos(rest, &resp->r_fpos, REQUIRES_NO_MORE);
			break;

		case CMD_WRITE:
			rest = get_fpos(rest, &resp->r_fpos, REQUIRES_MORE);
			if (rest == NULL)
				goto fail;
			rest =
			    get_longlong(rest, &resp->r_length,
					 REQUIRES_NO_MORE, "Invalid length");
			break;

		case CMD_READ:
			rest = get_fpos(rest, &resp->r_fpos, REQUIRES_MORE);
			if (rest == NULL)
				goto fail;
			rest =
			    get_longlong(rest, &resp->r_length, REQUIRES_MORE,
					 "Invalid length");
			if (rest == NULL)
				goto fail;
			rest =
			    get_str(rest, resp->r_data, &dummy_len,
				    REQUIRES_NO_MORE);
			if (dummy_len != resp->r_length) {
				strcpy(errdetail, "Read length doesn't match");
				errno = EINVAL;
				sprintf(badtoken, "%lld != %lld", dummy_len,
					resp->r_length);
				goto fail;
			}
			break;
		}
		break;

	case STATUS_AVAILABLE:
	case STATUS_GRANTED:
	case STATUS_DENIED:
	case STATUS_DEADLOCK:
		rest = get_fpos(rest, &resp->r_fpos, REQUIRES_MORE);
		if (rest == NULL)
			goto fail;
		if (resp->r_cmd != CMD_LIST) {
			rest = get_lock_type(rest, &resp->r_lock_type);
			if (rest == NULL)
				goto fail;
		}
		rest =
		    get_longlong(rest, &resp->r_start, REQUIRES_MORE,
				 "Invalid lock start");
		if (rest == NULL)
			goto fail;
		rest =
		    get_longlong(rest, &resp->r_length, REQUIRES_NO_MORE,
				 "Invalid lock length");
		break;

	case STATUS_CONFLICT:
		rest = get_fpos(rest, &resp->r_fpos, REQUIRES_MORE);
		if (rest == NULL)
			goto fail;
		rest =
		    get_long(rest, &resp->r_pid, REQUIRES_MORE,
			     "Invalid conflict pid");
		if (rest == NULL)
			goto fail;
		rest = get_lock_type(rest, &resp->r_lock_type);
		if (rest == NULL)
			goto fail;
		rest =
		    get_longlong(rest, &resp->r_start, REQUIRES_MORE,
				 "Invalid lock start");
		if (rest == NULL)
			goto fail;
		rest =
		    get_longlong(rest, &resp->r_length, REQUIRES_NO_MORE,
				 "Invalid lock length");
		break;

	case STATUS_CANCELED:
		if (resp->r_cmd == CMD_LOCKW) {
			rest = get_fpos(rest, &resp->r_fpos, REQUIRES_MORE);
			if (rest == NULL)
				goto fail;
			rest = get_lock_type(rest, &resp->r_lock_type);
			if (rest == NULL)
				goto fail;
			rest =
			    get_longlong(rest, &resp->r_start, REQUIRES_MORE,
					 "Invalid lock start");
			if (rest == NULL)
				goto fail;
			rest =
			    get_longlong(rest, &resp->r_length,
					 REQUIRES_NO_MORE,
					 "Invalid lock length");
		} else if (resp->r_cmd == CMD_ALARM) {
			rest =
			    get_long(rest, &resp->r_secs, REQUIRES_NO_MORE,
				     "Invalid alarm time");
		} else {
		}
		break;

	case STATUS_COMPLETED:
		break;

	case STATUS_ERRNO:
		rest =
		    get_long(rest, &resp->r_errno, REQUIRES_MORE,
			     "Invalid errno");
		if (rest == NULL)
			goto fail;
		strncpy(resp->r_data, rest, MAXSTR);
		rest += strlen(rest);
		break;

	case STATUS_PARSE_ERROR:
		break;

	case STATUS_ERROR:
		break;
	}

	if (rest != NULL)
		return rest;

 fail:
	resp->r_status = STATUS_PARSE_ERROR;
	sprintf(resp->r_data, "%s %ld ERRNO %d \"%s\" \"%s\" bad token \"%s\"",
		commands[resp->r_cmd].cmd_name, resp->r_tag, errno,
		strerror(errno), errdetail, badtoken);
	resp->r_cmd = NUM_COMMANDS;
	return NULL;
}