bool CMediaSession::initSGSClient() { LOGI("CMediaSession::initSGSClient(), begin"); mContext = sgs_ctx_create_ex(mHost.c_str(), mPort, (void *)this, register_fd_cb, unregister_fd_cb); if (!mContext) { LOGE("CMediaSession::initSGSClient(), failed to sgs_ctx_create"); return false; } sgs_ctx_set_channel_joined_cb(mContext, channel_joined_cb); sgs_ctx_set_channel_left_cb(mContext, channel_left_cb); sgs_ctx_set_channel_recv_msg_cb(mContext, channel_recv_msg_cb); sgs_ctx_set_disconnected_cb(mContext, disconnected_cb); sgs_ctx_set_logged_in_cb(mContext, logged_in_cb); sgs_ctx_set_login_failed_cb(mContext, login_failed_cb); sgs_ctx_set_reconnected_cb(mContext, reconnected_cb); sgs_ctx_set_recv_msg_cb(mContext, recv_msg_cb); mConnection = sgs_connection_create(mContext); if (!mConnection) { LOGE("CMediaSession::initSGSClient(), failed to sgs_connection_create"); return false; } int ret = sgs_connection_login(mConnection, mName.c_str(), mPassword.c_str()); if (ret != 0) { LOGE("CMediaSession::initSGSClient(), failed to sgs_connection_login"); return false; } return true; }
int testLogin(sgs_connection *connection) { sgs_connection_login(connection, "kickme", "password1"); waitForInput(connection); if (loginFailFail == 1){ printf("Log in failure test failed\n"); } else { printf("Log in failure test passed\n"); } sgs_connection_login(connection, "discme", "password2"); waitForInput(connection); if (loginDisconnectFail == 1){ printf("Log in disconnect test failed\n"); } else { printf("Log in disconnect test passed\n"); } if (loginFailFail || loginDisconnectFail){ return 1; } else { return 0; } }
int main(int argc, char** argv) { sgs_context *context; sgs_connection *connection; sgs_connection *session; /* Begin by initializing the read sets for reading, * writing, and exceptions; these sets are all sets * of file descriptors */ FD_ZERO(&g_master_readset); FD_ZERO(&g_master_writeset); FD_ZERO(&g_master_exceptset); /* Now, initialize all of the flags that will be * used to keep track of which tests pass and which * tests fail */ loginFailFail = loginDisconnectFail = loginFail = 1; channelJoinFail = channelLeaveFail = channelMessageFail = 1; sessionMessageFail = 1; /* Get any command line argumentss, and * set the appropriate (global) variables. Currently, * the command line can only specify the host and port * of the server, and ask for the usage message * to be printed */ g_hostname = DEFAULT_HOST; g_port = DEFAULT_PORT; getCommandArgs(argc, argv); /* Create a context object, and load it up with the right set * of callbacks. The register_fd and unregister_fd callbacks * are loaded as part of the create call for historical purposes */ context = sgs_ctx_create(g_hostname, g_port, register_fd_cb, unregister_fd_cb); if (context == NULL) { printf("error in context create\n"); exit(1); } loadContext(context); /*Now, create a connection to the server; if this doesn't work things * are messed up enough to require simply printing an error message * and getting out */ connection = sgs_connection_create(context); if (connection == NULL){ printf ("error in creating a connection to the server\n"); exit(1); } if (testLogin(connection) != 0) { printf ("Failed at least one login test\n"); exit(1); } sgs_connection_login(connection, loginName, loginName); waitForInput(connection); return(printResults()); }