1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
14 #include "liblj/livejournal.h"
23 #define PATH_BUF_SIZE 1024
26 conf_host_by_name(Configuration
*c
, const char *hostname
) {
28 for (l
= c
->hosts
; l
!= NULL
; l
= l
->next
) {
29 if (strcmp(hostname
, ((JamHost
*)l
->data
)->name
) == 0) {
37 conf_verify_dir(void) {
38 return verify_dir(app
.conf_dir
, NULL
);
42 conf_verify_a_host_exists() {
43 if (conf
.hosts
== NULL
) {
44 /* make a default host. */
45 LJServer
*s
= lj_server_new("http://www.livejournal.com");
46 JamHost
*host
= (JamHost
*)jam_host_lj_new(s
);
47 host
->name
= g_strdup("LiveJournal.com");
48 conf
.hosts
= g_slist_append(conf
.hosts
, host
);
53 conf_make_path(char *file
, char *buf
, int len
) {
55 path
= g_build_filename(app
.conf_dir
, file
, NULL
);
56 strncpy(buf
, path
, len
);
61 conf_make_account_path(JamAccount
*acc
, const char *path
) {
62 return g_build_filename(app
.conf_dir
,
63 "servers", jam_account_get_host(acc
)->name
,
64 "users", jam_account_get_username(acc
),
70 conf_rename_host(JamHost
*host
, const char *newname
, GError
**err
) {
71 char *oldpath
, *newpath
;
82 if ((newname
[0] == 0) ||
84 (newname
[1] == '.' || newname
[1] == '/' || newname
[1] == 0)) ||
85 (newname
[0] == '/')) {
86 g_set_error(err
, 0, 0, _("new host name is invalid"));
89 oldpath
= g_build_filename(app
.conf_dir
, "servers", host
->name
, NULL
);
90 if (!g_file_test(oldpath
, G_FILE_TEST_EXISTS
)) {
91 string_replace(&host
->name
, g_strdup(newname
));
95 newpath
= g_build_filename(app
.conf_dir
, "servers", newname
, NULL
);
96 if (rename(oldpath
, newpath
) < 0) {
97 g_set_error(err
, G_FILE_ERROR
, g_file_error_from_errno(errno
),
98 _("renaming '%s' to '%s': %s"), oldpath
, newpath
,
104 string_replace(&host
->name
, g_strdup(newname
));