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