| 38 static GList *connections_connecting = NULL; |
39 static GList *connections_connecting = NULL; |
| 39 static GaimConnectionUiOps *connection_ui_ops = NULL; |
40 static GaimConnectionUiOps *connection_ui_ops = NULL; |
| 40 |
41 |
| 41 static int connections_handle; |
42 static int connections_handle; |
| 42 |
43 |
| 43 GaimConnection * |
44 void |
| 44 gaim_connection_new(GaimAccount *account) |
45 gaim_connection_new(GaimAccount *account, gboolean regist, const char *password) |
| 45 { |
46 { |
| 46 GaimConnection *gc; |
47 GaimConnection *gc; |
| 47 |
48 GaimPlugin *prpl; |
| 48 g_return_val_if_fail(account != NULL, NULL); |
49 GaimPluginProtocolInfo *prpl_info; |
| |
50 |
| |
51 g_return_if_fail(account != NULL); |
| |
52 |
| |
53 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
| |
54 |
| |
55 if (prpl != NULL) |
| |
56 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
| |
57 else { |
| |
58 gchar *message; |
| |
59 |
| |
60 message = g_strdup_printf(_("Missing protocol plugin for %s"), |
| |
61 gaim_account_get_username(account)); |
| |
62 gaim_notify_error(NULL, regist ? _("Registration Error") : |
| |
63 _("Connection Error"), message, NULL); |
| |
64 g_free(message); |
| |
65 return; |
| |
66 } |
| |
67 |
| |
68 if (regist) |
| |
69 { |
| |
70 if (prpl_info->register_user == NULL) |
| |
71 return; |
| |
72 } |
| |
73 else |
| |
74 { |
| |
75 if ((password == NULL) && |
| |
76 !(prpl_info->options & OPT_PROTO_NO_PASSWORD) && |
| |
77 !(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL)) |
| |
78 { |
| |
79 gaim_debug_error("connection", "Can not connect to account %s without " |
| |
80 "a password.\n", gaim_account_get_username(account)); |
| |
81 return; |
| |
82 } |
| |
83 } |
| 49 |
84 |
| 50 gc = g_new0(GaimConnection, 1); |
85 gc = g_new0(GaimConnection, 1); |
| 51 |
86 gc->prpl = prpl; |
| 52 gc->prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
87 gc->password = g_strdup(password); |
| 53 |
|
| 54 gaim_connection_set_account(gc, account); |
88 gaim_connection_set_account(gc, account); |
| |
89 gaim_connection_set_state(gc, GAIM_CONNECTING); |
| |
90 connections = g_list_append(connections, gc); |
| 55 gaim_account_set_connection(account, gc); |
91 gaim_account_set_connection(account, gc); |
| 56 |
92 |
| 57 return gc; |
93 gaim_signal_emit(gaim_connections_get_handle(), "signing-on", gc); |
| |
94 |
| |
95 if (regist) |
| |
96 { |
| |
97 gaim_debug_info("connection", "Registering. gc = %p\n", gc); |
| |
98 |
| |
99 /* set this so we don't auto-reconnect after registering */ |
| |
100 gc->wants_to_die = TRUE; |
| |
101 |
| |
102 prpl_info->register_user(account); |
| |
103 } |
| |
104 else |
| |
105 { |
| |
106 gaim_debug_info("connection", "Connecting. gc = %p\n", gc); |
| |
107 |
| |
108 gaim_signal_emit(gaim_accounts_get_handle(), "account-connecting", account); |
| |
109 prpl_info->login(account, gaim_account_get_active_status(account)); |
| |
110 } |
| 58 } |
111 } |
| 59 |
112 |
| 60 void |
113 void |
| 61 gaim_connection_destroy(GaimConnection *gc) |
114 gaim_connection_destroy(GaimConnection *gc) |
| 62 { |
115 { |
| 73 gaim_debug_info("connection", "Destroying connection %p\n", gc); |
126 gaim_debug_info("connection", "Destroying connection %p\n", gc); |
| 74 |
127 |
| 75 account = gaim_connection_get_account(gc); |
128 account = gaim_connection_get_account(gc); |
| 76 gaim_account_set_connection(account, NULL); |
129 gaim_account_set_connection(account, NULL); |
| 77 |
130 |
| |
131 if (gc->password != NULL) |
| |
132 g_free(gc->password); |
| |
133 |
| 78 if (gc->display_name != NULL) |
134 if (gc->display_name != NULL) |
| 79 g_free(gc->display_name); |
135 g_free(gc->display_name); |
| 80 |
136 |
| 81 if (gc->disconnect_timeout) |
137 if (gc->disconnect_timeout) |
| 82 gaim_timeout_remove(gc->disconnect_timeout); |
138 gaim_timeout_remove(gc->disconnect_timeout); |
| 83 |
139 |
| 84 g_free(gc); |
140 g_free(gc); |
| 85 } |
|
| 86 |
|
| 87 static void |
|
| 88 request_pass_ok_cb(GaimAccount *account, const char *entry) |
|
| 89 { |
|
| 90 gaim_account_set_password(account, (*entry != '\0') ? entry : NULL); |
|
| 91 |
|
| 92 gaim_account_connect(account); |
|
| 93 } |
|
| 94 |
|
| 95 void |
|
| 96 gaim_connection_register(GaimConnection *gc) |
|
| 97 { |
|
| 98 GaimAccount *account; |
|
| 99 GaimConnectionUiOps *ops; |
|
| 100 GaimPluginProtocolInfo *prpl_info = NULL; |
|
| 101 |
|
| 102 g_return_if_fail(gc != NULL); |
|
| 103 |
|
| 104 gaim_debug_info("connection", "Registering. gc = %p\n", gc); |
|
| 105 |
|
| 106 ops = gaim_connections_get_ui_ops(); |
|
| 107 |
|
| 108 if (gc->prpl != NULL) |
|
| 109 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); |
|
| 110 else |
|
| 111 { |
|
| 112 gchar *message = g_strdup_printf(_("Missing protocol plugin for %s"), |
|
| 113 gaim_account_get_username(gaim_connection_get_account(gc))); |
|
| 114 |
|
| 115 gaim_debug_error("connection", "Could not get prpl info for %p\n", gc); |
|
| 116 gaim_notify_error(NULL, _("Registration Error"), |
|
| 117 message, NULL); |
|
| 118 g_free(message); |
|
| 119 return; |
|
| 120 } |
|
| 121 |
|
| 122 if (prpl_info->register_user == NULL) |
|
| 123 return; |
|
| 124 |
|
| 125 account = gaim_connection_get_account(gc); |
|
| 126 |
|
| 127 if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) |
|
| 128 return; |
|
| 129 |
|
| 130 gaim_connection_set_state(gc, GAIM_CONNECTING); |
|
| 131 |
|
| 132 connections = g_list_append(connections, gc); |
|
| 133 |
|
| 134 gaim_signal_emit(gaim_connections_get_handle(), "signing-on", gc); |
|
| 135 |
|
| 136 /* set this so we don't auto-reconnect after registering */ |
|
| 137 gc->wants_to_die = TRUE; |
|
| 138 |
|
| 139 gaim_debug_info("connection", "Calling register_user\n"); |
|
| 140 |
|
| 141 prpl_info->register_user(account); |
|
| 142 } |
|
| 143 |
|
| 144 |
|
| 145 void |
|
| 146 gaim_connection_connect(GaimConnection *gc) |
|
| 147 { |
|
| 148 GaimAccount *account; |
|
| 149 GaimPluginProtocolInfo *prpl_info = NULL; |
|
| 150 GaimStatus *status; |
|
| 151 |
|
| 152 g_return_if_fail(gc != NULL); |
|
| 153 |
|
| 154 gaim_debug_info("connection", "Connecting. gc = %p\n", gc); |
|
| 155 |
|
| 156 if (gc->prpl != NULL) |
|
| 157 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); |
|
| 158 else { |
|
| 159 gchar *message = g_strdup_printf(_("Missing protocol plugin for %s"), |
|
| 160 gaim_account_get_username(gaim_connection_get_account(gc))); |
|
| 161 |
|
| 162 gaim_debug_error("connection", "Could not get prpl info for %p\n", gc); |
|
| 163 gaim_notify_error(NULL, _("Connection Error"), message, NULL); |
|
| 164 g_free(message); |
|
| 165 return; |
|
| 166 } |
|
| 167 |
|
| 168 account = gaim_connection_get_account(gc); |
|
| 169 |
|
| 170 if (gaim_connection_get_state(gc) != GAIM_DISCONNECTED) |
|
| 171 return; |
|
| 172 |
|
| 173 if (!(prpl_info->options & OPT_PROTO_NO_PASSWORD) && |
|
| 174 !(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL) && |
|
| 175 gaim_account_get_password(account) == NULL) { |
|
| 176 gchar *primary; |
|
| 177 gchar *escaped; |
|
| 178 const gchar *username = gaim_account_get_username(account); |
|
| 179 |
|
| 180 gaim_debug_info("connection", "Requesting password\n"); |
|
| 181 gaim_connection_destroy(gc); |
|
| 182 escaped = g_markup_escape_text(username, strlen(username)); |
|
| 183 primary = g_strdup_printf(_("Enter password for %s (%s)"), escaped, |
|
| 184 gaim_account_get_protocol_name(account)); |
|
| 185 gaim_request_input(gc, _("Enter Password"), primary, NULL, NULL, |
|
| 186 FALSE, TRUE, NULL, |
|
| 187 _("OK"), G_CALLBACK(request_pass_ok_cb), |
|
| 188 _("Cancel"), NULL, account); |
|
| 189 g_free(primary); |
|
| 190 g_free(escaped); |
|
| 191 |
|
| 192 return; |
|
| 193 } |
|
| 194 |
|
| 195 gaim_connection_set_state(gc, GAIM_CONNECTING); |
|
| 196 |
|
| 197 connections = g_list_append(connections, gc); |
|
| 198 |
|
| 199 gaim_signal_emit(gaim_connections_get_handle(), "signing-on", gc); |
|
| 200 |
|
| 201 gaim_debug_info("connection", "Calling serv_login\n"); |
|
| 202 |
|
| 203 status = gaim_account_get_active_status(account); |
|
| 204 serv_login(account, status); |
|
| 205 } |
141 } |
| 206 |
142 |
| 207 void |
143 void |
| 208 gaim_connection_disconnect(GaimConnection *gc) |
144 gaim_connection_disconnect(GaimConnection *gc) |
| 209 { |
145 { |