/* * Dpi for FTP. * * This server checks the ftp-URL to be a directory (requires wget). * If true, it sends back an html representation of it, and if not * a dpip message (which is catched by dillo who redirects the ftp URL * to the downloads server). * * Feel free to polish! * * Copyright 2003-2007 Jorge Arellano Cid * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * */ /* * TODO: * - Send feedback about the FTP login process from wget's stderr. * i.e. capture our child's stderr, process it, and report back. * - Handle simultaneous connections. * If ftp.dpi is implemented with a low level ftp library, it becomes * possible to keep the connection alive, and thus make browsing of ftp * directories faster (this avoids one login per page, and forks). Perhaps * it's not worth, but can be done. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "../dpip/dpip.h" #include "dpiutil.h" #include "d_size.h" /* * Debugging macros */ #define _MSG(...) #define MSG(...) printf("[ftp dpi]: " __VA_ARGS__) /* * Global variables */ static SockHandler *sh = NULL; static char **dl_argv = NULL; /*---------------------------------------------------------------------------*/ /* TODO: could use dStr ADT! */ typedef struct ContentType_ { const char *str; int len; } ContentType_t; static const ContentType_t MimeTypes[] = { { "application/octet-stream", 24 }, { "text/html", 9 }, { "text/plain", 10 }, { "image/gif", 9 }, { "image/png", 9 }, { "image/jpeg", 10 }, { NULL, 0 } }; /* * Detects 'Content-Type' from a data stream sample. * * It uses the magic(5) logic from file(1). Currently, it * only checks the few mime types that Dillo supports. * * 'Data' is a pointer to the first bytes of the raw data. * * Return value: (0 on success, 1 on doubt, 2 on lack of data). */ static int a_Misc_get_content_type_from_data(void *Data, size_t Size, const char **PT) { int st = 1; /* default to "doubt' */ int Type = 0; /* default to "application/octet-stream" */ char *p = Data; size_t i, non_ascci; /* HTML try */ for (i = 0; i < Size && isspace(p[i]); ++i); if ((Size - i >= 5 && !dStrncasecmp(p+i, "= 5 && !dStrncasecmp(p+i, "= 6 && !dStrncasecmp(p+i, "= 14 && !dStrncasecmp(p+i, "= 17 && !dStrncasecmp(p+i, "