client::string_type client::get(const client::string_type & key)
 {
   string cmd = makecmd("GET") << key;
   cout<<"get cmd:"<<cmd<<endl;
   send_(cmd);
   return recv_bulk_reply_();
 }
 client::int_type client::lrange(const client::string_type & key, 
                                  client::int_type start, 
                                  client::int_type end,
                                  client::string_vector & out)
 {
   send_(makecmd("LRANGE") << key << ' ' << start << ' ' << end);
   return recv_multi_bulk_reply_(out);
 }
Beispiel #3
0
bool USHIEngineTester::startGame_(int startstm)
{
    board_.setStandardPosition();
    board_.setToMove((SHATRA::Color)startstm);
    game_.clear();

    // prepare new game for each
    for (int i=0; i<2; ++i)
    {
        send_(i, "ushinewgame");
        send_(i, "setoption name MultiPV value 1");
        send_(i, "setoption name USHI_AnalyseMode value false");
    }

    sendPosition_(board_.toMove(), board_.toSPN());

    return true;
}
 void client::set(const client::string_type & key, 
                  const client::string_type & value)
 {
   string cmd = makecmd("SET") << key << ' ' << value;    
   //send_(makecmd("SET") << key << ' ' << value.size() << CRLF << value);
   cout<<"client::set cmd:"<<cmd<<endl;
   send_(cmd);
   recv_ok_reply_();
 }
Beispiel #5
0
	result_type Peer::requestNiceConnectionTo(peer_id id)
	{
		result_type res;

		// try to connect with libnice
		TEST() std::cout << "requestNiceConnectionTo " << id << std::endl;
		res = send_type_(coordinatorFd, REQUEST_NICE_PEER_CREDENTIALS);
		res = send_(coordinatorFd, id);

		uint streamId;
		std::string localInfo;
		nice.startNewStream(streamId, localInfo);
		res = send_(coordinatorFd, localInfo);
		TEST() std::cout << "sent request for creds" << std::endl;

		streamsForConnections[id] = streamId;

		return res;
	}
Beispiel #6
0
void destroy_(int term)
/* destroy_() sets the process state to DELETE.  It then calls
    dispatch(). The argument term is an integer indicating if the
    termination is normal (0) or abnormal (1). */
{
 running->termsts = term;
 send_(tpin, &running, 4);
 running->state = DELETE;
 dispatch();
} /* end destroy_() */
  client::int_type client::sort(const client::string_type & key, 
                                client::string_vector & out,
                                client::sort_order order,
                                bool lexicographically)
  {
    send_(makecmd("SORT") << key 
          << (order == sort_order_ascending ? " ASC" : " DESC")
          << (lexicographically ? " ALPHA" : ""));

    return recv_multi_bulk_reply_(out);
  }
  client::datatype client::type(const client::string_type & key)
  {
    send_(makecmd("TYPE") << key);
    string response = recv_single_line_reply_();

    if (response == "none")   return datatype_none;
    if (response == "string") return datatype_string;
    if (response == "list")   return datatype_list;
    if (response == "set")    return datatype_set;

    return datatype_none;
  }
  void client::info(server_info & out)
  {
    send_(makecmd("INFO", true));
    string response = recv_bulk_reply_();

    if (response.empty())
      throw protocol_error("empty");

    string_vector lines;
    split_lines(response, lines);
    if (lines.empty())
      throw protocol_error("empty line for info");

    for (string_vector::const_iterator it = lines.begin();
         it != lines.end(); ++it)
    {
      const string & line = *it;
      string_vector line_parts;
      split(line, ':', line_parts);
      if (line_parts.size() != 2)
        throw protocol_error("unexpected line format for info");

      const string & key = line_parts[0];
      const string & val = line_parts[1];

      if (key == server_info_key_version)
        out.version = val;
      else if (key == server_info_key_bgsave_in_progress)
        out.bgsave_in_progress = value_from_string<unsigned long>(val) == 1;
      else if (key == server_info_key_connected_clients)
        out.connected_clients = value_from_string<unsigned long>(val);
      else if (key == server_info_key_connected_slaves)
        out.connected_slaves = value_from_string<unsigned long>(val);
      else if (key == server_info_key_used_memory)
        out.used_memory = value_from_string<unsigned long>(val);
      else if (key == server_info_key_changes_since_last_save)
        out.changes_since_last_save = value_from_string<unsigned long>(val);
      else if (key == server_info_key_last_save_time)
        out.last_save_time = value_from_string<unsigned long>(val);
      else if (key == server_info_key_total_connections_received)
        out.total_connections_received = value_from_string<unsigned long>(val);
      else if (key == server_info_key_total_commands_processed)
        out.total_commands_processed = value_from_string<unsigned long>(val);
      else if (key == server_info_key_uptime_in_seconds)
        out.uptime_in_seconds = value_from_string<unsigned long>(val);
      else if (key == server_info_key_uptime_in_days)
        out.uptime_in_days = value_from_string<unsigned long>(val);
      else if (key == server_info_key_role)
        out.role = val == server_info_value_role_master ? role_master : role_slave;
      else
        throw protocol_error(string("unexpected info key '") + key + "'");
    }
  }
Beispiel #10
0
	result_type Peer::requestNormalConnectionTo(peer_id id)
	{
		result_type res;

		// try to connect with normal sockets
		TEST() std::cout << "requestNormalConnectionTo " << id << std::endl;
		res = send_type_(coordinatorFd, REQUEST_PEER_CREDENTIALS);
		res = send_(coordinatorFd, id);
		TEST() std::cout << "sent request for creds" << std::endl;

		return res;
	}
// 0x0040159b
void do_login(struct state* arg_state) {
    // rsp -- 0xc0 bytes for locals -- rbp
    struct state* s = arg_state; // -0xb8(rsp)
    int len; // -0xa8(rsp)
    char* p1; // -0xa0(rsp)
    char* p2; // -0x98(rsp)
    char buf[0x80]; // -0x90(rsp)
    memset(buf, 0, 0x80);
    send_(s->sock, "Please send password for user ");
    send_(s->sock, s->username);
    send_(s->sock, "\n");
    p1 = p2 = recv_(s->sock);
    len = strlen(p1);
    for(i=0; (*p1 != ' ') && (i < len-1); i++) {
        buf[i] = *p1++;
    }
    if(*p1 == ' ') { p1++; }
    if(strncasecmp("PASS", buf, 4)) {
        send_(s->sock, "login with USER PASS.\n");
        return;
    }
    s->password = p1;
    hash_password(s->password);
    if(!strncmp(s->username, "blankwall", 9) && hash_password(s->password) == 0xd386d209) {
        send_(s->sock, "logged in.\n");
        return;
        // 0x00401780: movl $0x66, 0x202c7e(%rip) // this pokes a global, but I don't know which/where it's used
    } else {
        send_(s->sock, "Invalid login credentials.\n");
    }
}
Beispiel #12
0
	result_type Peer::whenNiceCredentialsAreRequested(const descriptor_pair & sourceDesc, peer_id sourceId)
	{
		result_type res = SUCCESS;

		peer_id requesterId;
		res = recv_(coordinatorFd, 0, requesterId);			// receive source credentials
		QUIT_IF_UNSUCCESSFUL(res);
		TEST() std::cout << "peer " << requesterId << " requested nice credentials" << std::endl;

		uint streamId;
		std::string localInfo;
		nice.startNewStream(streamId, localInfo);

		res = send_type_(coordinatorFd, PROVIDE_NICE_PEER_CREDENTIALS);
		res = send_(coordinatorFd, localInfo);
		res = send_(coordinatorFd, requesterId);
		TEST() std::cout << "sent creds, as requested" << std::endl;

		streamsForConnections[requesterId] = streamId;

		return res;
	}
Beispiel #13
0
void USHIEngineTester::stopEngine_(int stm)
{
    if (!process_[stm])
        return;

    send_(stm, "quit");

    SB_ET_DEBUG(stm, "waiting for finished");
    process_[stm]->waitForFinished(1000);
    process_[stm]->deleteLater();
    process_[stm] = 0;
    active_[stm] = 0;
}
  void client::shutdown()
  {
    send_(makecmd("SHUTDOWN", true));

    // we expected to get a connection_error as redis closes the connection on shutdown command.

    try
    {
      recv_ok_reply_();
    }
    catch (connection_error & e)
    {
    }
  }
Beispiel #15
0
fcppt::signal::auto_connection
sanguis::server::console::insert(
	fcppt::string const &_command,
	sge::console::callback::function const &_callback,
	fcppt::string const &_description
)
{
	send_(
		sanguis::messages::server::create(
			alda::message::init_record<
				sanguis::messages::server::add_console_command
			>(
				sanguis::messages::roles::command_name{} =
					sge::charconv::fcppt_string_to_utf8(
						_command
					),
				sanguis::messages::roles::command_description{} =
					sge::charconv::fcppt_string_to_utf8(
						_description
					)
			)
		)
	);

	// TODO: we have to know when a command doesn't exist anymore!
	known_commands_.push_back(
		sanguis::server::console_command_pair(
			_command,
			_description
		)
	);

	return
		object_.insert(
			sge::console::callback::parameters(
				_callback,
				sge::console::callback::name(
					sge::font::from_fcppt_string(
						_command
					)
				)
			)
			.short_description(
				sge::font::from_fcppt_string(
					_description
				)
			)
		);
}
Beispiel #16
0
int   table_to_Json(TABLE *t,IO_Structure * to) {
  // set some stuf up to restore Json brackets
  struct {int count;int total;} brk[8];int cur; char prev;
  int len; int i,rows;
  Triple Qin;char tmp[9];
  Code stmt;
  cur = 0;
  start_table(t,select_operator);
  stmt = get_ready_stmt();
  // peek at the header
  i = machine_step_fetch(&Qin,0); 
  rows = Qin.pointer;
  prev=Qin.link;
  brk[cur].total = Qin.pointer; brk[cur].count = 0;
  for(i=0;i<rows;i++) {
    if(i) machine_step_fetch(&Qin,0);
    len = machine_key_len(stmt); 
    // mke a stream json
    send_(Qin.key,len,to);
    send_(tmp,sprintf(tmp,"%c",Qin.link),to);
    // restor brckets
    brk[cur].count++;
    while(brk[cur].count == brk[cur].total) {
      cur--;brk[cur].count += brk[cur+1].count;
      send_("}",1,to);
    }
    if((Qin.pointer > 1) && (prev != '.') && ( prev != ',')) {
      cur++; brk[cur].count = 0;brk[cur].total = Qin.pointer;
      send_("{",1,to);
    }
        prev=Qin.link;
  }

  DBG_printf("TJ%s%c%3d\n",Qin.key,Qin.link,Qin.pointer);
return 0;
}
Beispiel #17
0
int
WSAAPI
Hookedsend(
	SOCKET s,
	const char *buf,
	int len,
	int flags
	)
{

	if ( DbgGetShellcodeFlag() == MCEDP_STATUS_SHELLCODE_FLAG_SET )
	{
		CHAR szPort[20];
        CHAR szUID[UID_SIZE];
		sockaddr_in sdata;
		PXMLNODE XmlLogNode;
		PXMLNODE XmlIDLogNode;
		int sock_len = sizeof(sockaddr);

		if ( len > 1 )
		{
			XmlIDLogNode = mxmlNewElement( XmlShellcode, "row");
			// type
			XmlLogNode = mxmlNewElement( XmlIDLogNode, "type");
			mxmlNewText( XmlLogNode, 0, "8");
			// send
			getpeername( s, (sockaddr *)&sdata, &sock_len);
			XmlLogNode = mxmlNewElement( XmlIDLogNode, "send_ip");
			mxmlNewText( XmlLogNode, 0, inet_ntoa(sdata.sin_addr));
			XmlLogNode = mxmlNewElement( XmlIDLogNode, "send_port");
			mxmlNewText( XmlLogNode, 0, _itoa(htons(sdata.sin_port), szPort, 10));
			XmlLogNode = mxmlNewElement( XmlIDLogNode, "send_datalen");
			mxmlNewText( XmlLogNode, 0, _itoa(len, szPort, 10));
            XmlLogNode = mxmlNewElement( XmlIDLogNode, "data_uid");
			mxmlNewText( XmlLogNode, 0, GenRandomStr(szUID, UID_SIZE-1));
            HexDumpToFile((PBYTE)buf, len ,szUID);
			// save
			SaveXml( XmlLog );
		}
	}

	return (send_( s, buf, len, flags));
}
Beispiel #18
0
	result_type Peer::whenPeerRegisters(const descriptor_pair & sourceDesc, peer_id sourceId)
	{
		result_type res = SUCCESS;
		int sourceFd = sourceDesc.desc;

		peer_id actualId;
		res = recv_(sourceFd, 0, actualId);
		TEST() std::cout << "peer " << actualId << " registering with this node " << std::endl;
		res = send_(sourceFd, this->ownId);
		LOG_AND_QUIT_IF_UNSUCCESSFUL(res, sourceDesc);
		setNewPeerStructures(sourceFd, actualId, DESCRIPTOR_SOCK);

		if (this->usingFreeformLayout) {
			this->nextPeers.push_back(actualId);
		}

		std::cout << knownPeers.toString() << std::endl;

		return res;
	}
Beispiel #19
0
	result_type Peer::requestRelayedConnectionTo(peer_id id)
	{
		result_type res = SUCCESS;

		if (options.doRelayMessages) {
			// No connection. All data to this peer will be sent through the coordinator
			TEST() std::cout << "requestRelayedConnectionTo " << id << std::endl;
			descriptor_pair desc(id, DESCRIPTOR_NONE);
			knownPeers.registerPeer(desc, id);
			preparePeerQueues(desc);

			res = send_type_(coordinatorFd, SET_RELAYED_CONNECTION);
			res = send_(coordinatorFd, id);
		} else if (!this->usingFreeformLayout) {
			res = send_type_(coordinatorFd, DEREGISTER);
			res = FAILURE;
		}
		std::cout << knownPeers.toString() << std::endl;
		establishNextConnectionIfAvailable();

		return res;
	}
 client::int_type client::sinter(const client::string_vector & keys, client::string_set & out)
 {
   send_(makecmd("SINTER") << keys);
   return recv_multi_bulk_reply_(out);
 }
 time_t client::lastsave()
 {
   send_(makecmd("LASTSAVE", true));
   return recv_int_reply_();
 }
 void client::bgsave()
 {
   send_(makecmd("BGSAVE", true));
   recv_ok_reply_();
 }
 void client::flushall()
 {
   send_(makecmd("FLUSHALL", true));
   recv_ok_reply_();
 }
 void client::flushdb()
 {
   send_(makecmd("FLUSHDB", true));
   recv_ok_reply_();
 }
 void client::move(const client::string_type & key, 
                   client::int_type dbindex)
 {
   send_(makecmd("MOVE") << key << ' ' << dbindex);
   recv_int_ok_reply_();
 }
 void client::select(client::int_type dbindex)
 {
   send_(makecmd("SELECT") << dbindex);
   recv_ok_reply_();
 }
 client::int_type client::smembers(const client::string_type & key, 
                                   client::string_set & out)
 {
   send_(makecmd("SMEMBERS") << key);
   return recv_multi_bulk_reply_(out);
 }
 client::int_type client::sunionstore(const client::string_type & dstkey, 
                                      const client::string_vector & keys)
 {
   send_(makecmd("SUNIONSTORE") << dstkey << ' ' << keys);
   return recv_int_reply_();
 }
void do_stuff(int arg_sock) {
    // rsp -- 0x990 bytes for locals -- rbp
    int sock = arg_sock; // -0x984(rbp)
    int i; // -0x978(rbp)
    int len; // -0x974(rbp)
    char* p1, p2 // -0x970(rbp), -0x968(rbp)
    // -0x960(rbp), 1224 bytes total
    struct {
        int sock; // -0x960(rbp)
        char* something1; // -0x950(rbp)
        char* something2; // -0x948(rbp)
        char* username; // offset 0x20, -0x940(rbp)
        char* password; // offset 0x28
        char dir[1024]; // offset 0xc0
    } state;
    int logged_in; // -0x4a0(rbp), overlap with dir?
    char buf[0x80]; // -0x490(rbp)
    char directory[1024]; // -0x410(rbp)
    alarm(65);
    srand(time(0));
    memset(state, 0, 1224);
    state->sock = sock;
    if(getcwd(directory, 0x400)) {
        strcpy(state->dir, directory);
    } else {
        error("CWD");
    }
    send_(sock, "Welcome to FTP server\n");
    for(;; free(p2)) {
        memset(buf, 0, 0x80);
        p1 = p2 = recv_(sock);
        len = strlen(p1);
        for(i=0; (*p1 != ' ') && (i < len-1); i++) {
            buf[i] = *p1++;
        }
        if(*p1 == ' ') { p1++; }
        p1[strlen(p1)-1] = 0;
        if(!strncasecmp("USER", buf, 4)) {
            if(logged_in) {
                send_(sock, "Cannot change user  ");
                send_(sock, state->username);
                send_(sock, "\n");
                continue;
            } else {
                state->username = p1;
                state->something2 = p1;
                do_login(state);
                continue;
            }
        }
        if(!strncasecmp("PASS", buf, 4)) {
            send_(sock, "send user first.\n");
            continue;
        }
        if(!strncasecmp("HELP", buf, 4)) {
            send_(sock, "USER PASS PASV PORT\nNOOP REIN LIST SYST SIZE\nRETR STOR PWD CWD\n");
            continue;
        }
        if(!logged_in) {
            send_(sock, "login with USER first.\n");
            continue;
        }
        if(!strncasecmp("REIN", buf, 4)) {
            logged_in = 0;
            continue;
        }
        if(!strncasecmp("PORT", buf, 4)) {
            do_port(...);
        }
        if(!strncasecmp("PASV", buf, 4)) {
            do_pasv(...);
        }
        if(!strncasecmp("STOR", buf, 4)) {
            do_stor(...);
        }
        if(!strncasecmp("RETR", buf, 4)) {
            do_retr(...);
        }
        if(!strncasecmp("QUIT", buf, 4)) {
            do_quit(...);
        }
        if(!strncasecmp("LIST", buf, 4)) {
            do_list(...);
        }
        if(!strncasecmp("SYST", buf, 4)) {
            do_syst(...);
        }
        if(!strncasecmp("NOOP", buf, 4)) {
            do_noop(...);
        }
        if(!strncasecmp("PWD", buf, 4)) {
            do_pwd(...);
        }
        if(!strncasecmp("CWD", buf, 4)) {
            do_cwd(...);
        }
        if(!strncasecmp("RDF", buf, 4)) {
            state->something1 = p1;
            state->something2 = buf;
            do_rdf(state);
        }
    }
}
 client::int_type client::sunion(const client::string_vector & keys,
                                 client::string_set & out)
 {
   send_(makecmd("SUNION") << keys);
   return recv_multi_bulk_reply_(out);
 }