Fix env memory bug.
Fix webby.pl::singleton. Add basic-auth user/pw to Request plstruct.
This commit is contained in:
parent
bedf525dcb
commit
ce6c536567
|
@ -70,6 +70,7 @@ struct Environment envForLambda(const Object* params, const Object* arg_forms, i
|
||||||
|
|
||||||
if (paramCount == 0) {
|
if (paramCount == 0) {
|
||||||
if (outer) {
|
if (outer) {
|
||||||
|
outer->refs += 1;
|
||||||
return *outer;
|
return *outer;
|
||||||
}
|
}
|
||||||
env.strings = NULL;
|
env.strings = NULL;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
(def div (element "div"))
|
(def div (element "div"))
|
||||||
(def article (element "article"))
|
(def article (element "article"))
|
||||||
|
|
||||||
(def singleton (fn (type) (fn (text) (cat "<" type " " (reduce (text "") cat) ">"))))
|
(def singleton (fn (type) (fn (text) (cat "<" type " " (reduce text cat "") ">"))))
|
||||||
(def link (singleton "link"))
|
(def link (singleton "link"))
|
||||||
|
|
||||||
(def attribute (fn (type) (fn (value) (cat type "='" value "'"))))
|
(def attribute (fn (type) (fn (value) (cat type "='" value "'"))))
|
||||||
|
|
|
@ -674,12 +674,17 @@ inline Object boolObject(int b)
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skips first and last chars! Assumed to be '"'
|
/// Skips first and last chars! Assumed to be '"'
|
||||||
inline Object objFromSlice(const char* string, int len)
|
inline Object objFromSlice(const char* string, int len)
|
||||||
{
|
{
|
||||||
return stringFromSlice(&string[1], len - 1);
|
return stringFromSlice(&string[1], len - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Object nullTerminated(const char* string)
|
||||||
|
{
|
||||||
|
return stringFromSlice(string, strlen(string));
|
||||||
|
}
|
||||||
|
|
||||||
inline Object stringFromSlice(const char* string, int len)
|
inline Object stringFromSlice(const char* string, int len)
|
||||||
{
|
{
|
||||||
Object o = symFromSlice(string, len);
|
Object o = symFromSlice(string, len);
|
||||||
|
|
|
@ -200,6 +200,8 @@ Object startList(Object start);
|
||||||
|
|
||||||
Object objFromSlice(const char* string, int len);
|
Object objFromSlice(const char* string, int len);
|
||||||
|
|
||||||
|
Object nullTerminated(const char* string);
|
||||||
|
|
||||||
Object stringFromSlice(const char* string, int len);
|
Object stringFromSlice(const char* string, int len);
|
||||||
|
|
||||||
Object symFromSlice(const char* string, int len);
|
Object symFromSlice(const char* string, int len);
|
||||||
|
|
21
src/web.c
21
src/web.c
|
@ -74,16 +74,25 @@ answer_to_connection(void* cls, struct MHD_Connection* connection,
|
||||||
size_t* upload_data_size, void** con_cls)
|
size_t* upload_data_size, void** con_cls)
|
||||||
{
|
{
|
||||||
char* page = NULL;
|
char* page = NULL;
|
||||||
printf("%s URL: '%s' :: ", method, url);
|
printf("%s :: %s URL: '%s'\n", method, version, url);
|
||||||
printf("version: %s\n", version);
|
if (upload_data) {
|
||||||
printf("upload_data: %s\n", upload_data);
|
printf("upload_data: %s\n", upload_data);
|
||||||
|
}
|
||||||
for (int i = 0; i < routeCount; i++) {
|
for (int i = 0; i < routeCount; i++) {
|
||||||
if (methodMatches(method, &routes[i]) && strcmp(url, routes[i].path) == 0) {
|
if (methodMatches(method, &routes[i]) && strcmp(url, routes[i].path) == 0) {
|
||||||
Object queryParams = listObject();
|
Object queryParams = listObject();
|
||||||
MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, add_query_param, &queryParams);
|
MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, add_query_param, &queryParams);
|
||||||
|
char* password = NULL;
|
||||||
|
char* username = MHD_basic_auth_get_username_password(connection, &password);
|
||||||
|
Object usernameO = username ? nullTerminated(username) : stringFromSlice("", 0);
|
||||||
|
Object passwordO = password ? nullTerminated(password) : stringFromSlice("", 0);
|
||||||
|
MHD_free(username);
|
||||||
|
MHD_free(password);
|
||||||
|
|
||||||
Object res = structObject(requestDefinition);
|
Object res = structObject(requestDefinition);
|
||||||
res.structObject->fields[0] = queryParams;
|
res.structObject->fields[0] = queryParams;
|
||||||
|
res.structObject->fields[1] = usernameO;
|
||||||
|
res.structObject->fields[2] = passwordO;
|
||||||
Object route = cloneObject(routes[i].routeAction);
|
Object route = cloneObject(routes[i].routeAction);
|
||||||
|
|
||||||
Object result = listEvalLambda(&route, &res, 2, routes[i].env);
|
Object result = listEvalLambda(&route, &res, 2, routes[i].env);
|
||||||
|
@ -99,10 +108,6 @@ answer_to_connection(void* cls, struct MHD_Connection* connection,
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) cls; /* Unused. Silent compiler warning. */
|
(void) cls; /* Unused. Silent compiler warning. */
|
||||||
(void) url; /* Unused. Silent compiler warning. */
|
|
||||||
(void) method; /* Unused. Silent compiler warning. */
|
|
||||||
(void) version; /* Unused. Silent compiler warning. */
|
|
||||||
(void) upload_data; /* Unused. Silent compiler warning. */
|
|
||||||
(void) upload_data_size; /* Unused. Silent compiler warning. */
|
(void) upload_data_size; /* Unused. Silent compiler warning. */
|
||||||
(void) con_cls; /* Unused. Silent compiler warning. */
|
(void) con_cls; /* Unused. Silent compiler warning. */
|
||||||
|
|
||||||
|
@ -117,7 +122,7 @@ answer_to_connection(void* cls, struct MHD_Connection* connection,
|
||||||
void initialize()
|
void initialize()
|
||||||
{
|
{
|
||||||
printf("Initializing...\n");
|
printf("Initializing...\n");
|
||||||
Object o = parseEval("(struct Request (queryParams))", global());
|
Object o = parseEval("(struct Request (queryParams username password))", global());
|
||||||
cleanObject(&o);
|
cleanObject(&o);
|
||||||
requestDefinition = getStructIndex("Request");
|
requestDefinition = getStructIndex("Request");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue