Changeset 472
- Timestamp:
- 07/24/2005 06:58:03 AM (3 years ago)
- Location:
- branches/lighttpd-1.3.x/src
- Files:
-
- 3 modified
-
mod_cml_funcs.c (modified) (3 diffs)
-
mod_cml_funcs.h (modified) (1 diff)
-
mod_cml_lua.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/lighttpd-1.3.x/src/mod_cml_funcs.c
r452 r472 6 6 #include <errno.h> 7 7 #include <unistd.h> 8 #include <dirent.h> 8 9 #include <stdio.h> 9 10 … … 75 76 76 77 if (n != 1) { 77 lua_pushstring(L, " expected one argument");78 lua_error(L); 79 } 80 81 if (!lua_isstring(L, 1)) { 82 lua_pushstring(L, " argument has to be a string");78 lua_pushstring(L, "file_mtime: expected one argument"); 79 lua_error(L); 80 } 81 82 if (!lua_isstring(L, 1)) { 83 lua_pushstring(L, "file_mtime: argument has to be a string"); 83 84 lua_error(L); 84 85 } 85 86 86 87 if (-1 == stat(lua_tostring(L, 1), &st)) { 87 lua_push string(L, "stat failed");88 lua_error(L);88 lua_pushnil(L); 89 return 1; 89 90 } 90 91 … … 93 94 return 1; 94 95 } 96 97 int f_dir_files_iter(lua_State *L) { 98 DIR *d; 99 struct dirent *de; 100 int n = lua_gettop(L); 101 102 d = lua_touserdata(L, lua_upvalueindex(1)); 103 104 if (NULL == (de = readdir(d))) { 105 /* EOF */ 106 closedir(d); 107 108 return 0; 109 } else { 110 lua_pushstring(L, de->d_name); 111 return 1; 112 } 113 } 114 115 int f_dir_files(lua_State *L) { 116 DIR *d; 117 int n = lua_gettop(L); 118 119 if (n != 1) { 120 lua_pushstring(L, "dir_files: expected one argument"); 121 lua_error(L); 122 } 123 124 if (!lua_isstring(L, 1)) { 125 lua_pushstring(L, "dir_files: argument has to be a string"); 126 lua_error(L); 127 } 128 129 /* check if there is a valid DIR handle on the stack */ 130 if (NULL == (d = opendir(lua_tostring(L, 1)))) { 131 lua_pushnil(L); 132 return 1; 133 } 134 135 /* push d into registry */ 136 lua_pushlightuserdata(L, d); 137 lua_pushcclosure(L, f_dir_files_iter, 1); 138 139 return 1; 140 } 141 142 int f_file_isreg(lua_State *L) { 143 struct stat st; 144 int n = lua_gettop(L); 145 146 if (n != 1) { 147 lua_pushstring(L, "file_isreg: expected one argument"); 148 lua_error(L); 149 } 150 151 if (!lua_isstring(L, 1)) { 152 lua_pushstring(L, "file_isreg: argument has to be a string"); 153 lua_error(L); 154 } 155 156 if (-1 == stat(lua_tostring(L, 1), &st)) { 157 lua_pushnil(L); 158 return 1; 159 } 160 161 lua_pushnumber(L, S_ISREG(st.st_mode)); 162 163 return 1; 164 } 165 95 166 96 167 #ifdef HAVE_MEMCACHE_H -
branches/lighttpd-1.3.x/src/mod_cml_funcs.h
r463 r472 9 9 int f_crypto_md5(lua_State *L); 10 10 int f_file_mtime(lua_State *L); 11 int f_file_isreg(lua_State *L); 12 int f_dir_files(lua_State *L); 13 11 14 int f_memcache_exists(lua_State *L); 12 15 int f_memcache_get_string(lua_State *L); -
branches/lighttpd-1.3.x/src/mod_cml_lua.c
r469 r472 2 2 #include <stdio.h> 3 3 #include <errno.h> 4 #include <time.h> 4 5 5 6 #include "mod_cml.h" … … 165 166 lua_register(L, "md5", f_crypto_md5); 166 167 lua_register(L, "file_mtime", f_file_mtime); 168 lua_register(L, "file_isreg", f_file_isreg); 169 lua_register(L, "dir_files", f_dir_files); 167 170 168 171 #ifdef HAVE_MEMCACHE_H … … 313 316 if (ret == 0) { 314 317 con->file_finished = 1; 315 318 319 /* no Last-Modified specified */ 320 if (mtime && NULL == array_get_element(con->response.headers, "Last-Modified")) { 321 char timebuf[sizeof("Sat, 23 Jul 2005 21:20:01 GMT")]; 322 323 strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&mtime)); 324 325 response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), timebuf, sizeof(timebuf) - 1); 326 } 327 316 328 if (http_response_handle_cachable(srv, con, mtime)) { 317 329 /* ok, the client already has our content,

