1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
11 #include "liblj/livejournal.h"
19 #define PATH_BUF_SIZE (1024)
26 JamHost
*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 gboolean
conf_verify_dir (void) {
38 return verify_dir(app
.conf_dir
, NULL
);
42 void conf_verify_a_host_exists (void) {
43 if (conf
.hosts
== NULL
) {
44 /* make a default host. */
45 LJServer
*s
= lj_server_new("http://lj.rossia.org");
46 JamHost
*host
= (JamHost
*) jam_host_lj_new(s
);
47 host
->name
= g_strdup("LJ.Rossia.Org");
48 conf
.hosts
= g_slist_append(conf
.hosts
, host
);
53 void conf_make_path (const char *file
, char *buf
, size_t bufsz
) {
54 char *path
= g_build_filename(app
.conf_dir
, file
, NULL
);
55 snprintf(buf
, bufsz
, "%s", path
);
60 char *conf_make_account_path (JamAccount
*acc
, const char *path
) {
62 return g_build_filename(app
.conf_dir
, "servers", jam_account_get_host(acc
)->name
, "users", jam_account_get_username(acc
), (path
? path
: ""), NULL
);
66 gboolean
conf_rename_host (JamHost
*host
, const char *newname
, GError
**err
) {
67 char *oldpath
, *newpath
;
77 if (newname
[0] == 0 || (newname
[0] == '.' && (newname
[1] == '.' || newname
[1] == '/' || newname
[1] == 0)) || newname
[0] == '/') {
78 g_set_error(err
, 0, 0, "%s", _("new host name is invalid"));
81 oldpath
= g_build_filename(app
.conf_dir
, "servers", host
->name
, NULL
);
82 if (!g_file_test(oldpath
, G_FILE_TEST_EXISTS
)) {
83 string_replace(&host
->name
, g_strdup(newname
));
87 newpath
= g_build_filename(app
.conf_dir
, "servers", newname
, NULL
);
88 if (rename(oldpath
, newpath
) < 0) {
89 g_set_error(err
, G_FILE_ERROR
, g_file_error_from_errno(errno
), _("renaming '%s' to '%s': %s"), oldpath
, newpath
, g_strerror(errno
));
94 string_replace(&host
->name
, g_strdup(newname
));