Example #1
0
bool
TAO::TypeCode::Value<StringType,
                     TypeCodeType,
                     FieldArrayType,
                     RefCountPolicy>::tao_marshal (
  TAO_OutputCDR & cdr,
  CORBA::ULong offset) const
{
  // A tk_value TypeCode has a "complex" parameter list type (see
  // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of
  // the CORBA specification), meaning that it must be marshaled into
  // a CDR encapsulation.

  // Create a CDR encapsulation.
  TAO_OutputCDR enc;

  // Account for the encoded CDR encapsulation length and byte order.
  //
  // Aligning on an octet since the next value after the CDR
  // encapsulation length will always be the byte order octet/boolean
  // in this case.
  offset = ACE_align_binary (offset + 4,
                             ACE_CDR::OCTET_ALIGN);

  bool const success =
    (enc << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER))
    && (enc << TAO_OutputCDR::from_string (this->base_attributes_.id (), 0))
    && (enc << TAO_OutputCDR::from_string (this->base_attributes_.name (), 0))
    && (enc << this->type_modifier_)
    && marshal (enc,
                Traits<StringType>::get_typecode (this->concrete_base_),
                offset + enc.total_length ())
    && (enc << this->nfields_);

  if (!success)
    return false;

  Value_Field<StringType, TypeCodeType> const * const begin =
    &this->fields_[0];
  Value_Field<StringType, TypeCodeType> const * const end =
    begin + this->nfields_;

  for (Value_Field<StringType, TypeCodeType> const * i = begin; i != end; ++i)
    {
      Value_Field<StringType, TypeCodeType> const & field = *i;

      if (!(enc << Traits<StringType>::get_string (field.name))
          || !marshal (enc,
                       Traits<StringType>::get_typecode (field.type),
                       offset + enc.total_length ())
          || !(enc << field.visibility))
        return false;
    }

  return
    cdr << static_cast<CORBA::ULong> (enc.total_length ())
    && cdr.write_octet_array_mb (enc.begin ());
}
Example #2
0
  void Marshaller::set_tuple(Tuple* tup) {
    stream << "p" << endl << tup->num_fields() << endl;

    for(size_t i = 0; i < tup->num_fields(); i++) {
      marshal(tup->at(state, i));
    }
  }
Example #3
0
TAO_BEGIN_VERSIONED_NAMESPACE_DECL

bool
TAO::TypeCode::Union<char const *,
                     CORBA::TypeCode_ptr const *,
                     TAO::TypeCode::Case<char const *,
                                         CORBA::TypeCode_ptr const *> const * const *,
                     TAO::Null_RefCount_Policy>::tao_marshal (
  TAO_OutputCDR & cdr,
  CORBA::ULong offset) const
{
  // A tk_union TypeCode has a "complex" parameter list type (see
  // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of
  // the CORBA specification), meaning that it must be marshaled into
  // a CDR encapsulation.

  // Create a CDR encapsulation.
  TAO_OutputCDR enc;

  // Account for the encoded CDR encapsulation length and byte order.
  //
  // Aligning on an octet since the next value after the CDR
  // encapsulation length will always be the byte order octet/boolean
  // in this case.
  offset = ACE_Utils::truncate_cast<CORBA::ULong> (
              ACE_align_binary (offset + 4,
                                ACE_CDR::OCTET_ALIGN));

  bool const success =
    (enc << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER))
    && (enc << TAO_OutputCDR::from_string (this->base_attributes_.id (), 0))
    && (enc << TAO_OutputCDR::from_string (this->base_attributes_.name (), 0))
    && marshal (enc,
                Traits<char const *>::get_typecode (this->discriminant_type_),
                ACE_Utils::truncate_cast<CORBA::ULong> (
                    offset + enc.total_length ()))
    && (enc << this->default_index_)
    && (enc << this->ncases_);

  if (!success)
    {
      return false;
    }

  // Note that we handle the default case below, too.

  for (CORBA::ULong i = 0; i < this->ncases_; ++i)
    {
      case_type const & c = *this->cases_[i];

      if (!c.marshal (enc, offset))
        {
          return false;
        }
    }

  return
    cdr << static_cast<CORBA::ULong> (enc.total_length ())
    && cdr.write_octet_array_mb (enc.begin ());
}
Example #4
0
void
Routing_Slip::enter_state_saving (Routing_Slip_Guard & guard)
{
  ++count_enter_saving_;
  if (!create_persistence_manager ())
  {
    // Note This should actually be a throw (out of memory)
    // but we cheat and make this a transient event.
    guard.release ();
    this->persistent_queue_.complete ();
    enter_state_transient (guard);
  }
  else
  {
    if (DEBUG_LEVEL > 8) ORBSVCS_DEBUG ((LM_DEBUG,
        ACE_TEXT ("(%P|%t) Routing Slip #%d: enter state SAVING\n"),
        this->sequence_
        ));
    this->state_ = rssSAVING;

    TAO_OutputCDR event_cdr;
    this->event_->marshal (event_cdr);

    const ACE_Message_Block *event_mb = event_cdr.begin ();
    TAO_OutputCDR rs_cdr;
    marshal (rs_cdr);
    const ACE_Message_Block *rs_mb = rs_cdr.begin ();

    guard.release ();
    this->rspm_->store (*event_mb, *rs_mb);
  }
}
Example #5
0
uint8_t config_save (void)
{
    char *file = dynprintf("%s", config_dir_and_file);
    marshal_p ctx;

    LOG("Saving config to: %s", file);

    ctx = marshal(file);
    if (!ctx) {
        WARN("Failed to save: %s", file);
        myfree(file);
        return (false);
    }

    marshal_config(ctx, &global_config);

    if (marshal_fini(ctx) < 0) {
        WARN("Failed to finalize: %s", file);
        myfree(file);
        return (false);
    }

    myfree(file);

    return (true);
}
Example #6
0
bool
TAO::TypeCode::Alias<StringType,
                     TypeCodeType,
                     RefCountPolicy>::tao_marshal (TAO_OutputCDR & cdr,
                                                   CORBA::ULong offset) const
{
  // A tk_alias TypeCode has a "complex" parameter list type (see
  // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of
  // the CORBA specification), meaning that it must be marshaled into
  // a CDR encapsulation.

  // Create a CDR encapsulation.

  TAO_OutputCDR enc;

  // Account for the encoded CDR encapsulation length and byte order.
  //
  // Aligning on an octet since the next value after the CDR
  // encapsulation length will always be the byte order octet/boolean
  // in this case.
  offset = ACE_Utils::truncate_cast<CORBA::ULong> (
              ACE_align_binary (offset + 4,
                                ACE_CDR::OCTET_ALIGN));

  return
    enc << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER)
    && enc << TAO_OutputCDR::from_string (this->attributes_.id (), 0)
    && enc << TAO_OutputCDR::from_string (this->attributes_.name (), 0)
    && marshal (enc,
                Traits<StringType>::get_typecode (this->content_type_),
                ACE_Utils::truncate_cast<CORBA::ULong> (
                    offset + enc.total_length ()))
    && cdr << static_cast<CORBA::ULong> (enc.total_length ())
    && cdr.write_octet_array_mb (enc.begin ());
}
Example #7
0
int _send(net_data_t *net_data) {
  char *msg = marshal(net_data);
  int len = strnlen(msg, MAX_NET_DATA_LEN);
  int res = sendto(fd, msg, len, 0,
                   (struct sockaddr *)&server_addr,
                   sizeof(server_addr));
  free(msg);
  return res;
}
Example #8
0
  void Marshaller::set_array(Array* ary) {
    size_t count = ary->size();

    stream << "A" << endl << count << endl;

    for(size_t i = 0; i < count; i++) {
      marshal(ary->get(state, i));
    }
  }
Example #9
0
int
main(int argc, char *argv[])
{
	const char *name;
	int ch, dofreespace, domarshal, dolabel, eval;

	dofreespace = domarshal = dolabel = eval = 0;

	while ((ch = getopt(argc, argv, "lfm")) != -1) {
		switch (ch) {
		case 'f':
			dofreespace++;
			break;
		case 'm':
			domarshal = 1;
			break;
		case 'l':
			dolabel = 1;
			break;
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (argc < 1)
		usage();
	if (dofreespace && domarshal)
		usage();
	if (dofreespace > 2)
		usage();

	while ((name = *argv++) != NULL) {
		if (ufs_disk_fillout(&disk, name) == -1) {
			ufserr(name);
			eval |= 1;
			continue;
		}
		if (dofreespace)
			eval |= dumpfreespace(name, dofreespace);
		else if (domarshal)
			eval |= marshal(name);
		else if (dolabel)
			eval |= dumpfsid();
		else
			eval |= dumpfs(name);
		ufs_disk_close(&disk);
	}
	exit(eval);
}
Example #10
0
intptr_t marshal(IoDynLib *self, IoObject *arg)
{
	intptr_t n = 0;

	if (ISNUMBER(arg))
	{
		n = IoNumber_asInt(arg);
	}
	else if (ISSYMBOL(arg))
	{
		n = (intptr_t)CSTRING(arg);
	}
	else if (ISLIST(arg))
	{
		int i;
		intptr_t *l = io_calloc(1, IoList_rawSize(arg) * sizeof(intptr_t));
		for (i = 0; i < IoList_rawSize(arg); i ++)
			l[i] = marshal(self, List_rawAt_(IoList_rawList(arg), i));
		n = (intptr_t)l;
	}
	else if (ISBUFFER(arg))
	{
		n = (intptr_t)IoSeq_rawBytes(arg);
	}
	else if (ISBLOCK(arg))
	{
		unsigned char *blk = io_calloc(1, 20), *p = blk;
		// FIXME: need trampoline code for other architectures
		*p++ = 0x68;
		*((intptr_t *)p) = (intptr_t)arg;
		p += sizeof(intptr_t);
		*p++ = 0xb8;
		*((intptr_t *)p) = (intptr_t)bouncer;
		p += sizeof(intptr_t);
		*p++ = 0xff;
		*p++ = 0xd0;
		*p++ = 0x83;
		*p++ = 0xc4;
		*p++ = 0x04;
		*p++ = 0xc3;
		n = (intptr_t)blk;
	}
	else
	{
		n =  (intptr_t)arg; //IONIL(self);
	}

	return n;
}
Example #11
0
File: init.cpp Project: tsavola/tap
static PyObject *marshal_py(PyObject *self, PyObject *args) noexcept
{
	PyObject *result = nullptr;
	PyObject *peer;
	PyObject *bytearray;
	PyObject *object = nullptr;

	if (PyArg_ParseTuple(args, "O!O!|O", &peer_type, &peer, &PyByteArray_Type, &bytearray, &object)) {
		if (marshal(*reinterpret_cast <PeerObject *>(peer), bytearray, object) == 0) {
			Py_INCREF(Py_None);
			result = Py_None;
		}
	}

	return result;
}
Example #12
0
void MethodCall::eval() {
  if (_mode == RToSmoke) 
    _stack = new Smoke::StackItem[length(_args) + 1];
  else if (_mode == SmokeToR)
    PROTECT(_args = allocVector(VECSXP, stackSize() - 1));
  if (_mode != Identity) {
    marshal();
    _called = false;
  } else invokeMethod();
  if (_mode == RToSmoke) {
    delete[] _stack;
    _stack = NULL;
  } else if (_mode == SmokeToR) {
    UNPROTECT(1);
    _args = NULL;
  }
}
Example #13
0
void
Routing_Slip::enter_state_updating (Routing_Slip_Guard & guard)
{
  ++count_enter_updating_;
  if (DEBUG_LEVEL > 8) ORBSVCS_DEBUG ((LM_DEBUG,
      ACE_TEXT ("(%P|%t) Routing Slip #%d: enter state UPDATING\n"),
      this->sequence_
      ));
  this->state_ = rssUPDATING;

  TAO_OutputCDR rs_cdr;
  marshal (rs_cdr);
  const ACE_Message_Block *rs_mb = rs_cdr.begin ();
  guard.release ();

  ACE_ASSERT (this->rspm_ != 0);
  this->rspm_->update (*rs_mb);
}
Example #14
0
/*

	closure: a GClosure
	return_value: a GValue to store the return value. May be NULL if the callback of closure doesn't return a value.
	n_param_values: the length of the param_values array
	param_values: an array of GValues holding the arguments on which to invoke the callback of closure
	invocation_hint: a context-dependent invocation hint
*/
void
g_closure_invoke (GClosure       *closure,
		  GValue /*out*/ *return_value,
		  guint           n_param_values,
		  const GValue   *param_values,
		  gpointer        invocation_hint)
{
	/*
	设置状态防止重入
	*/
	closure->ref_count += 1;
	closure->in_marshal = TRUE;

	// 得到marshal的指针
	if (closure->meta_marshal)
	{
	  	marshal_data = closure->notifiers[0].data;
	  	marshal = (GClosureMarshal) closure->notifiers[0].notify;
	}
	else
	{
	  	marshal_data = NULL;
	  	marshal = closure->marshal;
	}
	
	/*
	分别调用
		pre-notifer
		marshal
		post-notifier
	*/
	closure_invoke_notifiers (closure, PRE_NOTIFY);
	marshal (closure,
	       return_value,
	       n_param_values, param_values,
	       invocation_hint,
	       marshal_data);
	closure_invoke_notifiers (closure, POST_NOTIFY);
	
	// 恢复重入状态
	closure->in_marshal = in_marshal;  
	g_closure_unref (closure); 
}
Example #15
0
void main(int argc,char **argv)
{
	int aPort = IPPORT_RESERVED + 3612;
	struct sockaddr_in serverAddr, clientAddr;
	int s, n, i;

	if((s = socket(AF_INET, SOCK_DGRAM, 0))<0) {
		perror("socket failed");
		return;
	}
	makeReceiverSA(&serverAddr, aPort);
	if( bind(s, (struct sockaddr *)&serverAddr, sizeof(struct sockaddr_in))!= 0){
		perror("Bind failed\n");
		close(s);
		return;
	}
	
	printf("Listening for messages...\n");
	Message *curMessage = malloc(sizeof(Message)), *reply = malloc(sizeof(Message));
	RPCMessage *curRPC = malloc(sizeof(RPCMessage)), *replyRPC = malloc(sizeof(RPCMessage));
	do{
		Status stat = GetRequest(curMessage, s, (SocketAddress *)&clientAddr);

		unMarshal(curRPC, curMessage);
		printf("Got RPC Message: ");
		printRPCMessage(curRPC);

		stat = processRequest(curRPC, replyRPC);
		printf("Created reply:   ");
		printRPCMessage(replyRPC);

		marshal(replyRPC, reply);
		Status replyStatus = SendReply(reply, s, clientAddr);
		printf("\tSent reply with status %d\n", replyStatus);
	} while (curRPC->procedureId != STOP);
	free(curRPC);
	free(curMessage);
	free(reply);

	close(s);
}
Example #16
0
TAO_BEGIN_VERSIONED_NAMESPACE_DECL

bool
TAO::TypeCode::Struct<char const *,
                      CORBA::TypeCode_ptr const *,
                      TAO::TypeCode::Struct_Field<char const *,
                                                  CORBA::TypeCode_ptr const *> const *,
                      TAO::Null_RefCount_Policy>::tao_marshal (
  TAO_OutputCDR & cdr,
  CORBA::ULong offset) const
{
  // A tk_struct TypeCode has a "complex" parameter list type (see
  // Table 15-2 in Section 15.3.5.1 "TypeCode" in the CDR section of
  // the CORBA specification), meaning that it must be marshaled into
  // a CDR encapsulation.

  // Create a CDR encapsulation.
  TAO_OutputCDR enc;

  // Account for the encoded CDR encapsulation length and byte order.
  //
  // Aligning on an octet since the next value after the CDR
  // encapsulation length will always be the byte order octet/boolean
  // in this case.
  offset = ACE_Utils::truncate_cast<CORBA::ULong> (
              ACE_align_binary (offset + 4,
                                ACE_CDR::OCTET_ALIGN));

  bool const success =
    (enc << TAO_OutputCDR::from_boolean (TAO_ENCAP_BYTE_ORDER))
    && (enc << TAO_OutputCDR::from_string (this->base_attributes_.id (), 0))
    && (enc << TAO_OutputCDR::from_string (this->base_attributes_.name (), 0))
    && (enc << this->nfields_);

  if (!success)
    return false;

  Struct_Field<char const *, CORBA::TypeCode_ptr const *> const * const begin =
    &this->fields_[0];
  Struct_Field<char const *, CORBA::TypeCode_ptr const *> const * const end =
    begin + this->nfields_;

  for (Struct_Field<char const *, CORBA::TypeCode_ptr const *> const * i =
         begin;
       i != end;
       ++i)
    {
      Struct_Field<char const *, CORBA::TypeCode_ptr const *> const & field =
        *i;

      if (!(enc << TAO_OutputCDR::from_string (
                       Traits<char const *>::get_string (field.name), 0))
          || !marshal (enc,
                       Traits<char const *>::get_typecode (field.type),
                       ACE_Utils::truncate_cast<CORBA::ULong> (
                           offset + enc.total_length ())))
        return false;
    }

  return
    cdr << static_cast<CORBA::ULong> (enc.total_length ())
    && cdr.write_octet_array_mb (enc.begin ());
}
::DDS::ReturnCode_t FooDataWriterImpl::write_w_timestamp (
    const Foo & instance_data,
    ::DDS::InstanceHandle_t handle,
    const ::DDS::Time_t & source_timestamp
  )
{
  //  A lock is obtained on entering this method to serialize access to
  //  the contained data storage and interfaces.  This lock protects the
  //  marshaled data buffers as well as the instance data containers.

  ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex,
                    guard,
                    get_lock (),
                    ::DDS::RETCODE_ERROR);

  ACE_Message_Block* marshalled;
  int is_new = 0;
  ::DDS::InstanceHandle_t registered_handle;
  ::DDS::ReturnCode_t ret
    = this->get_or_create_instance_handle(registered_handle,
                                          instance_data,
                                          is_new,
                                          marshalled,
                                          source_timestamp);
  if (ret != ::DDS::RETCODE_OK)
  {
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT("(%P|%t) ")
                ACE_TEXT("FooDataWriterImpl::write, ")
                ACE_TEXT("register failed err=%d.\n"),
                ret));
  }

  if (handle == ::OpenDDS::DCPS::HANDLE_NIL)
  {
    // note: do not tell subscriber if there is an implicit registration.
    //    Subscriber must be able to handle a new instance without being
    //    told about it.

    handle = registered_handle;
  }

  if (handle == ::OpenDDS::DCPS::HANDLE_NIL)
  {
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT("(%P|%t) ")
                       ACE_TEXT("FooDataWriterImpl::write, ")
                       ACE_TEXT("The instance has not registered yet.")),
                       ::DDS::RETCODE_ERROR);
  }

  if (handle != registered_handle)
  {
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT("(%P|%t) ")
                       ACE_TEXT("FooDataWriterImpl::write, ")
                       ACE_TEXT("The given handle=%X is different from "
                       "registered handle=%X.\n"),
                       handle, registered_handle),
                       ::DDS::RETCODE_ERROR);
  }

  marshalled = marshal (instance_data); // FOR_WRITE
  return DataWriterImpl::write(marshalled, handle, source_timestamp);
}
Example #18
0
static void
expected_fail_marshal(int expected_error, const char *format, ...)
{
	struct wl_closure *closure;
	static const uint32_t opcode = 4444;
	static const struct wl_interface test_interface = {
		.name = "test_object"
	};
	static struct wl_object sender = { 0 };
	struct wl_message message = { "test", format, NULL };

	sender.interface = &test_interface;
	sender.id = 1234;
	va_list ap;

	va_start(ap, format);
	closure = wl_closure_vmarshal(&sender, opcode, ap, &message);
	va_end(ap);

	assert(closure == NULL);
	assert(errno == expected_error);
}

static void
expected_fail_marshal_send(struct marshal_data *data, int expected_error,
			   const char *format, ...)
{
	struct wl_closure *closure;
	static const uint32_t opcode = 4444;
	static struct wl_object sender = { NULL, NULL, 1234 };
	struct wl_message message = { "test", format, NULL };
	va_list ap;

	va_start(ap, format);
	closure = wl_closure_vmarshal(&sender, opcode, ap, &message);
	va_end(ap);

	assert(closure);
	assert(wl_closure_send(closure, data->write_connection) < 0);
	assert(errno == expected_error);

	wl_closure_destroy(closure);
}

TEST(connection_marshal_nullables)
{
	struct marshal_data data;
	struct wl_object object;
	struct wl_array array;
	const char text[] = "curry";

	setup_marshal_data(&data);

	expected_fail_marshal(EINVAL, "o", NULL);
	expected_fail_marshal(EINVAL, "s", NULL);
	expected_fail_marshal(EINVAL, "a", NULL);

	marshal(&data, "?o", 12, NULL);
	assert(data.buffer[2] == 0);

	marshal(&data, "?a", 12, NULL);
	assert(data.buffer[2] == 0);

	marshal(&data, "?s", 12, NULL);
	assert(data.buffer[2] == 0);

	object.id = 55293;
	marshal(&data, "?o", 12, &object);
	assert(data.buffer[2] == object.id);

	array.data = (void *) text;
	array.size = sizeof text;
	marshal(&data, "?a", 20, &array);
	assert(data.buffer[2] == array.size);
	assert(memcmp(&data.buffer[3], text, array.size) == 0);

	marshal(&data, "?s", 20, text);
	assert(data.buffer[2] == sizeof text);
	assert(strcmp((char *) &data.buffer[3], text) == 0);

	release_marshal_data(&data);
}

static void
validate_demarshal_u(struct marshal_data *data,
		     struct wl_object *object, uint32_t u)
{
	assert(data->value.u == u);
}
Example #19
0
IoDynLib *IoDynLib_justCall(IoDynLib *self, IoObject *locals, IoMessage *m, int isVoid)
{
	int n, rc = 0;
	intptr_t *params = NULL;
	IoSymbol *callName = IoMessage_locals_symbolArgAt_(m, locals, 0);
	void *f = DynLib_pointerForSymbolName_(DATA(self), CSTRING(callName));

	//printf("DynLib calling '%s'\n", CSTRING(callName));

	if (f == NULL)
	{
		IoState_error_(IOSTATE, m, "Error resolving call '%s'.", CSTRING(callName));
		return IONIL(self);
	}

	if (IoMessage_argCount(m) > 9)
	{
		IoState_error_(IOSTATE, m, "Error, too many arguments (%i) to call '%s'.",
					IoMessage_argCount(m) - 1,
					CSTRING(callName));
		return IONIL(self);
	}

	if (IoMessage_argCount(m) > 1)
	{
		params = io_calloc(1, IoMessage_argCount(m) * sizeof(unsigned int));
	}

	for (n = 0; n < IoMessage_argCount(m) - 1; n++)
	{
		IoObject *arg = IoMessage_locals_valueArgAt_(m, locals, n + 1);
		intptr_t p = marshal(self, arg);

		params[n] = p;

		/*
		if (p == 0)
		{
			IoState_error_(IOSTATE, m, "DynLib error marshalling argument (%i) to call '%s'.",
						n + 1, CSTRING(callName));
			// FIXME this can leak memory.
			io_free(params);
			return IONIL(self);
		}
		*/
	}

#if 0
	printf("calling %s with %i arguments\n",
	CSTRING(IoMessage_locals_symbolArgAt_(m, locals, 0)),
	IoMessage_argCount(m) - 1);
#endif

	IoState_pushCollectorPause(IOSTATE);

	if (isVoid)
	{
		IoDynLib_rawVoidCall(f, IoMessage_argCount(m), params);
	}
	else
	{
		rc = (int)IoDynLib_rawNonVoidCall(f, IoMessage_argCount(m), params);
	}

	IoState_popCollectorPause(IOSTATE);


	for (n = 0; n < IoMessage_argCount(m) - 1; n ++)
	{
		IoObject *arg = IoMessage_locals_valueArgAt_(m, locals, n + 1);
		demarshal(self, arg, params[n]);
	}

	io_free(params);

	return isVoid ? IONIL(self) : IONUMBER(rc);
}
Example #20
0
int
ACE_TMAIN (int, ACE_TCHAR *[])
{
  int error= 0;

  try
    {
      // Marshal part.

      TAO_OutputCDR cdr_out;

      test::UnionAllCovered_EnumerationDiscriminant uac_ed_out;
      // UnionAllCovered_EnumerationDiscriminant must have _default()
      // despite it has cases for all possible
      // values of enumeration. But since enumeration is just int it has
      // much more values than those listed in IDL.
      uac_ed_out._default ();
      marshal (cdr_out, uac_ed_out);

      test::UnionAllCovered_EnumerationDiscriminant uac_ed2_out;
      uac_ed2_out._d (static_cast<test::Enumeration> (10));
      marshal (cdr_out, uac_ed2_out);

      test::UnionWithDefault_EnumerationDiscriminant uwd_ed_out;
      uwd_ed_out._d (static_cast<test::Enumeration> (20));
      marshal (cdr_out, uwd_ed_out);

      test::UnionWithImplicitDefault_EnumerationDiscriminant uwid_ed_out;
      uwid_ed_out._default ();
      marshal (cdr_out, uwid_ed_out);

      test::UnionWithImplicitDefault_EnumerationDiscriminant uwid_ed2_out;
      uwid_ed2_out._d (static_cast<test::Enumeration> (30));
      marshal (cdr_out, uwid_ed2_out);

      test::UnionAllCovered_TypedefedEnumerationDiscriminant uac_ted_out;
      // UnionAllCovered_TypedefedEnumerationDiscriminant must have _default()
      // despite it has cases for all possible
      // values of enumeration. But since enumeration is just int it has
      // much more values than those listed in IDL.
      uac_ted_out._default ();
      marshal (cdr_out, uac_ted_out);

      test::UnionAllCovered_TypedefedEnumerationDiscriminant uac_ted2_out;
      uac_ted2_out._d (static_cast<test::Enumeration> (40));
      marshal (cdr_out, uac_ted2_out);

      test::UnionWithDefault_TypedefedEnumerationDiscriminant uwd_ted_out;
      uwd_ted_out._d (static_cast<test::Enumeration> (50));
      marshal (cdr_out, uwd_ted_out);

      test::UnionWithImplicitDefault_TypedefedEnumerationDiscriminant uwid_ted_out;
      uwid_ted_out._default ();
      marshal (cdr_out, uwid_ted_out);

      test::UnionWithImplicitDefault_TypedefedEnumerationDiscriminant uwid_ted2_out;
      uwid_ted2_out._d (static_cast<test::Enumeration> (60));
      marshal (cdr_out, uwid_ted2_out);

      test::UnionAllCovered_BooleanDiscriminant uac_bd_out;
      // uac_bd_out._default (); // no _default() since all labels are covered.
      uac_bd_out._d (static_cast<CORBA::Boolean> (3));
      marshal (cdr_out, uac_bd_out);

      test::UnionAllCovered_BooleanDiscriminant uac_bd2_out;
      uac_bd2_out._d (static_cast<CORBA::Boolean> (5));
      marshal (cdr_out, uac_bd2_out);

      test::UnionWithDefault_BooleanDiscriminant uwd_bd_out;
      uwd_bd_out._d (static_cast<CORBA::Boolean> (7));
      marshal (cdr_out, uwd_bd_out);

      test::UnionWithImplicitDefault_BooleanDiscriminant uwid_bd_out;
      uwid_bd_out._default ();
      marshal (cdr_out, uwid_bd_out);

      test::UnionWithImplicitDefault_BooleanDiscriminant uwid_bd2_out;
      uwid_bd2_out._d (static_cast<CORBA::Boolean> (9));
      marshal (cdr_out, uwid_bd2_out);

      test::UnionAllCovered_CharDiscriminant uac_cd_out;
      // uac_cd_out._default (); // no _default() since all labels are covered.
      marshal (cdr_out, uac_cd_out);

      test::UnionAllCovered_CharDiscriminant uac_cd2_out;
      uac_cd2_out._d (100);
      marshal (cdr_out, uac_cd2_out);

      test::UnionWithDefault_CharDiscriminant uwd_cd_out;
      uwd_cd_out._d (110);
      marshal (cdr_out, uwd_cd_out);

      test::UnionWithImplicitDefault_CharDiscriminant uwid_cd_out;
      uwid_cd_out._default ();
      marshal (cdr_out, uwid_cd_out);

      test::UnionWithImplicitDefault_CharDiscriminant uwid_cd2_out;
      uwid_cd2_out._d (120);
      marshal (cdr_out, uwid_cd2_out);

      test::UnionWithDefault_LongDiscriminant uwd_ld_out;
      uwd_ld_out._d (1000);
      marshal (cdr_out, uwd_ld_out);

      test::UnionWithImplicitDefault_LongDiscriminant uwid_ld_out;
      uwid_ld_out._default ();
      marshal (cdr_out, uwid_ld_out);

      test::UnionWithImplicitDefault_LongDiscriminant uwid_ld2_out;
      uwid_ld2_out._d (2000);
      marshal (cdr_out, uwid_ld2_out);

      // Demarshal part.

      TAO_InputCDR cdr_in (cdr_out);

      test::UnionAllCovered_EnumerationDiscriminant uac_ed_in;
      uac_ed_in._d (test::Enum1);
      demarshal (cdr_in, uac_ed_in, test::Enum1, uac_ed_out._d ());

      test::UnionAllCovered_EnumerationDiscriminant uac_ed2_in;
      uac_ed2_in._d (test::Enum1);
      demarshal (cdr_in, uac_ed2_in, test::Enum1, uac_ed2_out._d ());

      test::UnionWithDefault_EnumerationDiscriminant uwd_ed_in;
      uwd_ed_in._d (test::Enum1);
      demarshal (cdr_in, uwd_ed_in, test::Enum1, uwd_ed_out._d ());

      test::UnionWithImplicitDefault_EnumerationDiscriminant uwid_ed_in;
      uwid_ed_in._d (test::Enum1);
      demarshal (cdr_in, uwid_ed_in, test::Enum1, uwid_ed_out._d ());

      test::UnionWithImplicitDefault_EnumerationDiscriminant uwid_ed2_in;
      uwid_ed2_in._d (test::Enum1);
      demarshal (cdr_in, uwid_ed2_in, test::Enum1, uwid_ed2_out._d ());

      test::UnionAllCovered_TypedefedEnumerationDiscriminant uac_ted_in;
      uac_ted_in._d (test::Enum1);
      demarshal (cdr_in, uac_ted_in, test::Enum1, uac_ted_out._d ());

      test::UnionAllCovered_TypedefedEnumerationDiscriminant uac_ted2_in;
      uac_ted2_in._d (test::Enum1);
      demarshal (cdr_in, uac_ted2_in, test::Enum1, uac_ted2_out._d ());

      test::UnionWithDefault_TypedefedEnumerationDiscriminant uwd_ted_in;
      uwd_ted_in._d (test::Enum1);
      demarshal (cdr_in, uwd_ted_in, test::Enum1, uwd_ted_out._d ());

      test::UnionWithImplicitDefault_TypedefedEnumerationDiscriminant uwid_ted_in;
      uwid_ted_in._d (test::Enum1);
      demarshal (cdr_in, uwid_ted_in, test::Enum1, uwid_ted_out._d ());

      test::UnionWithImplicitDefault_TypedefedEnumerationDiscriminant uwid_ted2_in;
      uwid_ted2_in._d (test::Enum1);
      demarshal (cdr_in, uwid_ted2_in, test::Enum1, uwid_ted2_out._d ());

      test::UnionAllCovered_BooleanDiscriminant uac_bd_in;
      uac_bd_in._d (false);
      demarshal (cdr_in, uac_bd_in, false, uac_bd_out._d ());

      test::UnionAllCovered_BooleanDiscriminant uac_bd2_in;
      uac_bd2_in._d (false);
      demarshal (cdr_in, uac_bd2_in, false, uac_bd2_out._d ());

      test::UnionWithDefault_BooleanDiscriminant uwd_bd_in;
      uwd_bd_in._d (false);
      demarshal (cdr_in, uwd_bd_in, false, uwd_bd_out._d ());

      test::UnionWithImplicitDefault_BooleanDiscriminant uwid_bd_in;
      uwid_bd_in._d (true);
      demarshal (cdr_in, uwid_bd_in, true, uwid_bd_out._d ());

      test::UnionWithImplicitDefault_BooleanDiscriminant uwid_bd2_in;
      uwid_bd2_in._d (false);
      demarshal (cdr_in, uwid_bd2_in, false, uwid_bd2_out._d ());

      test::UnionAllCovered_CharDiscriminant uac_cd_in;
      uac_cd_in._d ('a');
      demarshal (cdr_in, uac_cd_in, 'a', uac_cd_out._d ());

      test::UnionAllCovered_CharDiscriminant uac_cd2_in;
      uac_cd2_in._d ('a');
      demarshal (cdr_in, uac_cd2_in, 'a', uac_cd2_out._d ());

      test::UnionWithDefault_CharDiscriminant uwd_cd_in;
      uwd_cd_in._d ('\1');
      demarshal (cdr_in, uwd_cd_in, '\1', uwd_cd_out._d ());

      test::UnionWithImplicitDefault_CharDiscriminant uwid_cd_in;
      uwid_cd_in._d ('\1');
      demarshal (cdr_in, uwid_cd_in, '\1', uwid_cd_out._d ());

      test::UnionWithImplicitDefault_CharDiscriminant uwid_cd2_in;
      uwid_cd2_in._d ('\1');
      demarshal (cdr_in, uwid_cd2_in, '\1', uwid_cd2_out._d ());

      test::UnionWithDefault_LongDiscriminant uwd_ld_in;
      uwd_ld_in._d (1);
      demarshal (cdr_in, uwd_ld_in, 1, uwd_ld_out._d ());

      test::UnionWithImplicitDefault_LongDiscriminant uwid_ld_in;
      uwid_ld_in._d (1);
      demarshal (cdr_in, uwid_ld_in, 1, uwid_ld_out._d ());

      test::UnionWithImplicitDefault_LongDiscriminant uwid_ld2_in;
      uwid_ld2_in._d (1);
      demarshal (cdr_in, uwid_ld2_in, 1, uwid_ld2_out._d ());
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      error= 1;
    }

  return error;
}
Example #21
0
static OM_uint32	init_sec_context
(OM_uint32		*minor_status,
 gss_opaque_t		claimant_cred_handle,
 gss_opaque_t		*context_handle,
 gss_name_t		target_name,
 OM_uint32		req_flags,
 OM_uint32		time_req,
 gss_channel_bindings_t input_chan_bindings,
 gss_buffer_t		input_token,
 gss_buffer_t		output_token,
 OM_uint32		*ret_flags,
 OM_uint32		*time_rec
     )
{
  nil_context ctx;
  nil_cred *cred;
  gss_opaque_t input_context = *context_handle;
  nil_time_t endtime;
  gss_buffer_desc namebuf;
  gss_OID namespace_oid;
  OM_uint32 minor;

  *context_handle = GSS_C_NO_CONTEXT;

  if ((input_token!=GSS_C_NO_BUFFER) && (input_token->length!=0)) {
    return GSS_S_DEFECTIVE_TOKEN;
  }

  if (input_context != GSS_C_NO_CONTEXT)
    return GSS_S_NO_CONTEXT;

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

  if (cred->usage == GSS_C_ACCEPT)
    return GSS_S_NO_CRED;
  
  if ((ctx.server = ilugss_copy_name(target_name)) == NULL)
    return GSS_S_BAD_NAME;

  if ((req_flags & GSS_C_ANON_FLAG) != 0)
    ctx.client = ilugssns_anonymous_default_name();
  else
    ctx.client = ilugss_copy_name(cred->name);
  if (ctx.client == NULL)
    return GSS_S_NO_CRED;

  ctx.flags = (req_flags & (GSS_C_ANON_FLAG));

  if ((time_req != GSS_C_INDEFINITE) && (time_req != 0))
    {
      ctx.endtime = time_req + time(NULL);
      if ((cred->endtime != GSS_C_INDEFINITE) &&
	  (ctx.endtime > cred->endtime))
	ctx.endtime = cred->endtime;
    }
  else
    ctx.endtime = GSS_C_INDEFINITE;
  if (time_rec != NULL)
    {
      if (ctx.endtime != GSS_C_INDEFINITE)
	*time_rec = (OM_uint32) (ctx.endtime - time(NULL));
      else
	*time_rec = GSS_C_INDEFINITE;
    }
  if (ret_flags != NULL)
    *ret_flags = ctx.flags;

  /* now create the output token */

  if (gss_display_name (&minor, cred->name, &namebuf, &namespace_oid) != GSS_S_COMPLETE)
    return GSS_S_DEFECTIVE_CREDENTIAL;

  output_token->length = sizeof(marshalled_context) + namebuf.length + namespace_oid->length;
  if ((output_token->value = ilugss_malloc(output_token->length)) == NULL)
    {
      output_token->length = 0;
      ilugss_free (namebuf.value);
      return GSS_S_FAILURE;
    }
  marshal (ctx.flags, ((marshalled_context *)(output_token->value))->flags);
  marshal (ctx.endtime, ((marshalled_context *)(output_token->value))->endtime);
  marshal (namebuf.length, ((marshalled_context *)(output_token->value))->caller_name_len);
  marshal (namespace_oid->length, ((marshalled_context *)(output_token->value))->namespace_oid_len);
  memcpy ((char *)(output_token->value) + sizeof(marshalled_context), namebuf.value, namebuf.length);
  memcpy ((char *)(output_token->value) + sizeof(marshalled_context) + namebuf.length,
	  (char *)(namespace_oid->elements), namespace_oid->length);
  ilugss_free(namebuf.value);

  if ((*context_handle = (gss_opaque_t) ilugss_malloc(sizeof(ctx))) == NULL)
    {
      ilugss_free (output_token->value);
      return GSS_S_FAILURE;
    }
  ctx.complete = TRUE;
  ctx.locally_initiated = TRUE;
  *((nil_context *)(*context_handle)) = ctx;
  add_context_handle(*context_handle);

  return GSS_S_COMPLETE;
}
 // This function is executed in the main V8/JavaScript thread. That means it's
 // safe to use V8 functions again. Don't forget the HandleScope!
 virtual Local<Value> CreateCallbackResult()
 {
     TRACE_FUNCTION;
     NanEscapableScope();
     return NanEscapeScope(marshal(m_analyzeResult));
 }