<%# //cppsp module to enable directory listing #include #define TO_C_STR(in,inLen,out) char out[inLen+1];\ memcpy(out,in,inLen);\ out[inLen]=0; DelegateChain)>::item* it; Server* server; void handleRequest(void*, Request& req, Response& resp, Delegate cb) { struct stat st; String s=server->mapPath(req.path,*req.sp); TO_C_STR(s.data(),s.length(),tmp); if(::stat(tmp,&st)>=0 && S_ISDIR(st.st_mode)) { server->handleDynamicRequest("/dir_list.cppsm",req,resp,cb); return; } (*it->prev)(req,resp,cb); } extern "C" void initModule(Server* s) { server=s; it=s->handleRequest.attach(&handleRequest); } extern "C" void deinitModule() { server->handleRequest.detach(it); } %> Index of <% htmlEscape(request->path,output); %>

Index of <% htmlEscape(request->path,output); %>

<% string path=server->mapPath(request->path.toSTDString()); vector list; auto tmp=[&](const char* name) { list.push_back(name); }; listDirectory(path.c_str(), &tmp); std::sort(list.begin(),list.end()); for(int i=0;i <% } %>
Name Last modified Size

<% htmlEscape(name.c_str(),output); %><%if(S_ISDIR(st.st_mode)){%>/<%}%> <%=buffer%> <%=(int64_t)st.st_size%>