예제 #1
0
파일: marshal.cpp 프로젝트: Emily/rubinius
  Symbol* UnMarshaller::get_symbol() {
    char stack_data[STACK_BUF_SZ];
    char *malloc_data = NULL;
    char *data = stack_data;
    size_t count;

    Encoding* enc = try_as<Encoding>(unmarshal());

    stream >> count;
    stream.get();

    if(count >= STACK_BUF_SZ) {
      malloc_data = (char*)malloc(count + 1);
      data = malloc_data;
    }

    stream.read(data, count + 1);
    data[count] = 0; // clamp

    String* str = String::create(state, data, count);
    if(enc) str->encoding(state, enc);

    Symbol* sym = state->symbol(str);

    if(malloc_data) {
      free(malloc_data);
    }

    return sym;
  }
예제 #2
0
파일: client.c 프로젝트: emgram769/game
net_data_t *_recv(void) {
  char *buf = calloc(MAX_NET_DATA_LEN, sizeof(char));
  net_data_t *n = NULL;
  if(recvfrom(fd, buf, MAX_NET_DATA_LEN, 0, NULL, NULL)) {
     n = unmarshal(buf);
  }
  free(buf);
  return n;
}
예제 #3
0
  Tuple* UnMarshaller::get_tuple() {
    size_t count;
    stream >> count;

    Tuple* tup = Tuple::create(state, count);

    for(size_t i = 0; i < count; i++) {
      tup->put(state, i, unmarshal());
    }

    return tup;
  }
예제 #4
0
  Array* UnMarshaller::get_array() {
    size_t count;
    stream >> count;

    Array* ary = Array::create(state, count);

    for(size_t i = 0; i < count; i++) {
      ary->set(state, i, unmarshal());
    }

    return ary;
  }
예제 #5
0
파일: init.cpp 프로젝트: tsavola/tap
static PyObject *unmarshal_py(PyObject *self, PyObject *args) noexcept
{
	PyObject *result = nullptr;
	PyObject *peer;
	Py_buffer buffer;

	if (PyArg_ParseTuple(args, "O!y*", &peer_type, &peer, &buffer)) {
		result = unmarshal(*reinterpret_cast <PeerObject *>(peer), buffer.buf, buffer.len);
		PyBuffer_Release(&buffer);
	}

	return result;
}
예제 #6
0
static ans_client_t *
open_ans(pxd_cred_t *credentials, char *ans_host, char *ans_blob, char *ans_key)
{
    ans_client_t *  result;
    ans_open_t      open;
    int             tries;

    memset(&open, 0, sizeof(open));

    open.clusterName   = ans_host;
    open.deviceType    = "default";
    open.application   = "pxd test";
    open.verbose       = true;
    open.callbacks     = &ans_callbacks;

    open.blob = unmarshal(ans_blob, &open.blobLength);
    open.key  = unmarshal(ans_key , &open.keyLength );

    result = ans_open(&open);

    tries = 15;

    while (!ans_login_done && tries-- > 0) {
        log("Waiting for a connection to the ANS server.\n");
        sleep(1);
    }

    if (!ans_login_done) {
        error("ans_open failed.\n");
        exit(1);
    }

    free((void *) open.blob);
    free((void *) open.key);
    return result;
}
예제 #7
0
  String* UnMarshaller::get_string() {
    size_t count;

    Encoding* enc = try_as<Encoding>(unmarshal());

    stream >> count;
    // String::create adds room for a trailing null on its own
    // using pinned here allows later stages to optimize these literal
    // strings better.
    String* str = String::create(state, NULL, count);

    stream.get(); // read off newline
    stream.read(reinterpret_cast<char*>(str->byte_address()), count);
    stream.get(); // read off newline

    if(enc) str->encoding(state, enc);

    return str;
  }
예제 #8
0
void FiberReferenceMap::unmarshalDynamicGlobals
(Array &dest, CArrRef src, char default_strategy,
 const hphp_string_map<char> &additional_strategies) {
  for (ArrayIter iter(src); iter; ++iter) {
    String key = iter.first().toString();
    CVarRef val = iter.secondRef();
    String fullKey = String("gv_") + key;

    FiberAsyncFunc::Strategy strategy =
      (FiberAsyncFunc::Strategy)default_strategy;
    hphp_string_map<char>::const_iterator it =
      additional_strategies.find(fullKey.data());
    if (it != additional_strategies.end()) {
      strategy = (FiberAsyncFunc::Strategy)it->second;
    }

    if (strategy != FiberAsyncFunc::GlobalStateIgnore) {
      Variant &dval = dest.lvalAt(key.fiberCopy());
      unmarshal(dval, val, strategy);
    }
  }
}
예제 #9
0
  CompiledCode* UnMarshaller::get_cmethod() {
    size_t ver;
    stream >> ver;

    CompiledCode* cm = CompiledCode::create(state);

    cm->metadata(state, unmarshal());
    cm->primitive(state, (Symbol*)unmarshal());
    cm->name(state, (Symbol*)unmarshal());
    cm->iseq(state, (InstructionSequence*)unmarshal());
    cm->stack_size(state, (Fixnum*)unmarshal());
    cm->local_count(state, (Fixnum*)unmarshal());
    cm->required_args(state, (Fixnum*)unmarshal());
    cm->post_args(state, (Fixnum*)unmarshal());
    cm->total_args(state, (Fixnum*)unmarshal());
    cm->splat(state, unmarshal());
    cm->literals(state, (Tuple*)unmarshal());
    cm->lines(state, (Tuple*)unmarshal());
    cm->file(state, (Symbol*)unmarshal());
    cm->local_names(state, (Tuple*)unmarshal());

    cm->post_marshal(state);

    return cm;
  }
예제 #10
0
/**
 * Disconnects the client from the server, deinitializes ENet and releases the engine core.
 * Allow up to 3 seconds for the disconnect to succeed and drop any packets received packets.
 */
void Client::disconnect()
{
	if(!m_pClientHost)
	{
		return;
	}

	// Send disconnecting request
	m_disconnectingEvent.connectionID = m_pPeer->connectID;
	network::send(m_disconnectingEvent, m_pPeer);

	enet_host_flush(m_pClientHost);


	//// Waiting for ACK
	//bool acked = false;
	//int startTime = glutGet(GLUT_ELAPSED_TIME);
	//
	//while (glutGet(GLUT_ELAPSED_TIME) - startTime < 3000 && enet_host_service(m_clientHost, &m_event, 3000) > 0) {
	//	switch (m_event.type) {
	//		case ENET_EVENT_TYPE_RECEIVE:
	//
	//			if (unmarshal(m_netObject, std::string((char*) m_event.packet->data, m_event.packet->dataLength))) {
	//				if (m_netObject.type == events::PlayerDisconnectingEvent::NETOBJ_PLAYER_DC) {
	//					if (unmarshal(m_disconnectingEvent, std::string((char*) m_event.packet->data, m_event.packet->dataLength))) {
	//						if (m_disconnectingEvent.connectionID == m_peer->connectID) {
	//							TRACE_NETWORK("Disconnection ACK-ed.", 0);
	//							acked = true;
	//						}
	//					}
	//				}
	//			}
	//
	//			enet_packet_destroy(m_event.packet);
	//
	//			break;
	//	}
	//}

	enet_peer_disconnect(m_pPeer, 0);

	// Allow up to 3 seconds for the disconnect to succeed and drop any packets received packets
	while (enet_host_service(m_pClientHost, &m_event, 3000) > 0)
	{
		switch (m_event.type)
		{
			case ENET_EVENT_TYPE_RECEIVE:
				if (unmarshal(m_disconnectingEvent, std::string((char*) m_event.packet->data, m_event.packet->dataLength)))
					if (m_disconnectingEvent.connectionID == m_pPeer->connectID)
					{
						TRACE_NETWORK("Disconnection ACK-ed.", 0);
					}

				enet_packet_destroy(m_event.packet);
				break;

			case ENET_EVENT_TYPE_DISCONNECT:
				TRACE_NETWORK("Disconnection succeeded.", 0);
				break;
		}
	}


	enet_host_destroy(m_pClientHost);
	enet_deinitialize();
}
예제 #11
0
/**
 * Listens to the packages sent by the server.
 *	- if the m_package is a GameState object: applies the changes to the scene.
 *	- if the m_clientTable in the m_package has changed: stores the updated one
 *	- if its the first run: replaces the dummy player with the real one created on the server
 *	- if its a lua command: it is a response to a lua command sent to the server earlier
 */
void Client::listen()
{
	if (m_clientId == k_clientIdNone)
	{
		return;
	}

	m_serviceResult = 1;

	do
	{
		m_serviceResult = enet_host_service(m_pClientHost, &m_event, 1);

		if (m_serviceResult > 0)
		{
			switch (m_event.type)
			{
				case ENET_EVENT_TYPE_CONNECT:
					TRACE_NETWORK("A new client connected from " << m_event.peer->address.host << ":" << m_event.peer->address.port, 0);
					m_event.peer->data = (void*)"New User";

					break;

				case ENET_EVENT_TYPE_RECEIVE:
					if (unmarshal(m_netObject, std::string((char*) m_event.packet->data, m_event.packet->dataLength)))
					{
						switch (m_netObject.type)
						{
							// getting back escape char
							case events::KeyEvent::NETOBJ_KEY_DOWN:
								//disconnect();

								break;

							case GameState::NETOBJ_GAMESTATE:
								if (unmarshal(m_package, std::string((char*) m_event.packet->data, m_event.packet->dataLength)))
								{
									///
									//// apply the changes to our entities
									//m_package.apply(m_pEngineCore->getRootNode(), EngineCore::getInstance()->getNodeIdDirectory());

									//// if the clientList changed -> save it to the local variable
									//if (!m_package.getClientTable().empty())
									//{
									//	m_clientTable = m_package.getClientTable();
									//}

									//if (m_pEngineCore->getPlayer()->getName().empty())
									//{
									//	// replace the dummy player with the real one
									//	if (m_pEngineCore->getNodeDirectory().find(m_clientTable[m_pPeer->connectID].clientName) != m_pEngineCore->getNodeDirectory().end())
									//	{
									//		// remove the dummy player from the bsp map
									//		//m_pEngineCore->getMap()->clearObservers();
									//		// delete dummy player
									//		delete m_pEngineCore->getPlayer();
									//		m_pEngineCore->setPlayer(std::static_pointer_cast<Player>(m_pEngineCore->getNodeDirectory().at(m_clientTable[m_pPeer->connectID].clientName)).get());

									//		// add the player to the bsp map
									//		//m_pEngineCore->getMap()->addObserver(m_clientId, m_pEngineCore->getPlayer());
									//	}
									//}
								}
								m_gamePaused = false;

								break;

							case events::LuaCommand::NETOBJ_LUACOMM:
								if (unmarshal(m_luaResponse, std::string((char*) m_event.packet->data, m_event.packet->dataLength)))
								{
									///logToConsole(m_luaResponse.command);
								}

								break;

							case events::ChatMessage::NETOBJ_CHATMSG:
								if (unmarshal(m_chatMessage, std::string((char*) m_event.packet->data, m_event.packet->dataLength)))
								{
									printToChatHistory(m_chatMessage.message);
								}

								break;
						}
					}

					enet_packet_destroy(m_event.packet);

					break;

				case ENET_EVENT_TYPE_DISCONNECT:
					TRACE_NETWORK(m_event.peer->data << " disconnected.", 0);

					break;

				default:
					GX_ASSERT(0 && "Error: unknown event type received.");
					//TRACE_ERROR("Error: unknown event type received.", 0);
			}
		}
	}
	while (m_serviceResult > 0);
}
예제 #12
0
파일: nil_scheme.c 프로젝트: spchamp/ilu
static OM_uint32	accept_sec_context
(OM_uint32		*minor_status,
 gss_opaque_t		*context_handle,
 gss_opaque_t		verifier_cred_handle,
 gss_buffer_t		input_token_buffer,
 gss_channel_bindings_t input_chan_bindings,
 gss_name_t		*src_name,
 gss_buffer_t		output_token,
 OM_uint32		*ret_flags,
 OM_uint32		*time_rec,
 gss_opaque_t		*delegated_cred_handle
     )
{
  gss_opaque_t input_context = *context_handle;
  gss_name_t caller;
  gss_buffer_desc namebuf;
  gss_OID_desc namespace_oid;
  nil_context ctx;
  nil_cred *cred;
  OM_uint32 major, minor;

  *context_handle = GSS_C_NO_CONTEXT;

  if (input_context != GSS_C_NO_CONTEXT)
    return GSS_S_NO_CONTEXT;

  if ((input_token_buffer == GSS_C_NO_BUFFER) || (input_token_buffer->length < sizeof(marshalled_context)))
    return GSS_S_DEFECTIVE_TOKEN;

  if (verifier_cred_handle == GSS_C_NO_CREDENTIAL)
    {
      if ((cred = get_default_credentials()) == NULL)
	return GSS_S_FAILURE;
    }
  else if (!validate_cred_handle(verifier_cred_handle))
    return GSS_S_DEFECTIVE_CREDENTIAL;
  else
    cred = (nil_cred *) verifier_cred_handle;

  if (cred->usage == GSS_C_INITIATE)
    return GSS_S_NO_CRED;
  
  if ((ctx.server = ilugss_copy_name(cred->name)) == NULL)
    return GSS_S_DEFECTIVE_CREDENTIAL;

  unmarshal (&major, ((marshalled_context *) (input_token_buffer->value))->caller_name_len);
  namebuf.length = major;
  unmarshal (&major, ((marshalled_context *) (input_token_buffer->value))->namespace_oid_len);
  namespace_oid.length = major;
  if (input_token_buffer->length < (sizeof(marshalled_context) + namebuf.length + namespace_oid.length))
    {
      (void) gss_release_name(&minor, &ctx.server);
      return GSS_S_DEFECTIVE_TOKEN;
    }
  unmarshal (&major, ((marshalled_context *) (input_token_buffer->value))->flags);
  ctx.flags = major;
  unmarshal (&major, ((marshalled_context *) (input_token_buffer->value))->endtime);
  ctx.endtime = major;
  if ((namebuf.value = ilugss_malloc(namebuf.length)) == NULL)
    {
      (void) gss_release_name(&minor, &ctx.server);
      return GSS_S_FAILURE;
    }
  memcpy ((char *) namebuf.value,
	  ((char *) (input_token_buffer->value)) + sizeof(marshalled_context),
	  namebuf.length);
  if ((namespace_oid.elements = ilugss_malloc(namespace_oid.length)) == NULL)
    {
      (void) gss_release_name(&minor, &ctx.server);
      ilugss_free (namebuf.value);
      return GSS_S_FAILURE;
    }
  memcpy ((char *) (namespace_oid.elements),
	  ((char *) (input_token_buffer->value)) + sizeof(marshalled_context) + namebuf.length,
	  namespace_oid.length);
  ctx.client = (gss_name_t) NULL;
  if ((major = gss_import_name (&minor, &namebuf, &namespace_oid, &ctx.client)) != GSS_S_COMPLETE)
    {
      (void) gss_release_name(&minor, &ctx.server);
      ilugss_free (namebuf.value);
      ilugss_free (namespace_oid.elements);
      return GSS_S_DEFECTIVE_TOKEN;
    }
  (void) gss_release_buffer (&minor, &namebuf);
  ilugss_free (namespace_oid.elements);

  if (src_name != NULL)
    {
      if ((*src_name = ilugss_copy_name(ctx.client)) == NULL)
	{
	  (void) gss_release_name(&minor, &ctx.server);
	  (void) gss_release_name(&minor, &ctx.client);
	  return GSS_S_FAILURE;
	}
    }

  if ((*context_handle = (gss_opaque_t) ilugss_malloc(sizeof(ctx))) == NULL)
    {
      if (src_name != NULL)
	(void) gss_release_name (&minor, src_name);
      (void) gss_release_name(&minor, &ctx.server);
      (void) gss_release_name(&minor, &ctx.client);
      return GSS_S_FAILURE;
    }
  ctx.complete = TRUE;
  ctx.locally_initiated = FALSE;
  *((nil_context *)(*context_handle)) = ctx;

  add_context_handle (*context_handle);

  if (ret_flags != NULL)
    *ret_flags = ctx.flags;

  if (time_rec != NULL)
    {
      if (ctx.endtime != GSS_C_INDEFINITE)
	*time_rec = ctx.endtime - time(NULL);
      else
	*time_rec = GSS_C_INDEFINITE;
    }

  return GSS_S_COMPLETE;
}
예제 #13
0
파일: marshal.cpp 프로젝트: Emily/rubinius
  CompiledCode* UnMarshaller::get_compiled_code() {
    size_t ver;
    stream >> ver;

    CompiledCode* code = CompiledCode::create(state);

    code->metadata(state, unmarshal());
    code->primitive(state, force_as<Symbol>(unmarshal()));
    code->name(state, force_as<Symbol>(unmarshal()));
    code->iseq(state, force_as<InstructionSequence>(unmarshal()));
    code->stack_size(state, force_as<Fixnum>(unmarshal()));
    code->local_count(state, force_as<Fixnum>(unmarshal()));
    code->required_args(state, force_as<Fixnum>(unmarshal()));
    code->post_args(state, force_as<Fixnum>(unmarshal()));
    code->total_args(state, force_as<Fixnum>(unmarshal()));
    code->splat(state, force_as<Fixnum>(unmarshal()));
    code->literals(state, force_as<Tuple>(unmarshal()));
    code->lines(state, force_as<Tuple>(unmarshal()));
    code->file(state, force_as<Symbol>(unmarshal()));
    code->local_names(state, force_as<Tuple>(unmarshal()));

    code->post_marshal(state);

    return code;
  }