1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: s; c-basic-offset: 4 -*- */
3 * Authors : Patrick Patterson <ppatters@nit.ca>
4 * Scott MacLean <scott@nit.ca>
5 * William Lachance <wlach@nit.ca>
7 * Copyright 2003-2004, Net Integration Technologies, Inc.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include "wvstringlist.h"
29 #include <sys/types.h>
38 void get_evo_uri_from_eit_key(WvStringParm eit_key
, WvStringParm storage_owner
, WvString
&evo_uri
)
40 WvStringList eit_folder_keys
;
41 eit_folder_keys
.split(eit_key
, ".");
44 if (eit_folder_keys
.count() < 2)
47 WvString owner
= eit_folder_keys
.popstr();
48 if (strcmp(storage_owner
.cstr(), owner
.cstr()) != 0)
49 evo_uri
.append("/Public Folders/%s", owner
);
51 WvStringList::Iter
folder_key(eit_folder_keys
);
54 for(;folder_key
.next();)
56 evo_uri
.append("/%s", folder_key());
61 void get_physical_path_from_evo_uri(WvStringParm evo_uri
, WvString
&path
, WvString
&subfolders_path
)
66 path
.append("%s/evolution/local/", g_get_home_dir());
69 dirs
.split((evo_uri
.cstr()+1), "/");
73 path
.append(dirs
.popstr());
74 WvStringList::Iter
dir(dirs
);
79 subfolders_path
= path
;
80 subfolders_path
.append("/subfolders");
81 path
.append("/subfolders/%s", dir());
85 bool eitpath_is_local(WvStringParm path
, WvStringParm owner
)
87 return !strncmp(path
, owner
, owner
.len());
90 WvString
convert_eitpath_to_evopath(WvStringParm eitpath
, WvStringParm owner
)
92 WvLog
log("convert_eitpath_to_evopath");
94 dirs
.split(eitpath
, ".");
97 WvStringList::Iter
i(dirs
);
98 //assert(dirs.count() > 1);
100 if (dirs
.count() <= 1)
109 evopath
.append("/Public Folders/%s", i());
111 while (i
.next()) // skip folder owner
120 WvString
convert_evopath_to_eitpath(WvStringParm evopath
, WvStringParm owner
)
122 // FIXME: What to do with folder names with '.' in them?
124 dirs
.split(evopath
, "/");
126 WvString
eitpath("");
127 WvStringList::Iter
i(dirs
);
132 if (i() == "Public Folders")
138 eitpath
.append("%s.%s", owner
, i());
152 void destroy_dir(WvStringParm path
)
154 // FIXME: We might actually want to do some error checking here and warn
155 // the user if things are going badly here. These operations should never
156 // fail normally though.. and if they do, the worst that can happen is that
157 // the user won't be able to create a folder.. whopdee doo
159 DIR *dir
= opendir(path
.cstr());
160 if(dir
== NULL
) // nothing to do, can't access dir (probably 'cause it's already gone)
163 struct dirent
*current
= readdir(dir
);
166 // The following 10 lines of code are from the friendly hackers @ Ximian
168 if(current
->d_name
[0] == '.')
170 if(current
->d_name
[1] == '\0' ||
171 (current
->d_name
[1] == '.' && current
->d_name
[2] == '\0'))
173 current
= readdir(dir
);
178 WvString
full_path("%s/%s", path
, current
->d_name
);
180 stat(full_path
.cstr(), &buf
);
181 unlink(full_path
.cstr());
182 current
= readdir(dir
);
186 rmdir(path
.cstr()); // this will vonly succeed when it should