Fix env memory bug.

Fix webby.pl::singleton.
Add basic-auth user/pw to Request plstruct.
This commit is contained in:
Sage Vaillancourt 2022-03-29 14:40:18 -04:00 committed by Sage Vaillancourt
parent bedf525dcb
commit ce6c536567
5 changed files with 23 additions and 10 deletions

View File

@ -70,6 +70,7 @@ struct Environment envForLambda(const Object* params, const Object* arg_forms, i
if (paramCount == 0) {
if (outer) {
outer->refs += 1;
return *outer;
}
env.strings = NULL;

View File

@ -18,7 +18,7 @@
(def div (element "div"))
(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 attribute (fn (type) (fn (value) (cat type "='" value "'"))))

View File

@ -674,12 +674,17 @@ inline Object boolObject(int b)
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)
{
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)
{
Object o = symFromSlice(string, len);

View File

@ -200,6 +200,8 @@ Object startList(Object start);
Object objFromSlice(const char* string, int len);
Object nullTerminated(const char* string);
Object stringFromSlice(const char* string, int len);
Object symFromSlice(const char* string, int len);

View File

@ -74,16 +74,25 @@ answer_to_connection(void* cls, struct MHD_Connection* connection,
size_t* upload_data_size, void** con_cls)
{
char* page = NULL;
printf("%s URL: '%s' :: ", method, url);
printf("version: %s\n", version);
printf("upload_data: %s\n", upload_data);
printf("%s :: %s URL: '%s'\n", method, version, url);
if (upload_data) {
printf("upload_data: %s\n", upload_data);
}
for (int i = 0; i < routeCount; i++) {
if (methodMatches(method, &routes[i]) && strcmp(url, routes[i].path) == 0) {
Object queryParams = listObject();
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);
res.structObject->fields[0] = queryParams;
res.structObject->fields[1] = usernameO;
res.structObject->fields[2] = passwordO;
Object route = cloneObject(routes[i].routeAction);
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) 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) con_cls; /* Unused. Silent compiler warning. */
@ -117,7 +122,7 @@ answer_to_connection(void* cls, struct MHD_Connection* connection,
void initialize()
{
printf("Initializing...\n");
Object o = parseEval("(struct Request (queryParams))", global());
Object o = parseEval("(struct Request (queryParams username password))", global());
cleanObject(&o);
requestDefinition = getStructIndex("Request");
}