Ejemplo n.º 1
0
uint8_t config_load (void)
{
    char *file = dynprintf("%s", config_dir_and_file);
    demarshal_p ctx;

    /*
     * Default settings.
     */
    global_config.video_pix_width = 0;
    global_config.video_pix_height = 0;
    global_config.sound_volume = 10;
    global_config.music_volume = 5;
    global_config.display_sync = 0;
    global_config.full_screen = 0;
    global_config.intro_screen = 1;
    global_config.fps_counter = 0;
    global_config.deathmatch = 0;
    global_config.deathmatch_monsters = 0;

    if (!global_config.server_name[0]) {
        strncpy(global_config.server_name, "unnamed-server", 
                sizeof(global_config.server_name) - 1);
    }

    global_config.server_max_players = 4;
    global_config.server_port = SERVER_DEFAULT_PORT;

    if (!(ctx = demarshal(file))) {
        myfree(file);
        return (true);
    }

    if (!demarshal_config(ctx, &global_config)) {
        MSG_BOX("Failed to parse: %s", file);
    }

    myfree(file);
    demarshal_fini(ctx);

    return (true);
}
Ejemplo n.º 2
0
IoObject *demarshal(IoObject *self, IoObject *arg, intptr_t n)
{
	if (ISNUMBER(arg))
	{
		return IONUMBER(n);
	}
	else if (ISSYMBOL(arg))
	{
		if (n == 0)
			return IOSYMBOL("");
		return IOSYMBOL((char*)n);
	}
	else if (ISLIST(arg))
	{
		intptr_t *values = (intptr_t *)n;
		int i;

		for (i = 0; i < IoList_rawSize(arg); i ++)
		{
			IoObject *value = List_at_(IoList_rawList(arg), i);
			List_at_put_(IoList_rawList(arg), i, demarshal(self, value, values[i]));
		}

		io_free(values);
		return arg;
	}
	else if (ISBUFFER(arg))
	{
		return arg;
	}
	else if (ISBLOCK(arg))
	{
		return arg;
	}

	return IONIL(self);
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
0
int callFunction(const char *app, const char *obj, const char *func, const KStringList args)
{
    QString f = func; // Qt is better with unicode strings, so use one.
    int left = f.find('(');
    int right = f.find(')');

    if(right < left)
    {
        qWarning("parentheses do not match");
        return (1);
    }

    if(left < 0)
    {
        // try to get the interface from the server
        bool ok = false;
        KStringList funcs = dcop->remoteFunctions(app, obj, &ok);
        QCString realfunc;
        if(!ok && args.isEmpty())
            goto doit;
        if(!ok)
        {
            qWarning("object not accessible");
            return (1);
        }
        for(const auto &it : funcs)
        {
            int l = it.find('(');
            int s;
            if(l > 0)
                s = it.findRev(' ', l);
            else
                s = it.find(' ');

            if(s < 0)
                s = 0;
            else
                s++;

            if(l > 0 && it.mid(s, l - s) == func)
            {
                realfunc = it.mid(s);
                const QString arguments = it.mid(l + 1, it.find(')') - l - 1);
                uint a = arguments.contains(',');
                if((a == 0 && !arguments.isEmpty()) || a > 0)
                    a++;
                if(a == args.count())
                    break;
            }
        }
        if(realfunc.isEmpty())
        {
            qWarning("no such function");
            return (1);
        }
        f = realfunc;
        left = f.find('(');
        right = f.find(')');
    }

doit:
    if(left < 0)
        f += "()";

    // This may seem expensive but is done only once per invocation
    // of dcop, so it should be OK.
    //
    //
    QStringList intTypes;
    intTypes << "int"
             << "unsigned"
             << "long"
             << "bool";

    QStringList types;
    if(left > 0 && left + 1 < right - 1)
    {
        types = QStringList::split(',', f.mid(left + 1, right - left - 1));
        for(QStringList::Iterator it = types.begin(); it != types.end(); ++it)
        {
            QString lt = (*it).simplifyWhiteSpace();

            int s = lt.find(' ');

            // If there are spaces in the name, there may be two
            // reasons: the parameter name is still there, ie.
            // "QString URL" or it's a complicated int type, ie.
            // "unsigned long long int bool".
            //
            //
            if(s > 0)
            {
                QStringList partl = QStringList::split(' ', lt);

                // The zero'th part is -- at the very least -- a
                // type part. Any trailing parts *might* be extra
                // int-type keywords, or at most one may be the
                // parameter name.
                //
                //
                s = 1;

                while(s < static_cast< int >(partl.count()) && intTypes.contains(partl[s]))
                {
                    s++;
                }

                if(s < static_cast< int >(partl.count()) - 1)
                {
                    qWarning("The argument `%s' seems syntactically wrong.", lt.latin1());
                }
                if(s == static_cast< int >(partl.count()) - 1)
                {
                    partl.remove(partl.at(s));
                }

                lt = partl.join(" ");
                lt = lt.simplifyWhiteSpace();
            }

            (*it) = lt;
        }
        QString fc = f.left(left);
        fc += '(';
        bool first = true;
        for(QStringList::Iterator it = types.begin(); it != types.end(); ++it)
        {
            if(!first)
                fc += ",";
            first = false;
            fc += *it;
        }
        fc += ')';
        f = fc;
    }

    QByteArray data, replyData;
    QCString replyType;
    QDataStream arg(data, IO_WriteOnly);

    uint i = 0;
    for(QStringList::Iterator it = types.begin(); it != types.end(); ++it)
        marshall(arg, args, i, *it);

    if(i != args.count())
    {
        qWarning("arguments do not match");
        return (1);
    }

    if(!dcop->call(app, obj, f.latin1(), data, replyType, replyData))
    {
        qWarning("call failed");
        return (1);
    }
    else
    {
        QDataStream reply(replyData, IO_ReadOnly);

        if(replyType != "void" && replyType != "ASYNC")
        {
            QCString replyString = demarshal(reply, replyType);
            if(!replyString.isEmpty())
                printf("%s\n", replyString.data());
            else
                printf("\n");
        }
    }
    return 0;
}