Guest User

Untitled

a guest
Feb 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. static int req_dispatch(lua_State* L) {
  2. request_rec* r = check_request_rec(L, 1);
  3. const char *name = luaL_checkstring(L, 2);
  4. ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "dispatching %s", name);
  5. lua_pop(L, 2);
  6.  
  7. lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
  8. apr_hash_t* dispatch = lua_touserdata(L, 1);
  9. lua_pop(L, 1);
  10.  
  11. req_fun_t* rft = apr_hash_get(dispatch, name, APR_HASH_KEY_STRING);
  12. if (rft) {
  13. ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "rft -> %d, type -> %d", (int)rft, rft->type);
  14. switch(rft->type) {
  15. case APW_REQ_FUNTYPE_LUACFUN: {
  16. ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s -> lua_CFunction", name);
  17. lua_CFunction func = rft->fun;
  18. lua_pushcfunction(L, func);
  19. return 1;
  20. }
  21. case APW_REQ_FUNTYPE_STRING: {
  22. ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s -> string", name);
  23. req_field_string_f func = rft->fun;
  24. char* rs = (*func)(r);
  25. lua_pushstring(L, rs);
  26. return 1;
  27. }
  28. case APW_REQ_FUNTYPE_INT: {
  29. ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s -> int", name);
  30. req_field_int_f func = rft->fun;
  31. int rs = (*func)(r);
  32. lua_pushnumber(L, rs);
  33. return 1;
  34. }
  35. case APW_REQ_FUNTYPE_BOOLEAN: {
  36. ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "%s -> boolean", name);
  37. req_field_int_f func = rft->fun;
  38. int rs = (*func)(r);
  39. lua_pushboolean(L, rs);
  40. return 1;
  41. }
  42. }
  43. }
  44.  
  45. ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "nothing for %s", name);
  46. return 0;
  47. }
Add Comment
Please, Sign In to add comment