This commit is contained in:
ame 2024-02-02 08:37:52 -06:00
parent 18a0280167
commit 3218ddb895
3 changed files with 74 additions and 7 deletions

View file

@ -294,7 +294,7 @@ void* handle_client(void *_arg){
str* aa = str_init(portc);
str_push(aa, table[k]->c);
void* v = parray_get(paths, aa->c);
void* v = parray_find(paths, aa->c);
if(v == NULL){
str* resp;
@ -339,9 +339,31 @@ void* handle_client(void *_arg){
lua_settable(L, res_idx);
//the function(s)
struct sarray_t* awa = (struct sarray_t*)v;
//get all function that kinda match
parray_t* owo = (parray_t*)v;
for(int i = 0; i != owo->len; i++){
//though these are arrays of arrays we have to iterate *again*
struct sarray_t* awa = (struct sarray_t*)owo->P[i].value;
for(int z = 0; z != awa->len; z++){
struct lchar* wowa = awa->cs[z];
luaL_loadbuffer(L, wowa->c, wowa->len, wowa->c);
int func = lua_gettop(L);
lua_pushvalue(L, func); // push function call
lua_pushvalue(L, res_idx); //push methods related to dealing with the request
lua_pushvalue(L, req_idx); //push info about the request
//call the function
lua_call(L, 2, 0);
}
}
/*
for(int i = 0; i != awa->len; i++){
struct lchar* wowa = awa->cs[i];
//struct lchar* wowa = awa->cs[i];
luaL_loadbuffer(L, wowa->c, wowa->len, wowa->c);
int func = lua_gettop(L);
@ -352,7 +374,8 @@ void* handle_client(void *_arg){
//call the function
lua_call(L, 2, 0);
}
}*/
}
}

View file

@ -35,11 +35,51 @@ void* parray_get(parray_t* p, char* key){
return NULL;
}
void parray_lclear(parray_t* p){
free(p->P);
free(p);
}
void parray_clear(parray_t* p, int clear_val){
for(int i = 0; i != p->len; i++){
str_free(p[i].P->key);
if(clear_val) free(p[i].P->value);
}
free(p->P);
free(p);
parray_lclear(p);
}
int fmatch(char* s, char* p) {
int slen = strlen(s);
int plen = strlen(p);
int sidx = 0, pidx = 0, lastWildcardIdx = -1, sBacktrackIdx = -1, nextToWildcardIdx = -1;
for(;sidx < slen;) {
if (pidx < plen && (p[pidx] == '?' || p[pidx] == s[sidx])) {
sidx++;
pidx++;
} else if (pidx < plen && p[pidx] == '*') {
lastWildcardIdx = pidx;
nextToWildcardIdx = ++pidx;
sBacktrackIdx = sidx;
} else if (lastWildcardIdx == -1) {
return 0;
} else {
pidx = nextToWildcardIdx;
sidx = sBacktrackIdx++;
}
}
for(int i = pidx; i < plen; i++) if(p[i] != '*') return 0;
return 1;
}
parray_t* parray_find(parray_t* p, char* match){
parray_t* ret = malloc(sizeof * ret);
ret->P = malloc(sizeof * ret->P * p->len);
ret->len = 0;
for(int i = 0; i != p->len; i++){
if(fmatch(match, p->P[i].key->c)){
ret->P[ret->len] = p->P[i];
ret->len++;
}
}
return ret;
}

View file

@ -15,4 +15,8 @@ void parray_set(parray_t*, char*, void*);
void* parray_get(parray_t* , char*);
void parray_clear(parray_t*, int);
void parray_clear(parray_t*, int);
void parray_lclear(parray_t*);
parray_t* parray_find(parray_t*, char*);