1
|
1 /*****************************************************************************/
|
|
2 /* gftp-text.c - text port of gftp */
|
|
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-text.h"
|
33
|
21 static const char cvsid[] = "$Id$";
|
1
|
22
|
|
23 static gftp_request * gftp_text_locreq = NULL;
|
|
24 static gftp_request * gftp_text_remreq = NULL;
|
|
25 static volatile int cancel = 0;
|
|
26 static int configuration_changed = 0,
|
|
27 number_commands = 30;
|
|
28
|
|
29 struct _gftp_text_methods gftp_text_methods[] = {
|
|
30 {N_("about"), 2, gftp_text_about, NULL,
|
|
31 N_("Shows gFTP information")},
|
|
32 {N_("ascii"), 2, gftp_text_ascii, &gftp_text_remreq,
|
|
33 N_("Sets the current file transfer mode to Ascii (only for FTP)")},
|
|
34 {N_("binary"), 1, gftp_text_binary, &gftp_text_remreq,
|
|
35 N_("Sets the current file transfer mode to Binary (only for FTP)")},
|
|
36 {N_("cd"), 2, gftp_text_cd, &gftp_text_remreq,
|
|
37 N_("Changes the remote working directory")},
|
|
38 {N_("chdir"), 3, gftp_text_cd, &gftp_text_remreq,
|
|
39 N_("Changes the remote working directory")},
|
|
40 {N_("chmod"), 3, gftp_text_chmod, &gftp_text_remreq,
|
|
41 N_("Changes the permissions of a remote file")},
|
|
42 {N_("close"), 2, gftp_text_close, &gftp_text_remreq,
|
|
43 N_("Disconnects from the remote site")},
|
|
44 {N_("delete"), 1, gftp_text_delete, &gftp_text_remreq,
|
|
45 N_("Removes a remote file")},
|
|
46 {N_("get"), 1, gftp_text_mget_file, NULL,
|
|
47 N_("Downloads remote file(s)")},
|
|
48 {N_("help"), 1, gftp_text_help, NULL,
|
|
49 N_("Shows this help screen")},
|
|
50 {N_("lcd"), 3, gftp_text_cd, &gftp_text_locreq,
|
|
51 N_("Changes the local working directory")},
|
|
52 {N_("lchdir"), 4, gftp_text_cd, &gftp_text_locreq,
|
|
53 N_("Changes the local working directory")},
|
|
54 {N_("lchmod"), 4, gftp_text_chmod, &gftp_text_locreq,
|
|
55 N_("Changes the permissions of a local file")},
|
|
56 {N_("ldelete"), 2, gftp_text_delete, &gftp_text_locreq,
|
|
57 N_("Removes a local file")},
|
|
58 {N_("lls"), 2, gftp_text_ls, &gftp_text_locreq,
|
|
59 N_("Shows the directory listing for the current local directory")},
|
|
60 {N_("lmkdir"), 2, gftp_text_mkdir, &gftp_text_locreq,
|
|
61 N_("Creates a local directory")},
|
|
62 {N_("lpwd"), 2, gftp_text_pwd, &gftp_text_locreq,
|
|
63 N_("Show current local directory")},
|
|
64 {N_("lrename"), 3, gftp_text_rename, &gftp_text_locreq,
|
|
65 N_("Rename a local file")},
|
|
66 {N_("lrmdir"), 3, gftp_text_rmdir, &gftp_text_locreq,
|
|
67 N_("Remove a local directory")},
|
|
68 {N_("ls"), 2, gftp_text_ls, &gftp_text_remreq,
|
|
69 N_("Shows the directory listing for the current remote directory")},
|
|
70 {N_("mget"), 2, gftp_text_mget_file, NULL,
|
|
71 N_("Downloads remote file(s)")},
|
|
72 {N_("mkdir"), 2, gftp_text_mkdir, &gftp_text_remreq,
|
|
73 N_("Creates a remote directory")},
|
|
74 {N_("mput"), 2, gftp_text_mput_file, NULL,
|
|
75 N_("Uploads local file(s)")},
|
|
76 {N_("open"), 1, gftp_text_open, &gftp_text_remreq,
|
|
77 N_("Opens a connection to a remote site")},
|
|
78 {N_("put"), 2, gftp_text_mput_file, NULL,
|
|
79 N_("Uploads local file(s)")},
|
|
80 {N_("pwd"), 2, gftp_text_pwd, &gftp_text_remreq,
|
|
81 N_("Show current remote directory")},
|
|
82 {N_("quit"), 1, gftp_text_quit, NULL,
|
|
83 N_("Exit from gFTP")},
|
|
84 {N_("rename"), 2, gftp_text_rename, &gftp_text_remreq,
|
|
85 N_("Rename a remote file")},
|
|
86 {N_("rmdir"), 2, gftp_text_rmdir, &gftp_text_remreq,
|
|
87 N_("Remove a remote directory")},
|
|
88 {N_("set"), 1, gftp_text_set, NULL,
|
|
89 N_("Show configuration file variables. You can also set variables by set var=val")},
|
|
90 {NULL, 0, NULL, NULL, NULL}};
|
|
91
|
|
92 int
|
|
93 main (int argc, char **argv)
|
|
94 {
|
|
95 gftp_request * request;
|
|
96 size_t len, cmdlen;
|
|
97 char *pos, *stpos;
|
|
98 int i;
|
|
99 #ifdef HAVE_LIBREADLINE
|
|
100 char *tempstr, prompt[20];
|
|
101 #else
|
|
102 char tempstr[512];
|
|
103 #endif
|
|
104
|
|
105 #ifdef HAVE_GETTEXT
|
|
106 setlocale (LC_ALL, "");
|
|
107 bindtextdomain ("gftp", LOCALE_DIR);
|
|
108 textdomain ("gftp");
|
|
109 #endif
|
|
110
|
|
111 signal (SIGCHLD, sig_child);
|
|
112 signal (SIGPIPE, SIG_IGN);
|
|
113
|
|
114 gftp_read_config_file (argv, 0);
|
|
115
|
|
116 /* SSH doesn't support reading the password with askpass via the command
|
|
117 line */
|
|
118 ssh_use_askpass = sshv2_use_sftp_subsys = 0;
|
|
119
|
|
120 if (gftp_parse_command_line (&argc, &argv) != 0)
|
|
121 exit (0);
|
|
122
|
|
123 gftp_text_remreq = gftp_request_new ();
|
|
124 gftp_text_remreq->logging_function = gftp_text_log;
|
|
125
|
|
126 gftp_text_locreq = gftp_request_new ();
|
|
127 gftp_text_locreq->logging_function = gftp_text_log;
|
|
128 gftp_protocols[GFTP_LOCAL_NUM].init (gftp_text_locreq);
|
|
129 if (startup_directory != NULL && *startup_directory != '\0')
|
|
130 gftp_set_directory (gftp_text_locreq, startup_directory);
|
|
131 gftp_connect (gftp_text_locreq);
|
|
132
|
|
133 gftp_text_log (gftp_logging_misc, NULL, "%s, Copyright (C) 1998-2002 Brian Masney <", version);
|
|
134 gftp_text_log (gftp_logging_recv, NULL, "masneyb@gftp.org");
|
|
135 gftp_text_log (gftp_logging_misc, NULL, _(">.\nIf you have any questions, comments, or suggestions about this program, please feel free to email them to me. You can always find out the latest news about gFTP from my website at http://www.gftp.org/\n"));
|
|
136 gftp_text_log (gftp_logging_misc, NULL, "\n");
|
|
137 gftp_text_log (gftp_logging_misc, NULL, _("gFTP comes with ABSOLUTELY NO WARRANTY; for details, see the COPYING file. This is free software, and you are welcome to redistribute it under certain conditions; for details, see the COPYING file\n"));
|
|
138 gftp_text_log (gftp_logging_misc, NULL, "\n");
|
|
139
|
|
140 if (argc == 3 && strcmp (argv[1], "-d") == 0)
|
|
141 {
|
|
142 if ((pos = strrchr (argv[2], '/')) != NULL)
|
|
143 *pos = '\0';
|
|
144 gftp_text_open (gftp_text_remreq, argv[2], NULL);
|
|
145
|
|
146 if (pos != NULL)
|
|
147 *pos = '/';
|
|
148
|
|
149 gftp_text_mget_file (gftp_text_remreq, pos + 1, NULL);
|
|
150 exit (0);
|
|
151 }
|
|
152 else if (argc == 2)
|
|
153 gftp_text_open (gftp_text_remreq, argv[1], NULL);
|
|
154
|
|
155 #ifdef HAVE_LIBREADLINE
|
|
156 g_snprintf (prompt, sizeof (prompt), "%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
157 while ((tempstr = readline (prompt)))
|
|
158 #else
|
|
159 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
160 while (fgets (tempstr, sizeof (tempstr), stdin) != NULL)
|
|
161 #endif
|
|
162 {
|
|
163 len = strlen (tempstr);
|
|
164 if (tempstr[len - 1] == '\n')
|
|
165 tempstr[--len] = '\0';
|
|
166 if (tempstr[len - 1] == '\r')
|
|
167 tempstr[--len] = '\0';
|
|
168
|
|
169 for (stpos = tempstr; *stpos == ' '; stpos++);
|
|
170
|
|
171 for (pos = tempstr + len - 1;
|
|
172 (*pos == ' ' || *pos == '\t') && pos > tempstr;
|
|
173 pos--)
|
|
174 *pos = '\0';
|
|
175
|
|
176 if (*stpos == '\0')
|
|
177 {
|
|
178 #ifndef HAVE_LIBREADLINE
|
|
179 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
180 #endif
|
|
181 continue;
|
|
182 }
|
|
183
|
|
184 #ifdef HAVE_LIBREADLINE
|
|
185 add_history (tempstr);
|
|
186 #endif
|
|
187
|
|
188 if ((pos = strchr (stpos, ' ')) != NULL)
|
|
189 *pos = '\0';
|
|
190 cmdlen = strlen (stpos);
|
|
191
|
|
192 for (i=0; gftp_text_methods[i].command != NULL; i++)
|
|
193 {
|
|
194 if (strcmp (gftp_text_methods[i].command, stpos) == 0)
|
|
195 break;
|
|
196 else if (cmdlen >= gftp_text_methods[i].minlen &&
|
|
197 strncmp (gftp_text_methods[i].command, stpos, cmdlen) == 0)
|
|
198 break;
|
|
199 }
|
|
200
|
|
201 if (pos != NULL)
|
|
202 pos++;
|
|
203 else
|
|
204 pos = "";
|
|
205
|
|
206 if (gftp_text_methods[i].command != NULL)
|
|
207 {
|
|
208 if (gftp_text_methods[i].request != NULL)
|
|
209 request = *gftp_text_methods[i].request;
|
|
210 else
|
|
211 request = NULL;
|
|
212
|
|
213 if (gftp_text_methods[i].func (request, pos, NULL) == 0)
|
|
214 break;
|
|
215 }
|
|
216 else
|
|
217 gftp_text_log (gftp_logging_error, NULL,
|
|
218 _("Error: Command not recognized\n"));
|
|
219
|
|
220 #ifdef HAVE_LIBREADLINE
|
|
221 free (tempstr);
|
|
222 #else
|
|
223 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
|
|
224 #endif
|
|
225 }
|
|
226
|
|
227 if (logfd != NULL)
|
|
228 fclose (logfd);
|
|
229 gftp_text_quit (NULL, NULL, NULL);
|
|
230
|
|
231 return (0);
|
|
232 }
|
|
233
|
|
234
|
|
235 void
|
|
236 gftp_text_log (gftp_logging_level level, void *ptr, const char *string, ...)
|
|
237 {
|
|
238 char tempstr[512], *stpos, *endpos;
|
|
239 va_list argp;
|
|
240 int sw;
|
|
241
|
|
242 g_return_if_fail (string != NULL);
|
|
243
|
|
244 switch (level)
|
|
245 {
|
|
246 case gftp_logging_send:
|
|
247 printf ("%s", COLOR_GREEN);
|
|
248 break;
|
|
249 case gftp_logging_recv:
|
|
250 printf ("%s", COLOR_YELLOW);
|
|
251 break;
|
|
252 case gftp_logging_error:
|
|
253 printf ("%s", COLOR_RED);
|
|
254 break;
|
|
255 default:
|
|
256 printf ("%s", COLOR_DEFAULT);
|
|
257 break;
|
|
258 }
|
|
259
|
|
260 va_start (argp, string);
|
|
261 g_vsnprintf (tempstr, sizeof (tempstr), string, argp);
|
|
262 va_end (argp);
|
|
263
|
|
264 if (logfd != NULL)
|
|
265 {
|
|
266 fwrite (tempstr, 1, strlen (tempstr), logfd);
|
|
267 if (ferror (logfd))
|
|
268 {
|
|
269 fclose (logfd);
|
|
270 logfd = NULL;
|
|
271 }
|
|
272 else
|
|
273 fflush (logfd);
|
|
274 }
|
|
275
|
|
276 sw = gftp_text_get_win_size ();
|
|
277 stpos = tempstr;
|
|
278 endpos = tempstr + 1;
|
|
279 do
|
|
280 {
|
|
281 if (strlen (stpos) <= sw)
|
|
282 {
|
|
283 printf ("%s", stpos);
|
|
284 break;
|
|
285 }
|
|
286 for (endpos = stpos + sw - 1; *endpos != ' ' && endpos > stpos; endpos--);
|
|
287 if (endpos != stpos)
|
|
288 {
|
|
289 *endpos = '\0';
|
|
290 }
|
|
291 printf ("%s\n", stpos);
|
|
292 stpos = endpos + 1;
|
|
293 }
|
|
294 while (stpos != endpos);
|
|
295
|
|
296 printf ("%s", COLOR_DEFAULT);
|
|
297 }
|
|
298
|
|
299
|
|
300 int
|
|
301 gftp_text_open (gftp_request * request, char *command, gpointer *data)
|
|
302 {
|
|
303 char tempstr[255], *pos;
|
|
304
|
|
305 if (GFTP_IS_CONNECTED (request))
|
|
306 {
|
|
307 gftp_disconnect (request);
|
|
308 }
|
|
309
|
|
310 if (*command == '\0')
|
|
311 {
|
|
312 gftp_text_log (gftp_logging_error, NULL,
|
|
313 _("usage: open [[ftp://][user:pass@]ftp-site[:port][/directory]]\n"));
|
|
314 return (1);
|
|
315 }
|
|
316
|
|
317 if (gftp_parse_url (request, command) < 0)
|
|
318 {
|
|
319 gftp_text_log (gftp_logging_error, NULL,
|
|
320 _("Could not parse URL %s\n"), command);
|
|
321 return (1);
|
|
322 }
|
|
323
|
|
324 if (strcmp (GFTP_GET_USERNAME (request), "anonymous") == 0)
|
|
325 {
|
|
326 if ((pos = gftp_text_ask_question ("Username [anonymous]", 1, tempstr,
|
|
327 sizeof (tempstr))) != NULL)
|
|
328 {
|
|
329 gftp_set_username (request, pos);
|
|
330 if (request->password)
|
|
331 {
|
|
332 g_free (request->password);
|
|
333 request->password = NULL;
|
|
334 }
|
|
335 }
|
|
336 }
|
|
337
|
|
338 if (strcmp (GFTP_GET_USERNAME (request), "anonymous") != 0 &&
|
|
339 (request->password == NULL || *request->password == '\0'))
|
|
340 {
|
|
341 if ((pos = gftp_text_ask_question ("Password", 0, tempstr,
|
|
342 sizeof (tempstr))) == NULL)
|
|
343 return (1);
|
|
344 gftp_set_password (request, pos);
|
|
345 }
|
|
346
|
|
347 gftp_connect (request);
|
|
348 return (1);
|
|
349 }
|
|
350
|
|
351
|
|
352 int
|
|
353 gftp_text_close (gftp_request * request, char *command, gpointer *data)
|
|
354 {
|
|
355 gftp_disconnect (request);
|
|
356 return (1);
|
|
357 }
|
|
358
|
|
359
|
|
360 int
|
|
361 gftp_text_about (gftp_request * request, char *command, gpointer *data)
|
|
362 {
|
|
363 char *str;
|
|
364
|
|
365 gftp_text_log (gftp_logging_misc, NULL,
|
|
366 "%s. Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org>\n", version);
|
|
367
|
|
368 str = _("Translated by");
|
|
369 if (strcmp (str, "Translated by") != 0)
|
|
370 gftp_text_log (gftp_logging_misc, NULL, "%s\n", str);
|
|
371 return (1);
|
|
372 }
|
|
373
|
|
374
|
|
375 int
|
|
376 gftp_text_quit (gftp_request * request, char *command, gpointer *data)
|
|
377 {
|
|
378 gftp_clear_cache_files ();
|
|
379 if (configuration_changed)
|
|
380 gftp_write_config_file ();
|
|
381 return (0);
|
|
382 }
|
|
383
|
|
384
|
|
385 int
|
|
386 gftp_text_pwd (gftp_request * request, char *command, gpointer *data)
|
|
387 {
|
|
388 if (!GFTP_IS_CONNECTED (request))
|
|
389 {
|
|
390 gftp_text_log (gftp_logging_error, NULL,
|
|
391 _("Error: Not connected to a remote site\n"));
|
|
392 return (1);
|
|
393 }
|
|
394 gftp_text_log (gftp_logging_misc, NULL, "%s\n", request->directory);
|
|
395 return (1);
|
|
396 }
|
|
397
|
|
398
|
|
399 int
|
|
400 gftp_text_cd (gftp_request * request, char *command, gpointer *data)
|
|
401 {
|
|
402 char *newdir = NULL;
|
|
403
|
|
404 if (!GFTP_IS_CONNECTED (request))
|
|
405 {
|
|
406 gftp_text_log (gftp_logging_error, NULL,
|
|
407 _("Error: Not connected to a remote site\n"));
|
|
408 return (1);
|
|
409 }
|
|
410 else if (*command == '\0')
|
|
411 {
|
|
412 gftp_text_log (gftp_logging_error, NULL, _("usage: chdir <directory>\n"));
|
|
413 return (1);
|
|
414 }
|
|
415 else if (request->protonum == GFTP_LOCAL_NUM &&
|
|
416 (newdir = expand_path (command)) == NULL)
|
|
417 {
|
|
418 gftp_text_log (gftp_logging_error, NULL, _("usage: chdir <directory>\n"));
|
|
419 return (1);
|
|
420 }
|
|
421
|
|
422 gftp_set_directory (request, newdir != NULL ? newdir : command);
|
|
423
|
|
424 if (newdir != NULL)
|
|
425 g_free (newdir);
|
|
426
|
|
427 return (1);
|
|
428 }
|
|
429
|
|
430
|
|
431 int
|
|
432 gftp_text_mkdir (gftp_request * request, char *command, gpointer *data)
|
|
433 {
|
|
434 if (!GFTP_IS_CONNECTED (request))
|
|
435 {
|
|
436 gftp_text_log (gftp_logging_error, NULL,
|
|
437 _("Error: Not connected to a remote site\n"));
|
|
438 return (1);
|
|
439 }
|
|
440
|
|
441 if (*command == '\0')
|
|
442 {
|
|
443 gftp_text_log (gftp_logging_error, NULL,
|
|
444 _("usage: mkdir <new directory>\n"));
|
|
445 }
|
|
446 else
|
|
447 {
|
|
448 gftp_make_directory (request, command);
|
|
449 }
|
|
450 return (1);
|
|
451 }
|
|
452
|
|
453
|
|
454 int
|
|
455 gftp_text_rmdir (gftp_request * request, char *command, gpointer *data)
|
|
456 {
|
|
457 if (!GFTP_IS_CONNECTED (request))
|
|
458 {
|
|
459 gftp_text_log (gftp_logging_error, NULL,
|
|
460 _("Error: Not connected to a remote site\n"));
|
|
461 return (1);
|
|
462 }
|
|
463
|
|
464 if (*command == '\0')
|
|
465 {
|
|
466 gftp_text_log (gftp_logging_error, NULL, _("usage: rmdir <directory>\n"));
|
|
467 }
|
|
468 else
|
|
469 {
|
|
470 gftp_remove_directory (request, command);
|
|
471 }
|
|
472 return (1);
|
|
473 }
|
|
474
|
|
475
|
|
476 int
|
|
477 gftp_text_delete (gftp_request * request, char *command, gpointer *data)
|
|
478 {
|
|
479 if (!GFTP_IS_CONNECTED (request))
|
|
480 {
|
|
481 gftp_text_log (gftp_logging_error, NULL,
|
|
482 _("Error: Not connected to a remote site\n"));
|
|
483 return (1);
|
|
484 }
|
|
485
|
|
486 if (*command == '\0')
|
|
487 {
|
|
488 gftp_text_log (gftp_logging_error, NULL,_("usage: delete <file>\n"));
|
|
489 }
|
|
490 else
|
|
491 {
|
|
492 gftp_remove_file (request, command);
|
|
493 }
|
|
494 return (1);
|
|
495 }
|
|
496
|
|
497
|
|
498 int
|
|
499 gftp_text_rename (gftp_request * request, char *command, gpointer *data)
|
|
500 {
|
|
501 char *pos;
|
|
502
|
|
503 if (!GFTP_IS_CONNECTED (request))
|
|
504 {
|
|
505 gftp_text_log (gftp_logging_error, NULL,
|
|
506 _("Error: Not connected to a remote site\n"));
|
|
507 return (1);
|
|
508 }
|
|
509
|
|
510 if ((pos = strchr (command, ' ')) != NULL)
|
|
511 *pos++ = '\0';
|
|
512
|
|
513 if (*command == '\0' || pos == NULL || *pos == '\0')
|
|
514 {
|
|
515 gftp_text_log (gftp_logging_error, NULL,
|
|
516 _("usage: rename <old name> <new name>\n"));
|
|
517 }
|
|
518 else
|
|
519 {
|
|
520 gftp_rename_file (request, command, pos);
|
|
521 }
|
|
522 return (1);
|
|
523 }
|
|
524
|
|
525
|
|
526 int
|
|
527 gftp_text_chmod (gftp_request * request, char *command, gpointer *data)
|
|
528 {
|
|
529 char *pos;
|
|
530
|
|
531 if (!GFTP_IS_CONNECTED (request))
|
|
532 {
|
|
533 gftp_text_log (gftp_logging_error, NULL,
|
|
534 _("Error: Not connected to a remote site\n"));
|
|
535 return (1);
|
|
536 }
|
|
537
|
|
538 if ((pos = strchr (command, ' ')) != NULL)
|
|
539 *pos++ = '\0';
|
|
540
|
|
541 if (*command == '\0' || pos == NULL || *pos == '\0')
|
|
542 {
|
|
543 gftp_text_log (gftp_logging_error, NULL,
|
|
544 _("usage: chmod <mode> <file>\n"));
|
|
545 }
|
|
546 else
|
|
547 {
|
|
548 gftp_chmod (request, pos, strtol (command, NULL, 10));
|
|
549 }
|
|
550 return (1);
|
|
551 }
|
|
552
|
|
553
|
|
554 int
|
|
555 gftp_text_ls (gftp_request * request, char *command, gpointer *data)
|
|
556 {
|
|
557 char *color, buf[20], *filespec;
|
|
558 time_t curtime;
|
|
559 gftp_file fle;
|
|
560
|
|
561 time (&curtime);
|
|
562 if (!GFTP_IS_CONNECTED (request))
|
|
563 {
|
|
564 gftp_text_log (gftp_logging_error, NULL,
|
|
565 _("Error: Not connected to a remote site\n"));
|
|
566 return (1);
|
|
567 }
|
|
568
|
|
569 filespec = *command != '\0' ? command : NULL;
|
|
570 if (gftp_list_files (request) != 0)
|
|
571 return (1);
|
|
572
|
|
573 while (gftp_get_next_file (request, filespec, &fle) > 0)
|
|
574 {
|
|
575 if (strcmp (fle.file, ".") == 0)
|
|
576 {
|
|
577 gftp_file_destroy (&fle);
|
|
578 continue;
|
|
579 }
|
|
580
|
|
581 if (*fle.attribs == 'd')
|
|
582 color = COLOR_BLUE;
|
|
583 else if (*fle.attribs == 'l')
|
|
584 color = COLOR_WHITE;
|
|
585 else if (strchr (fle.attribs, 'x') != NULL)
|
|
586 color = COLOR_GREEN;
|
|
587 else
|
|
588 color = COLOR_DEFAULT;
|
|
589
|
|
590 if (curtime > fle.datetime + 6 * 30 * 24 * 60 * 60 ||
|
|
591 curtime < fle.datetime - 60 * 60)
|
|
592 strftime (buf, sizeof (buf), "%b %d %Y", localtime (&fle.datetime));
|
|
593 else
|
|
594 strftime (buf, sizeof (buf), "%b %d %H:%M", localtime (&fle.datetime));
|
|
595
|
16
|
596 #if defined (_LARGEFILE_SOURCE)
|
|
597 printf ("%s %8s %8s %10lld %s %s%s%s\n",
|
|
598 #else
|
|
599 printf ("%s %8s %8s %10ld %s %s%s%s\n",
|
|
600 #endif
|
|
601 fle.attribs, fle.user, fle.group,
|
1
|
602 fle.size, buf, color, fle.file, COLOR_DEFAULT);
|
|
603 gftp_file_destroy (&fle);
|
|
604 }
|
|
605 gftp_end_transfer (request);
|
|
606 return (1);
|
|
607 }
|
|
608
|
|
609
|
|
610 int
|
|
611 gftp_text_binary (gftp_request * request, char *command, gpointer *data)
|
|
612 {
|
|
613 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
614 {
|
|
615 gftp_text_log (gftp_logging_error, NULL,
|
|
616 _("Error: Not connected to a remote site\n"));
|
|
617 return (1);
|
|
618 }
|
|
619
|
|
620 gftp_set_data_type (gftp_text_remreq, GFTP_TYPE_BINARY);
|
|
621 gftp_set_data_type (gftp_text_locreq, GFTP_TYPE_BINARY);
|
|
622 return (1);
|
|
623 }
|
|
624
|
|
625
|
|
626 int
|
|
627 gftp_text_ascii (gftp_request * request, char *command, gpointer *data)
|
|
628 {
|
|
629 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
630 {
|
|
631 gftp_text_log (gftp_logging_error, NULL,
|
|
632 _("Error: Not connected to a remote site\n"));
|
|
633 return (1);
|
|
634 }
|
|
635
|
|
636 gftp_set_data_type (gftp_text_remreq, GFTP_TYPE_ASCII);
|
|
637 gftp_set_data_type (gftp_text_locreq, GFTP_TYPE_ASCII);
|
|
638 return (1);
|
|
639 }
|
|
640
|
|
641
|
|
642 int
|
|
643 gftp_text_mget_file (gftp_request * request, char *command, gpointer *data)
|
|
644 {
|
|
645 gftp_transfer * transfer;
|
|
646 gftp_file * fle;
|
|
647
|
|
648 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
649 {
|
|
650 gftp_text_log (gftp_logging_error, NULL,
|
|
651 _("Error: Not connected to a remote site\n"));
|
|
652 return (1);
|
|
653 }
|
|
654
|
|
655 if (*command == '\0')
|
|
656 {
|
|
657 gftp_text_log (gftp_logging_error, NULL, _("usage: mget <filespec>\n"));
|
|
658 return (1);
|
|
659 }
|
|
660
|
|
661 transfer = g_malloc0 (sizeof (*transfer));
|
|
662 transfer->fromreq = gftp_text_remreq;
|
|
663 transfer->toreq = gftp_text_locreq;
|
|
664 transfer->transfer_direction = GFTP_DIRECTION_DOWNLOAD;
|
|
665
|
|
666 /* FIXME - ask whether to resume/skip/overwrite */
|
|
667 if (gftp_list_files (transfer->fromreq) != 0)
|
|
668 {
|
|
669 transfer->fromreq = transfer->toreq = NULL;
|
|
670 free_tdata (transfer);
|
|
671 return (1);
|
|
672 }
|
|
673 fle = g_malloc0 (sizeof (*fle));
|
|
674 while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
|
|
675 {
|
|
676 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
|
|
677 {
|
|
678 gftp_file_destroy (fle);
|
|
679 continue;
|
|
680 }
|
|
681 transfer->files = g_list_append (transfer->files, fle);
|
|
682 fle = g_malloc (sizeof (*fle));
|
|
683 }
|
|
684 g_free (fle);
|
|
685 gftp_end_transfer (transfer->fromreq);
|
|
686
|
|
687 if (transfer->files == NULL)
|
|
688 {
|
|
689 transfer->fromreq = transfer->toreq = NULL;
|
|
690 free_tdata (transfer);
|
|
691 return (1);
|
|
692 }
|
|
693
|
|
694 if (gftp_get_all_subdirs (transfer, NULL) != 0)
|
|
695 {
|
|
696 transfer->fromreq = transfer->toreq = NULL;
|
|
697 free_tdata (transfer);
|
|
698 return (1);
|
|
699 }
|
|
700
|
|
701 if (transfer->files == NULL)
|
|
702 {
|
|
703 transfer->fromreq = transfer->toreq = NULL;
|
|
704 free_tdata (transfer);
|
|
705 return (1);
|
|
706 }
|
|
707
|
|
708 gftp_text_transfer_files (transfer);
|
|
709 transfer->fromreq = transfer->toreq = NULL;
|
|
710 free_tdata (transfer);
|
|
711 return (1);
|
|
712 }
|
|
713
|
|
714
|
|
715 int
|
|
716 gftp_text_mput_file (gftp_request * request, char *command, gpointer *data)
|
|
717 {
|
|
718 gftp_transfer * transfer;
|
|
719 gftp_file * fle;
|
|
720
|
|
721 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
|
|
722 {
|
|
723 gftp_text_log (gftp_logging_error, NULL,
|
|
724 _("Error: Not connected to a remote site\n"));
|
|
725 return (1);
|
|
726 }
|
|
727
|
|
728 if (*command == '\0')
|
|
729 {
|
|
730 gftp_text_log (gftp_logging_error, NULL, _("usage: mput <filespec>\n"));
|
|
731 return (1);
|
|
732 }
|
|
733
|
|
734 transfer = g_malloc0 (sizeof (*transfer));
|
|
735 transfer->fromreq = gftp_text_locreq;
|
|
736 transfer->toreq = gftp_text_remreq;
|
|
737 transfer->transfer_direction = GFTP_DIRECTION_UPLOAD;
|
|
738
|
|
739 if (gftp_list_files (transfer->fromreq) != 0)
|
|
740 {
|
|
741 transfer->fromreq = transfer->toreq = NULL;
|
|
742 free_tdata (transfer);
|
|
743 return (1);
|
|
744 }
|
|
745 fle = g_malloc (sizeof (*fle));
|
|
746 while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
|
|
747 {
|
|
748 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
|
|
749 {
|
|
750 gftp_file_destroy (fle);
|
|
751 continue;
|
|
752 }
|
|
753 transfer->files = g_list_append (transfer->files, fle);
|
|
754 fle = g_malloc (sizeof (*fle));
|
|
755 }
|
|
756 g_free (fle);
|
|
757 gftp_end_transfer (transfer->fromreq);
|
|
758
|
|
759 if (transfer->files == NULL)
|
|
760 {
|
|
761 transfer->fromreq = transfer->toreq = NULL;
|
|
762 free_tdata (transfer);
|
|
763 return (1);
|
|
764 }
|
|
765
|
|
766 if (gftp_get_all_subdirs (transfer, NULL) != 0)
|
|
767 {
|
|
768 transfer->fromreq = transfer->toreq = NULL;
|
|
769 free_tdata (transfer);
|
|
770 return (1);
|
|
771 }
|
|
772
|
|
773 if (transfer->files == NULL)
|
|
774 {
|
|
775 transfer->fromreq = transfer->toreq = NULL;
|
|
776 free_tdata (transfer);
|
|
777 return (1);
|
|
778 }
|
|
779
|
|
780 gftp_text_transfer_files (transfer);
|
|
781 transfer->fromreq = transfer->toreq = NULL;
|
|
782 free_tdata (transfer);
|
|
783 return (1);
|
|
784 }
|
|
785
|
|
786
|
|
787 int
|
|
788 gftp_text_transfer_files (gftp_transfer * transfer)
|
|
789 {
|
|
790 char *tempstr, buf[8192], *progress = "|/-\\";
|
|
791 struct timeval updatetime;
|
|
792 long fromsize, total;
|
|
793 gftp_file * curfle;
|
|
794 int i, j, sw, tot;
|
|
795 ssize_t num_read;
|
|
796
|
|
797 for (transfer->curfle = transfer->files;
|
|
798 transfer->curfle != NULL;
|
|
799 transfer->curfle = transfer->curfle->next)
|
|
800 {
|
|
801 curfle = transfer->curfle->data;
|
|
802 if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP)
|
|
803 continue;
|
|
804
|
|
805 if (curfle->isdir && transfer->toreq->mkdir != NULL)
|
|
806 {
|
|
807 transfer->toreq->mkdir (transfer->toreq, curfle->destfile);
|
|
808 continue;
|
|
809 }
|
|
810
|
|
811 if (maxkbs > 0)
|
|
812 {
|
|
813 gftp_text_log (gftp_logging_misc, NULL,
|
|
814 _("File transfer will be throttled to %.2f KB/s\n"),
|
|
815 maxkbs);
|
|
816 }
|
|
817
|
|
818 transfer->curtrans = curfle->startsize;
|
|
819 fromsize = gftp_transfer_file (transfer->fromreq, curfle->file, NULL,
|
|
820 curfle->startsize, transfer->toreq, curfle->destfile,
|
|
821 NULL, curfle->startsize);
|
|
822 if (fromsize < 0)
|
|
823 return (1);
|
|
824
|
|
825 gettimeofday (&transfer->starttime, NULL);
|
|
826 memcpy (&transfer->lasttime, &transfer->starttime,
|
|
827 sizeof (transfer->lasttime));
|
|
828 memset (&updatetime, 0, sizeof (updatetime));
|
|
829
|
|
830 total = 0;
|
|
831 i = 0;
|
|
832 while (!cancel && (num_read = gftp_get_next_file_chunk (transfer->fromreq,
|
|
833 buf, sizeof (buf))) > 0)
|
|
834 {
|
|
835 printf ("\r%c ", progress[i++]);
|
|
836 fflush (stdout);
|
|
837 if (progress[i] == '\0')
|
|
838 i = 0;
|
|
839
|
|
840 total += num_read;
|
|
841 gftp_text_calc_kbs (transfer, num_read);
|
|
842 if (transfer->lasttime.tv_sec - updatetime.tv_sec >= 1 || total >= fromsize)
|
|
843 {
|
|
844 sw = gftp_text_get_win_size () - 20;
|
|
845 tot = (float) total / (float) fromsize * (float) sw;
|
|
846
|
|
847 if (tot > sw)
|
|
848 tot = sw;
|
|
849 printf ("[");
|
|
850 for (j=0; j<tot; j++)
|
|
851 printf ("=");
|
|
852 for (j=0; j<sw-tot; j++)
|
|
853 printf (" ");
|
|
854 printf ("] @ %.2fKB/s", transfer->kbs);
|
|
855 fflush (stdout);
|
|
856 memcpy (&updatetime, &transfer->lasttime, sizeof (updatetime));
|
|
857 }
|
|
858
|
|
859 if (GFTP_GET_DATA_TYPE (transfer->fromreq) == GFTP_TYPE_ASCII)
|
|
860 tempstr = gftp_convert_ascii (buf, &num_read, 1);
|
|
861 else
|
|
862 tempstr = buf;
|
|
863
|
|
864 if (gftp_put_next_file_chunk (transfer->toreq, tempstr, num_read) < 0)
|
|
865 {
|
|
866 num_read = -1;
|
|
867 break;
|
|
868 }
|
|
869
|
|
870 /* We don't have to free tempstr for a download because new memory is
|
|
871 not allocated for it in that case */
|
|
872 if (GFTP_GET_DATA_TYPE (transfer->fromreq) ==
|
|
873 GFTP_TYPE_ASCII && !transfer->transfer_direction)
|
|
874 g_free (tempstr);
|
|
875 }
|
|
876 printf ("\n");
|
|
877
|
|
878 if (num_read < 0)
|
|
879 {
|
|
880 gftp_text_log (gftp_logging_misc, NULL,
|
|
881 _("Could not download %s\n"), curfle->file);
|
|
882 gftp_disconnect (transfer->fromreq);
|
|
883 gftp_disconnect (transfer->toreq);
|
|
884 }
|
|
885 else
|
|
886 {
|
|
887 gftp_text_log (gftp_logging_misc, NULL,
|
|
888 _("Successfully transferred %s\n"), curfle->file);
|
|
889 gftp_end_transfer (transfer->fromreq);
|
|
890 gftp_end_transfer (transfer->toreq);
|
|
891 }
|
|
892
|
|
893 }
|
|
894 return (1);
|
|
895 }
|
|
896
|
|
897
|
|
898 int
|
|
899 gftp_text_help (gftp_request * request, char *command, gpointer *data)
|
|
900 {
|
|
901 int i, j, ele, numrows, numcols = 6;
|
|
902
|
|
903 if (command != NULL && *command != '\0')
|
|
904 {
|
|
905 for (i=0; gftp_text_methods[i].command != NULL; i++)
|
|
906 {
|
|
907 if (strcmp (gftp_text_methods[i].command, command) == 0)
|
|
908 break;
|
|
909 }
|
|
910
|
|
911 if (gftp_text_methods[i].cmd_description != NULL)
|
|
912 printf ("%s\n", _(gftp_text_methods[i].cmd_description));
|
|
913 else
|
|
914 *command = '\0';
|
|
915 }
|
|
916
|
|
917 if (command == NULL || *command == '\0')
|
|
918 {
|
|
919 numrows = number_commands / numcols;
|
|
920 if (number_commands % numcols != 0)
|
|
921 numrows++;
|
|
922
|
|
923 printf (_("Supported commands:\n\n"));
|
|
924 for (i=0; i<numrows; i++)
|
|
925 {
|
|
926 printf (" ");
|
|
927 for (j=0; j<numcols; j++)
|
|
928 {
|
|
929 ele = i + j * numrows;
|
|
930 if (ele >= number_commands)
|
|
931 break;
|
|
932 printf ("%-10s", gftp_text_methods[ele].command);
|
|
933 }
|
|
934 printf ("\n");
|
|
935 }
|
|
936
|
|
937 printf ("\n");
|
|
938 }
|
|
939 return (1);
|
|
940 }
|
|
941
|
|
942
|
|
943 int
|
|
944 gftp_text_set (gftp_request * request, char *command, gpointer *data)
|
|
945 {
|
|
946 char *pos, *backpos;
|
|
947 int i;
|
|
948
|
|
949 if (command == NULL || *command == '\0')
|
|
950 {
|
|
951 for (i=0; config_file_vars[i].key != NULL; i++)
|
|
952 {
|
|
953 switch (config_file_vars[i].type)
|
|
954 {
|
|
955 case CONFIG_CHARTEXT:
|
|
956 printf ("%s = %s\n", config_file_vars[i].key,
|
|
957 *(char **) config_file_vars[i].var);
|
|
958 break;
|
|
959 case CONFIG_INTTEXT:
|
|
960 case CONFIG_CHECKBOX:
|
|
961 printf ("%s = %d\n", config_file_vars[i].key,
|
|
962 *(int *) config_file_vars[i].var);
|
|
963 break;
|
|
964 case CONFIG_FLOATTEXT:
|
|
965 printf ("%s = %.2f\n", config_file_vars[i].key,
|
|
966 *(float *) config_file_vars[i].var);
|
|
967 break;
|
|
968 }
|
|
969 }
|
|
970 }
|
|
971 else
|
|
972 {
|
|
973 if ((pos = strchr (command, '=')) == NULL)
|
|
974 {
|
|
975 gftp_text_log (gftp_logging_error, NULL,
|
|
976 _("usage: set [variable = value]\n"));
|
|
977 return (1);
|
|
978 }
|
|
979 *pos = '\0';
|
|
980
|
|
981 for (backpos = pos - 1;
|
|
982 (*backpos == ' ' || *backpos == '\t') && backpos > command;
|
|
983 backpos--)
|
|
984 *backpos = '\0';
|
|
985 for (++pos; *pos == ' ' || *pos == '\t'; pos++);
|
|
986
|
|
987 for (i=0; config_file_vars[i].key != NULL; i++)
|
|
988 {
|
|
989 if (strcmp (config_file_vars[i].key, command) == 0)
|
|
990 break;
|
|
991 }
|
|
992
|
|
993 if (config_file_vars[i].key == NULL)
|
|
994 {
|
|
995 gftp_text_log (gftp_logging_error, NULL,
|
|
996 _("Error: Variable %s is not a valid configuration variable.\n"), command);
|
|
997 return (1);
|
|
998 }
|
|
999
|
|
1000 configuration_changed = 1;
|
|
1001 switch (config_file_vars[i].type)
|
|
1002 {
|
|
1003 case CONFIG_CHARTEXT:
|
|
1004 if (*(char **) config_file_vars[i].var != NULL)
|
|
1005 g_free (*(char **) config_file_vars[i].var);
|
|
1006 *(char **) config_file_vars[i].var = g_strconcat (pos, NULL);
|
|
1007 break;
|
|
1008 case CONFIG_CHECKBOX:
|
|
1009 *(int *) config_file_vars[i].var = *pos == '1' ? 1 : 0;
|
|
1010 break;
|
|
1011 case CONFIG_INTTEXT:
|
|
1012 *(int *) config_file_vars[i].var = strtol (pos, NULL, 10);
|
|
1013 break;
|
|
1014 case CONFIG_FLOATTEXT:
|
|
1015 *(float *) config_file_vars[i].var = strtod (pos, NULL);
|
|
1016 break;
|
|
1017 default:
|
|
1018 gftp_text_log (gftp_logging_error, NULL,
|
|
1019 _("Error: You cannot change this variable\n"));
|
|
1020 break;
|
|
1021 }
|
|
1022 }
|
|
1023
|
|
1024 return (1);
|
|
1025 }
|
|
1026
|
|
1027
|
|
1028 char *
|
|
1029 gftp_text_ask_question (const char *question, int echo, char *buf, size_t size)
|
|
1030 {
|
|
1031 struct termios term, oldterm;
|
|
1032 sigset_t sig, sigsave;
|
|
1033 char *pos, *termname;
|
|
1034 FILE *infd, *outfd;
|
|
1035
|
|
1036 if (!echo)
|
|
1037 {
|
|
1038 sigemptyset (&sig);
|
|
1039 sigaddset (&sig, SIGINT);
|
|
1040 sigaddset (&sig, SIGTSTP);
|
|
1041 sigprocmask (SIG_BLOCK, &sig, &sigsave);
|
|
1042
|
|
1043 termname = ctermid (NULL);
|
|
1044 if ((infd = fopen (termname, "r+")) == NULL)
|
|
1045 {
|
|
1046
|
|
1047 gftp_text_log (gftp_logging_error, NULL,
|
|
1048 "Cannot open controlling terminal %s\n", termname);
|
|
1049 return (NULL);
|
|
1050 }
|
|
1051 outfd = infd;
|
|
1052
|
|
1053 tcgetattr (0, &term);
|
|
1054 oldterm = term;
|
|
1055 term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
|
|
1056 tcsetattr (fileno (infd), TCSAFLUSH, &term);
|
|
1057 }
|
|
1058 else
|
|
1059 {
|
|
1060 infd = stdin;
|
|
1061 outfd = stdout;
|
|
1062 }
|
|
1063
|
|
1064 fprintf (outfd, "%s%s%s: ", COLOR_BLUE, question, COLOR_DEFAULT);
|
|
1065
|
|
1066 if (fgets (buf, size, infd) == NULL)
|
|
1067 return (NULL);
|
|
1068 buf[size - 1] = '\0';
|
|
1069
|
|
1070 if (!echo)
|
|
1071 {
|
|
1072 fprintf (outfd, "\n");
|
|
1073 tcsetattr (fileno (infd), TCSAFLUSH, &oldterm);
|
|
1074 fclose (outfd);
|
|
1075 sigprocmask (SIG_SETMASK, &sigsave, NULL);
|
|
1076 }
|
|
1077
|
|
1078 for (pos = buf + strlen (buf) - 1; *pos == ' ' || *pos == '\r' ||
|
|
1079 *pos == '\n'; pos--);
|
|
1080 *(pos+1) = '\0';
|
|
1081
|
|
1082 for (pos = buf; *pos == ' '; pos++);
|
|
1083 if (*pos == '\0')
|
|
1084 return (NULL);
|
|
1085
|
|
1086 return (pos);
|
|
1087 }
|
|
1088
|
|
1089
|
|
1090 int
|
|
1091 gftp_text_get_win_size (void)
|
|
1092 {
|
|
1093 struct winsize size;
|
|
1094 int ret;
|
|
1095
|
|
1096 if (ioctl (0, TIOCGWINSZ, (char *) &size) < 0)
|
|
1097 ret = 80;
|
|
1098 else
|
|
1099 ret = size.ws_col;
|
|
1100 return (ret);
|
|
1101 }
|
|
1102
|
|
1103
|
|
1104 void
|
|
1105 gftp_text_calc_kbs (gftp_transfer * tdata, ssize_t num_read)
|
|
1106 {
|
|
1107 unsigned long waitusecs;
|
|
1108 double difftime, curkbs;
|
|
1109 gftp_file * tempfle;
|
|
1110 struct timeval tv;
|
|
1111 unsigned long toadd;
|
|
1112
|
|
1113 gettimeofday (&tv, NULL);
|
|
1114
|
|
1115 tempfle = tdata->curfle->data;
|
|
1116 tdata->trans_bytes += num_read;
|
|
1117 tdata->curtrans += num_read;
|
|
1118 tdata->stalled = 0;
|
|
1119
|
|
1120 difftime = (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0);
|
|
1121 if (difftime == 0)
|
|
1122 tdata->kbs = (double) tdata->trans_bytes / 1024.0;
|
|
1123 else
|
|
1124 tdata->kbs = (double) tdata->trans_bytes / 1024.0 / difftime;
|
|
1125
|
|
1126 difftime = (tv.tv_sec - tdata->lasttime.tv_sec) + ((double) (tv.tv_usec - tdata->lasttime.tv_usec) / 1000000.0);
|
|
1127
|
|
1128 if (difftime <= 0)
|
|
1129 curkbs = (double) (num_read / 1024.0);
|
|
1130 else
|
|
1131 curkbs = (double) (num_read / 1024.0 / difftime);
|
|
1132
|
|
1133 if (tdata->fromreq->maxkbs > 0 &&
|
|
1134 curkbs > tdata->fromreq->maxkbs)
|
|
1135 {
|
|
1136 waitusecs = (double) num_read / 1024.0 / tdata->fromreq->maxkbs * 1000000.0 - difftime;
|
|
1137
|
|
1138 if (waitusecs > 0)
|
|
1139 {
|
|
1140 difftime += ((double) waitusecs / 1000000.0);
|
|
1141 usleep (waitusecs);
|
|
1142 }
|
|
1143 }
|
|
1144
|
|
1145 /* I don't call gettimeofday (&tdata->lasttime) here because this will use
|
|
1146 less system resources. This will be close enough for what we need */
|
|
1147 difftime += tdata->lasttime.tv_usec / 1000000.0;
|
|
1148 toadd = (long) difftime;
|
|
1149 difftime -= toadd;
|
|
1150 tdata->lasttime.tv_sec += toadd;
|
|
1151 tdata->lasttime.tv_usec = difftime * 1000000.0;
|
|
1152 }
|
|
1153
|
|
1154
|
|
1155 void
|
|
1156 sig_child (int signo)
|
|
1157 {
|
|
1158 }
|
|
1159
|
|
1160
|
|
1161 #if !defined (HAVE_GETADDRINFO) || !defined (HAVE_GAI_STRERROR)
|
|
1162
|
|
1163 struct hostent *
|
|
1164 r_gethostbyname (const char *name, struct hostent *result_buf, int *h_errnop)
|
|
1165 {
|
|
1166 struct hostent *hent;
|
|
1167
|
|
1168 if ((hent = gethostbyname (name)) == NULL)
|
|
1169 {
|
|
1170 if (h_errnop)
|
|
1171 *h_errnop = h_errno;
|
|
1172 }
|
|
1173 else
|
|
1174 {
|
|
1175 *result_buf = *hent;
|
|
1176 hent = result_buf;
|
|
1177 }
|
|
1178 return (hent);
|
|
1179 }
|
|
1180
|
|
1181
|
|
1182 struct servent *
|
|
1183 r_getservbyname (const char *name, const char *proto,
|
|
1184 struct servent *result_buf, int *h_errnop)
|
|
1185 {
|
|
1186 struct servent *sent;
|
|
1187
|
|
1188 if ((sent = getservbyname (name, proto)) == NULL)
|
|
1189 {
|
|
1190 if (h_errnop)
|
|
1191 *h_errnop = h_errno;
|
|
1192 }
|
|
1193 else
|
|
1194 {
|
|
1195 *result_buf = *sent;
|
|
1196 sent = result_buf;
|
|
1197 }
|
|
1198 return (sent);
|
|
1199 }
|
|
1200
|
|
1201 #endif /* HAVE_GETADDRINFO */
|
|
1202
|