Example #1
0
CS_RETCODE SybConnection::init_()
{
    CS_RETCODE retcode;
    CS_INT netio_type = CS_SYNC_IO;

    // Get a context handle to use.
    if ((retcode = cs_ctx_alloc(EX_CTLIB_VERSION, &sContext_)) != CS_SUCCEED) {
        SysLogger::error("init_: cs_ctx_alloc() failed");
        return retcode;
    }

    // Initialize Open Client.
    if ((retcode = ct_init(sContext_, EX_CTLIB_VERSION)) != CS_SUCCEED) {
        SysLogger::error("init_: ct_init() failed");
        cs_ctx_drop(sContext_);
        sContext_ = NULL;
        return retcode;
    }

    // Install client message handlers.
    if ((retcode = ct_callback(sContext_, NULL, CS_SET, CS_CLIENTMSG_CB,
                               (CS_VOID *)clientmsg_cb)) != CS_SUCCEED) {
        SysLogger::error("init_: ct_callback(CS_CLIENTMSG_CB) failed");
        ct_exit(sContext_, CS_FORCE_EXIT);
        cs_ctx_drop(sContext_);
        sContext_ = NULL;
        return retcode;
    }

    // Install server message handlers.
    if ((retcode = ct_callback(sContext_, NULL, CS_SET, CS_SERVERMSG_CB,
                               (CS_VOID *)servermsg_cb)) != CS_SUCCEED) {
        SysLogger::error("init_: ct_callback(CS_SERVERMSG_CB) failed");
        ct_exit(sContext_, CS_FORCE_EXIT);
        cs_ctx_drop(sContext_);
        sContext_ = NULL;
        return retcode;
    }

    // Set the input/output type to synchronous.
    if ((retcode = ct_config(sContext_, CS_SET, CS_NETIO, &netio_type,
                             CS_UNUSED, NULL)) != CS_SUCCEED) {
        SysLogger::error("init_: ct_config() failed");
        ct_exit(sContext_, CS_FORCE_EXIT);
        cs_ctx_drop(sContext_);
        sContext_ = NULL;
        return retcode;
    }

    return CS_SUCCEED;
}
Example #2
0
/* Note: the programmer must not allow the context to be
   GC'd until all connections are closed, or they'll be killed. */
void mltds_ct_ctx_finalize(value context)
{
    CS_CONTEXT* ctx = context_ptr(context);

    ct_exit(ctx, CS_FORCE_EXIT);
    cs_ctx_drop(ctx);
}
Example #3
0
int
main(int argc, char **argv)
{
	CS_CONTEXT *ctx;
	CS_CONNECTION *conn;
	int ret = 1;

	read_login_info();
	
	if (cs_ctx_alloc(CS_VERSION_100, &ctx) != CS_SUCCEED) {
		fprintf(stderr, "Context Alloc failed!\n");
		return ret;
	}
	if (ct_init(ctx, CS_VERSION_100) != CS_SUCCEED) {
		fprintf(stderr, "Library Init failed!\n");
		return ret;
	}
	if (ct_con_alloc(ctx, &conn) != CS_SUCCEED) {
		fprintf(stderr, "Connect Alloc failed!\n");
		return ret;
	}
	if (ct_con_props(conn, CS_SET, CS_USERNAME, (CS_VOID*) "sa", CS_NULLTERM, NULL) != CS_SUCCEED) {
		fprintf(stderr, "ct_con_props() SET USERNAME failed!\n");
		return ret;
	}
	if (ct_con_props(conn, CS_SET, CS_PASSWORD, (CS_VOID*) "invalid", CS_NULLTERM, NULL) != CS_SUCCEED) {
		fprintf(stderr, "ct_con_props() SET PASSWORD failed!\n");
		return ret;
	}
	if (ct_connect(conn, SERVER, CS_NULLTERM) != CS_FAIL) {
		fprintf(stderr, "Connection succeeded??\n");
		return ret;
	}

	if (ct_cancel(conn, NULL, CS_CANCEL_ALL) != CS_SUCCEED) {
		fprintf(stderr, "ct_cancel() failed!\n");
		return ret;
	}
	if (ct_close(conn, CS_UNUSED) != CS_SUCCEED) {
		fprintf(stderr, "ct_close() failed!\n");
		return ret;
	}
	if (ct_con_drop(conn) != CS_SUCCEED) {
		fprintf(stderr, "ct_con_drop() failed!\n");
		return ret;
	}
	if (ct_exit(ctx, CS_UNUSED) != CS_SUCCEED) {
		fprintf(stderr, "ct_exit() failed!\n");
		return ret;
	}
	if (cs_ctx_drop(ctx) != CS_SUCCEED) {
		fprintf(stderr, "cs_ctx_drop() failed!\n");
		return ret;
	}

	fprintf(stdout, "Test succeeded\n");
	return 0;
}
Example #4
0
static VALUE connection_Close(VALUE self) {
	TDS_Connection* conn;
	
	Data_Get_Struct(self, TDS_Connection, conn);

	ct_close(conn->connection, CS_FORCE_CLOSE);
	ct_exit(conn->context, CS_FORCE_EXIT);

	conn->connection = NULL;
	conn->context = NULL;

	return Qnil;
}
Example #5
0
CS_RETCODE
try_ctlogout(CS_CONTEXT * ctx, CS_CONNECTION * conn, CS_COMMAND * cmd, int verbose)
{
CS_RETCODE ret;

	ret = ct_cancel(conn, NULL, CS_CANCEL_ALL);
	if (ret != CS_SUCCEED) {
		if (verbose) {
			fprintf(stderr, "ct_cancel() failed!\n");
		}
		return ret;
	}
	ct_cmd_drop(cmd);
	ct_close(conn, CS_UNUSED);
	ct_con_drop(conn);
	ct_exit(ctx, CS_UNUSED);
	cs_ctx_drop(ctx);

	return CS_SUCCEED;
}
Example #6
0
static void
check_topology_on(dbref player, dbref i)
{
    warn_type flags;

    /* Skip it if it's NOWARN or the player checking is the owner and
     * is NOWARN.  Also skip GOING objects.
     */
    if (Going(i) || NoWarn(i))
        return;

    /* If the owner is checking, use the flags on the object, and fall back
     * on the owner's flags as default. If it's not the owner checking
     * (therefore, an admin), ignore the object flags, use the admin's flags
     */
    if (Owner(player) == Owner(i)) {
        if (!(flags = Warnings(i)))
            flags = Warnings(player);
    } else
        flags = Warnings(player);

    ct_generic(player, i, flags);

    switch (Typeof(i)) {
    case TYPE_ROOM:
        ct_room(player, i, flags);
        break;
    case TYPE_THING:
        ct_thing(player, i, flags);
        break;
    case TYPE_EXIT:
        ct_exit(player, i, flags);
        break;
    case TYPE_PLAYER:
        ct_player(player, i, flags);
        break;
    }
    return;
}
Example #7
0
CS_RETCODE SybConnection::ctx_cleanup_(CS_RETCODE status)
{
    if (sContext_) {
        CS_RETCODE retcode;
        CS_INT exit_option;

        exit_option = (status != CS_SUCCEED) ? CS_FORCE_EXIT : CS_UNUSED;
        retcode = ct_exit(sContext_, exit_option);
        if (retcode != CS_SUCCEED) {
            SysLogger::error("con_cleanup_: ct_exit() failed");
            return retcode;
        }
        retcode = cs_ctx_drop(sContext_);
        if (retcode != CS_SUCCEED) {
            SysLogger::error("con_cleanup_: cs_ctx_drop() failed");
            return retcode;
        }
        return retcode;
    } else {
        return CS_SUCCEED;
    }
}
Example #8
0
/*
 * ct_send SQL |select name = @@servername|
 * ct_bind variable
 * ct_fetch and print results
 */
int
main(int argc, char **argv)
{
	int verbose = 1;
	CS_CONTEXT *ctx;
	CS_RETCODE ret;
	CS_DATAFMT srcfmt;
	CS_INT src = 32768;
	CS_DATAFMT dstfmt;
	CS_SMALLINT dst;
	CS_DATETIME dst_date;

	int i;

	CS_INT num_msgs;
	CS_CLIENTMSG client_message;

	fprintf(stdout, "%s: Testing context callbacks\n", __FILE__);

	srcfmt.datatype = CS_INT_TYPE;
	srcfmt.maxlength = sizeof(CS_INT);
	srcfmt.locale = NULL;

	dstfmt.datatype = CS_SMALLINT_TYPE;
	dstfmt.maxlength = sizeof(CS_SMALLINT);
	dstfmt.locale = NULL;

	if (verbose) {
		fprintf(stdout, "Trying clientmsg_cb with context\n");
	}
	if (cs_ctx_alloc(CS_VERSION_100, &ctx) != CS_SUCCEED) {
		fprintf(stderr, "cs_ctx_alloc() failed\n");
	}
	if (ct_init(ctx, CS_VERSION_100) != CS_SUCCEED) {
		fprintf(stderr, "ct_init() failed\n");
	}

	if (cs_diag(ctx, CS_INIT, CS_UNUSED, CS_UNUSED, NULL) != CS_SUCCEED) {
		fprintf(stderr, "cs_diag(CS_INIT) failed\n");
		return 1;
	}

	if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst, NULL) == CS_SUCCEED) {
		fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
		return 1;
	}

	dstfmt.datatype = CS_DATETIME_TYPE;
	dstfmt.maxlength = sizeof(CS_DATETIME);
	dstfmt.locale = NULL;

	if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst_date, NULL) == CS_SUCCEED) {
		fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
		return 1;
	}

	if (cs_diag(ctx, CS_STATUS, CS_CLIENTMSG_TYPE, CS_UNUSED, &num_msgs) != CS_SUCCEED) {
		fprintf(stderr, "cs_diag(CS_STATUS) failed\n");
		return 1;
	}

	for (i = 0; i < num_msgs; i++ ) {

		if (cs_diag(ctx, CS_GET, CS_CLIENTMSG_TYPE, i + 1, &client_message) != CS_SUCCEED) {
			fprintf(stderr, "cs_diag(CS_GET) failed\n");
			return 1;
		}
	
	    cslibmsg_cb(NULL, &client_message);
	
	}

	if ((ret = cs_diag(ctx, CS_GET, CS_CLIENTMSG_TYPE, i + 1, &client_message)) != CS_NOMSG) {
		fprintf(stderr, "cs_diag(CS_GET) did not fail with CS_NOMSG\n");
		return 1;
	}

	if (cs_diag(ctx, CS_CLEAR, CS_CLIENTMSG_TYPE, CS_UNUSED, NULL) != CS_SUCCEED) {
		fprintf(stderr, "cs_diag(CS_CLEAR) failed\n");
		return 1;
	}

	if (cs_diag(ctx, CS_STATUS, CS_CLIENTMSG_TYPE, CS_UNUSED, &num_msgs) != CS_SUCCEED) {
		fprintf(stderr, "cs_diag(CS_STATUS) failed\n");
		return 1;
	}
	if (num_msgs != 0) {
		fprintf(stderr, "cs_diag(CS_CLEAR) failed there are still %d messages on queue\n", num_msgs);
		return 1;
	}

	if (ct_exit(ctx, CS_UNUSED) != CS_SUCCEED) {
		fprintf(stderr, "ct_exit() failed\n");
	}
	if (cs_ctx_drop(ctx) != CS_SUCCEED) {
		fprintf(stderr, "cx_ctx_drop() failed\n");
	}

	return 0;
}