Hi Ivo, First of all thanks for sharing this.
On Thu, May 17, 2012 at 12:28 PM, Ivo Brunnbauer <[email protected]> wrote: > Hi, I'm proposing/+releasing my deflate compression plugin for monkey, I > explain shortly how it works: > In the conf file you can add directories relative to the htdocs folder which > will be watched and served compressed. The plugin creates a hidden > compressed version of each file in the watched folders and compresses and > serves that version of the file when a request comes in for the normal file. > This is the most efficient way to do it, every file only gets compressed > only a single time, no runtime compression. > It watches the directory with inotify and recompresses files on change > event, so you can even have it running during development and deployment, > and it will serve new files you add as compressed too. > > It uses the raw deflate algorithm from zlib, therefore it will work in all > browsers except <= Android 1.6, if I remember my initial research correctly. > It's both faster and more efficient than gzip. I have not tested the plugin yet, just looking around pretty quickly i would suggest some changes: 1) format strings: + char* directoryDup = malloc(256); + memset(directoryDup, '\0', 256); + strcat(directoryDup, directory_path); + strcat(directoryDup, "/"); + strcat(directoryDup, ent->d_name); those calls are too expensive to compose a buffer, please use mk_api->string_build(...) 2) Validate files: + FILE* source = fopen(directoryDup, "r"); + FILE* dest = fopen(hiddenname, "w+"); If some path have some permission problems the next functions will fail as it does not contain validation 3) Memory allocation: Please use mk_api->mem_alloc() instead of direct malloc() 4) Constant string length: mk_header_content_encoding_deflate.len = strlen(MK_HEADER_CONTENT_ENCODING_DEFLATE); this can be replaced with: mk_header_content_encoding_deflate.len = sizeof(MK_HEADER_CONTENT_ENCODING_DEFLATE) - 1; 5) Split strings: char** res = splitstring(&line, " ", &counter, 10); please check the API call mk_api->str_split_line(); 6) Directories: + readlink("/proc/self/exe", fullpath, 512); + char* test = dirname(dirname(fullpath)); + sprintf(fullpath, "%s%s", test, "/htdocs/"); you can get the htdocs path using the information from the virtual host struct (make sure it works with virtualhosts) If you need help with this let me know so we can talk on IRC to move forward, regards, > > _______________________________________________ > Monkey mailing list > [email protected] > http://lists.monkey-project.com/listinfo/monkey > -- Eduardo Silva http://edsiper.linuxchile.cl http://www.monkey-project.com _______________________________________________ Monkey mailing list [email protected] http://lists.monkey-project.com/listinfo/monkey
