comparison lib/bookmark.c @ 1:8b1883341c6f

Initial revision
author masneyb
date Mon, 05 Aug 2002 19:46:57 +0000
parents
children c8ec7877432e
comparison
equal deleted inserted replaced
0:674ed97069fd 1:8b1883341c6f
1 /*****************************************************************************/
2 /* local.c - functions that will use the local system */
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */
4 /* */
5 /* This program is free software; you can redistribute it and/or modify */
6 /* it under the terms of the GNU General Public License as published by */
7 /* the Free Software Foundation; either version 2 of the License, or */
8 /* (at your option) any later version. */
9 /* */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU General Public License for more details. */
14 /* */
15 /* You should have received a copy of the GNU General Public License */
16 /* along with this program; if not, write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
18 /*****************************************************************************/
19
20 #include "gftp.h"
21
22 static int bookmark_parse_url ( gftp_request * request,
23 const char * url );
24
25 void
26 bookmark_init (gftp_request * request)
27 {
28 g_return_if_fail (request != NULL);
29
30 request->protonum = GFTP_BOOKMARK_NUM;
31 request->init = bookmark_init;
32 request->destroy = NULL;
33 request->connect = NULL;
34 request->disconnect = NULL;
35 request->get_file = NULL;
36 request->put_file = NULL;
37 request->transfer_file = NULL;
38 request->get_next_file_chunk = NULL;
39 request->put_next_file_chunk = NULL;
40 request->end_transfer = NULL;
41 request->list_files = NULL;
42 request->get_next_file = NULL;
43 request->set_data_type = NULL;
44 request->get_file_size = NULL;
45 request->chdir = NULL;
46 request->rmdir = NULL;
47 request->rmfile = NULL;
48 request->mkdir = NULL;
49 request->rename = NULL;
50 request->chmod = NULL;
51 request->set_file_time = NULL;
52 request->site = NULL;
53 request->parse_url = bookmark_parse_url;
54 request->url_prefix = "bookmark";
55 request->protocol_name = "Bookmark";
56 request->need_hostport = 0;
57 request->need_userpass = 0;
58 request->use_threads = 0;
59 request->use_cache = 0;
60 request->always_connected = 0;
61 gftp_set_config_options (request);
62 }
63
64 static int
65 bookmark_parse_url (gftp_request * request, const char * url)
66 {
67 gftp_bookmarks * tempentry;
68 const char * pos;
69 int i;
70
71 g_return_val_if_fail (request != NULL, -2);
72 g_return_val_if_fail (url != NULL, -2);
73
74 if ((pos = strstr (url, "://")) != NULL)
75 pos += 3;
76 else
77 pos = url;
78
79 if ((tempentry = g_hash_table_lookup (bookmarks_htable, pos)) == NULL)
80 {
81 request->logging_function (gftp_logging_error, request->user_data,
82 _("Error: Could not find bookmark %s\n"), pos);
83 return (-2);
84 }
85 else if (tempentry->hostname == NULL || *tempentry->hostname == '\0' ||
86 tempentry->user == NULL || *tempentry->user == '\0')
87 {
88 request->logging_function (gftp_logging_error, request->user_data,
89 _("Bookmarks Error: There are some missing entries in this bookmark. Make sure you have a hostname and username\n"));
90 return (-2);
91 }
92
93 gftp_set_username (request, tempentry->user);
94 if (strncmp (tempentry->pass, "@EMAIL@", 7) == 0)
95 gftp_set_password (request, emailaddr);
96 else
97 gftp_set_password (request, tempentry->pass);
98 if (tempentry->acct != NULL)
99 gftp_set_account (request, tempentry->acct);
100 gftp_set_hostname (request, tempentry->hostname);
101 gftp_set_directory (request, tempentry->remote_dir);
102 gftp_set_port (request, tempentry->port);
103 gftp_set_sftpserv_path (request, tempentry->sftpserv_path);
104
105 for (i = 0; gftp_protocols[i].name; i++)
106 {
107 if (strcmp (gftp_protocols[i].name, tempentry->protocol) == 0)
108 {
109 gftp_protocols[i].init (request);
110 break;
111 }
112 }
113
114 if (!gftp_protocols[i].name)
115 gftp_protocols[0].init (request);
116
117 return (0);
118 }
119