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 .write_conv
= null_write_conv
,
61 * This should initialize the UI components for all the modules. Here we
62 * just initialize the UI for conversations.
64 purple_conversations_set_ui_ops(&null_conv_uiops
);
67 static PurpleCoreUiOps null_core_uiops
=
69 .ui_init
= null_ui_init
,
75 /* Set a custom user directory (optional) */
76 purple_util_set_user_dir(CUSTOM_USER_DIRECTORY
);
78 /* We do not want any debugging for now to keep the noise to a minimum. */
79 purple_debug_set_enabled(FALSE
);
81 /* Set the core-uiops, which is used to
82 * - initialize the ui specific preferences.
83 * - initialize the debug ui.
84 * - initialize the ui components for all the modules.
85 * - uninitialize the ui components for all the modules when the core terminates.
87 purple_core_set_ui_ops(&null_core_uiops
);
89 /* Now that all the essential stuff has been set, let's try to init the core. It's
90 * necessary to provide a non-NULL name for the current ui to the core. This name
91 * is used by stuff that depends on this ui, for example the ui-specific plugins. */
92 if (!purple_core_init(UI_ID
)) {
93 /* Initializing the core failed. Terminate. */
95 "libpurple initialization failed. Dumping core.\n"
96 "Please report this!\n");
100 /* Set path to search for plugins. The core (libpurple) takes care of loading the
101 * core-plugins, which includes the in-tree protocols. So it is not essential to add
102 * any path here, but it might be desired, especially for ui-specific plugins. */
103 purple_plugins_add_search_path(CUSTOM_PLUGIN_PATH
);
104 purple_plugins_refresh();
106 /* Load the preferences. */
109 /* Load the desired plugins. The client should save the list of loaded plugins in
110 * the preferences using purple_plugins_save_loaded(PLUGIN_SAVE_PREF) */
111 purple_plugins_load_saved(PLUGIN_SAVE_PREF
);
115 signed_on(PurpleConnection
*gc
, gpointer null
)
117 PurpleAccount
*account
= purple_connection_get_account(gc
);
118 printf("Account connected: %s %s\n", purple_account_get_username(account
), purple_account_get_protocol_id(account
));
122 connect_to_signals_for_demonstration_purposes_only(void)
125 purple_signal_connect(purple_connections_get_handle(), "signed-on", &handle
,
126 PURPLE_CALLBACK(signed_on
), NULL
);
129 #if defined(_WIN32) || defined(__BIONIC__)
131 # define PASS_MAX 1024
134 getpass(const gchar
*prompt
)
136 static gchar buff
[PASS_MAX
+ 1];
139 g_fprintf(stderr
, "%s", prompt
);
142 while (i
< sizeof(buff
) - 1) {
144 buff
[i
] = getc(stdin
);
148 if (buff
[i
] == '\r' || buff
[i
] == '\n')
153 g_fprintf(stderr
, "\n");
157 #endif /* _WIN32 || __BIONIC__ */
159 int main(int argc
, char *argv
[])
164 const char *protocol
= NULL
;
167 GMainLoop
*loop
= g_main_loop_new(NULL
, FALSE
);
168 PurpleAccount
*account
;
169 PurpleSavedStatus
*status
;
173 /* libpurple's built-in DNS resolution forks processes to perform
174 * blocking lookups without blocking the main process. It does not
175 * handle SIGCHLD itself, so if the UI does not you quickly get an army
176 * of zombie subprocesses marching around.
178 signal(SIGCHLD
, SIG_IGN
);
183 printf("libpurple initialized.\n");
185 list
= purple_protocols_get_all();
186 for (i
= 0, iter
= list
; iter
; iter
= iter
->next
) {
187 PurpleProtocol
*protocol
= iter
->data
;
188 if (protocol
&& purple_protocol_get_name(protocol
)) {
189 printf("\t%d: %s\n", i
++, purple_protocol_get_name(protocol
));
190 names
= g_list_append(names
, (gpointer
)purple_protocol_get_id(protocol
));
196 while (num
< 0 || num
>= i
) {
197 printf("Select the protocol [0-%d]: ", i
- 1);
198 res
= fgets(name
, sizeof(name
), stdin
);
200 fprintf(stderr
, "Failed to get protocol selection.");
203 if (sscanf(name
, "%d", &num
) != 1) {
207 protocol
= g_list_nth_data(names
, num
);
209 fprintf(stderr
, "Failed to get protocol.");
213 printf("Username: ");
214 res
= fgets(name
, sizeof(name
), stdin
);
216 fprintf(stderr
, "Failed to read user name.");
219 name
[strlen(name
) - 1] = 0; /* strip the \n at the end */
221 /* Create the account */
222 account
= purple_account_new(name
, protocol
);
224 /* Get the password for the account */
225 password
= getpass("Password: ");
226 purple_account_set_password(account
, password
, NULL
, NULL
);
228 /* It's necessary to enable the account first. */
229 purple_account_set_enabled(account
, UI_ID
, TRUE
);
231 /* Now, to connect the account(s), create a status and activate it. */
232 status
= purple_savedstatus_new(NULL
, PURPLE_STATUS_AVAILABLE
);
233 purple_savedstatus_activate(status
);
235 connect_to_signals_for_demonstration_purposes_only();
237 g_main_loop_run(loop
);