コード例 #1
0
ファイル: upnp.c プロジェクト: Mons/libpurple-mini
void
purple_upnp_discover(PurpleUPnPCallback cb, gpointer cb_data)
{
	/* Socket Setup Variables */
	int sock;
	struct hostent* hp;

	/* UDP RECEIVE VARIABLES */
	UPnPDiscoveryData *dd;

	if (control_info.status == PURPLE_UPNP_STATUS_DISCOVERING) {
		if (cb) {
			discovery_callbacks = g_slist_append(
					discovery_callbacks, cb);
			discovery_callbacks = g_slist_append(
					discovery_callbacks, cb_data);
		}
		return;
	}

	dd = g_new0(UPnPDiscoveryData, 1);
	if (cb) {
		discovery_callbacks = g_slist_append(discovery_callbacks, cb);
		discovery_callbacks = g_slist_append(discovery_callbacks,
				cb_data);
	}

	/* Set up the sockets */
	sock = socket(AF_INET, SOCK_DGRAM, 0);
	if(sock == -1) {
		purple_debug_error("upnp",
			"purple_upnp_discover(): Failed In sock creation\n");
		/* Short circuit the retry attempts */
		dd->retry_count = NUM_UDP_ATTEMPTS;
		purple_timeout_add(10, purple_upnp_discover_timeout, dd);
		return;
	}

	dd->fd = sock;

	/* TODO: Non-blocking! */
	if((hp = gethostbyname(HTTPMU_HOST_ADDRESS)) == NULL) {
		purple_debug_error("upnp",
			"purple_upnp_discover(): Failed In gethostbyname\n");
		/* Short circuit the retry attempts */
		dd->retry_count = NUM_UDP_ATTEMPTS;
		purple_timeout_add(10, purple_upnp_discover_timeout, dd);
		return;
	}

	memset(&(dd->server), 0, sizeof(struct sockaddr));
	dd->server.sin_family = AF_INET;
	memcpy(&(dd->server.sin_addr), hp->h_addr_list[0], hp->h_length);
	dd->server.sin_port = htons(HTTPMU_HOST_PORT);

	control_info.status = PURPLE_UPNP_STATUS_DISCOVERING;

	purple_upnp_discover_send_broadcast(dd);
}
コード例 #2
0
ファイル: stun.c プロジェクト: CkNoSFeRaTU/pidgin
PurpleStunNatDiscovery *purple_stun_discover(StunCallback cb) {
	const char *servername = purple_prefs_get_string("/purple/network/stun_server");

	purple_debug_info("stun", "using server %s\n", servername);

	if(nattype.status == PURPLE_STUN_STATUS_DISCOVERING) {
		if(cb)
			callbacks = g_slist_append(callbacks, cb);
		return &nattype;
	}

	if(nattype.status != PURPLE_STUN_STATUS_UNDISCOVERED) {
		gboolean use_cached_result = TRUE;

		/** Deal with the server name having changed since we did the
		    lookup */
		if (servername && strlen(servername) > 1
				&& !purple_strequal(servername, nattype.servername)) {
			use_cached_result = FALSE;
		}

		/* If we don't have a successful status and it has been 5
		   minutes since we last did a lookup, redo the lookup */
		if (nattype.status != PURPLE_STUN_STATUS_DISCOVERED
				&& (time(NULL) - nattype.lookup_time) > 300) {
			use_cached_result = FALSE;
		}

		if (use_cached_result) {
			if(cb)
				purple_timeout_add(10, call_callback, cb);
			return &nattype;
		}
	}

	if(!servername || (strlen(servername) < 2)) {
		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;
		nattype.lookup_time = time(NULL);
		if(cb)
			purple_timeout_add(10, call_callback, cb);
		return &nattype;
	}

	nattype.status = PURPLE_STUN_STATUS_DISCOVERING;
	nattype.publicip[0] = '\0';
	g_free(nattype.servername);
	nattype.servername = g_strdup(servername);

	callbacks = g_slist_append(callbacks, cb);
	purple_srv_resolve_account(NULL, "stun", "udp", servername, do_test1,
		(gpointer) servername);

	return &nattype;
}
コード例 #3
0
ファイル: upnp.c プロジェクト: Lilitana/Pidgin
static void
purple_upnp_discover_send_broadcast(UPnPDiscoveryData *dd)
{
	gchar *sendMessage = NULL;
	size_t totalSize;
	gboolean sentSuccess;

	/* because we are sending over UDP, if there is a failure
	   we should retry the send NUM_UDP_ATTEMPTS times. Also,
	   try different requests for WANIPConnection and WANPPPConnection*/
	for(; dd->retry_count < NUM_UDP_ATTEMPTS; dd->retry_count++) {
		sentSuccess = FALSE;

		if((dd->retry_count % 2) == 0) {
			strncpy(dd->service_type, WAN_IP_CONN_SERVICE, sizeof(dd->service_type));
		} else {
			strncpy(dd->service_type, WAN_PPP_CONN_SERVICE, sizeof(dd->service_type));
		}

		sendMessage = g_strdup_printf(SEARCH_REQUEST_STRING, dd->service_type);

		totalSize = strlen(sendMessage);

		do {
			if(sendto(dd->fd, sendMessage, totalSize, 0,
					(struct sockaddr*) &(dd->server),
					sizeof(struct sockaddr_in)
					) == totalSize) {
				sentSuccess = TRUE;
				break;
			}
		} while (errno == EINTR || errno == EAGAIN);

		g_free(sendMessage);

		if(sentSuccess) {
			dd->tima = purple_timeout_add(DISCOVERY_TIMEOUT,
				purple_upnp_discover_timeout, dd);
			dd->inpa = purple_input_add(dd->fd, PURPLE_INPUT_READ,
				purple_upnp_discover_udp_read, dd);

			return;
		}
	}

	/* We have already done all our retries. Make sure that the callback
	 * doesn't get called before the original function returns */
	dd->tima = purple_timeout_add(10, purple_upnp_discover_timeout, dd);
}
コード例 #4
0
static void
skype_message_received(char *orig_message)
{
	guint request_number;
	guint *key;
	int string_pos;
	char *message;
	
	if (strlen(orig_message) == 0)
		return;
	
	message = g_strdup(orig_message);
	g_free(orig_message);

	skype_debug_info("skype", "Received: %s\n", message);

	if(message[0] == '#')
	{
		//It's a reply from a call we've made - update the hash table
		sscanf(message, "#%u %n", &request_number, &string_pos);
		key = g_new(guint, 1);
		*key = request_number;
		
		g_static_mutex_lock2(&mutex);
		g_hash_table_insert(message_queue, key, g_strdup(&message[string_pos]));
		g_cond_broadcast(condition);
		g_static_mutex_unlock2(&mutex);
		
		g_free(message);
	} else {
		purple_timeout_add(1, (GSourceFunc)skype_handle_received_message, (gpointer)message);
	}
}
コード例 #5
0
ファイル: buddytime.c プロジェクト: Javran/purple-plugin-pack
static gboolean
plugin_load(PurplePlugin * plugin)
{
	plugin_self = plugin;

	purple_signal_connect(purple_conversations_get_handle(), "conversation-created", plugin,
	                      PURPLE_CALLBACK(timezone_createconv_cb), NULL);

	purple_plugin_ipc_register(plugin, BUDDYTIME_BUDDY_GET_TIMEZONE,
	                           PURPLE_CALLBACK(buddy_get_timezone),
	                           marshal_POINTER__POINTER_BOOL,
	                           purple_value_new(PURPLE_TYPE_STRING),
	                           2,
	                           purple_value_new(PURPLE_TYPE_SUBTYPE,
	                                            PURPLE_SUBTYPE_BLIST_NODE),
	                           purple_value_new(PURPLE_TYPE_BOOLEAN));

	purple_plugin_ipc_register(plugin, BUDDYTIME_TIMEZONE_GET_TIME,
	                           PURPLE_CALLBACK(timezone_get_time),
	                           marshal_POINTER__POINTER_POINTER_POINTER,
	                           purple_value_new(PURPLE_TYPE_INT),
	                           2,
	                           purple_value_new(PURPLE_TYPE_POINTER),
	                           purple_value_new(PURPLE_TYPE_POINTER));

	/* This is done as an idle callback to avoid an infinite loop
	 * when we try to load the UI plugin which depends on this plugin
	 * which isn't officially loaded yet. */
	purple_timeout_add(0, load_ui_plugin, NULL);

	return TRUE;
}
コード例 #6
0
ファイル: soap.c プロジェクト: Draghtnod/pidgin
static void
msn_soap_connection_handle_next(MsnSoapConnection *conn)
{
	msn_soap_connection_sanitize(conn, FALSE);

	conn->run_timer = purple_timeout_add(0, msn_soap_connection_run, conn);
}
コード例 #7
0
ファイル: splitter.c プロジェクト: rgenoud/purple-plugin-pack
/* create message queue and prepare timer callbacks */
static void
split_and_send(message_to_conv *msg_to_conv, const char **message) {
	gint message_delay_ms;

	g_return_if_fail( msg_to_conv != NULL );
	g_return_if_fail( message     != NULL );
	g_return_if_fail( *message    != NULL );

	/* read and validate preferences */
	current_split_size = purple_prefs_get_int("/plugins/core/splitter/split_size");
	if( current_split_size > MAX_SPLIT_SIZE ) current_split_size = MAX_SPLIT_SIZE;
	if( current_split_size < MIN_SPLIT_SIZE ) current_split_size = MIN_SPLIT_SIZE;

	message_delay_ms = purple_prefs_get_int("/plugins/core/splitter/delay_ms");
	if( message_delay_ms > MAX_DELAY_MS ) message_delay_ms = MAX_DELAY_MS;
	if( message_delay_ms < MIN_DELAY_MS ) message_delay_ms = MIN_DELAY_MS;

	/* prepare message queue */
	msg_to_conv->messages = create_message_queue(*message);
	g_return_if_fail( msg_to_conv->messages != NULL );

	/* initialize message send timer */
	purple_timeout_add( (g_queue_get_length(msg_to_conv->messages) > 1) ? message_delay_ms : 0,
			  (GSourceFunc)send_message_timer_cb,
			  msg_to_conv);

	/* free the original message and ensure it does not get sent */
	g_free((char*)*message);
	*message = NULL;
}
コード例 #8
0
ファイル: tgp-ft.c プロジェクト: prodigeni/telegram-purple
static void tgprpl_xfer_send_init (PurpleXfer *X) {
  struct tgp_xfer_send_data *data = X->data;
  
  purple_xfer_start (X, -1, NULL, 0);
  
  const char *file = purple_xfer_get_filename (X);
  const char *localfile = purple_xfer_get_local_filename (X);
  const char *who = purple_xfer_get_remote_user (X);
  debug ("xfer_on_init (file=%s, local=%s, who=%s)", file, localfile, who);
  
  tgl_peer_t *P = find_peer_by_name (data->conn->TLS, who);
  if (P) {
    if (tgl_get_peer_type (P->id) != TGL_PEER_ENCR_CHAT) {
      tgl_do_send_document (data->conn->TLS, P->id, (char*) localfile, NULL,
                            0, TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgprpl_xfer_on_finished, data);
    }
    else {
      purple_notify_message (_telegram_protocol, PURPLE_NOTIFY_MSG_ERROR, "Not supported",
                             "Sorry, sending documents to encrypted chats not yet supported.",
                             NULL, NULL, NULL);
    }
  }
  
  data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X);
}
コード例 #9
0
ファイル: skypeweb_contacts.c プロジェクト: rtmf/skype4pidgin
void
skypeweb_get_icon(PurpleBuddy *buddy)
{
	if (!buddy) return;
	
	purple_timeout_add(100, skypeweb_get_icon_queuepop, (gpointer)buddy);
}
コード例 #10
0
ファイル: tgp-msg.c プロジェクト: Houlbek/telegram-purple
static void tgp_msg_send_schedule (struct tgl_state *TLS, gchar *chunk, tgl_peer_id_t to) {
  g_queue_push_tail (tls_get_data (TLS)->out_messages, tgp_msg_sending_init (TLS, chunk, to));
  if (tls_get_data (TLS)->out_timer) {
    purple_timeout_remove (tls_get_data (TLS)->out_timer);
  }
  tls_get_data (TLS)->out_timer = purple_timeout_add (0, tgp_msg_send_schedule_cb, tls_get_data (TLS));
}
コード例 #11
0
ファイル: dnsquery.c プロジェクト: arminius2/apolloim
PurpleDnsQueryData *
purple_dnsquery_a(const char *hostname, int port,
				PurpleDnsQueryConnectFunction callback, gpointer data)
{
	PurpleDnsQueryData *query_data;

	g_return_val_if_fail(hostname != NULL, NULL);
	g_return_val_if_fail(port	  != 0, NULL);
	g_return_val_if_fail(callback != NULL, NULL);

	query_data = g_new(PurpleDnsQueryData, 1);
	query_data->hostname = g_strdup(hostname);
	g_strstrip(query_data->hostname);
	query_data->port = port;
	query_data->callback = callback;
	query_data->data = data;

	if (strlen(query_data->hostname) == 0)
	{
		purple_dnsquery_destroy(query_data);
		g_return_val_if_reached(NULL);
	}

	/* Don't call the callback before returning */
	query_data->timeout = purple_timeout_add(0, resolve_host, query_data);

	return query_data;
}
コード例 #12
0
ファイル: dnsquery.c プロジェクト: arminius2/apolloim
PurpleDnsQueryData *
purple_dnsquery_a(const char *hostname, int port,
				PurpleDnsQueryConnectFunction callback, gpointer data)
{
	PurpleDnsQueryData *query_data;

	g_return_val_if_fail(hostname != NULL, NULL);
	g_return_val_if_fail(port	  != 0, NULL);
	g_return_val_if_fail(callback != NULL, NULL);

	query_data = g_new(PurpleDnsQueryData, 1);
	query_data->hostname = g_strdup(hostname);
	g_strstrip(query_data->hostname);
	query_data->port = port;
	query_data->callback = callback;
	query_data->data = data;
	query_data->resolver = NULL;

	if (strlen(query_data->hostname) == 0)
	{
		purple_dnsquery_destroy(query_data);
		g_return_val_if_reached(NULL);
	}

	queued_requests = g_slist_append(queued_requests, query_data);

	purple_debug_info("dns", "DNS query for '%s' queued\n", query_data->hostname);

	query_data->timeout = purple_timeout_add(0, resolve_host, query_data);

	return query_data;
}
コード例 #13
0
ファイル: dnsquery.c プロジェクト: CkNoSFeRaTU/pidgin
PurpleDnsQueryData *
purple_dnsquery_a_account(PurpleAccount *account, const char *hostname, int port,
				PurpleDnsQueryConnectFunction callback, gpointer data)
{
	PurpleDnsQueryData *query_data;

	g_return_val_if_fail(hostname != NULL, NULL);
	g_return_val_if_fail(port != 0, NULL);
	g_return_val_if_fail(callback != NULL, NULL);

	purple_debug_info("dnsquery", "Performing DNS lookup for %s\n", hostname);

	query_data = g_new0(PurpleDnsQueryData, 1);
	query_data->hostname = g_strdup(hostname);
	g_strstrip(query_data->hostname);
	query_data->port = port;
	query_data->callback = callback;
	query_data->data = data;
	query_data->account = account;

	if (*query_data->hostname == '\0')
	{
		purple_dnsquery_destroy(query_data);
		g_return_val_if_reached(NULL);
	}

	query_data->timeout = purple_timeout_add(0, initiate_resolving, query_data);

	return query_data;
}
コード例 #14
0
ファイル: irc-more.c プロジェクト: Javran/purple-plugin-pack
static void
irc_receiving_text(PurpleConnection *gc, const char **incoming, gpointer null)
{
	char **splits, *str;
	PurpleAccount *account = NULL;

	if (!incoming || !*incoming || !**incoming)   /* oh the fun .. I can do this all day! */
		return;

	splits = g_strsplit(*incoming, " ", -1);

	/* if there's not at least 5 elements in the string array, this isn't a kick; ignore  */
	if(g_strv_length(splits) < 5)
		return;

	account = purple_connection_get_account(gc);
	str = g_ascii_strdown(splits[1], -1);

	if (strcmp(str, "kick") == 0 && splits[2] && splits[3]) {
		char *name = splits[2];
		GList *chats = purple_get_chats();
		while (chats) {
			PurpleConversation *conv = chats->data;
			chats = chats->next;
			if (purple_conversation_get_account(conv) == account
					&& strcmp(purple_conversation_get_name(conv), name) == 0) {
				purple_timeout_add(100, show_them, conv);
				break;
			}
		}
	}

	g_free(str);
	g_strfreev(splits);
}
コード例 #15
0
ファイル: tgp-ft.c プロジェクト: Houlbek/telegram-purple
static void tgprpl_xfer_send_init (PurpleXfer *X) {
  debug ("tgprpl_xfer_send_init(): sending xfer accepted.");

  struct tgp_xfer_send_data *data;
  const char *file, *localfile, *who;
  tgl_peer_t *P;

  data = X->data;
  purple_xfer_start (X, -1, NULL, 0);

  file = purple_xfer_get_filename (X);
  localfile = purple_xfer_get_local_filename (X);
  who = purple_xfer_get_remote_user (X);
  debug ("xfer_on_init (file=%s, local=%s, who=%s)", file, localfile, who);

  P = tgp_blist_lookup_peer_get (data->conn->TLS, who);
  g_return_if_fail (P);

  if (tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT) {
    purple_xfer_error (PURPLE_XFER_SEND, data->conn->pa, who,
        _("Sorry, sending documents to encrypted chats not yet supported."));
    purple_xfer_cancel_local (X);
    return;
  }

  tgl_do_send_document (data->conn->TLS, P->id, (char*) localfile, NULL, 0,
      TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgprpl_xfer_send_on_finished, data);

  // see comment in tgprpl_xfer_recv_init()
  purple_xfer_ref (X);

  data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X);
  data->loading = TRUE;
}
コード例 #16
0
ファイル: session.c プロジェクト: mikecpt/msn-pecan
MsnSession *
msn_session_new (const gchar *username,
                 const gchar *password,
                 gboolean http_method)
{
    MsnSession *session;

    session = g_new0 (MsnSession, 1);

    session->username = pn_normalize (username);
    session->password = g_strndup (password, 16);

#ifdef INTERNAL_MAINLOOP
    session->g_main_loop = g_main_loop_new  (NULL, FALSE);
    session->g_main_loop_timer = purple_timeout_add (1000, g_main_context_iteration_timer, NULL);
#endif

    session->config = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

    /** @todo sb and ns need this here but should be updated on-the-fly. */
    msn_session_set_bool (session, "use_http_method", http_method);

#if 0
    if (session->http_method)
    {
        PnNode *foo;
        foo = PN_NODE (pn_http_server_new ("foo server"));
        foo->session = session;
        session->http_conn = foo;
    }
#endif

    session->dp_manager = pn_dp_manager_new (session);

    session->notification = msn_notification_new (session);
    pn_node_set_id(session->notification->cmdproc->conn,
                   session->conn_count++, "ns");

    session->contactlist = pn_contactlist_new (session);

    session->user = pn_contact_new (NULL);
    pn_contact_set_passport (session->user, session->username);

    session->conv_seq = 1;

    session->oim_session = pn_oim_session_new (session);

    session->conversations = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) msn_switchboard_unref);
    session->chats = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) msn_switchboard_unref);

#if defined(PECAN_CVR)
    session->links = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) pn_peer_link_unref);
#endif /* defined(PECAN_CVR) */

    purple_signal_connect (purple_conversations_get_handle(), "conversation-created",
                           session, PURPLE_CALLBACK (conversation_created_cb), session);

    return session;
}
コード例 #17
0
ファイル: qq_types.c プロジェクト: 5rather/pidgin-lwqq
void qq_dispatch(LwqqCommand cmd,unsigned long timeout)
{
	if(timeout==0)timeout=10;
	LwqqCommand* d = s_malloc0(sizeof(*d));
	*d = cmd;

	purple_timeout_add(timeout,did_dispatch,d);
}
コード例 #18
0
ファイル: spotify.cpp プロジェクト: fry/pidgin-spotify
static gboolean plugin_load(PurplePlugin *plugin) {
	guint poll_interval = 3000;
	spotify_plugin = plugin;

	// register the timeout
	spotify_handle = purple_timeout_add(poll_interval, spotify_poll, NULL);

	return TRUE;
}
コード例 #19
0
ファイル: ssl-gnutls.c プロジェクト: Lilitana/Pidgin
static void
ssl_gnutls_connect(PurpleSslConnection *gsc)
{
	PurpleSslGnutlsData *gnutls_data;
	static const int cert_type_priority[2] = { GNUTLS_CRT_X509, 0 };

	gnutls_data = g_new0(PurpleSslGnutlsData, 1);
	gsc->private_data = gnutls_data;

	gnutls_init(&gnutls_data->session, GNUTLS_CLIENT);
#ifdef HAVE_GNUTLS_PRIORITY_FUNCS
	{
		const char *prio_str = NULL;
		gboolean set = FALSE;

		/* Let's see if someone has specified a specific priority */
		if (gsc->host && host_priorities)
			prio_str = g_hash_table_lookup(host_priorities, gsc->host);

		if (prio_str)
			set = (GNUTLS_E_SUCCESS ==
					gnutls_priority_set_direct(gnutls_data->session, prio_str,
				                               NULL));

		if (!set)
			gnutls_priority_set(gnutls_data->session, default_priority);
	}
#else
	gnutls_set_default_priority(gnutls_data->session);
#endif

	gnutls_certificate_type_set_priority(gnutls_data->session,
		cert_type_priority);

	gnutls_credentials_set(gnutls_data->session, GNUTLS_CRD_CERTIFICATE,
		xcred);

	gnutls_transport_set_ptr(gnutls_data->session, GINT_TO_POINTER(gsc->fd));

	gnutls_data->handshake_handler = purple_input_add(gsc->fd,
		PURPLE_INPUT_READ, ssl_gnutls_handshake_cb, gsc);

	/* Orborde asks: Why are we configuring a callback, then
	   (almost) immediately calling it?

	   Answer: gnutls_handshake (up in handshake_cb) needs to be called
	   once in order to get the ball rolling on the SSL connection.
	   Once it has done so, only then will the server reply, triggering
	   the callback.

	   Since the logic driving gnutls_handshake is the same with the first
	   and subsequent calls, we'll just fire the callback immediately to
	   accomplish this.
	*/
	gnutls_data->handshake_timer = purple_timeout_add(0, start_handshake_cb,
	                                                  gsc);
}
コード例 #20
0
bool ReceiveFile::receive() {
	if (m_stream->recv() != ConnNoError || shouldStop()) {
		m_file.close();
		Log("ReceiveFile", "transferFinished");
		purple_timeout_add(1000,&transferFinished,this);
		return false;
	}
	return true;
}
コード例 #21
0
ファイル: mqtt.c プロジェクト: duxet/adium-facebook
static void
fb_mqtt_ping(FbMqtt *mqtt)
{
	FbMqttPrivate *priv = mqtt->priv;

	fb_mqtt_timeout_clear(mqtt);
	priv->tev = purple_timeout_add(FB_MQTT_TIMEOUT_PING,
	                               fb_mqtt_cb_ping, mqtt);
}
コード例 #22
0
ファイル: tgp-msg.c プロジェクト: prodigeni/telegram-purple
static void tgp_msg_send_schedule (struct tgl_state *TLS, gchar *chunk, tgl_peer_id_t to) {
  connection_data *conn = TLS->ev_base;
  struct tgp_msg_sending *D = tgp_msg_sending_init (TLS, chunk, to);
  g_queue_push_tail (conn->out_messages, D);

  if (conn->out_timer) {
    purple_timeout_remove (conn->out_timer);
  }
  conn->out_timer = purple_timeout_add (0, tgp_msg_send_schedule_cb, conn);
}
コード例 #23
0
ファイル: stun.c プロジェクト: N8Fear/purple-facebook
static void
hbn_listen_cb(int fd, gpointer data) {
	StunHBNListenData *ld = (StunHBNListenData *)data;
	GInetAddress *address = NULL;
	GSocketAddress *socket_address = NULL;
	struct stun_conn *sc;
	static struct stun_header hdr_data;

	if(fd < 0) {
		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;
		nattype.lookup_time = time(NULL);
		do_callbacks();
		return;
	}

	sc = g_new0(struct stun_conn, 1);
	sc->fd = fd;

	sc->addr.sin_family = AF_INET;
	sc->addr.sin_port = htons(purple_network_get_port_from_fd(fd));
	sc->addr.sin_addr.s_addr = INADDR_ANY;

	sc->incb = purple_input_add(fd, PURPLE_INPUT_READ, reply_cb, sc);

	address = G_INET_ADDRESS(ld->addresses->data);
	socket_address = g_inet_socket_address_new(address, ld->port);

	g_socket_address_to_native(socket_address, &(sc->addr), g_socket_address_get_native_size(socket_address), NULL);

	g_object_unref(G_OBJECT(address));
	g_object_unref(G_OBJECT(socket_address));
	g_resolver_free_addresses(ld->addresses);
	g_free(ld);

	hdr_data.type = htons(MSGTYPE_BINDINGREQUEST);
	hdr_data.len = 0;
	hdr_data.transid[0] = rand();
	hdr_data.transid[1] = ntohl(((int)'g' << 24) + ((int)'a' << 16) + ((int)'i' << 8) + (int)'m');
	hdr_data.transid[2] = rand();
	hdr_data.transid[3] = rand();

	if(sendto(sc->fd, &hdr_data, sizeof(struct stun_header), 0,
			(struct sockaddr *)&(sc->addr),
			sizeof(struct sockaddr_in)) < (gssize)sizeof(struct stun_header)) {
		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;
		nattype.lookup_time = time(NULL);
		do_callbacks();
		close_stun_conn(sc);
		return;
	}
	sc->test = 1;
	sc->packet = &hdr_data;
	sc->packetsize = sizeof(struct stun_header);
	sc->timeout = purple_timeout_add(500, (GSourceFunc) timeoutfunc, sc);
}
コード例 #24
0
ファイル: purple-schedule.c プロジェクト: rravinuthala/sipe
gpointer sipe_backend_schedule_mseconds(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public,
					guint timeout,
					gpointer data)
{
	struct purple_schedule *schedule = g_malloc(sizeof(struct purple_schedule));
	schedule->core_data = data;
	schedule->timeout_handler = purple_timeout_add(timeout,
						       purple_timeout_execute,
						       schedule);
	return(schedule);
}
コード例 #25
0
ファイル: soap.c プロジェクト: Draghtnod/pidgin
static void
msn_soap_connected_cb(gpointer data, PurpleSslConnection *ssl,
		PurpleInputCondition cond)
{
	MsnSoapConnection *conn = data;

	conn->connected = TRUE;

	if (conn->run_timer == 0)
		conn->run_timer = purple_timeout_add(0, msn_soap_connection_run, conn);
}
コード例 #26
0
ファイル: transaction.c プロジェクト: D1RiP/pidgin-nateon
void
nateon_transaction_set_timeout_cb(NateonTransaction *trans, NateonTimeoutCb cb)
{
	if (trans->timer)
	{
		purple_debug_error("nateon", "This shouldn't be happening\n");
		purple_timeout_remove(trans->timer);
	}
	trans->timeout_cb = cb;
	trans->timer = purple_timeout_add(60000, transaction_timeout, trans);
}
コード例 #27
0
void FiletransferRepeater::gotData(const std::string &data) {
	m_buffer.append(std::string(data));
	if (m_wantsData) {
		m_wantsData = false;
		purple_timeout_add(0,&ui_got_data,m_xfer);
	}
	else if (m_send)
		m_resender->wakeUp();
	else
		std::cout << "got data but don't want them yet\n";
}
コード例 #28
0
ファイル: upnp.c プロジェクト: Lilitana/Pidgin
static void
do_port_mapping_cb(gboolean has_control_mapping, gpointer data)
{
	UPnPMappingAddRemove *ar = data;

	if (has_control_mapping) {
		gchar action_name[25];
		gchar *action_params;
		if(ar->add) {
			const gchar *internal_ip;
			/* get the internal IP */
			if(!(internal_ip = purple_upnp_get_internal_ip())) {
				purple_debug_error("upnp",
					"purple_upnp_set_port_mapping(): couldn't get local ip\n");
				ar->success = FALSE;
				ar->tima = purple_timeout_add(0, fire_ar_cb_async_and_free, ar);
				return;
			}
			strncpy(action_name, "AddPortMapping",
					sizeof(action_name));
			action_params = g_strdup_printf(
					ADD_PORT_MAPPING_PARAMS,
					ar->portmap, ar->protocol, ar->portmap,
					internal_ip);
		} else {
			strncpy(action_name, "DeletePortMapping", sizeof(action_name));
			action_params = g_strdup_printf(
				DELETE_PORT_MAPPING_PARAMS,
				ar->portmap, ar->protocol);
		}

		ar->gfud = purple_upnp_generate_action_message_and_send(action_name,
						action_params, done_port_mapping_cb, ar);

		g_free(action_params);
		return;
	}

	ar->success = FALSE;
	ar->tima = purple_timeout_add(0, fire_ar_cb_async_and_free, ar);
}
コード例 #29
0
static void ap_gtk_timeout_start (APUpdateType type) {
  APProgressBar *progress_bar;

  progress_bar = g_hash_table_lookup (progress_bars, GINT_TO_POINTER(type));
  if (progress_bar->timeout) {
    purple_timeout_remove (progress_bar->timeout);
  }
  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar->bar), 0);
  progress_bar->timeout = 
          purple_timeout_add (BAH, progress_update, progress_bar);
  progress_update (progress_bar);
}
コード例 #30
0
ファイル: stun.c プロジェクト: CkNoSFeRaTU/pidgin
static void hbn_listen_cb(int fd, gpointer data) {
	GSList *hosts = data;
	struct stun_conn *sc;
	static struct stun_header hdr_data;

	if(fd < 0) {
		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;
		nattype.lookup_time = time(NULL);
		do_callbacks();
		return;
	}

	sc = g_new0(struct stun_conn, 1);
	sc->fd = fd;

	sc->addr.sin_family = AF_INET;
	sc->addr.sin_port = htons(purple_network_get_port_from_fd(fd));
	sc->addr.sin_addr.s_addr = INADDR_ANY;

	sc->incb = purple_input_add(fd, PURPLE_INPUT_READ, reply_cb, sc);

	hosts = g_slist_delete_link(hosts, hosts);
	memcpy(&(sc->addr), hosts->data, sizeof(struct sockaddr_in));
	g_free(hosts->data);
	hosts = g_slist_delete_link(hosts, hosts);
	while (hosts) {
		hosts = g_slist_delete_link(hosts, hosts);
		g_free(hosts->data);
		hosts = g_slist_delete_link(hosts, hosts);
	}

	hdr_data.type = htons(MSGTYPE_BINDINGREQUEST);
	hdr_data.len = 0;
	hdr_data.transid[0] = rand();
	hdr_data.transid[1] = ntohl(((int)'g' << 24) + ((int)'a' << 16) + ((int)'i' << 8) + (int)'m');
	hdr_data.transid[2] = rand();
	hdr_data.transid[3] = rand();

	if(sendto(sc->fd, &hdr_data, sizeof(struct stun_header), 0,
			(struct sockaddr *)&(sc->addr),
			sizeof(struct sockaddr_in)) < (gssize)sizeof(struct stun_header)) {
		nattype.status = PURPLE_STUN_STATUS_UNKNOWN;
		nattype.lookup_time = time(NULL);
		do_callbacks();
		close_stun_conn(sc);
		return;
	}
	sc->test = 1;
	sc->packet = &hdr_data;
	sc->packetsize = sizeof(struct stun_header);
	sc->timeout = purple_timeout_add(500, (GSourceFunc) timeoutfunc, sc);
}