#endif
#include "afb-method.h"
-#include "afb-req-itf.h"
+#include <afb/afb-req-itf.h>
#include "afb-msg-json.h"
#include "afb-context.h"
#include "afb-hreq.h"
static char empty_string[] = "";
-static const char uuid_header[] = "x-afb-uuid";
-static const char uuid_arg[] = "uuid";
-static const char uuid_cookie[] = "uuid";
+static const char key_for_uuid[] = "x-afb-uuid";
+static const char old_key_for_uuid[] = "uuid";
-static const char token_header[] = "x-afb-token";
-static const char token_arg[] = "token";
-static const char token_cookie[] = "token";
+static const char key_for_token[] = "x-afb-token";
+static const char old_key_for_token[] = "token";
static char *cookie_name = NULL;
static char *cookie_setter = NULL;
.context_get = (void*)afb_context_get,
.context_set = (void*)afb_context_set,
.addref = (void*)afb_hreq_addref,
- .unref = (void*)afb_hreq_unref
+ .unref = (void*)afb_hreq_unref,
+ .session_close = (void*)afb_context_close,
+ .session_set_LOA = (void*)afb_context_change_loa
};
static struct hreq_data *get_data(struct afb_hreq *hreq, const char *key, int create)
int afb_hreq_redirect_to(struct afb_hreq *hreq, const char *url)
{
+ /* TODO: append the query part! */
afb_hreq_reply_static(hreq, MHD_HTTP_MOVED_PERMANENTLY, 0, NULL,
MHD_HTTP_HEADER_LOCATION, url, NULL);
DEBUG("redirect from [%s] to [%s]", hreq->url, url);
if (hreq->context.session != NULL)
return 0;
- uuid = afb_hreq_get_header(hreq, uuid_header);
+ uuid = afb_hreq_get_header(hreq, key_for_uuid);
if (uuid == NULL)
- uuid = afb_hreq_get_argument(hreq, uuid_arg);
+ uuid = afb_hreq_get_argument(hreq, key_for_uuid);
if (uuid == NULL)
uuid = afb_hreq_get_cookie(hreq, cookie_name);
+ if (uuid == NULL)
+ uuid = afb_hreq_get_argument(hreq, old_key_for_uuid);
- token = afb_hreq_get_header(hreq, token_header);
+ token = afb_hreq_get_header(hreq, key_for_token);
if (token == NULL)
- token = afb_hreq_get_argument(hreq, token_arg);
+ token = afb_hreq_get_argument(hreq, key_for_token);
if (token == NULL)
- token = afb_hreq_get_cookie(hreq, token_cookie);
+ token = afb_hreq_get_argument(hreq, old_key_for_token);
return afb_context_connect(&hreq->context, uuid, token);
}
cookie_setter = NULL;
path = path ? : "/";
- rc = asprintf(&cookie_name, "x-afb-uuid-%d", port);
+ rc = asprintf(&cookie_name, "%s-%d", key_for_uuid, port);
if (rc < 0)
return 0;
rc = asprintf(&cookie_setter, "%s=%%s; Path=%s; Max-Age=%d; HttpOnly",