Beispiel #1
0
static void jabber_logout( struct im_connection *ic )
{
	struct jabber_data *jd = ic->proto_data;
	
	while( jd->filetransfers )
		imcb_file_canceled( ic, ( ( struct jabber_transfer *) jd->filetransfers->data )->ft, "Logging out" );

	while( jd->streamhosts )
	{
		jabber_streamhost_t *sh = jd->streamhosts->data;
		jd->streamhosts = g_slist_remove( jd->streamhosts, sh );
		g_free( sh->jid );
		g_free( sh->host );
		g_free( sh );
	}

	if( jd->fd >= 0 )
		jabber_end_stream( ic );
	
	while( ic->groupchats )
		jabber_chat_free( ic->groupchats->data );
	
	if( jd->r_inpa >= 0 )
		b_event_remove( jd->r_inpa );
	if( jd->w_inpa >= 0 )
		b_event_remove( jd->w_inpa );
	
	if( jd->ssl )
		ssl_disconnect( jd->ssl );
	if( jd->fd >= 0 )
		closesocket( jd->fd );
	
	if( jd->tx_len )
		g_free( jd->txq );
	
	if( jd->node_cache )
		g_hash_table_destroy( jd->node_cache );
	
	jabber_buddy_remove_all( ic );
	
	xt_free( jd->xt );
	
	g_free( jd->oauth2_access_token );
	g_free( jd->away_message );
	g_free( jd->username );
	g_free( jd->me );
	g_free( jd );
	
	jabber_connections = g_slist_remove( jabber_connections, ic );
}
Beispiel #2
0
/* immed=1 makes this function pretty much equal to irc_free(), except that
   this one will "log". In case the connection is already broken and we
   shouldn't try to write to it. */
void irc_abort(irc_t *irc, int immed, char *format, ...)
{
	char *reason = NULL;

	if (format != NULL) {
		va_list params;

		va_start(params, format);
		reason = g_strdup_vprintf(format, params);
		va_end(params);
	}

	if (reason) {
		irc_write(irc, "ERROR :Closing link: %s", reason);
	}

	ipc_to_master_str("OPERMSG :Client exiting: %s@%s [%s]\r\n",
	                  irc->user->nick ? irc->user->nick : "(NONE)",
	                  irc->user->host, reason ? : "");

	g_free(reason);

	irc_flush(irc);
	if (immed) {
		irc_free(irc);
	} else {
		b_event_remove(irc->ping_source_id);
		irc->ping_source_id = b_timeout_add(1, (b_event_handler) irc_free, irc);
	}
}
Beispiel #3
0
static gboolean http_canread(gpointer data, gint source, b_input_condition cond)
{
	int nlc = 0;
	int pos = 0;
	struct PHB *phb = data;
	char inputline[8192];

	b_event_remove(phb->inpa);

	while ((pos < sizeof(inputline) - 1) && (nlc != 2) && (read(source, &inputline[pos++], 1) == 1)) {
		if (inputline[pos - 1] == '\n') {
			nlc++;
		} else if (inputline[pos - 1] != '\r') {
			nlc = 0;
		}
	}
	inputline[pos] = '\0';

	if ((memcmp(HTTP_GOODSTRING, inputline, strlen(HTTP_GOODSTRING)) == 0) ||
	    (memcmp(HTTP_GOODSTRING2, inputline, strlen(HTTP_GOODSTRING2)) == 0)) {
		phb->func(phb->data, source, B_EV_IO_READ);
		return phb_free(phb, TRUE);
	}

	return phb_free(phb, FALSE);
}
Beispiel #4
0
void ipc_child_disable()
{
	b_event_remove( global.listen_watch_source_id );
	close( global.listen_socket );
	
	global.listen_socket = -1;
}
Beispiel #5
0
void ipc_master_free_one( struct bitlbee_child *c )
{
	GSList *l;
	
	b_event_remove( c->ipc_inpa );
	closesocket( c->ipc_fd );
	
	if( c->to_fd != -1 )
		close( c->to_fd );
	
	g_free( c->host );
	g_free( c->nick );
	g_free( c->realname );
	g_free( c->password );
	g_free( c );
	
	child_list = g_slist_remove( child_list, c );
	
	/* Also, if any child has a reference to this one, remove it. */
	for( l = child_list; l; l = l->next )
	{
		struct bitlbee_child *oc = l->data;
		
		if( oc->to_child == c )
			ipc_master_takeover_fail( oc, FALSE );
	}
}
Beispiel #6
0
/* This one is actually pretty simple... Might get more calls if we can't write 
   the whole request at once. */
static gboolean http_connected( gpointer data, int source, b_input_condition cond )
{
	struct http_request *req = data;
	int st;
	
	if( source < 0 )
		goto error;
	
	if( req->inpa > 0 )
		b_event_remove( req->inpa );
	
	sock_make_nonblocking( req->fd );
	
	if( req->ssl )
	{
		st = ssl_write( req->ssl, req->request + req->bytes_written,
		                req->request_length - req->bytes_written );
		if( st < 0 )
		{
			if( ssl_errno != SSL_AGAIN )
			{
				ssl_disconnect( req->ssl );
				goto error;
			}
		}
	}
	else
	{
		st = write( source, req->request + req->bytes_written,
		                    req->request_length - req->bytes_written );
		if( st < 0 )
		{
			if( !sockerr_again() )
			{
				closesocket( req->fd );
				goto error;
			}
		}
	}
	
	if( st > 0 )
		req->bytes_written += st;
	
	if( req->bytes_written < req->request_length )
		req->inpa = b_input_add( source,
		                         req->ssl ? ssl_getdirection( req->ssl ) : B_EV_IO_WRITE,
	        	                 http_connected, req );
	else
		req->inpa = b_input_add( source, B_EV_IO_READ, http_incoming_data, req );
	
	return FALSE;
	
error:
	if( req->status_string == NULL )
		req->status_string = g_strdup( "Error while writing HTTP request" );
	
	req->func( req );
	http_free( req );
	return FALSE;
}
Beispiel #7
0
/**
 * Logout method. Just free the twitter_data.
 */
static void twitter_logout(struct im_connection *ic)
{
	struct twitter_data *td = ic->proto_data;

	// Set the status to logged out.
	ic->flags &= ~OPT_LOGGED_IN;

	// Remove the main_loop function from the function queue.
	b_event_remove(td->main_loop_id);

	if (td->timeline_gc)
		imcb_chat_free(td->timeline_gc);

	if (td) {
		http_close(td->stream);
		oauth_info_free(td->oauth_info);
		g_free(td->user);
		g_free(td->prefix);
		g_free(td->url_host);
		g_free(td->url_path);
		g_free(td->log);
		g_free(td);
	}

	twitter_connections = g_slist_remove(twitter_connections, ic);
}
Beispiel #8
0
static gboolean s5_canread_again(gpointer data, gint source, b_input_condition cond)
{
	unsigned char buf[512];
	struct PHB *phb = data;

	b_event_remove(phb->inpa);

	if (read(source, buf, 10) < 10) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}
	if ((buf[0] != 0x05) || (buf[1] != 0x00)) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}

	phb->func(phb->data, source, GAIM_INPUT_READ);
	g_free(phb->host);
	g_free(phb);
	
	return FALSE;
}
Beispiel #9
0
static gboolean http_canread(gpointer data, gint source, b_input_condition cond)
{
	int nlc = 0;
	int pos = 0;
	struct PHB *phb = data;
	char inputline[8192];

	b_event_remove(phb->inpa);

	while ((pos < sizeof(inputline)-1) && (nlc != 2) && (read(source, &inputline[pos++], 1) == 1)) {
		if (inputline[pos - 1] == '\n')
			nlc++;
		else if (inputline[pos - 1] != '\r')
			nlc = 0;
	}
	inputline[pos] = '\0';

	if ((memcmp(HTTP_GOODSTRING, inputline, strlen(HTTP_GOODSTRING)) == 0) ||
	    (memcmp(HTTP_GOODSTRING2, inputline, strlen(HTTP_GOODSTRING2)) == 0)) {
		phb->func(phb->data, source, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}

	close(source);
	phb->func(phb->data, -1, GAIM_INPUT_READ);
	g_free(phb->host);
	g_free(phb);
	
	return FALSE;
}
Beispiel #10
0
static gboolean s5_canread(gpointer data, gint source, b_input_condition cond)
{
	unsigned char buf[512];
	struct PHB *phb = data;

	b_event_remove(phb->inpa);

	if (read(source, buf, 2) < 2) {
		return phb_free(phb, FALSE);
	}

	if ((buf[0] != 0x05) || (buf[1] == 0xff)) {
		return phb_free(phb, FALSE);
	}

	if (buf[1] == 0x02) {
		unsigned int i = strlen(proxyuser), j = strlen(proxypass);
		buf[0] = 0x01;  /* version 1 */
		buf[1] = i;
		memcpy(buf + 2, proxyuser, i);
		buf[2 + i] = j;
		memcpy(buf + 2 + i + 1, proxypass, j);
		if (write(source, buf, 3 + i + j) < 3 + i + j) {
			return phb_free(phb, FALSE);
		}

		phb->inpa = b_input_add(source, B_EV_IO_READ, s5_readauth, phb);
	} else {
		s5_sendconnect(phb, source);
	}

	return FALSE;
}
Beispiel #11
0
static gboolean s5_readauth(gpointer data, gint source, b_input_condition cond)
{
	unsigned char buf[512];
	struct PHB *phb = data;

	b_event_remove(phb->inpa);

	if (read(source, buf, 2) < 2) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}

	if ((buf[0] != 0x01) || (buf[1] != 0x00)) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}

	s5_sendconnect(phb, source);
	
	return FALSE;
}
Beispiel #12
0
/**
 * Closes the underlying #http_request.
 *
 * @param callback TRUE to execute the callback, otherwise FALSE.
 *
 * @param req The #SteamHttpReq.
 **/
static void steam_http_req_close(SteamHttpReq *req, gboolean callback)
{
    g_return_if_fail(req != NULL);

    b_event_remove(req->toid);

    if ((req->err == NULL) && (req->scode == 0)) {
        g_set_error(&req->err, STEAM_HTTP_ERROR, STEAM_HTTP_ERROR_CLOSED,
                    "Request closed");
    }

    if (callback && (req->func != NULL))
        req->func(req, req->data);

    if (req->request != NULL) {
        /* Prevent more than one call to request->func() */
        req->request->func = steam_http_req_close_nuller;
        req->request->data = NULL;

        if (!(req->request->flags & STEAM_HTTP_CLIENT_FREED))
            http_close(req->request);
    }

    req->status    = NULL;
    req->scode     = 0;
    req->header    = NULL;
    req->body      = NULL;
    req->body_size = 0;
    req->toid      = 0;
    req->request   = NULL;
}
Beispiel #13
0
static gboolean gaim_io_connected(gpointer data, gint source, b_input_condition cond)
{
	struct PHB *phb = data;
	socklen_t len;
	int error = ETIMEDOUT;
	len = sizeof(error);
	
	if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0 || error) {
		if ((phb->gai_cur = phb->gai_cur->ai_next)) {
			int new_fd;
			b_event_remove(phb->inpa);
			if ((new_fd = proxy_connect_none(NULL, 0, phb))) {
				b_event_remove(phb->inpa);
				closesocket(source);
				dup2(new_fd, source);
				closesocket(new_fd);
				phb->inpa = b_input_add(source, B_EV_IO_WRITE, gaim_io_connected, phb);
				return FALSE;
			}
		}
		freeaddrinfo(phb->gai);
		closesocket(source);
		b_event_remove(phb->inpa);
		phb->inpa = 0;
		if( phb->proxy_func )
			phb->proxy_func(phb->proxy_data, -1, B_EV_IO_READ);
		else {
			phb->func(phb->data, -1, B_EV_IO_READ);
			g_free(phb);
		}
		return FALSE;
	}
	freeaddrinfo(phb->gai);
	sock_make_blocking(source);
	b_event_remove(phb->inpa);
	phb->inpa = 0;
	if( phb->proxy_func )
		phb->proxy_func(phb->proxy_data, source, B_EV_IO_READ);
	else {
		phb->func(phb->data, source, B_EV_IO_READ);
		g_free(phb);
	}
	
	return FALSE;
}
Beispiel #14
0
/**
 * Clears an enacted connection timeout.
 *
 * @param mqtt The #fb_mqtt.
 **/
static void fb_mqtt_timeout_clear(fb_mqtt_t *mqtt)
{
    g_return_if_fail(mqtt != NULL);

    if (mqtt->tev > 0) {
        b_event_remove(mqtt->tev);
        mqtt->tev = 0;
    }
}
Beispiel #15
0
static gboolean http_canwrite(gpointer data, gint source, b_input_condition cond)
{
	char cmd[384];
	struct PHB *phb = data;
	unsigned int len;
	int error = ETIMEDOUT;
	if (phb->inpa > 0)
		b_event_remove(phb->inpa);
	len = sizeof(error);
	if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}
	sock_make_blocking(source);

	g_snprintf(cmd, sizeof(cmd), "CONNECT %s:%d HTTP/1.1\r\nHost: %s:%d\r\n", phb->host, phb->port,
		   phb->host, phb->port);
	if (send(source, cmd, strlen(cmd), 0) < 0) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}

	if (strlen(proxyuser) > 0) {
		char *t1, *t2;
		t1 = g_strdup_printf("%s:%s", proxyuser, proxypass);
		t2 = tobase64(t1);
		g_free(t1);
		g_snprintf(cmd, sizeof(cmd), "Proxy-Authorization: Basic %s\r\n", t2);
		g_free(t2);
		if (send(source, cmd, strlen(cmd), 0) < 0) {
			close(source);
			phb->func(phb->data, -1, GAIM_INPUT_READ);
			g_free(phb->host);
			g_free(phb);
			return FALSE;
		}
	}

	g_snprintf(cmd, sizeof(cmd), "\r\n");
	if (send(source, cmd, strlen(cmd), 0) < 0) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}

	phb->inpa = b_input_add(source, GAIM_INPUT_READ, http_canread, phb);
	
	return FALSE;
}
void discord_ws_cleanup(discord_data *dd)
{
  if (dd->keepalive_loop_id > 0) {
    b_event_remove(dd->keepalive_loop_id);
    dd->keepalive_loop_id = 0;
  }
  if (dd->lwsctx != NULL) {
    lws_context_destroy(dd->lwsctx);
  }
}
Beispiel #17
0
int irc_user_free( irc_t *irc, irc_user_t *iu )
{
	static struct im_connection *last_ic;
	static char *msg;
	
	if( !iu )
		return 0;
	
	if( iu->bu &&
	    ( iu->bu->ic->flags & OPT_LOGGING_OUT ) &&
	    iu->bu->ic != last_ic )
	{
		char host_prefix[] = "bitlbee.";
		char *s;
		
		/* Irssi recognises netsplits by quitmsgs with two
		   hostnames, where a hostname is a "word" with one
		   of more dots. Mangle no-dot hostnames a bit. */
		if( strchr( irc->root->host, '.' ) )
			*host_prefix = '\0';
		
		last_ic = iu->bu->ic;
		g_free( msg );
		if( !set_getbool( &irc->b->set, "simulate_netsplit" ) )
			msg = g_strdup( "Account off-line" );
		else if( ( s = strchr( iu->bu->ic->acc->user, '@' ) ) )
			msg = g_strdup_printf( "%s%s %s", host_prefix,
			        irc->root->host, s + 1 );
		else
			msg = g_strdup_printf( "%s%s %s.%s",
				host_prefix, irc->root->host,
				iu->bu->ic->acc->prpl->name, irc->root->host );
	}
	else if( !iu->bu || !( iu->bu->ic->flags & OPT_LOGGING_OUT ) )
	{
		g_free( msg );
		msg = g_strdup( "Removed" );
		last_ic = NULL;
	}
	irc_user_quit( iu, msg );
	
	irc->users = g_slist_remove( irc->users, iu );
	g_hash_table_remove( irc->nick_user_hash, iu->key );
	
	g_free( iu->nick );
	if( iu->nick != iu->user ) g_free( iu->user );
	if( iu->nick != iu->host ) g_free( iu->host );
	if( iu->nick != iu->fullname ) g_free( iu->fullname );
	g_free( iu->pastebuf );
	if( iu->pastebuf_timer ) b_event_remove( iu->pastebuf_timer );
	g_free( iu->key );
	g_free( iu );
	
	return 1;
}
Beispiel #18
0
static gboolean s4_canwrite(gpointer data, gint source, b_input_condition cond)
{
	unsigned char packet[12];
	struct hostent *hp;
	struct PHB *phb = data;
	socklen_t len;
	int error = ETIMEDOUT;
	gboolean is_socks4a = (proxytype == PROXY_SOCKS4A);

	if (phb->inpa > 0) {
		b_event_remove(phb->inpa);
	}
	len = sizeof(error);
	if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
		return phb_free(phb, FALSE);
	}
	sock_make_blocking(source);

	if (!is_socks4a && !(hp = gethostbyname(phb->host))) {
		return phb_free(phb, FALSE);
	}

	packet[0] = 4;
	packet[1] = 1;
	packet[2] = phb->port >> 8;
	packet[3] = phb->port & 0xff;
	if (is_socks4a) {
		packet[4] = 0;
		packet[5] = 0;
		packet[6] = 0;
		packet[7] = 1;
	} else {
		packet[4] = (unsigned char) (hp->h_addr_list[0])[0];
		packet[5] = (unsigned char) (hp->h_addr_list[0])[1];
		packet[6] = (unsigned char) (hp->h_addr_list[0])[2];
		packet[7] = (unsigned char) (hp->h_addr_list[0])[3];
	}
	packet[8] = 0;
	if (write(source, packet, 9) != 9) {
		return phb_free(phb, FALSE);
	}

	if (is_socks4a) {
		size_t host_len = strlen(phb->host) + 1; /* include the \0 */

		if (write(source, phb->host, host_len) != host_len) {
			return phb_free(phb, FALSE);
		}
	}

	phb->inpa = b_input_add(source, B_EV_IO_READ, s4_canread, phb);

	return FALSE;
}
Beispiel #19
0
gboolean cmd_identify_finish(gpointer data, gint fd, b_input_condition cond)
{
	char *account_on[] = { "account", "on", NULL };
	irc_t *irc = data;

	if (set_getbool(&irc->b->set, "auto_connect")) {
		cmd_account(irc, account_on);
	}

	b_event_remove(irc->login_source_id);
	irc->login_source_id = -1;
	return FALSE;
}
Beispiel #20
0
static gboolean s4_canwrite(gpointer data, gint source, b_input_condition cond)
{
	unsigned char packet[12];
	struct hostent *hp;
	struct PHB *phb = data;
	unsigned int len;
	int error = ETIMEDOUT;
	if (phb->inpa > 0)
		b_event_remove(phb->inpa);
	len = sizeof(error);
	if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}
	sock_make_blocking(source);

	/* XXX does socks4 not support host name lookups by the proxy? */
	if (!(hp = gethostbyname(phb->host))) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}

	packet[0] = 4;
	packet[1] = 1;
	packet[2] = phb->port >> 8;
	packet[3] = phb->port & 0xff;
	packet[4] = (unsigned char)(hp->h_addr_list[0])[0];
	packet[5] = (unsigned char)(hp->h_addr_list[0])[1];
	packet[6] = (unsigned char)(hp->h_addr_list[0])[2];
	packet[7] = (unsigned char)(hp->h_addr_list[0])[3];
	packet[8] = 0;
	if (write(source, packet, 9) != 9) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}

	phb->inpa = b_input_add(source, GAIM_INPUT_READ, s4_canread, phb);
	
	return FALSE;
}
Beispiel #21
0
static gboolean s4_canread(gpointer data, gint source, b_input_condition cond)
{
	unsigned char packet[12];
	struct PHB *phb = data;

	b_event_remove(phb->inpa);

	memset(packet, 0, sizeof(packet));
	if (read(source, packet, 9) >= 4 && packet[1] == 90) {
		phb->func(phb->data, source, B_EV_IO_READ);
		return phb_free(phb, TRUE);
	}

	return phb_free(phb, FALSE);
}
Beispiel #22
0
void ssl_disconnect( void *conn_ )
{
	struct scd *conn = conn_;
	
	if( conn->inpa != -1 )
		b_event_remove( conn->inpa );
	
	if( conn->established )
		gnutls_bye( conn->session, GNUTLS_SHUT_WR );
	
	closesocket( conn->fd );
	
	if( conn->session )
		gnutls_deinit( conn->session );
	g_free( conn );
}
Beispiel #23
0
void ssl_disconnect(void *conn_)
{
    struct scd *conn = conn_;

    if (conn->inpa != -1) {
        b_event_remove(conn->inpa);
    }

    if (conn->established) {
        SSL_shutdown(conn->ssl);
    }

    closesocket(conn->fd);

    ssl_conn_free(conn);
}
Beispiel #24
0
void msn_ns_close( struct msn_handler_data *handler )
{
	if( handler->fd >= 0 )
	{
		closesocket( handler->fd );
		b_event_remove( handler->inpa );
	}
	
	handler->fd = handler->inpa = -1;
	g_free( handler->rxq );
	g_free( handler->cmd_text );
	
	handler->rxlen = 0;
	handler->rxq = NULL;
	handler->cmd_text = NULL;
}
Beispiel #25
0
int irc_channel_free(irc_channel_t *ic)
{
	irc_t *irc;
	GSList *l;

	if (ic == NULL) {
		return 0;
	}
	irc = ic->irc;

	if (ic->flags & IRC_CHANNEL_JOINED) {
		irc_channel_del_user(ic, irc->user, IRC_CDU_KICK, "Cleaning up channel");
	}

	if (ic->f->_free) {
		ic->f->_free(ic);
	}

	while (ic->set) {
		set_del(&ic->set, ic->set->key);
	}

	irc->channels = g_slist_remove(irc->channels, ic);
	while (ic->users) {
		g_free(ic->users->data);
		ic->users = g_slist_remove(ic->users, ic->users->data);
	}

	for (l = irc->users; l; l = l->next) {
		irc_user_t *iu = l->data;

		if (iu->last_channel == ic) {
			iu->last_channel = irc->default_channel;
		}
	}

	if (ic->pastebuf_timer) {
		b_event_remove(ic->pastebuf_timer);
	}

	g_free(ic->name);
	g_free(ic->topic);
	g_free(ic->topic_who);
	g_free(ic);

	return 1;
}
Beispiel #26
0
static gssize prplcb_xfer_write( PurpleXfer *xfer, const guchar *buffer, gssize size )
{
	struct prpl_xfer_data *px = xfer->ui_data;
	gboolean st;
	
	fprintf( stderr, "xfer_write %d %d\n", size, px->buf_len );
	
	b_event_remove( px->ready_timer );
	px->ready_timer = 0;
	
	st = px->ft->write( px->ft, (char*) buffer, size );
	
	if( st && xfer->bytes_remaining == size )
		imcb_file_finished( px->ft );
	
	return st ? size : 0;
}
Beispiel #27
0
static gboolean s5_canread_again(gpointer data, gint source, b_input_condition cond)
{
	unsigned char buf[512];
	struct PHB *phb = data;

	b_event_remove(phb->inpa);

	if (read(source, buf, 10) < 10) {
		return phb_free(phb, FALSE);
	}
	if ((buf[0] != 0x05) || (buf[1] != 0x00)) {
		return phb_free(phb, FALSE);
	}

	phb->func(phb->data, source, B_EV_IO_READ);
	return phb_free(phb, TRUE);
}
Beispiel #28
0
static void ipc_master_cmd_deaf( irc_t *data, char **cmd )
{
	if( global.conf->runmode == RUNMODE_DAEMON )
	{
		b_event_remove( global.listen_watch_source_id );
		close( global.listen_socket );
		
		global.listen_socket = global.listen_watch_source_id = -1;
	
		ipc_to_children_str( "OPERMSG :Closed listening socket, waiting "
		                     "for all users to disconnect." );
	}
	else
	{
		ipc_to_children_str( "OPERMSG :The DEAF command only works in "
		                     "normal daemon mode. Try DIE instead." );
	}
}
Beispiel #29
0
static gboolean s5_canwrite(gpointer data, gint source, b_input_condition cond)
{
	unsigned char buf[512];
	int i;
	struct PHB *phb = data;
	unsigned int len;
	int error = ETIMEDOUT;
	if (phb->inpa > 0)
		b_event_remove(phb->inpa);
	len = sizeof(error);
	if (getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}
	sock_make_blocking(source);

	i = 0;
	buf[0] = 0x05;		/* SOCKS version 5 */
	if (proxyuser[0]) {
		buf[1] = 0x02;	/* two methods */
		buf[2] = 0x00;	/* no authentication */
		buf[3] = 0x02;	/* username/password authentication */
		i = 4;
	} else {
		buf[1] = 0x01;
		buf[2] = 0x00;
		i = 3;
	}

	if (write(source, buf, i) < i) {
		close(source);
		phb->func(phb->data, -1, GAIM_INPUT_READ);
		g_free(phb->host);
		g_free(phb);
		return FALSE;
	}

	phb->inpa = b_input_add(source, GAIM_INPUT_READ, s5_canread, phb);
	
	return FALSE;
}
Beispiel #30
0
static gboolean s5_readauth(gpointer data, gint source, b_input_condition cond)
{
	unsigned char buf[512];
	struct PHB *phb = data;

	b_event_remove(phb->inpa);

	if (read(source, buf, 2) < 2) {
		return phb_free(phb, FALSE);
	}

	if ((buf[0] != 0x01) || (buf[1] != 0x00)) {
		return phb_free(phb, FALSE);
	}

	s5_sendconnect(phb, source);

	return FALSE;
}