4 * Pidgin is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #include <glib/gprintf.h>
39 /*** Conversation uiops ***/
41 null_write_conv(PurpleConversation
*conv
, PurpleMessage
*msg
)
43 time_t mtime
= purple_message_get_time(msg
);
45 printf("(%s) %s %s: %s\n",
46 purple_conversation_get_name(conv
),
47 purple_utf8_strftime("(%H:%M:%S)", localtime(&mtime
)),
48 purple_message_get_author_alias(msg
),
49 purple_message_get_contents(msg
));
52 static PurpleConversationUiOps null_conv_uiops
=
54 NULL
, /* create_conversation */
55 NULL
, /* destroy_conversation */
56 NULL
, /* write_chat */
58 null_write_conv
, /* write_conv */
59 NULL
, /* chat_add_users */
60 NULL
, /* chat_rename_user */
61 NULL
, /* chat_remove_users */
62 NULL
, /* chat_update_user */
65 NULL
, /* send_confirm */
76 * This should initialize the UI components for all the modules. Here we
77 * just initialize the UI for conversations.
79 purple_conversations_set_ui_ops(&null_conv_uiops
);
82 static PurpleCoreUiOps null_core_uiops
=
100 /* Set a custom user directory (optional) */
101 purple_util_set_user_dir(CUSTOM_USER_DIRECTORY
);
103 /* We do not want any debugging for now to keep the noise to a minimum. */
104 purple_debug_set_enabled(FALSE
);
106 /* Set the core-uiops, which is used to
107 * - initialize the ui specific preferences.
108 * - initialize the debug ui.
109 * - initialize the ui components for all the modules.
110 * - uninitialize the ui components for all the modules when the core terminates.
112 purple_core_set_ui_ops(&null_core_uiops
);
114 /* Now that all the essential stuff has been set, let's try to init the core. It's
115 * necessary to provide a non-NULL name for the current ui to the core. This name
116 * is used by stuff that depends on this ui, for example the ui-specific plugins. */
117 if (!purple_core_init(UI_ID
)) {
118 /* Initializing the core failed. Terminate. */
120 "libpurple initialization failed. Dumping core.\n"
121 "Please report this!\n");
125 /* Set path to search for plugins. The core (libpurple) takes care of loading the
126 * core-plugins, which includes the in-tree protocols. So it is not essential to add
127 * any path here, but it might be desired, especially for ui-specific plugins. */
128 purple_plugins_add_search_path(CUSTOM_PLUGIN_PATH
);
129 purple_plugins_refresh();
131 /* Load the preferences. */
134 /* Load the desired plugins. The client should save the list of loaded plugins in
135 * the preferences using purple_plugins_save_loaded(PLUGIN_SAVE_PREF) */
136 purple_plugins_load_saved(PLUGIN_SAVE_PREF
);
140 signed_on(PurpleConnection
*gc
, gpointer null
)
142 PurpleAccount
*account
= purple_connection_get_account(gc
);
143 printf("Account connected: %s %s\n", purple_account_get_username(account
), purple_account_get_protocol_id(account
));
147 connect_to_signals_for_demonstration_purposes_only(void)
150 purple_signal_connect(purple_connections_get_handle(), "signed-on", &handle
,
151 PURPLE_CALLBACK(signed_on
), NULL
);
154 #if defined(_WIN32) || defined(__BIONIC__)
156 # define PASS_MAX 1024
159 getpass(const gchar
*prompt
)
161 static gchar buff
[PASS_MAX
+ 1];
164 g_fprintf(stderr
, "%s", prompt
);
167 while (i
< sizeof(buff
) - 1) {
169 buff
[i
] = getc(stdin
);
173 if (buff
[i
] == '\r' || buff
[i
] == '\n')
178 g_fprintf(stderr
, "\n");
182 #endif /* _WIN32 || __BIONIC__ */
184 int main(int argc
, char *argv
[])
189 const char *protocol
= NULL
;
192 GMainLoop
*loop
= g_main_loop_new(NULL
, FALSE
);
193 PurpleAccount
*account
;
194 PurpleSavedStatus
*status
;
198 /* libpurple's built-in DNS resolution forks processes to perform
199 * blocking lookups without blocking the main process. It does not
200 * handle SIGCHLD itself, so if the UI does not you quickly get an army
201 * of zombie subprocesses marching around.
203 signal(SIGCHLD
, SIG_IGN
);
208 printf("libpurple initialized.\n");
210 list
= purple_protocols_get_all();
211 for (i
= 0, iter
= list
; iter
; iter
= iter
->next
) {
212 PurpleProtocol
*protocol
= iter
->data
;
213 if (protocol
&& purple_protocol_get_name(protocol
)) {
214 printf("\t%d: %s\n", i
++, purple_protocol_get_name(protocol
));
215 names
= g_list_append(names
, (gpointer
)purple_protocol_get_id(protocol
));
220 printf("Select the protocol [0-%d]: ", i
-1);
221 res
= fgets(name
, sizeof(name
), stdin
);
223 fprintf(stderr
, "Failed to gets protocol selection.");
226 if (sscanf(name
, "%d", &num
) == 1)
227 protocol
= g_list_nth_data(names
, num
);
229 fprintf(stderr
, "Failed to gets protocol.");
233 printf("Username: ");
234 res
= fgets(name
, sizeof(name
), stdin
);
236 fprintf(stderr
, "Failed to read user name.");
239 name
[strlen(name
) - 1] = 0; /* strip the \n at the end */
241 /* Create the account */
242 account
= purple_account_new(name
, protocol
);
244 /* Get the password for the account */
245 password
= getpass("Password: ");
246 purple_account_set_password(account
, password
, NULL
, NULL
);
248 /* It's necessary to enable the account first. */
249 purple_account_set_enabled(account
, UI_ID
, TRUE
);
251 /* Now, to connect the account(s), create a status and activate it. */
252 status
= purple_savedstatus_new(NULL
, PURPLE_STATUS_AVAILABLE
);
253 purple_savedstatus_activate(status
);
255 connect_to_signals_for_demonstration_purposes_only();
257 g_main_loop_run(loop
);