src/server/safs/objecttype.c

changeset 415
d938228c382e
parent 201
196a3caebdc7
child 428
ab58e46b50a5
equal deleted inserted replaced
414:99a34860c105 415:d938228c382e
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include <ucx/string.h> 29 #include <cx/string.h>
30 #include <ucx/map.h> 30 #include <cx/map.h>
31 31
32 #include "objecttype.h" 32 #include "objecttype.h"
33 #include "../util/pblock.h" 33 #include "../util/pblock.h"
34 34
35 #include "../daemon/config.h" 35 #include "../daemon/config.h"
36 #include "../daemon/session.h" 36 #include "../daemon/session.h"
37 37
38 int object_type_by_extension(pblock *pb, Session *sn, Request *rq) { 38 int object_type_by_extension(pblock *pb, Session *sn, Request *rq) {
39 sstr_t path = sstr(pblock_findkeyval(pb_key_path, rq->vars)); 39 cxstring path = cx_str(pblock_findkeyval(pb_key_path, rq->vars));
40 //printf("\nobject_type_by_extension: {%s}[%d]\n\n", path); 40 //printf("\nobject_type_by_extension: {%s}[%d]\n\n", path);
41 41
42 sstr_t ct; 42 cxstring ct;
43 if(path.ptr[path.length - 1] == '/') { 43 if(path.ptr[path.length - 1] == '/') {
44 // directory 44 // directory
45 ct = sstrn("internal/directory", 18); 45 ct = (cxstring)CX_STR("internal/directory");
46 } else { 46 } else {
47 sstr_t ext; 47 cxstring ext;
48 ext.length = 0; 48 ext.length = 0;
49 for(int i=path.length - 1;i>=0;i--) { 49 for(int i=path.length - 1;i>=0;i--) {
50 if(path.ptr[i] == '.') { 50 if(path.ptr[i] == '.') {
51 ext.ptr = path.ptr + i + 1; 51 ext.ptr = path.ptr + i + 1;
52 ext.length = path.length - i - 1; 52 ext.length = path.length - i - 1;
64 64
65 WS_ASSERT(config); 65 WS_ASSERT(config);
66 WS_ASSERT(config->mimetypes); 66 WS_ASSERT(config->mimetypes);
67 WS_ASSERT(config->mimetypes->map); 67 WS_ASSERT(config->mimetypes->map);
68 68
69 char *type = ucx_map_sstr_get(config->mimetypes->map, ext); 69 char *type = cxMapGet(config->mimetypes->map, cx_hash_key_bytes((const unsigned char*)ext.ptr, ext.length));
70 70
71 if(!type) { 71 if(!type) {
72 return REQ_NOACTION; 72 return REQ_NOACTION;
73 } 73 }
74 74

mercurial