void process_img_all(void) { DIR *dp; struct dirent *dentp; struct stat sb; int len, ret, nfiles = 0; char *ext; if ((dp = opendir(".")) == NULL) { printf("Access denied to current directory!\n"); return; } while ((dentp = readdir(dp)) != NULL) { if (strcmp(dentp->d_name, ".") == 0 || strcmp(dentp->d_name, "..") == 0) continue; if (stat(dentp->d_name, &sb) != 0 || !S_ISREG(sb.st_mode)) continue; len = strlen(dentp->d_name); if (len < 5) continue; if (len >= 5 && dentp->d_name[len - 4] == '.') ext = &dentp->d_name[len - 3]; else if (len >= 6 && dentp->d_name[len - 5] == '.') ext = &dentp->d_name[len - 4]; else continue; if (strcasecmp(ext, "png") == 0) { if (nfiles++ == 0 && !g_verbose) status_header(); ret = process_image_png(dentp->d_name); if (!g_verbose && ret) status_line(dentp->d_name, ret); } else if (strcasecmp(ext, "jpg") == 0 || strcasecmp(ext, "jpeg") == 0) { if (nfiles++ == 0 && !g_verbose) status_header(); ret = process_image_jpg(dentp->d_name); if (!g_verbose && ret) status_line(dentp->d_name, ret); } } if (nfiles == 0) printf("No files found\n"); }
void process_img_all(void) { WIN32_FIND_DATA finddata; HANDLE hFind; int len, ret, nfiles = 0; char *ext; hFind = FindFirstFile("*", &finddata); if (hFind == INVALID_HANDLE_VALUE) { printf("No files found\n"); return; } do { if ( (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || (finddata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) || (finddata.dwFileAttributes & FILE_ATTRIBUTE_DEVICE) ) continue; len = strlen(finddata.cFileName); if (len < 5) continue; if (len >= 5 && finddata.cFileName[len - 4] == '.') ext = &finddata.cFileName[len - 3]; else if (len >= 6 && finddata.cFileName[len - 5] == '.') ext = &finddata.cFileName[len - 4]; else continue; if (strcasecmp(ext, "png") == 0) { if (nfiles++ == 0 && !g_verbose) status_header(); ret = process_image_png(finddata.cFileName); if (!g_verbose && ret) status_line(finddata.cFileName, ret); } else if (strcasecmp(ext, "jpg") == 0 || strcasecmp(ext, "jpeg") == 0) { if (nfiles++ == 0 && !g_verbose) status_header(); ret = process_image_jpg(finddata.cFileName); if (!g_verbose && ret) status_line(finddata.cFileName, ret); } } while (FindNextFile(hFind, &finddata)); FindClose(hFind); if (nfiles == 0) printf("No files found\n"); }
void run() { HTTPServer s(num_threads_); s.set_request_handler([this](const Request& req, Response& res) { for (auto router : routers_) { if (router.handle(req, res)) { LOG_DBG << "Route " << req.path(); return true; } } LOG_DBG << "Request handler not found in dynamic router"; return false; }) .set_error_handler([this](int code, const std::string& msg, const Request& req, Response& res) { LOG_DBG << "Handle error:" << code << " " << msg << "with path " << req.path(); if (error_handler_ && error_handler_(code,msg,req,res)) { return true; } LOG_DBG << "In defaule error handler"; std::string html; auto s = status_header(code); html = "<html><head><title>" + s.second + "</title></head>"; html += "<body>"; html += "<h1>" + boost::lexical_cast<std::string>(s.first) + " " + s.second + " " + "</h1>"; if (!msg.empty()) { html += "<br> <h2>Message: " + msg + "</h2>"; } html += "</body></html>"; res.set_status_code(s.first); res.write(html); return true; }) .public_dir(public_dir_) .listen(listen_addr_, listen_port_) .run(); }
void run() { HTTPServer s(num_threads_); s.set_request_handler([this](Request& req, Response& res) { return Invoke<sizeof...(Aspect)>(res, &Cinatra::dispatch, this, req, res); }) .set_error_handler([this](int code, const std::string& msg, Request& req, Response& res) { LOG_DBG << "Handle error:" << code << " " << msg << " with path " << req.path(); if (error_handler_ && error_handler_(code,msg,req,res)) { return true; } LOG_DBG << "In defaule error handler"; std::string html; auto s = status_header(code); html = "<html><head><title>" + s.second + "</title></head>"; html += "<body>"; html += "<h1>" + boost::lexical_cast<std::string>(s.first) + " " + s.second + " " + "</h1>"; if (!msg.empty()) { html += "<br> <h2>Message: " + msg + "</h2>"; } html += "</body></html>"; res.set_status_code(s.first); res.write(html); return true; }) .static_dir(static_dir_) #ifdef CINATRA_ENABLE_HTTPS .https_config(config_) #endif // CINATRA_ENABLE_HTTPS .listen(listen_addr_, listen_port_) .run(); }
int main(int argc, char **argv) { int i, opt, ret; while ((opt = gumbo_getopt(argc, argv, ":h?v")) != -1) { switch (opt) { case '?': case 'h': imginf_help(); return 1; case 'v': g_verbose = 1; break; default: printf("imginf: Incorrect usage (%c)\n", Optopt); imginf_help(); } } for (i = Optind; i < argc; i++) { ret = file_seems_valid(argv[i]); if (!ret) { printf("Invalid file argument: %s\n", argv[i]); return 2; } } if (Optind == argc) { process_img_all(); return 0; } /* Process each image on the command line. No wildcards are allowed */ if (!g_verbose) status_header(); for (i = Optind; i < argc; i++) { ret = file_seems_valid(argv[i]); if (ret == 1) { ret = process_image_png(argv[i]); if (!g_verbose && ret) status_line(argv[i], ret); } else if (ret == 2) { ret = process_image_jpg(argv[i]); if (!g_verbose && ret) status_line(argv[i], ret); } } return 0; }