+/**
+ * Gets the control cookie
+ * @param buffer A storage buffer of exactly CONTROL_KEY_BUFSIZ length to
+ store the control key
+ */
+void FCGI_GetControlCookie(char buffer[CONTROL_KEY_BUFSIZ])
+{
+ const char *cookies = getenv("COOKIE_STRING");
+ const char *start = strstr(cookies, "mctxkey=");
+
+ if (start != NULL) {
+ const char *end;
+ size_t limit = CONTROL_KEY_BUFSIZ;
+ start += 8; //Ah, magic numbers (the length of mctxkey= - 1)
+ end = strchr(start, ';');
+ if (end != NULL && (end-start) < CONTROL_KEY_BUFSIZ) {
+ limit = (end-start) + 1;
+ }
+ snprintf(buffer, limit, "%s", start);
+ Log(LOGDEBUG, "buf: %s", buffer);
+ } else {
+ *buffer = 0;
+ }
+}
+
+/**
+ * Sends the control key to the user as a cookie.
+ * @param context the context to work in
+ * @param set Whether to set or unset the control cookie
+ */
+void FCGI_SendControlCookie(FCGIContext *context, bool set) {
+ if (set) {
+ printf("Set-Cookie: mctxkey=%s\r\n", context->control_key);
+ } else {
+ printf("Set-Cookie: mctxkey=\r\n");
+ }
+}
+