static void rssyl_get_last_num(Folder *folder, FolderItem *item)
{
gchar *path;
- DIR *dp;
- struct dirent *d;
+ const char *f;
+ GDir *dp;
+ GError *error = NULL;
gint max = 0;
gint num;
path = folder_item_get_path(item);
g_return_if_fail(path != NULL);
- if( (dp = opendir(path)) == NULL ) {
- FILE_OP_ERROR(item->path, "opendir");
+ if( (dp = g_dir_open(path, 0, &error)) == NULL ) {
+ FILE_OP_ERROR(item->path, "g_dir_open");
+ debug_print("g_dir_open() failed on \"%s\", error %d (%s).\n",
+ path, error->code, error->message);
+ g_error_free(error);
g_free(path);
return;
}
g_free(path);
- while( (d = readdir(dp)) != NULL ) {
- if( (num = to_number(d->d_name)) > 0 && dirent_is_regular_file(d) ) {
+ while( (f = g_dir_read_name(dp)) != NULL) {
+ if ((num = to_number(f)) > 0 &&
+ g_file_test(f, G_FILE_TEST_IS_REGULAR)) {
if( max < num )
max = num;
}
}
- closedir(dp);
+ g_dir_close(dp);
debug_print("Last number in dir %s = %d\n", item->path, max);
item->last_num = max;
g_free(ritem->url);
ritem->url = g_strdup(attr->value);
}
+ /* (int) URL auth */
+ if (!strcmp(attr->name, "auth")) {
+ ritem->auth->type = atoi(attr->value);
+ }
+ /* (str) Auth user */
+ if (!strcmp(attr->name, "auth_user")) {
+ g_free(ritem->auth->username);
+ ritem->auth->username = g_strdup(attr->value);
+ }
+ /* (str) Auth pass */
+ if (!strcmp(attr->name, "auth_pass")) {
+ gsize len = 0;
+ guchar *pwd = g_base64_decode(attr->value, &len);
+ g_free(ritem->auth->password);
+ ritem->auth->password = (gchar *)pwd;
+ }
/* (str) Official title */
if( !strcmp(attr->name, "official_title")) {
g_free(ritem->official_title);
/* (str) URL */
if( ri->url != NULL )
xml_tag_add_attr(tag, xml_attr_new("uri", ri->url));
+ /* (int) Auth */
+ tmp = g_strdup_printf("%d", ri->auth->type);
+ xml_tag_add_attr(tag, xml_attr_new("auth", tmp));
+ g_free(tmp);
+ /* (str) Auth user */
+ if (ri->auth->username != NULL)
+ xml_tag_add_attr(tag, xml_attr_new("auth_user", ri->auth->username));
+ /* (str) Auth pass */
+ if (ri->auth->password != NULL) {
+ gchar *pwd = g_base64_encode(ri->auth->password, strlen(ri->auth->password));
+ xml_tag_add_attr(tag, xml_attr_new("auth_pass", pwd));
+ g_free(pwd);
+ }
/* (str) Official title */
if( ri->official_title != NULL )
xml_tag_add_attr(tag, xml_attr_new("official_title", ri->official_title));
RFolderItem *ritem = g_new0(RFolderItem, 1);
ritem->url = NULL;
+ ritem->auth = g_new0(FeedAuth, 1);
+ ritem->auth->type = FEED_AUTH_NONE;
+ ritem->auth->username = NULL;
+ ritem->auth->password = NULL;
ritem->official_title = NULL;
ritem->source_id = NULL;
ritem->items = NULL;
g_return_if_fail(ritem != NULL);
g_free(ritem->url);
+ if (ritem->auth->username)
+ g_free(ritem->auth->username);
+ if (ritem->auth->password)
+ g_free(ritem->auth->password);
+ g_free(ritem->auth);
g_free(ritem->official_title);
g_slist_free(ritem->items);
MsgNumberList **list, gboolean *old_uids_valid)
{
gchar *path;
- DIR *dp;
- struct dirent *d;
+ GDir *dp;
+ const gchar *d;
+ GError *error = NULL;
gint num, nummsgs = 0;
g_return_val_if_fail(item != NULL, -1);
path = folder_item_get_path(item);
g_return_val_if_fail(path != NULL, -1);
- if( (dp = opendir(path)) == NULL ) {
- FILE_OP_ERROR(item->path, "opendir");
+ if( (dp = g_dir_open(path, 0, &error)) == NULL ) {
+ debug_print("g_dir_open() failed on \"%s\", error %d (%s).\n",
+ path, error->code, error->message);
+ g_error_free(error);
g_free(path);
return -1;
}
g_free(path);
- while( (d = readdir(dp)) != NULL ) {
- if( (num = to_number(d->d_name)) > 0 ) {
+ while( (d = g_dir_read_name(dp)) != NULL ) {
+ if( (num = to_number(d)) > 0 ) {
*list = g_slist_prepend(*list, GINT_TO_POINTER(num));
nummsgs++;
}
}
-
- closedir(dp);
+ g_dir_close(dp);
debug_print("RSSyl: get_num_list: returning %d\n", nummsgs);
return nummsgs;
}
-static gboolean rssyl_scan_required(Folder *folder, FolderItem *item)
+static gboolean rssyl_is_msg_changed(Folder *folder, FolderItem *item,
+ MsgInfo *msginfo)
{
- return TRUE;
+ GStatBuf s;
+ gchar *path = NULL;
+ gchar *itempath = NULL;
+
+ g_return_val_if_fail(folder != NULL, FALSE);
+ g_return_val_if_fail(item != NULL, FALSE);
+ g_return_val_if_fail(msginfo != NULL, FALSE);
+
+ itempath = folder_item_get_path(item);
+ path = g_strconcat(itempath, G_DIR_SEPARATOR_S, itos(msginfo->msgnum), NULL);
+ g_free(itempath);
+
+ if (g_stat(path, &s) < 0 ||
+ msginfo->size != s.st_size || (
+ (msginfo->mtime - s.st_mtime != 0) &&
+ (msginfo->mtime - s.st_mtime != 3600) &&
+ (msginfo->mtime - s.st_mtime != -3600))) {
+ g_free(path);
+ return TRUE;
+ }
+
+ g_free(path);
+ return FALSE;
}
static gchar *rssyl_fetch_msg(Folder *folder, FolderItem *item, gint num)
g_return_val_if_fail(destfile != NULL, -1);
debug_print("RSSyl: add_msgs: new filename is '%s'\n", destfile);
- if( link(fileinfo->file, destfile) < 0 ) {
- if( copy_file(fileinfo->file, destfile, TRUE) < 0 ) {
- g_warning("can't copy message %s to %s\n", fileinfo->file, destfile);
- g_free(destfile);
- return -1;
- }
+ if( copy_file(fileinfo->file, destfile, TRUE) < 0 ) {
+ g_warning("can't copy message %s to %s\n", fileinfo->file, destfile);
+ g_free(destfile);
+ return -1;
}
if( relation != NULL )
file = rssyl_fetch_msg(folder, item, num);
g_return_val_if_fail(file != NULL, -1);
- need_scan = rssyl_scan_required(folder, item);
+ need_scan = mh_get_class()->scan_required(folder, item);
/* are we doing a folder move ? */
tmp = g_strdup_printf("%s.tmp", file);
static void rssyl_copy_private_data(Folder *folder, FolderItem *oldi,
FolderItem *newi)
{
- gchar *dpathold;
-/* gchar *dpathnew;*/
+ gchar *dpathold, *dpathnew;
RFolderItem *olditem = (RFolderItem *)oldi,
*newitem = (RFolderItem *)newi;
newitem->url = g_strdup(olditem->url);
}
+ if (olditem->auth != NULL) {
+ if (newitem->auth != NULL) {
+ if (newitem->auth->username != NULL) {
+ g_free(newitem->auth->username);
+ newitem->auth->username = NULL;
+ }
+ if (newitem->auth->password != NULL) {
+ g_free(newitem->auth->password);
+ newitem->auth->password = NULL;
+ }
+ g_free(newitem->auth);
+ }
+ newitem->auth = g_new0(FeedAuth, 1);
+ newitem->auth->type = olditem->auth->type;
+ if (olditem->auth->username != NULL)
+ newitem->auth->username = g_strdup(olditem->auth->username);
+ if (olditem->auth->password != NULL)
+ newitem->auth->password = g_strdup(olditem->auth->password);
+ }
+
if (olditem->official_title != NULL) {
g_free(newitem->official_title);
newitem->official_title = g_strdup(olditem->official_title);
dpathold = g_strconcat(rssyl_item_get_path(oldi->folder, oldi),
G_DIR_SEPARATOR_S, RSSYL_DELETED_FILE, NULL);
- if (is_file_exist(dpathold)) {
-/* dpathnew = g_strconcat(rssyl_item_get_path(newi->folder, newi),
- G_DIR_SEPARATOR_S, RSSYL_DELETED_FILE, NULL);
- move_file(dpathold, dpathnew, TRUE);
- g_free(dpathnew);*/
- g_remove(dpathold);
- }
+ dpathnew = g_strconcat(rssyl_item_get_path(newi->folder, newi),
+ G_DIR_SEPARATOR_S, RSSYL_DELETED_FILE, NULL);
+ move_file(dpathold, dpathnew, TRUE);
g_free(dpathold);
+ g_free(dpathnew);
}
rssyl_class.rename_folder = rssyl_rename_folder;
rssyl_class.remove_folder = rssyl_remove_folder;
rssyl_class.get_num_list = rssyl_get_num_list;
- rssyl_class.scan_required = rssyl_scan_required;
+ rssyl_class.scan_required = mh_get_class()->scan_required;
rssyl_class.item_set_xml = rssyl_item_set_xml;
rssyl_class.item_get_xml = rssyl_item_get_xml;
rssyl_class.add_msgs = rssyl_add_msgs;
rssyl_class.remove_msg = rssyl_remove_msg;
rssyl_class.remove_msgs = NULL;
+ rssyl_class.is_msg_changed = rssyl_is_msg_changed;
// rssyl_class.change_flags = rssyl_change_flags;
rssyl_class.change_flags = NULL;
rssyl_class.subscribe = rssyl_subscribe_uri;