コード例 #1
0
ファイル: session.c プロジェクト: dmp0x7c5/test-repo
struct obc_session *obc_session_create(const char *source,
						const char *destination,
						const char *service,
						uint8_t channel,
						const char *owner,
						session_callback_t function,
						void *user_data)
{
	DBusConnection *conn;
	struct obc_session *session;
	struct obc_transport *transport;
	struct obc_driver *driver;

	if (destination == NULL)
		return NULL;

	session = session_find(source, destination, service, channel, owner);
	if (session != NULL)
		goto proceed;

	/* FIXME: Do proper transport lookup when the API supports it */
	transport = obc_transport_find("Bluetooth");
	if (transport == NULL)
		return NULL;

	driver = obc_driver_find(service);
	if (driver == NULL)
		return NULL;

	conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
	if (conn == NULL)
		return NULL;

	session = g_try_malloc0(sizeof(*session));
	if (session == NULL)
		return NULL;

	session->refcount = 1;
	session->transport = transport;
	session->driver = driver;
	session->conn = conn;
	session->source = g_strdup(source);
	session->destination = g_strdup(destination);
	session->channel = channel;
	session->queue = g_queue_new();

	if (owner)
		obc_session_set_owner(session, owner, owner_disconnected);

proceed:
	if (session_connect(session, function, user_data) < 0) {
		obc_session_unref(session);
		return NULL;
	}

	DBG("session %p transport %s driver %s", session,
			session->transport->name, session->driver->service);

	return session;
}
コード例 #2
0
ファイル: session.c プロジェクト: KpuBopy4ka/obexd-map
static void adapter_reply(DBusPendingCall *call, void *user_data)
{
	DBusError err;
	DBusMessage *reply;
	struct callback_data *callback = user_data;
	struct obc_session *session = callback->session;
	struct pending_req *req = find_session_request(session, call);

	reply = dbus_pending_call_steal_reply(call);

	session->pending_calls = g_slist_remove(session->pending_calls, req);
	pending_req_finalize(req);

	dbus_error_init(&err);
	if (dbus_set_error_from_message(&err, reply)) {
		error("manager replied with an error: %s, %s",
				err.name, err.message);
		dbus_error_free(&err);

		goto failed;
	}

	if (session_connect(session, callback) < 0)
		goto failed;

	goto proceed;

failed:
	obc_session_unref(session);
	g_free(callback);

proceed:
	dbus_message_unref(reply);
}
コード例 #3
0
static int connect_pppoe_ses(void)
{
    int i,err=-1;
    if( pppoe_server == 1 ){
	srv_init_ses(ses,devnam);
    }else{
	client_init_ses(ses,devnam);
    }
    strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam));

    err= session_connect ( ses );

    if(err < 0){
	poe_fatal(ses,"Failed to negotiate PPPoE connection: %d %m",errno,errno);
    }


    poe_info(ses,"Connecting PPPoE socket: %E %04x %s %p",
	     ses->sp.sa_addr.pppoe.remote,
	     ses->sp.sa_addr.pppoe.sid,
	     ses->sp.sa_addr.pppoe.dev,ses);

    err = connect(ses->fd, (struct sockaddr*)&ses->sp,
		  sizeof(struct sockaddr_pppox));


    if( err < 0 ){
	poe_fatal(ses,"Failed to connect PPPoE socket: %d %m",errno,errno);
	return err;
    }
    /* Once the logging is fixed, print a message here indicating
       connection parameters */

    return ses->fd;
}
コード例 #4
0
ファイル: bluetooth.c プロジェクト: ghent360/bluez
static guint bluetooth_connect(const char *source, const char *destination,
				const char *service, uint16_t port,
				obc_transport_func func, void *user_data)
{
	struct bluetooth_session *session;
	static guint id = 0;

	DBG("src %s dest %s service %s port %u",
				source, destination, service, port);

	if (destination == NULL)
		return 0;

	session = g_try_malloc0(sizeof(*session));
	if (session == NULL)
		return 0;

	session->id = ++id;
	session->func = func;
	session->port = port;
	session->user_data = user_data;

	str2ba(destination, &session->dst);
	str2ba(source, &session->src);

	if (session_connect(session) < 0) {
		g_free(session);
		return 0;
	}

	session->service = g_strdup(service);
	sessions = g_slist_prepend(sessions, session);

	return session->id;
}
コード例 #5
0
void client_socket_utils::session_connect(std::vector<socket_session_ptr>& vSession)
{
	for (int i = 0; i < vSession.size(); ++i)
	{
		session_connect(vSession[i]);
	}
}
コード例 #6
0
ファイル: managesieve.c プロジェクト: stesachse/claws
static gint sieve_session_connect(SieveSession *session)
{
	session->state = SIEVE_CAPABILITIES;
	session->authenticated = FALSE;
	session->tls_init_done = FALSE;
	return session_connect(SESSION(session), session->host,
			session->port);
}
コード例 #7
0
ファイル: session-test.c プロジェクト: hmallat/connman
static void test_session_connect_disconnect_notify(struct test_session *session)
{
	enum test_session_state state = get_session_state(session);
	enum test_session_state next_state = state;
	DBusMessage *msg;

	LOG("state %d session %p %s state %d", state, session,
		session->notify_path, session->info->state);

	switch (state) {
	case TEST_SESSION_STATE_0:
		if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
			next_state = TEST_SESSION_STATE_1;
		if (session->info->state == CONNMAN_SESSION_STATE_CONNECTED) {
			LOG("state was already connected, continuing");
			next_state = TEST_SESSION_STATE_2;
		}
		break;
	case TEST_SESSION_STATE_1:
		if (session->info->state >= CONNMAN_SESSION_STATE_CONNECTED)
			next_state = TEST_SESSION_STATE_2;
		break;
	case TEST_SESSION_STATE_2:
		if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
			next_state = TEST_SESSION_STATE_3;
	default:
		break;
	}

	if (state == next_state)
		return;

	set_session_state(session, next_state);

	LOG("next_state %d", next_state);

	switch (next_state) {
	case TEST_SESSION_STATE_1:
		msg = session_connect(session->connection, session);
		g_assert(msg);
		dbus_message_unref(msg);
		return;
	case TEST_SESSION_STATE_2:
		msg = session_disconnect(session->connection, session);
		g_assert(msg);
		dbus_message_unref(msg);
		return;
	case TEST_SESSION_STATE_3:
		util_session_cleanup(session);
		util_idle_call(session->fix, util_quit_loop,
				util_session_destroy);
		return;
	default:
		return;
	}
}
コード例 #8
0
ファイル: session-test.c プロジェクト: hmallat/connman
static void test_session_policy_notify(struct test_session *session)
{
	enum test_session_state state = get_session_state(session);
	enum test_session_state next_state = state;
	DBusMessage *msg;

	LOG("state %d session %p %s state %d", state, session,
		session->notify_path, session->info->state);

	switch (state) {
	case TEST_SESSION_STATE_0:
		if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
			next_state = TEST_SESSION_STATE_1;
		break;
	case TEST_SESSION_STATE_1:
		if (session->info->state >= CONNMAN_SESSION_STATE_CONNECTED)
			next_state = TEST_SESSION_STATE_2;
		break;
	case TEST_SESSION_STATE_2:
		if (session->info->state == CONNMAN_SESSION_STATE_DISCONNECTED)
			next_state = TEST_SESSION_STATE_3;
	default:
		break;
	}

	if (state == next_state)
		return;

	set_session_state(session, next_state);

	LOG("next_state %d", next_state);

	switch (next_state) {
	case TEST_SESSION_STATE_1:
		policy_allowed_bearers("ethernet");

		msg = session_connect(session->connection, session);
		g_assert(msg);
		dbus_message_unref(msg);
		return;
	case TEST_SESSION_STATE_2:
		policy_allowed_bearers("");
		return;
	case TEST_SESSION_STATE_3:
		policy_remove_file();
		util_session_cleanup(session);
		util_idle_call(session->fix, util_quit_loop,
				util_session_destroy);
		return;
	default:
		return;
	}
}
コード例 #9
0
static void test_session_connect_disconnect_notify(struct test_session *session)
{
	enum test_session_state state = get_session_state(session);
	enum test_session_state next_state = state;
	DBusMessage *msg;

	LOG("state %d session %p %s online %d", state, session,
		session->notify_path, session->info->online);

	switch (state) {
	case TEST_SESSION_STATE_0:
		if (session->info->online == FALSE)
			next_state = TEST_SESSION_STATE_1;
		break;
	case TEST_SESSION_STATE_1:
		if (session->info->online == TRUE)
			next_state = TEST_SESSION_STATE_2;
		break;
	case TEST_SESSION_STATE_2:
		if (session->info->online == FALSE)
			next_state = TEST_SESSION_STATE_3;
	default:
		break;
	}

	if (state == next_state)
		return;

	set_session_state(session, next_state);

	LOG("next_state %d", next_state);

	switch (next_state) {
	case TEST_SESSION_STATE_1:
		msg = session_connect(session->connection, session);
		g_assert(msg != NULL);
		dbus_message_unref(msg);
		return;
	case TEST_SESSION_STATE_2:
		msg = session_disconnect(session->connection, session);
		g_assert(msg != NULL);
		dbus_message_unref(msg);
		return;
	case TEST_SESSION_STATE_3:
		util_session_cleanup(session);
		util_idle_call(session->fix, util_quit_loop,
				util_session_destroy);
		return;
	default:
		return;
	}
}
コード例 #10
0
void session_startup(gint argc, gchar **argv)
{
    gchar *dir;
    ObtPaths *p;

    if (!ob_sm_use) return;

    sm_argc = argc;
    sm_argv = argv;

    p = obt_paths_new();
    dir = g_build_filename(obt_paths_cache_home(p),
                           "openbox", "sessions", NULL);
    obt_paths_unref(p), p = NULL;

    if (!obt_paths_mkdir_path(dir, 0700)) {
        g_message(_("Unable to make directory \"%s\": %s"),
                  dir, g_strerror(errno));
    }

    if (ob_sm_save_file != NULL) {
        if (ob_sm_restore) {
            ob_debug_type(OB_DEBUG_SM, "Loading from session file %s",
                          ob_sm_save_file);
            session_load_file(ob_sm_save_file);
        }
    } else {
        gchar *filename;

        /* this algo is from metacity */
        filename = g_strdup_printf("%u-%u-%u.obs",
                                   (guint)time(NULL),
                                   (guint)getpid(),
                                   g_random_int());
        ob_sm_save_file = g_build_filename(dir, filename, NULL);
        g_free(filename);
    }

    if (session_connect()) {
        session_setup_program();
        session_setup_user();
        session_setup_restart_style(TRUE);
        session_setup_pid();
        session_setup_priority();
        session_setup_clone_command();
    }

    g_free(dir);
}
コード例 #11
0
ファイル: session_test.c プロジェクト: tidatida/lagopus
void
test_session_tcp6(void) {
    lagopus_result_t ret;
    char cbuf[256] = {0};
    char sbuf[256] = {0};
    lagopus_session_t sesc, sess, sesa;
    struct addrunion dst, src;

    ret = session_create(SESSION_TCP6|SESSION_PASSIVE, &sess);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    addrunion_ipv6_set(&src, "::0");
    ret = session_bind(sess, &src, 10023);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    ret = session_create(SESSION_TCP6|SESSION_ACTIVE, &sesc);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    addrunion_ipv6_set(&dst, "::1");
    ret = session_connect(sesc, &dst, 10023, NULL, 0);
    if (ret == 0 || errno == EINPROGRESS)  {
        TEST_ASSERT(true);
    } else {
        TEST_ASSERT(false);
    }

    ret = session_accept(sess, &sesa);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_NOT_NULL(sesa);

    TEST_ASSERT_TRUE(session_is_alive(sess));
    TEST_ASSERT_TRUE(session_is_alive(sesc));
    TEST_ASSERT_TRUE(session_is_alive(sesa));

    snprintf(cbuf, sizeof(cbuf), "hogehoge\n");
    ret = session_write(sesc, cbuf, strlen(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));
    ret = session_read(sesa, sbuf, sizeof(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));

    ret = session_write(sesa, sbuf, strlen(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));
    ret = session_read(sesc, cbuf, sizeof(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));

    session_destroy(sesc);
    session_destroy(sesa);
    session_destroy(sess);
}
コード例 #12
0
/**
	@brief Open a Jabber session for a transport_client.
	@param client Pointer to the transport_client.
	@param username Jabber user name.
	@param password Password for the Jabber logon.
	@param resource Resource name for the Jabber logon.
	@param connect_timeout How many seconds to wait for the connection to open.
	@param auth_type An enum: either AUTH_PLAIN or AUTH_DIGEST (see notes).
	@return 1 if successful, or 0 upon error.

	Besides opening the Jabber session, create a Jabber ID for future use.

	If @a connect_timeout is -1, wait indefinitely for the Jabber server to respond.  If
	@a connect_timeout is zero, don't wait at all.  If @a timeout is positive, wait that
	number of seconds before timing out.  If @a connect_timeout has a negative value other
	than -1, the results are not well defined.

	The value of @a connect_timeout applies to each of two stages in the logon procedure.
	Hence the logon may take up to twice the amount of time indicated.

	If we connect as a Jabber component, we send the password as an SHA1 hash.  Otherwise
	we look at the @a auth_type.  If it's AUTH_PLAIN, we send the password as plaintext; if
	it's AUTH_DIGEST, we send it as a hash.
 */
int client_connect( transport_client* client,
		const char* username, const char* password, const char* resource,
		int connect_timeout, enum TRANSPORT_AUTH_TYPE  auth_type ) {
	if( client == NULL )
		return 0;

	// Create and store a Jabber ID
	if( client->xmpp_id )
		free( client->xmpp_id );
	client->xmpp_id = va_list_to_string( "%s@%s/%s", username, client->host, resource );

	// Open a transport_session
	return session_connect( client->session, username,
			password, resource, connect_timeout, auth_type );
}
コード例 #13
0
ファイル: session-test.c プロジェクト: hmallat/connman
static void test_session_connect(struct test_fix *fix)
{
	struct test_session *session;
	DBusMessage *msg;

	util_session_create(fix, 1);
	session = fix->session;

	session->notify_path = g_strdup("/foo");
	session->notify =  test_session_connect_notify;
	util_session_init(session);

	msg = session_connect(session->connection, session);
	g_assert(msg);
	g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR);

	dbus_message_unref(msg);
}
コード例 #14
0
ファイル: pppoe.c プロジェクト: OPSF/uClinux
static int connect_pppoe_ses(void)
{
    int err=-1;
    if( pppoe_server == 1 ){
	srv_init_ses(ses,devnam);
    }else{
	client_init_ses(ses,devnam);
    }
#if 0
    ses->np=1;  /* jamal debug the discovery portion */
#endif
    strcpy(ppp_devnam, devnam);

    err= session_connect ( ses );

    if(err < 0){
	    if (!kill_link)
		poe_error(ses,"Failed to negotiate PPPoE connection: %d - %m",
				errno,errno);
		return -1;
    }

    poe_info(ses,"Connecting PPPoE socket: %E %04x %s %p",
	     ses->sp.sa_addr.pppoe.remote,
	     ses->sp.sa_addr.pppoe.sid,
	     ses->sp.sa_addr.pppoe.dev,ses);

    err = connect(ses->fd, (struct sockaddr*)&ses->sp,
		  sizeof(struct sockaddr_pppox));


    if( err < 0 ){
	poe_fatal(ses,"Failed to connect PPPoE socket: %d %m",errno,errno);
	return err;
    }
#if 0
    if (ses->np)
     	fatal("discovery complete\n");
#endif
    /* Once the logging is fixed, print a message here indicating
       connection parameters */

    return ses->fd;
}
コード例 #15
0
ファイル: session-test.c プロジェクト: leinomii/connman
static gboolean test_session_connect(gpointer data)
{
	struct test_fix *fix = data;
	struct test_session *session;
	DBusMessage *msg;

	util_session_create(fix, 1);
	session = fix->session;

	session->notify_path = g_strdup("/foo");
	session->notify =  test_session_connect_notify;
	util_session_init(session);

	msg = session_connect(session->connection, session);
	g_assert(msg != NULL);
	g_assert(dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_ERROR);

	dbus_message_unref(msg);

	return FALSE;
}
コード例 #16
0
ファイル: pppoefwd.c プロジェクト: hajuuk/R7000
int main(int argc, char** argv){
    int ret;
    struct session *ses = (struct session *)malloc(sizeof(struct session));

    if(!ses) return -1;

    ret = relay_init_ses(ses,argv[1],argv[2]);
    
    if( ret < 0 ){
	return -1;
    }

    ses->log_to_fd = 1;
    ses->opt_debug=1;
    while(1)
	ret = session_connect(ses);
    
    
    
    return ret;


}
コード例 #17
0
ファイル: bluetooth.c プロジェクト: dmp0x7c5/test-repo
static void adapter_reply(DBusPendingCall *call, void *user_data)
{
	struct bluetooth_session *session = user_data;
	DBusError err;
	DBusMessage *reply;
	GError *gerr = NULL;

	reply = dbus_pending_call_steal_reply(call);

	session->pending_calls = g_slist_remove(session->pending_calls, call);
	finalize_call(call);

	dbus_error_init(&err);
	if (dbus_set_error_from_message(&err, reply)) {
		error("manager replied with an error: %s, %s",
				err.name, err.message);
		dbus_error_free(&err);

		goto failed;
	}

	if (session_connect(session) == 0)
		goto proceed;

failed:
	g_set_error(&gerr, OBC_BT_ERROR, -EINVAL,
					"Unable to request session");
	if (session->func)
		session->func(session->io, gerr, session->user_data);
	g_clear_error(&gerr);

	session_destroy(session);

proceed:
	dbus_message_unref(reply);
}
コード例 #18
0
ファイル: pppoe.c プロジェクト: hrulez/Actiontec-V1000H
static int connect_pppoe_ses(void)
{
    int err=-1;
    int rcvbuf; //brcm
    
    // cwu
#if 0
    if( pppoe_server == 1 ){
	srv_init_ses(ses,devnam);
    }else{
	client_init_ses(ses,devnam);
    }
#endif
    client_init_ses(ses,devnam);
    
#if 0
    ses->np=1;  /* jamal debug the discovery portion */
#endif
    strlcpy(ppp_devnam, devnam, sizeof(ppp_devnam));

	//brcm
    if (disc_sock > 0) {
	    rcvbuf=5000;
        setsockopt(disc_sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf));
    }    
    err= session_connect ( ses );

	/* 
	*  brcm, after pppoe session is up, we don't read disc_sock, 
	*  reduce socket rx buffer to avoid to exhaust all rx buffer 
	*/
    if (disc_sock > 0) {
	    rcvbuf=256;
        setsockopt(disc_sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf));
    }    

    if(err < 0){
	if (!link_up(devnam)) 
	    return 0;
	else if (!get_sock_intf(devnam))
	    return 0;
	else
    	    poe_fatal(ses,"Failed to negotiate PPPoE connection: %d %m",errno,errno);
    }

    // cwu
    /*
    poe_info(ses,"Connecting PPPoE socket: %E %04x %s %p",
	     ses->sp.sa_addr.pppoe.remote,
	     ses->sp.sa_addr.pppoe.sid,
	     ses->sp.sa_addr.pppoe.dev,ses);
    */
    
    err = connect(ses->fd, (struct sockaddr*)&ses->sp,
		  sizeof(struct sockaddr_pppox));


    if( err < 0 ){
	poe_fatal(ses,"Failed to connect PPPoE socket: %d %m",errno,errno);
	return err;
    }
#if 0
    if (ses->np)
     	fatal("discovery complete\n");
#endif
    /* Once the logging is fixed, print a message here indicating
       connection parameters */

    return ses->fd;
}
コード例 #19
0
ファイル: inc.c プロジェクト: mrvdb/claws-mail
static IncState inc_pop3_session_do(IncSession *session)
{
	Pop3Session *pop3_session = POP3_SESSION(session->session);
	IncProgressDialog *inc_dialog = (IncProgressDialog *)session->data;
	gchar *server;
	gchar *account_name;
	gushort port;
	gchar *buf;

	debug_print("getting new messages of account %s...\n",
		    pop3_session->ac_prefs->account_name);
		    
	pop3_session->ac_prefs->last_pop_login_time = time(NULL);

	buf = g_strdup_printf(_("%s: Retrieving new messages"),
			      pop3_session->ac_prefs->recv_server);
	gtk_window_set_title(GTK_WINDOW(inc_dialog->dialog->window), buf);
	g_free(buf);

	server = pop3_session->ac_prefs->recv_server;
	account_name = pop3_session->ac_prefs->account_name;
#ifdef USE_GNUTLS
	port = pop3_session->ac_prefs->set_popport ?
		pop3_session->ac_prefs->popport :
		pop3_session->ac_prefs->ssl_pop == SSL_TUNNEL ? 995 : 110;
	SESSION(pop3_session)->ssl_type = pop3_session->ac_prefs->ssl_pop;
	if (pop3_session->ac_prefs->ssl_pop != SSL_NONE)
		SESSION(pop3_session)->nonblocking =
			pop3_session->ac_prefs->use_nonblocking_ssl;
#else
	if (pop3_session->ac_prefs->ssl_pop != SSL_NONE) {
		if (alertpanel_full(_("Insecure connection"),
			_("This connection is configured to be secured "
			  "using SSL, but SSL is not available in this "
			  "build of Claws Mail. \n\n"
			  "Do you want to continue connecting to this "
			  "server? The communication would not be "
			  "secure."),
			  GTK_STOCK_CANCEL, _("Con_tinue connecting"), 
			  NULL, FALSE, NULL, ALERT_WARNING,
			  G_ALERTDEFAULT) != G_ALERTALTERNATE)
			return INC_CANCEL;
	}
	port = pop3_session->ac_prefs->set_popport ?
		pop3_session->ac_prefs->popport : 110;
#endif

	buf = g_strdup_printf(_("Account '%s': Connecting to POP3 server: %s:%d..."),
				account_name, server, port);
	statuswindow_print_all("%s", buf);
	log_message(LOG_PROTOCOL, "%s\n", buf);

	progress_dialog_set_label(inc_dialog->dialog, buf);
	GTK_EVENTS_FLUSH();
	g_free(buf);

	session_set_timeout(SESSION(pop3_session),
			    prefs_common.io_timeout_secs * 1000);
	
	if (session_connect(SESSION(pop3_session), server, port) < 0) {
		if(!prefs_common.no_recv_err_panel) {
			if((prefs_common.recv_dialog_mode == RECV_DIALOG_ALWAYS) ||
			    ((prefs_common.recv_dialog_mode == RECV_DIALOG_MANUAL) && focus_window)) {
				manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
			}
			alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
					 server, port);
			manage_window_focus_out(inc_dialog->dialog->window, NULL, NULL);
		} else {
			log_error(LOG_PROTOCOL, _("Can't connect to POP3 server: %s:%d\n"),
			    server, port);
		}
		session->inc_state = INC_CONNECT_ERROR;
		statuswindow_pop_all();
		return INC_CONNECT_ERROR;
	}

	while (session_is_running(SESSION(pop3_session)) &&
	       session->inc_state != INC_CANCEL)
		gtk_main_iteration();

	if (session->inc_state == INC_SUCCESS) {
		switch (pop3_session->error_val) {
		case PS_SUCCESS:
			switch (SESSION(pop3_session)->state) {
			case SESSION_ERROR:
				if (pop3_session->state == POP3_READY)
					session->inc_state = INC_CONNECT_ERROR;
				else
					session->inc_state = INC_ERROR;
				break;
			case SESSION_EOF:
				session->inc_state = INC_EOF;
				break;
			case SESSION_TIMEOUT:
				session->inc_state = INC_TIMEOUT;
				break;
			default:
				session->inc_state = INC_SUCCESS;
				break;
			}
			break;
		case PS_AUTHFAIL:
			session->inc_state = INC_AUTH_FAILED;
			break;
		case PS_IOERR:
			session->inc_state = INC_IO_ERROR;
			break;
		case PS_SOCKET:
			session->inc_state = INC_SOCKET_ERROR;
			break;
		case PS_LOCKBUSY:
			session->inc_state = INC_LOCKED;
			break;
		default:
			session->inc_state = INC_ERROR;
			break;
		}
	}

	session_disconnect(SESSION(pop3_session));
	statusbar_pop_all();

	return session->inc_state;
}
コード例 #20
0
ファイル: send_message.c プロジェクト: eworm-de/claws-mail
gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, gboolean keep_session)
{
	Session *session;
	SMTPSession *smtp_session;
	gushort port = 0;
	gchar buf[BUFFSIZE];
	gint ret = 0;
	gboolean was_inited = FALSE;
	MsgInfo *tmp_msginfo = NULL;
	MsgFlags flags = {0, 0};
	long fp_pos = 0;
	gchar spec_from[BUFFSIZE];
	ProxyInfo *proxy_info = NULL;

	cm_return_val_if_fail(ac_prefs != NULL, -1);
	cm_return_val_if_fail(ac_prefs->address != NULL, -1);
	cm_return_val_if_fail(ac_prefs->smtp_server != NULL, -1);
	cm_return_val_if_fail(to_list != NULL, -1);
	cm_return_val_if_fail(fp != NULL, -1);

	/* get the From address used, not necessarily the ac_prefs',
	 * because it's editable. */

	fp_pos = ftell(fp);
	if (fp_pos < 0) {
		perror("ftell");
		return -1;
	}
	tmp_msginfo = procheader_parse_stream(fp, flags, TRUE, FALSE);
	if (fseek(fp, fp_pos, SEEK_SET) < 0) {
		perror("fseek");
		return -1;
	}

	if (tmp_msginfo && tmp_msginfo->extradata && tmp_msginfo->extradata->resent_from) {
		strncpy2(spec_from, tmp_msginfo->extradata->resent_from, BUFFSIZE-1);
		extract_address(spec_from);
	} else if (tmp_msginfo && tmp_msginfo->from) {
		strncpy2(spec_from, tmp_msginfo->from, BUFFSIZE-1);
		extract_address(spec_from);
	} else {
		strncpy2(spec_from, ac_prefs->address, BUFFSIZE-1);
	}
	if (tmp_msginfo) {
		procmsg_msginfo_free(&tmp_msginfo);
	}

	if (!ac_prefs->session) {
		/* we can't reuse a previously initialised session */
		session = smtp_session_new(ac_prefs);
		session->ssl_cert_auto_accept = ac_prefs->ssl_certs_auto_accept;

		smtp_session = SMTP_SESSION(session);

		if (ac_prefs->set_domain && ac_prefs->domain && strlen(ac_prefs->domain)) {
			smtp_session->hostname = g_strdup(ac_prefs->domain);
		} else {
			smtp_session->hostname = NULL;
		}

#ifdef USE_GNUTLS
		port = ac_prefs->set_smtpport ? ac_prefs->smtpport :
			ac_prefs->ssl_smtp == SSL_TUNNEL ? SSMTP_PORT : SMTP_PORT;
		session->ssl_type = ac_prefs->ssl_smtp;
		if (ac_prefs->ssl_smtp != SSL_NONE)
			session->nonblocking = ac_prefs->use_nonblocking_ssl;
		if (ac_prefs->set_gnutls_priority && ac_prefs->gnutls_priority &&
		    strlen(ac_prefs->gnutls_priority))
			session->gnutls_priority = g_strdup(ac_prefs->gnutls_priority);
		session->use_tls_sni = ac_prefs->use_tls_sni;
#else
		if (ac_prefs->ssl_smtp != SSL_NONE) {
			if (alertpanel_full(_("Insecure connection"),
				_("This connection is configured to be secured "
				  "using SSL/TLS, but SSL/TLS is not available "
				  "in this build of Claws Mail. \n\n"
				  "Do you want to continue connecting to this "
				  "server? The communication would not be "
				  "secure."),
				  GTK_STOCK_CANCEL, _("Con_tinue connecting"), NULL,
					ALERTFOCUS_FIRST, FALSE, NULL, ALERT_WARNING) != G_ALERTALTERNATE) {
				session_destroy(session);
				return -1;
			}
		}
		port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT;
#endif

		if (ac_prefs->use_smtp_auth) {
			smtp_session->forced_auth_type = ac_prefs->smtp_auth_type;
			if (ac_prefs->smtp_userid && strlen(ac_prefs->smtp_userid)) {
				smtp_session->user = g_strdup(ac_prefs->smtp_userid);
				if (password_get(smtp_session->user,
							ac_prefs->smtp_server, "smtp", port,
							&(smtp_session->pass))) {
					/* NOP */;
				} else if ((smtp_session->pass =
						passwd_store_get_account(ac_prefs->account_id,
								PWS_ACCOUNT_SEND)) == NULL) {
					smtp_session->pass =
						input_dialog_query_password_keep
							(ac_prefs->smtp_server,
							 smtp_session->user,
							 &(ac_prefs->session_smtp_passwd));
					if (!smtp_session->pass) {
						session_destroy(session);
						return -1;
					}
				}
			} else {
				smtp_session->user = g_strdup(ac_prefs->userid);
				if (password_get(smtp_session->user,
							ac_prefs->smtp_server, "smtp", port,
							&(smtp_session->pass))) {
					/* NOP */;
				} else if ((smtp_session->pass = passwd_store_get_account(
							ac_prefs->account_id, PWS_ACCOUNT_RECV)) == NULL) {
					smtp_session->pass =
						input_dialog_query_password_keep
							(ac_prefs->smtp_server,
							 smtp_session->user,
							 &(ac_prefs->session_smtp_passwd));
					if (!smtp_session->pass) {
						session_destroy(session);
						return -1;
					}
				}
			}
		} else {
			smtp_session->user = NULL;
			smtp_session->pass = NULL;
		}

		send_dialog = send_progress_dialog_create();
		send_dialog->session = session;
		smtp_session->dialog = send_dialog;

		progress_dialog_list_set(send_dialog->dialog, 0, NULL, 
					 ac_prefs->smtp_server, 
					 _("Connecting"));

		if (ac_prefs->pop_before_smtp
		    && (ac_prefs->protocol == A_POP3)
		    && (time(NULL) - ac_prefs->last_pop_login_time) > (60 * ac_prefs->pop_before_smtp_timeout)) {
			g_snprintf(buf, sizeof(buf), _("Doing POP before SMTP..."));
			log_message(LOG_PROTOCOL, "%s\n", buf);
			progress_dialog_set_label(send_dialog->dialog, buf);
			progress_dialog_list_set_status(send_dialog->dialog, 0, _("POP before SMTP"));
			GTK_EVENTS_FLUSH();
			inc_pop_before_smtp(ac_prefs);
		}

		g_snprintf(buf, sizeof(buf), _("Account '%s': Connecting to SMTP server: %s:%d..."),
				ac_prefs->account_name, ac_prefs->smtp_server, port);
		progress_dialog_set_label(send_dialog->dialog, buf);
		log_message(LOG_PROTOCOL, "%s\n", buf);

		session_set_recv_message_notify(session, send_recv_message, send_dialog);
		session_set_send_data_progressive_notify
			(session, send_send_data_progressive, send_dialog);
		session_set_send_data_notify(session, send_send_data_finished, send_dialog);

	} else {
		/* everything is ready to start at MAIL FROM:, just
		 * reinit useful variables. 
		 */
		session = SESSION(ac_prefs->session);
		ac_prefs->session = NULL;
		smtp_session = SMTP_SESSION(session);
		smtp_session->state = SMTP_HELO;
		send_dialog = (SendProgressDialog *)smtp_session->dialog;
		was_inited = TRUE;
	}

	/* This has to be initialised for every mail sent */
	smtp_session->from = g_strdup(spec_from);
	smtp_session->to_list = to_list;
	smtp_session->cur_to = to_list;
	smtp_session->send_data = (guchar *)get_outgoing_rfc2822_str(fp);
	smtp_session->send_data_len = strlen((gchar *)smtp_session->send_data);

	if (ac_prefs->use_proxy && ac_prefs->use_proxy_for_send) {
		if (ac_prefs->use_default_proxy) {
			proxy_info = (ProxyInfo *)&(prefs_common.proxy_info);
			if (proxy_info->use_proxy_auth)
				proxy_info->proxy_pass = passwd_store_get(PWS_CORE, PWS_CORE_PROXY,
						PWS_CORE_PROXY_PASS);
		} else {
			proxy_info = (ProxyInfo *)&(ac_prefs->proxy_info);
			if (proxy_info->use_proxy_auth)
				proxy_info->proxy_pass = passwd_store_get_account(ac_prefs->account_id,
						PWS_ACCOUNT_PROXY_PASS);
		}
	}
	SESSION(smtp_session)->proxy_info = proxy_info;

	session_set_timeout(session,
			    prefs_common.io_timeout_secs * 1000);
	/* connect if necessary */
	if (!was_inited && session_connect(session, ac_prefs->smtp_server,
				port) < 0) {
		session_destroy(session);
		send_progress_dialog_destroy(send_dialog);
		ac_prefs->session = NULL;
		return -1;
	}

	debug_print("send_message_smtp(): begin event loop\n");

	if (was_inited) {
		/* as the server is quiet, start sending ourselves */
		smtp_from(smtp_session);
	}

	while (session_is_running(session) && send_dialog->cancelled == FALSE
		&& SMTP_SESSION(session)->state != SMTP_MAIL_SENT_OK)
		gtk_main_iteration();

	if (SMTP_SESSION(session)->error_val == SM_AUTHFAIL) {
		if (ac_prefs->session_smtp_passwd) {
			g_free(ac_prefs->session_smtp_passwd);
			ac_prefs->session_smtp_passwd = NULL;
		}
		ret = -1;
	} else if (SMTP_SESSION(session)->state == SMTP_MAIL_SENT_OK) {
		log_message(LOG_PROTOCOL, "%s\n", _("Mail sent successfully."));
		ret = 0;
	} else if (session->state == SESSION_EOF &&
		   SMTP_SESSION(session)->state == SMTP_QUIT) {
		/* consider EOF right after QUIT successful */
		log_warning(LOG_PROTOCOL, "%s\n", _("Connection closed by the remote host."));
		ret = 0;
	} else if (session->state == SESSION_ERROR ||
		   session->state == SESSION_EOF ||
		   session->state == SESSION_TIMEOUT ||
		   SMTP_SESSION(session)->state == SMTP_ERROR ||
		   SMTP_SESSION(session)->error_val != SM_OK)
		ret = -1;
	else if (send_dialog->cancelled == TRUE)
		ret = -1;

	if (ret == -1) {
		manage_window_focus_in(send_dialog->dialog->window, NULL, NULL);
		send_put_error(session);
		manage_window_focus_out(send_dialog->dialog->window, NULL, NULL);
	}

	/* if we should close the connection, let's do it.
	 * Close it in case of error, too, as it helps reinitializing things
	 * easier.
	 */
	if (!keep_session || ret != 0) {
		if (session_is_connected(session))
			smtp_quit(smtp_session);
		while (session_is_connected(session) && !send_dialog->cancelled)
			gtk_main_iteration();
		session_destroy(session);
		ac_prefs->session = NULL;
		send_progress_dialog_destroy(send_dialog);
	} else {
		g_free(smtp_session->from);
		g_free(smtp_session->send_data);
		g_free(smtp_session->error_msg);
	}
	if (keep_session && ret == 0 && ac_prefs->session == NULL)
		ac_prefs->session = SMTP_SESSION(session);


	statusbar_pop_all();
	statusbar_verbosity_set(FALSE);
	return ret;
}
コード例 #21
0
ファイル: session_test.c プロジェクト: tidatida/lagopus
void
test_session_tcp(void) {
    lagopus_result_t ret;
    char cbuf[256] = {0};
    char sbuf[256] = {0};
    bool b;
    lagopus_session_t sesc, sess, sesa, sesp[3];
    struct addrunion dst, src;

    ret = session_create(SESSION_TCP|SESSION_PASSIVE, &sess);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    addrunion_ipv4_set(&src, "0.0.0.0");
    ret = session_bind(sess, &src, 10022);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    ret = session_create(SESSION_TCP|SESSION_ACTIVE, &sesc);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    addrunion_ipv4_set(&dst, "127.0.0.1");
    ret = session_connect(sesc, &dst, 10022, NULL, 0);
    if (ret == 0 || errno == EINPROGRESS)  {
        TEST_ASSERT(true);
    } else {
        TEST_ASSERT(false);
    }

    session_write_event_set(sesc);
    session_read_event_set(sess);
    sesp[0] = sesc;
    sesp[1] = sess;
    ret = session_poll(sesp, 2, 1);
    TEST_ASSERT_EQUAL(2, ret);

    ret = session_is_writable(sesc, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_TRUE(b);

    ret = session_is_readable(sess, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_TRUE(b);

    ret = session_accept(sess, &sesa);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_NOT_NULL(sesa);

    TEST_ASSERT_TRUE(session_is_alive(sess));
    TEST_ASSERT_TRUE(session_is_alive(sesc));
    TEST_ASSERT_TRUE(session_is_alive(sesa));

    session_write_event_set(sesc);
    session_read_event_set(sess);
    session_read_event_set(sesa);
    sesp[0] = sesc;
    sesp[1] = sess;
    sesp[2] = sesa;
    ret = session_poll(sesp, 3, 1);
    TEST_ASSERT_EQUAL(1, ret);

    ret = session_is_writable(sesc, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_TRUE(b);

    ret = session_is_readable(sess, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_FALSE(b);

    ret = session_is_readable(sesa, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_FALSE(b);

    snprintf(cbuf, sizeof(cbuf), "hogehoge\n");
    ret = session_write(sesc, cbuf, strlen(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));

    session_read_event_set(sesa);
    sesp[0] = sesa;
    ret = session_poll(sesp, 1, 1);
    TEST_ASSERT_EQUAL(1, ret);

    ret = session_is_readable(sesa, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_TRUE(b);

    ret = session_read(sesa, sbuf, sizeof(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));
    ret = session_write(sesa, sbuf, strlen(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));
    ret = session_read(sesc, cbuf, sizeof(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));

    session_close(sesc);
    TEST_ASSERT_FALSE(session_is_alive(sesc));

    session_close(sesa);
    TEST_ASSERT_FALSE(session_is_alive(sesa));

    session_close(sess);
    TEST_ASSERT_FALSE(session_is_alive(sesa));

    session_write_event_set(sesc);
    session_read_event_set(sess);
    session_read_event_set(sesa);
    sesp[0] = sesc;
    sesp[1] = sess;
    sesp[2] = sesa;
    ret = session_poll(sesp, 3, 1);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_TIMEDOUT, ret);

    ret = session_is_writable(sesc, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_FALSE(b);

    ret = session_is_readable(sess, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_FALSE(b);

    ret = session_is_readable(sesa, &b);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_FALSE(b);

    session_destroy(sesc);
    session_destroy(sesa);
    session_destroy(sess);
}
コード例 #22
0
ファイル: session_test.c プロジェクト: tidatida/lagopus
void
test_session_fgets(void) {
    ssize_t ret;
    char *c;
#if 0
    char cbuf[256] = {0};
#endif
    char sbuf[256] = {0};
    lagopus_session_t sesc, sess, sesa, sesp[1];
    struct addrunion dst, src;

    ret = session_create(SESSION_TCP|SESSION_PASSIVE, &sess);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    addrunion_ipv4_set(&src, "0.0.0.0");
    ret = session_bind(sess, &src, 10022);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    ret = session_create(SESSION_TCP|SESSION_ACTIVE, &sesc);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    addrunion_ipv4_set(&dst, "127.0.0.1");
    ret = session_connect(sesc, &dst, 10022, NULL, 0);
    if (ret == 0 || errno == EINPROGRESS)  {
        TEST_ASSERT(true);
    } else {
        TEST_ASSERT(false);
    }

    ret = session_accept(sess, &sesa);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_NOT_NULL(sesa);

    TEST_ASSERT_TRUE(session_is_alive(sess));
    TEST_ASSERT_TRUE(session_is_alive(sesc));
    TEST_ASSERT_TRUE(session_is_alive(sesa));

    ret = session_printf(sesc, "%s", "hogehoge\n\nhoge");
    TEST_ASSERT_EQUAL(ret, strlen("hogehoge\n\nhoge"));

    session_read_event_set(sesa);
    sesp[0] = sesa;
    ret = session_poll(sesp, 1, 1);
    TEST_ASSERT_EQUAL(ret, 1);

    c = session_fgets(sbuf, 5, sesa);
    fprintf(stderr, "1.%s\n", sbuf);
    TEST_ASSERT_NOT_NULL(c);
    TEST_ASSERT_EQUAL(0, strncmp(sbuf, "hoge", 5));

    c = session_fgets(sbuf, 10, sesa);
    fprintf(stderr, "2.%s\n", sbuf);
    TEST_ASSERT_NOT_NULL(c);
    TEST_ASSERT_EQUAL(0, strncmp(sbuf, "hoge\n", 5));

    c = session_fgets(sbuf, 10, sesa);
    fprintf(stderr, "3.%s\n", sbuf);
    TEST_ASSERT_NOT_NULL(c);
    TEST_ASSERT_EQUAL(0, strncmp(sbuf, "\n", 1));

    c = session_fgets(sbuf, 5, sesa);
    fprintf(stderr, "4.%s\n", sbuf);
    TEST_ASSERT_NOT_NULL(c);
    TEST_ASSERT_EQUAL(0, strncmp(sbuf, "hoge", 5));

#if 0
    do {
        fprintf(stderr, "out:%s", sbuf);
        fgets(cbuf, sizeof(cbuf), stdin);
        fprintf(stderr, "in :%s", cbuf);
        session_write(sesc, cbuf, strlen(cbuf));
    } while (session_fgets(sbuf, sizeof(sbuf), sesa) != NULL);
#endif

    session_close(sesc);
    TEST_ASSERT_FALSE(session_is_alive(sesc));
    session_close(sesa);
    TEST_ASSERT_FALSE(session_is_alive(sesa));
    session_close(sess);
    TEST_ASSERT_FALSE(session_is_alive(sesa));

    session_destroy(sesc);
    session_destroy(sesa);
    session_destroy(sess);
}
コード例 #23
0
ファイル: session_test.c プロジェクト: tidatida/lagopus
void
test_session_tls(void) {
#if 0 /* this test code is not work, use openssl s_server/s_client commands for tls session tests. */
    lagopus_result_t ret;
    char cbuf[256] = {0};
    char sbuf[256] = {0};
    lagopus_session_t sesc, sess, sesa;
    struct addrunion src, dst;

    session_tls_set_ca_dir("ca");
    session_tls_set_server_cert("./server1.pem");
    session_tls_set_server_key("./server1_key_nopass.pem");
    session_tls_set_client_key("./client1_key_nopass.pem");

    ret = session_create(SESSION_TCP|SESSION_PASSIVE|SESSION_TLS, &sess);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    addrunion_ipv4_set(&src, "0.0.0.0");
    ret = session_bind(sess, &src, 10024);

    addrunion_ipv4_set(&dst, "127.0.0.1");
    ret = session_create(SESSION_TCP|SESSION_TLS|SESSION_ACTIVE, &sesc);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);

    ret = session_connect(sesc, &dst, 10024, &dst, 0);
    if (ret == 0 || errno == EINPROGRESS)  {
        TEST_ASSERT(true);
    } else {
        TEST_ASSERT(false);
    }

    ret = session_accept(sess, &sesa);
    TEST_ASSERT_EQUAL(LAGOPUS_RESULT_OK, ret);
    TEST_ASSERT_NOT_NULL(sesa);

    TEST_ASSERT_TRUE(session_is_alive(sess));
    TEST_ASSERT_TRUE(session_is_alive(sesa));

    ret = session_read(sesa, sbuf, sizeof(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));

    ret = session_write(sesa, sbuf, strlen(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));

    TEST_ASSERT_TRUE(session_is_alive(sesc));

    snprintf(cbuf, sizeof(cbuf), "hogehoge\n");
    ret = session_write(sesc, cbuf, strlen(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));
    ret = session_read(sesa, sbuf, sizeof(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));

    ret = session_write(sesa, sbuf, strlen(sbuf));
    TEST_ASSERT_EQUAL(ret, strlen(sbuf));
    ret = session_read(sesc, cbuf, sizeof(cbuf));
    TEST_ASSERT_EQUAL(ret, strlen(cbuf));

    session_destroy(sesc);
    session_destroy(sesa);
    session_destroy(sess);
#endif
}
コード例 #24
0
ファイル: session-test.c プロジェクト: leinomii/connman
static void test_session_connect_free_ride_notify(struct test_session *session)
{
	struct test_session *session0 = get_session(session, 0);
	struct test_session *session1 = get_session(session, 1);
	enum test_session_state state = get_session_state(session);
	enum test_session_state next_state = state;
	DBusMessage *msg;

	LOG("state %d session %p %s state %d", state, session,
		session->notify_path, session->info->state);

	switch (state) {
	case TEST_SESSION_STATE_0:
		if (session0->info->state == CONNMAN_SESSION_STATE_DISCONNECTED
				&& session1->info->state ==
					CONNMAN_SESSION_STATE_DISCONNECTED) {
			next_state = TEST_SESSION_STATE_1;
		}

		break;
	case TEST_SESSION_STATE_1:
		if (session0->info->state >= CONNMAN_SESSION_STATE_CONNECTED &&
				session1->info->state >=
					CONNMAN_SESSION_STATE_CONNECTED) {
			next_state = TEST_SESSION_STATE_2;
		}

		break;
	case TEST_SESSION_STATE_2:
		if (session0->info->state == CONNMAN_SESSION_STATE_DISCONNECTED
				&& session1->info->state ==
					CONNMAN_SESSION_STATE_DISCONNECTED) {
			next_state = TEST_SESSION_STATE_3;
		}

		break;
	case TEST_SESSION_STATE_3:

		return;
	}

	if (state == next_state)
		return;

	set_session_state(session, next_state);

	LOG("next_state %d", next_state);

	switch (next_state) {
	case TEST_SESSION_STATE_0:

		return;
	case TEST_SESSION_STATE_1:
		msg = session_connect(session0->connection, session0);
		g_assert(msg != NULL);
		dbus_message_unref(msg);

		return;

	case TEST_SESSION_STATE_2:
		msg = session_disconnect(session0->connection, session0);
		g_assert(msg != NULL);
		dbus_message_unref(msg);

		return;
	case TEST_SESSION_STATE_3:
		util_session_cleanup(session0);
		util_session_cleanup(session1);

		util_idle_call(session0->fix, util_quit_loop,
				util_session_destroy);

		return;
	}
}
コード例 #25
0
dk_session_t *
smtp_connect (char * host1, caddr_t * err_ret, caddr_t sender, caddr_t recipient, caddr_t msg_body)
{
  volatile int rc, inx, len, addr, at;
  dk_session_t * volatile ses = dk_session_allocate (SESCLASS_TCPIP);
  caddr_t cmd = NULL;
  char resp [1024];
  char tmp [1024], *ptmp;
  char c;
  caddr_t volatile hf = NULL, host;

  if (!strchr (host1, ':'))
    {
      host = dk_alloc_box (strlen (host1) + 4, DV_SHORT_STRING);
      strcpy_box_ck (host, host1);
      strcat_box_ck (host, ":25");
    }
  else
    {
      host = box_dv_short_string (host1);
    }

  rc = session_set_address (ses->dks_session, host);
  dk_free_box (host); host = NULL;

  if (SER_SUCC != rc)
    {
      PrpcSessionFree (ses);
      *err_ret = srv_make_new_error ("2E000", "SM002", "Cannot resolve host in smtp_send");
      return NULL;
    }
  rc = session_connect (ses->dks_session);
  if (SER_SUCC != rc)
    {
      if (rc != SER_NOREC)
	session_disconnect (ses->dks_session);
      PrpcSessionFree (ses);
      *err_ret = srv_make_new_error ("08001", "SM003", "Cannot connect in smtp_send");
      return NULL;
    }


  cmd = dk_alloc_box (MAX (MAX (box_length(sender), box_length(recipient)), 1000) + 24, DV_LONG_STRING);

  /* get initial line */
  IS_OK_GO (ses, resp, rc, RESP_OK)
  /* send HELO */
  if (gethostname (tmp, sizeof (tmp)))
    strcpy_ck (tmp, "localhost");
  snprintf (cmd, box_length (cmd), "HELO %s\r\n", tmp);
  /*WRITE_CMD (ses, rc, "HELO virtuoso.mail\r\n");*/
  WRITE_CMD (ses, rc, cmd);
  IS_OK_GO (ses, resp, rc, RESP_OK)

  /* send SENDER */
  len = box_length (sender);
  ptmp = tmp;
  addr = -1;
  at = 0;
  for (inx = 0; inx < len; inx++)
    {
      c = sender [inx];
      if (c == '<')
	addr = 1;
      else if (c == '>' && addr == 1)
	addr = 2;
      else if (c == '>' && addr == -1)
	{
	  strcpy_ck (resp, "Unbalanced <...> in sender e-mail address.");
	  goto error_end;
	}
      else if (c == '@')
	at = 1;
      if (((ptmp - tmp) < sizeof(tmp)) && (addr == 1 || addr == 2))
	*ptmp++ = c;
      else if ((ptmp - tmp) >= sizeof(tmp))
	{
	  strcpy_ck (resp, "Sender\'s e-mail address is too long.");
	  goto error_end;
	}

      if (addr == 2)
	{
	  *ptmp = 0;
	  snprintf (cmd, box_length (cmd), "MAIL FROM: %s\r\n", tmp);
	  WRITE_CMD (ses, rc, cmd);
	  IS_OK_GO (ses, resp, rc, RESP_OK)
	  break;
	}
    }