loudmouth/lm-connection.c
changeset 248 09a3e0e55ab8
parent 247 a519eff901e6
child 249 2cca5ec7b573
equal deleted inserted replaced
247:a519eff901e6 248:09a3e0e55ab8
   152 static void      connection_incoming_data        (LmSocket        *socket, 
   152 static void      connection_incoming_data        (LmSocket        *socket, 
   153 						  const gchar     *buf,
   153 						  const gchar     *buf,
   154 						  LmConnection    *connection);
   154 						  LmConnection    *connection);
   155 static gboolean  connection_get_server_from_jid  (const gchar     *jid,
   155 static gboolean  connection_get_server_from_jid  (const gchar     *jid,
   156 						  gchar          **server);
   156 						  gchar          **server);
       
   157 static void      connection_send_stream_header   (LmConnection    *connection);
   157 
   158 
   158 static void
   159 static void
   159 connection_free (LmConnection *connection)
   160 connection_free (LmConnection *connection)
   160 {
   161 {
   161 	int        i;
   162 	int        i;
   768 	} 
   769 	} 
   769 	
   770 	
   770 	return FALSE;
   771 	return FALSE;
   771 }
   772 }
   772 
   773 
       
   774 static void
       
   775 connection_send_stream_header (LmConnection *connection)
       
   776 {
       
   777 	LmMessage *m;
       
   778 	gchar     *server_from_jid;
       
   779 
       
   780 	lm_verbose ("Sending stream header\n");
       
   781 
       
   782 	if (!connection_get_server_from_jid (connection->jid, &server_from_jid)) {
       
   783 		server_from_jid = g_strdup (connection->server);
       
   784 	}
       
   785 
       
   786 	m = lm_message_new (server_from_jid, LM_MESSAGE_TYPE_STREAM);
       
   787 	lm_message_node_set_attributes (m->node,
       
   788 					"xmlns:stream", 
       
   789 					"http://etherx.jabber.org/streams",
       
   790 					"xmlns", "jabber:client",
       
   791 					"version", "1.0",
       
   792 					NULL);
       
   793 	
       
   794 	g_free (server_from_jid);
       
   795 
       
   796 	if (!lm_connection_send (connection, m, NULL)) {
       
   797 		lm_verbose ("Failed to send stream information\n");
       
   798 		_lm_connection_do_close (connection);
       
   799 	}
       
   800 		
       
   801 	lm_message_unref (m);
       
   802 }
       
   803 
   773 void 
   804 void 
   774 _lm_connection_socket_result (LmConnection *connection, gboolean result)
   805 _lm_connection_socket_result (LmConnection *connection, gboolean result)
   775 {
   806 {
   776 	LmMessage *m;
       
   777 	gchar     *server_from_jid;
       
   778 
       
   779 	if (!result) {
   807 	if (!result) {
   780 		_lm_connection_do_close (connection);
   808 		_lm_connection_do_close (connection);
   781 
   809 
   782 		if (connection->open_cb) {
   810 		if (connection->open_cb) {
   783 			LmCallback *cb = connection->open_cb;
   811 			LmCallback *cb = connection->open_cb;
   801 		_lm_connection_do_close (connection);
   829 		_lm_connection_do_close (connection);
   802 
   830 
   803 		return;
   831 		return;
   804 	}
   832 	}
   805 
   833 
   806 	if (!connection_get_server_from_jid (connection->jid, &server_from_jid)) {
   834 	connection_send_stream_header (connection);
   807 		server_from_jid = g_strdup (connection->server);
       
   808 	}
       
   809 
       
   810 	m = lm_message_new (server_from_jid, LM_MESSAGE_TYPE_STREAM);
       
   811 	lm_message_node_set_attributes (m->node,
       
   812 					"xmlns:stream", 
       
   813 					"http://etherx.jabber.org/streams",
       
   814 					"xmlns", "jabber:client",
       
   815 					"version", "1.0",
       
   816 					NULL);
       
   817 	
       
   818 	g_free (server_from_jid);
       
   819 	lm_verbose ("Opening stream...");
       
   820 
       
   821 	if (!lm_connection_send (connection, m, NULL)) {
       
   822 		lm_verbose ("Failed to send stream information\n");
       
   823 		_lm_connection_do_close (connection);
       
   824 	}
       
   825 		
       
   826 	lm_message_unref (m);
       
   827 }
   835 }
   828 
   836 
   829 gboolean 
   837 gboolean 
   830 _lm_connection_async_connect_waiting (LmConnection *connection)
   838 _lm_connection_async_connect_waiting (LmConnection *connection)
   831 {
   839 {
  1181 connection_sasl_auth_finished (LmSASL *sasl,
  1189 connection_sasl_auth_finished (LmSASL *sasl,
  1182 			       LmConnection *connection,
  1190 			       LmConnection *connection,
  1183 			       gboolean success,
  1191 			       gboolean success,
  1184 			       const gchar *reason)
  1192 			       const gchar *reason)
  1185 {
  1193 {
  1186 	gchar     *server_from_jid;
       
  1187 	LmMessage *m;
       
  1188 
       
  1189 	if (!success) {
  1194 	if (!success) {
  1190 		lm_verbose ("SASL authentication failed, closing connection\n");
  1195 		lm_verbose ("SASL authentication failed, closing connection\n");
  1191 		connection_call_auth_cb (connection, FALSE);
  1196 		connection_call_auth_cb (connection, FALSE);
  1192 		return;
  1197 		return;
  1193 	}
  1198 	}
  1194 
  1199 
  1195 	if (!connection_get_server_from_jid (connection->jid, &server_from_jid)) {
  1200 	connection_send_stream_header (connection);
  1196 		server_from_jid = g_strdup (connection->server);
       
  1197 	}
       
  1198 
       
  1199 	m = lm_message_new (server_from_jid, LM_MESSAGE_TYPE_STREAM);
       
  1200 	lm_message_node_set_attributes (m->node,
       
  1201 					"xmlns:stream", 
       
  1202 					"http://etherx.jabber.org/streams",
       
  1203 					"xmlns", "jabber:client",
       
  1204 					"version", "1.0",
       
  1205 					NULL);
       
  1206 
       
  1207 	g_free (server_from_jid);
       
  1208 
       
  1209 	lm_verbose ("Reopening XMPP 1.0 stream...");
       
  1210 
       
  1211 	if (!lm_connection_send (connection, m, NULL)) {
       
  1212 		lm_verbose ("Failed to send stream information\n");
       
  1213 		_lm_connection_do_close (connection);
       
  1214 	}
       
  1215 		
       
  1216 	lm_message_unref (m);
       
  1217 }
  1201 }
  1218 
  1202 
  1219 /**
  1203 /**
  1220  * lm_connection_authenticate:
  1204  * lm_connection_authenticate:
  1221  * @connection: #LmConnection to authenticate.
  1205  * @connection: #LmConnection to authenticate.