static void Init_RhoBlobs() { const char* szBlobPath = rho_rhodesapp_getblobsdirpath(); const char* szUserPath = rho_native_rhodbpath(); RAWLOG_INFO1("Init_RhoBlobs: %s", szBlobPath ); rho_file_recursive_createdir(szBlobPath, szUserPath); }
String CRhodesAppBase::getDBFileRoot() { #ifndef RHODES_EMULATOR String strDbFileRoot = rho_native_rhodbpath();//getRhoRootPath(); #else String strDbFileRoot = getRhoRootPath() + RHO_EMULATOR_DIR; #endif return strDbFileRoot; }
String CRhodesAppBase::resolveDBFilesPath(const String& strFilePath) { #ifndef RHODES_EMULATOR String strDbFileRoot = rho_native_rhodbpath();//getRhoRootPath(); #else String strDbFileRoot = getRhoRootPath() + RHO_EMULATOR_DIR; #endif if ( strFilePath.length() == 0 || String_startsWith(strFilePath, strDbFileRoot) || String_startsWith(strFilePath, "file://")) return strFilePath; return CFilePath::join(strDbFileRoot, strFilePath); }
bool CHttpServer::send_file(String const &path, HeaderList const &hdrs) { String fullPath = CFilePath::normalizePath(path); if (String_startsWith(fullPath,"/app/db/db-files") ) fullPath = CFilePath::join( rho_native_rhodbpath(), path.substr(4) ); else if (fullPath.find(m_root) != 0 && fullPath.find(m_strRhoRoot) != 0 && fullPath.find(m_strRuntimeRoot) != 0 && fullPath.find(m_userroot) != 0 && fullPath.find(m_strRhoUserRoot) != 0) fullPath = CFilePath::join( m_root, path ); struct stat st; bool bCheckExist = true; #ifdef RHODES_EMULATOR String strPlatform = RHOSIMCONF().getString("platform"); if ( strPlatform.length() > 0 ) { String fullPath1 = fullPath; int nDot = fullPath1.rfind('.'); if ( nDot >= 0 ) fullPath1.insert(nDot, String(".") + strPlatform); else fullPath1 += String(".") + strPlatform; if (stat(fullPath1.c_str(), &st) == 0 && S_ISREG(st.st_mode)) { fullPath = fullPath1; bCheckExist = false; } } #endif bool doesNotExists = bCheckExist && (stat(fullPath.c_str(), &st) != 0 || !S_ISREG(st.st_mode)); if ( doesNotExists ) { // looking for files at 'rho/apps' at runtime folder fullPath = CFilePath::join( m_strRuntimeRoot, path ); } if (verbose) RAWTRACE1("Sending file %s...", fullPath.c_str()); if ( doesNotExists ) { if ( stat(fullPath.c_str(), &st) != 0 || !S_ISREG(st.st_mode) ) { doesNotExists = true; }else doesNotExists = false; } #ifdef RHODES_EMULATOR if ( doesNotExists ) { CTokenizer oTokenizer( RHOSIMCONF().getString("ext_path"), ";" ); while (oTokenizer.hasMoreTokens()) { String tok = oTokenizer.nextToken(); tok = String_trim(tok); String fullPath1 = CFilePath::join( tok, path ); if (stat(fullPath1.c_str(), &st) == 0 && S_ISREG(st.st_mode)) { fullPath = fullPath1; doesNotExists = false; break; } } } #endif if ( doesNotExists ) { if (verbose) RAWLOG_ERROR1("The file %s was not found", path.c_str()); String error = "<!DOCTYPE html><html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + path + " was not found.</font></html>"; send_response(create_response("404 Not Found",error)); return false; } PROF_START("LOW_FILE"); FILE *fp = fopen(fullPath.c_str(), "rb"); PROF_STOP("LOW_FILE"); if (!fp) { if (verbose) RAWLOG_ERROR1("The file %s could not be opened", path.c_str()); String error = "<!DOCTYPE html><html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + path + " could not be opened.</font></html"; send_response(create_response("404 Not Found",error)); return false; } HeaderList headers; // Detect mime type headers.push_back(Header("Content-Type", get_mime_type(path))); if ( String_startsWith(path, "/public") ) { headers.push_back(Header("Expires", "Thu, 15 Apr 2020 20:00:00 GMT") ); headers.push_back(Header("Cache-Control", "max-age=2592000") ); } // Content length char* buf = new char[FILE_BUF_SIZE]; String start_line; size_t file_size = st.st_size; size_t range_begin = 0, range_end = file_size - 1; size_t content_size = file_size; if (parse_range(hdrs, &range_begin, &range_end)) { if (range_end >= file_size) range_end = file_size - 1; if (range_begin >= range_end) range_begin = range_end - 1; content_size = range_end - range_begin + 1; if (fseek(fp, range_begin, SEEK_SET) == -1) { RAWLOG_ERROR1("Can not seek to specified range start: %lu", (unsigned long)range_begin); snprintf(buf, FILE_BUF_SIZE, "bytes */%lu", (unsigned long)file_size); headers.push_back(Header("Content-Range", buf)); send_response(create_response("416 Request Range Not Satisfiable",headers)); fclose(fp); delete[] buf; return false; } snprintf(buf, FILE_BUF_SIZE, "bytes %lu-%lu/%lu", (unsigned long)range_begin, (unsigned long)range_end, (unsigned long)file_size); headers.push_back(Header("Content-Range", buf)); start_line = "206 Partial Content"; } else { start_line = "200 OK"; } snprintf(buf, FILE_BUF_SIZE, "%lu", (unsigned long)content_size); headers.push_back(Header("Content-Length", buf)); // Send headers if (!send_response(create_response(start_line, headers))) { if (verbose) RAWLOG_ERROR1("Can not send headers while sending file %s", path.c_str()); fclose(fp); delete[] buf; return false; } // Send body for (size_t start = range_begin; start < range_end + 1;) { size_t need_to_read = range_end - start + 1; if (need_to_read == 0) break; if (need_to_read > FILE_BUF_SIZE) need_to_read = FILE_BUF_SIZE; PROF_START("LOW_FILE"); size_t n = fread(buf, 1, need_to_read, fp);//fread(buf, 1, need_to_read, fp); PROF_STOP("LOW_FILE"); if (n < need_to_read) { if (ferror(fp) ) { if (verbose) RAWLOG_ERROR2("Can not read part of file (at position %lu): %s", (unsigned long)start, strerror(errno)); } else if ( feof(fp) ) { if (verbose) RAWLOG_ERROR1("End of file reached, but we expect data (%lu bytes)", (unsigned long)need_to_read); } fclose(fp); delete[] buf; return false; } start += n; if (!send_response_body(String(buf, n))) { if (verbose) RAWLOG_ERROR1("Can not send part of data while sending file %s", path.c_str()); fclose(fp); delete[] buf; return false; } } PROF_START("LOW_FILE"); fclose(fp); PROF_STOP("LOW_FILE"); delete[] buf; if (verbose) RAWTRACE1("File %s was sent successfully", path.c_str()); return false; }
VALUE __rhoGetDBDir(void) { return rb_str_new2(rho_native_rhodbpath()); }