From: visor Date: Wed, 11 Feb 2015 15:27:17 +0000 (+0900) Subject: base64 option of the response-file function. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=fb5063d8221a8c484cdc87bed2fb6254fc3c98f7;p=hmh%2Fhhml.git base64 option of the response-file function. --- diff --git a/lib/motorenv.cc b/lib/motorenv.cc index 738b760..c80a4ec 100644 --- a/lib/motorenv.cc +++ b/lib/motorenv.cc @@ -510,22 +510,28 @@ void MotorEnv::doMotorFile (const ustring& file, bool skipHead, const ustring& } } -void MotorEnv::outputFile (const ustring& src, const ustring& type) { +void MotorEnv::outputFile (const ustring& src, const ustring& type, bool base64) { if (isPlainFile (src)) { if (! responseDone) standardResponse (type); - output->out_file (src); + if (base64) + output->out_file_base64 (src); + else + output->out_file (src); } else { if (! responseDone) noContentResponse (); } } -void MotorEnv::outputFile (const ustring& src, const ustring& type, bool finline, const ustring& dispname) { +void MotorEnv::outputFile (const ustring& src, const ustring& type, bool finline, const ustring& dispname, bool base64) { if (isPlainFile (src)) { if (! responseDone) standardResponse (type, uEmpty, dispname, finline); - output->out_file (src); + if (base64) + output->out_file_base64 (src); + else + output->out_file (src); } else { if (! responseDone) noContentResponse (); diff --git a/lib/motorenv.h b/lib/motorenv.h index 28b57ac..b8cdc8e 100644 --- a/lib/motorenv.h +++ b/lib/motorenv.h @@ -89,8 +89,8 @@ class MotorEnv { }; virtual void doMotor (const ustring& file, const ustring& type, MotorOutput* out = NULL); virtual void doMotorFile (const ustring& file, bool skipHead, const ustring& type, MotorOutput* out = NULL); - virtual void outputFile (const ustring& src, const ustring& type); - virtual void outputFile (const ustring& src, const ustring& type, bool finline, const ustring& dispname); + virtual void outputFile (const ustring& src, const ustring& type, bool base64 = false); + virtual void outputFile (const ustring& src, const ustring& type, bool finline, const ustring& dispname, bool base64 = false); virtual void standardResponse () { standardResponse (mimetype); }; diff --git a/lib/motoroutput.cc b/lib/motoroutput.cc index 9d0217c..539fa31 100644 --- a/lib/motoroutput.cc +++ b/lib/motoroutput.cc @@ -1,5 +1,6 @@ #include "motoroutput.h" #include "ml.h" +#include "util_base64.h" #include "util_string.h" #include "filemacro.h" #include "ustring.h" @@ -116,6 +117,21 @@ MotorOutput* MotorOutput::out_file (const ustring& src) { return this; } +MotorOutput* MotorOutput::out_file_base64 (const ustring& src) { + FileMacro f; + ustring b (64, '\0'); + ustring::iterator p = b.begin (); + ssize_t s; + + if (f.openRead (src.c_str ())) { + while ((s = f.read (&(*p), 57)) > 0) { + out_raw (base64Encode (p, p + s)); + out (CharConst ("\n")); + } + } + return this; +} + MotorOutput* MotorOutput::outamp (const ustring& t) { outamp (t.begin (), t.end (), &re_encode); return this; diff --git a/lib/motoroutput.h b/lib/motoroutput.h index dd8cdd5..4a2b2a6 100644 --- a/lib/motoroutput.h +++ b/lib/motoroutput.h @@ -38,6 +38,7 @@ class MotorOutput { virtual MotorOutput* out_noCtrl (const ustring& str); virtual MotorOutput* outNbsp (); virtual MotorOutput* out_file (const ustring& srcFile); + virtual MotorOutput* out_file_base64 (const ustring& srcFile); virtual MotorOutput* outamp (const ustring& t); virtual MotorOutput* outamp_br (const ustring& t); virtual MotorOutput* outamp_wbr (const ustring& t); diff --git a/modules/ml-store.cc b/modules/ml-store.cc index 7155dea..c7f170e 100644 --- a/modules/ml-store.cc +++ b/modules/ml-store.cc @@ -564,7 +564,7 @@ MNode* ml_set_xserial (MNode* cell, MlEnv* mlenv) { /*DOC: ===read-file=== - (read-file FILENAME [#serial | #named | :serial BOOL | :named BOOL] [:code ENCODING]) -> STRING + (read-file FILENAME [#serial | #named] [:code ENCODING]) -> STRING (read-file [:source-serial FILENAME | :source-named FILENAME | :source-static FILENAME] [:code ENCODING]) -> STRING */ @@ -630,7 +630,7 @@ MNode* ml_read_file (MNode* cell, MlEnv* mlenv) { /*DOC: ===write-file=== - (write-file FILENAME STRING [#serial | #named | :serial BOOL | :named BOOL] [:code ENCODING] + (write-file FILENAME STRING [#serial | #named] [:code ENCODING] [#crlf | :crlf BOOL]) -> NIL */ @@ -814,7 +814,7 @@ MNode* ml_new_storage (MNode* cell, MlEnv* mlenv) { /*DOC: ===set-storage=== - (set-storage NAME [#create | :create BOOL]) -> NIL + (set-storage NAME [#create]) -> NIL */ //#AFUNC set-storage ml_set_storage @@ -965,7 +965,7 @@ MNode* ml_restore_file (MNode* cell, MlEnv* mlenv) { /*DOC: ===delete-file=== - (delete-file NAME_STORAGE [#serial | #named | :serial BOOL | :named BOOL]) -> NIL + (delete-file NAME_STORAGE [#serial | #named]) -> NIL (delete-file [:target-serial FILENAME | :target-named FILENAME]) -> NIL */ @@ -1013,7 +1013,7 @@ MNode* ml_delete_file (MNode* cell, MlEnv* mlenv) { /*DOC: ===rename-file=== - (rename-file FROM_FILE TO_FILE [#serial | #named | :serial BOOL | :named BOOL]) -> NIL + (rename-file FROM_FILE TO_FILE [#serial | #named]) -> NIL */ //#AFUNC rename-file ml_rename_file @@ -1130,8 +1130,8 @@ public: /*DOC: ===response-motor=== - (response-motor HTMLFILE [#serial | #named | #static | :serial BOOL | :named BOOL | :static BOOL] [:type MIME_TYPE] [#continue | :continue BOOL]) -> NIL - (response-motor [:source-serial FILENAME | :source-named FILENAME | :source-static FILENAME] [:type MIME_TYPE] [#continue | :continue BOOL]) -> NIL + (response-motor HTMLFILE [#serial | #named | #static] [:type MIME_TYPE] [#continue]) -> NIL + (response-motor [:source-serial FILENAME | :source-named FILENAME | :source-static FILENAME] [:type MIME_TYPE] [#continue]) -> NIL */ //#AFUNC response-motor ml_response_motor @@ -1214,23 +1214,11 @@ MNode* ml_response_motor (MNode* cell, MlEnv* mlenv) { } /*DOC: ===response-file=== - (response-file FILENAME [#serial | #named | #static | :serial BOOL | :named BOOL | :static BOOL] - [:type MIME_TYPE] [#inline | :inline BOOL] [:name NAME]) -> NIL + (response-file FILENAME [#serial | #named | #static] [:type MIME_TYPE] [#inline] [:name NAME] [#base64]) -> NIL */ //#AFUNC response-file ml_response_file MNode* ml_response_file (MNode* cell, MlEnv* mlenv) { -#if 0 - ResponseParam par (mlenv); - par.proc (cell, mlenv, false); - if (par.finline || par.dispname.length () > 0) { - mlenv->env->outputFile (par.src, par.type, par.finline, par.dispname); - } else { - mlenv->env->outputFile (par.src, par.type); - } - if (! par.cflag) - mlenv->breakProg (); -#endif MNode* arg = cell->cdr (); StoreType storetype (mlenv); ustring type; @@ -1238,6 +1226,7 @@ MNode* ml_response_file (MNode* cell, MlEnv* mlenv) { ustring dispname; bool cflag = false; bool finline = false; + bool fbase64 = false; MNodePtr t; std::vector keywords; static paramList kwlist[] = { @@ -1251,6 +1240,7 @@ MNode* ml_response_file (MNode* cell, MlEnv* mlenv) { {CharConst ("serial"), true}, // 7 {CharConst ("named"), true}, // 8 {CharConst ("static"), true}, // 9 + {CharConst ("base64"), true}, // 10 {NULL, 0, 0} }; @@ -1284,6 +1274,8 @@ MNode* ml_response_file (MNode* cell, MlEnv* mlenv) { if (keywords[9] && eval_bool (keywords[9], mlenv)) // static storetype.setStatic (); #endif + if (keywords[10]) + fbase64 = eval_bool (keywords[10], mlenv); // base64 src = storetype.src (mlenv); if (type.empty ()) { @@ -1297,9 +1289,9 @@ MNode* ml_response_file (MNode* cell, MlEnv* mlenv) { } if (finline || dispname.length () > 0) { - mlenv->env->outputFile (src, type, finline, dispname); + mlenv->env->outputFile (src, type, finline, dispname, fbase64); } else { - mlenv->env->outputFile (src, type); + mlenv->env->outputFile (src, type, fbase64); } if (! cflag) mlenv->breakProg (); @@ -1309,7 +1301,7 @@ MNode* ml_response_file (MNode* cell, MlEnv* mlenv) { /*DOC: ===filesize=== - (filesize FILENAME [#serial | #named | :serial BOOL | :named BOOL]) -> INTEGER or NIL + (filesize FILENAME [#serial | #named]) -> INTEGER or NIL (filesize [:source-serial FILENAME | :source-named FILENAME | :source-static FILENAME]) -> INTEGER or NIL */ @@ -1366,7 +1358,7 @@ MNode* ml_filesize (MNode* cell, MlEnv* mlenv) { /*DOC: ===list-files=== - (list-files [#serial | #named | :serial BOOL | :named BOOL]) -> LIST_of_FILENAMES + (list-files [#serial | #named]) -> LIST_of_FILENAMES */ //#AFUNC list-files ml_list_files