1
|
1 /*****************************************************************************/
|
33
|
2 /* bookmark.c - functions for connecting to a site via a bookmark */
|
1
|
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"
|
33
|
21 static const char cvsid[] = "$Id$";
|
1
|
22
|
|
23 static int bookmark_parse_url ( gftp_request * request,
|
|
24 const char * url );
|
|
25
|
|
26 void
|
|
27 bookmark_init (gftp_request * request)
|
|
28 {
|
|
29 g_return_if_fail (request != NULL);
|
|
30
|
|
31 request->protonum = GFTP_BOOKMARK_NUM;
|
|
32 request->init = bookmark_init;
|
|
33 request->destroy = NULL;
|
|
34 request->connect = NULL;
|
|
35 request->disconnect = NULL;
|
|
36 request->get_file = NULL;
|
|
37 request->put_file = NULL;
|
|
38 request->transfer_file = NULL;
|
|
39 request->get_next_file_chunk = NULL;
|
|
40 request->put_next_file_chunk = NULL;
|
|
41 request->end_transfer = NULL;
|
|
42 request->list_files = NULL;
|
|
43 request->get_next_file = NULL;
|
|
44 request->set_data_type = NULL;
|
|
45 request->get_file_size = NULL;
|
|
46 request->chdir = NULL;
|
|
47 request->rmdir = NULL;
|
|
48 request->rmfile = NULL;
|
|
49 request->mkdir = NULL;
|
|
50 request->rename = NULL;
|
|
51 request->chmod = NULL;
|
|
52 request->set_file_time = NULL;
|
|
53 request->site = NULL;
|
|
54 request->parse_url = bookmark_parse_url;
|
|
55 request->url_prefix = "bookmark";
|
|
56 request->protocol_name = "Bookmark";
|
|
57 request->need_hostport = 0;
|
|
58 request->need_userpass = 0;
|
|
59 request->use_threads = 0;
|
|
60 request->use_cache = 0;
|
|
61 request->always_connected = 0;
|
|
62 gftp_set_config_options (request);
|
|
63 }
|
|
64
|
|
65 static int
|
|
66 bookmark_parse_url (gftp_request * request, const char * url)
|
|
67 {
|
|
68 gftp_bookmarks * tempentry;
|
|
69 const char * pos;
|
|
70 int i;
|
|
71
|
|
72 g_return_val_if_fail (request != NULL, -2);
|
|
73 g_return_val_if_fail (url != NULL, -2);
|
|
74
|
|
75 if ((pos = strstr (url, "://")) != NULL)
|
|
76 pos += 3;
|
|
77 else
|
|
78 pos = url;
|
|
79
|
|
80 if ((tempentry = g_hash_table_lookup (bookmarks_htable, pos)) == NULL)
|
|
81 {
|
|
82 request->logging_function (gftp_logging_error, request->user_data,
|
|
83 _("Error: Could not find bookmark %s\n"), pos);
|
|
84 return (-2);
|
|
85 }
|
|
86 else if (tempentry->hostname == NULL || *tempentry->hostname == '\0' ||
|
|
87 tempentry->user == NULL || *tempentry->user == '\0')
|
|
88 {
|
|
89 request->logging_function (gftp_logging_error, request->user_data,
|
|
90 _("Bookmarks Error: There are some missing entries in this bookmark. Make sure you have a hostname and username\n"));
|
|
91 return (-2);
|
|
92 }
|
|
93
|
|
94 gftp_set_username (request, tempentry->user);
|
|
95 if (strncmp (tempentry->pass, "@EMAIL@", 7) == 0)
|
|
96 gftp_set_password (request, emailaddr);
|
|
97 else
|
|
98 gftp_set_password (request, tempentry->pass);
|
|
99 if (tempentry->acct != NULL)
|
|
100 gftp_set_account (request, tempentry->acct);
|
|
101 gftp_set_hostname (request, tempentry->hostname);
|
|
102 gftp_set_directory (request, tempentry->remote_dir);
|
|
103 gftp_set_port (request, tempentry->port);
|
|
104 gftp_set_sftpserv_path (request, tempentry->sftpserv_path);
|
|
105
|
|
106 for (i = 0; gftp_protocols[i].name; i++)
|
|
107 {
|
|
108 if (strcmp (gftp_protocols[i].name, tempentry->protocol) == 0)
|
|
109 {
|
|
110 gftp_protocols[i].init (request);
|
|
111 break;
|
|
112 }
|
|
113 }
|
|
114
|
|
115 if (!gftp_protocols[i].name)
|
|
116 gftp_protocols[0].init (request);
|
|
117
|
|
118 return (0);
|
|
119 }
|
|
120
|