completed get_handle_login
This commit is contained in:
parent
7f4a319353
commit
6b84d45674
31
src/http.c
31
src/http.c
@ -277,6 +277,25 @@ guess_mime_type(char *filename)
|
|||||||
return "text/plain";
|
return "text/plain";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check a token is not expired. */
|
||||||
|
static bool validate_token_exp(struct http_transaction *ta, char* grants) {
|
||||||
|
|
||||||
|
char *gs = calloc(strlen(grants) + 1, sizeof(char));
|
||||||
|
memcpy(gs, grants, strlen(grants) + 1);
|
||||||
|
char *end;
|
||||||
|
char *expire = strtok_r(gs, "{\":, }", &end);
|
||||||
|
while (expire != NULL) {
|
||||||
|
if (!strcasecmp(expire, "exp")) {
|
||||||
|
int exp = atoi(strtok_r(NULL, "{\":, }", &end));
|
||||||
|
if (time(NULL) >= exp) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Handle HTTP transaction for static files. */
|
/* Handle HTTP transaction for static files. */
|
||||||
static bool
|
static bool
|
||||||
handle_static_asset(struct http_transaction *ta, char *basedir)
|
handle_static_asset(struct http_transaction *ta, char *basedir)
|
||||||
@ -345,16 +364,16 @@ static bool get_handle_login(struct http_transaction *ta) {
|
|||||||
return send_error(ta, HTTP_OK, "{}\n");
|
return send_error(ta, HTTP_OK, "{}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// check expiration, still implementing
|
if (!validate_token_exp(ta, grants)) {
|
||||||
if (1) {
|
|
||||||
return send_error(ta, HTTP_PERMISSION_DENIED,"Forbidden.\n");
|
return send_error(ta, HTTP_PERMISSION_DENIED,"Forbidden.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Still implementing
|
char *json = buffer_ensure_capacity(&ta->resp_body, MAX_HEADER_LEN);
|
||||||
|
int len = snprintf(json, strlen(grants) + 2, "%s\n", grants);
|
||||||
|
int length = len > MAX_HEADER_LEN ? MAX_HEADER_LEN - 1 : len;
|
||||||
|
ta->resp_body.len += length;
|
||||||
|
|
||||||
return send_response(ta);
|
return send_response(ta);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int val_api_url(struct http_transaction *ta) {
|
static int val_api_url(struct http_transaction *ta) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user