/**
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2015 ForgeRock AS.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vrt.h>
#include <vrt_obj.h>
#include <sys/resource.h>
#include <vsa.h>
#include <pthread.h>
#include <unistd.h>
#include "version.h"
#include "am.h"
#include "list.h"
#define HTTP_HDR_SET 0
#define AM_ADD_HEADER_RESP_DELIVER(r, n, v) am_add_header(r, n, v, AM_SUCCESS, HTTP_HDR_SET, HDR_RESP)
struct agent_instance {
unsigned long instance_id;
char *conf_file;
int status;
};
struct header {
int type;
int unset;
char *name;
char *value;
};
struct request {
int status;
int inauth;
char *body;
char *notes;
};
static int n_init = 0;
char *url_decode(const char *str);
do {
if (n_init++ != 1) break;
break;
}
if (cache_param->wthread_stacksize > 0) {
/*if (cache_param->wthread_stacksize < min_stack_sz) {
fprintf(stderr, "am_vmod_init failed. minimum stack size required %ld, configured %ld bytes. "
"Consider adjusting thread_pool_stack parameter value\n",
min_stack_sz, cache_param->wthread_stacksize);
break;
}*/
}
break;
}
break;
}
fprintf(stderr, "am_vmod_init failed. failed to load agent bootstrap configuration file (%s)\n", conf);
break;
}
} while (0);
}
if (t != NULL) {
delete_request_list(&t->next);
free(t);
t = NULL;
}
}
struct header *h;
if (h == NULL) {
return AM_ENOMEM;
}
return AM_ENOMEM;
}
/* http_SetHeader requires both h->name as Varnish header and h->value as header + value */
return AM_ENOMEM;
}
}
AM_LIST_INSERT(r->headers, h);
return AM_SUCCESS;
}
/* request list is not yet available for this worker thread,
* create one now and register this request */
return NULL;
}
return req_list;
}
/* list is there already, register this request */
if (req_list_entry == NULL) {
return NULL;
}
return req_list_entry;
}
if (request_list == NULL) {
return NULL;
}
return e;
}
}
return NULL;
}
return NULL;
}
return header;
}
return NULL;
}
}
NOTNULL(VRT_r_server_identity(req->ctx)), /* varnishd -i option; must be in the form: -i "http://agent.fqdn" */
return AM_ERROR;
}
return AM_SUCCESS;
}
}
const char *current_cookies;
if (ISVALID(current_cookies)) {
if (h == NULL) {
return AM_ENOMEM;
}
strcat(h, "; ");
strcat(h, current_cookies);
return AM_SUCCESS;
}
return AM_SUCCESS;
}
/* value is empty, agent is setting the cookie in response */
}
}
return AM_SUCCESS;
}
}
switch (v) {
case AM_SUCCESS:
case AM_PDP_DONE:
case AM_DONE:
case AM_NOT_HANDLING:
return 200;
case AM_NOT_FOUND:
return 404;
case AM_INTERNAL_REDIRECT:
case AM_REDIRECT:
return 302;
case AM_FORBIDDEN:
return 403;
case AM_BAD_REQUEST:
return 400;
case AM_NOT_IMPLEMENTED:
return 501;
default:
return 500;
}
}
return AM_EINVAL;
}
switch (status) {
case AM_JSON_RESPONSE:
{
case AM_PDP_DONE:
break;
case AM_REDIRECT:
case AM_INTERNAL_REDIRECT:
break;
default:
{
break;
}
}
break;
}
case AM_PDP_DONE:
{
/* special handler for x-www-form-urlencoded POST data */
int form_sz;
break;
}
if (a == NULL) {
break;
}
if (eq) {
*eq++ = 0;
"%s<input type=\"hidden\" name=\"%s\" value=\"%s\"/>",
} else {
"%s<input type=\"hidden\" name=\"%s\" value=\"\"/>",
}
}
}
}
break;
}
break;
}
break;
}
case AM_INTERNAL_REDIRECT:
case AM_REDIRECT:
{
break;
}
default:
{
}
break;
}
}
return AM_SUCCESS;
}
const char *content_length_s;
char *body;
int bytes_read;
errno = 0;
return AM_NOT_FOUND;
}
return AM_ENOMEM;
}
while (content_length) {
if (bytes_read <= 0) {
return AM_ERROR;
}
total_read += bytes_read;
}
return AM_SUCCESS;
}
ar->post_data_sz);
}
}
return AM_SUCCESS;
}
unsigned int result = 0;
int status;
VSLb(ctx->vsl, SLT_VCL_Error, "am_vmod failed to allocate memory for agent instance data structures");
return result;
}
VSLb(ctx->vsl, SLT_VCL_Error, "am_vmod failed to initialize agent instance, configuration: %s, error: %s",
AM_LOG_ERROR(settings->instance_id, "vmod_authenticate(): failed to initialize agent instance, error: %s",
return result;
}
VSLb(ctx->vsl, SLT_VCL_Error, "am_vmod failed to get agent configuration instance, configuration: %s, error: %s",
AM_LOG_ERROR(settings->instance_id, "vmod_authenticate(): failed to get agent configuration instance, error: %s",
return result;
}
}
}
}
return result;
}
switch (where) {
case HDR_REQ:
case HDR_BEREQ:
return ctx->http_bereq;
case HDR_BERESP:
return ctx->http_beresp;
case HDR_RESP:
default:
return NULL;
}
}
}
if (request_list == NULL) return;
/* remove request from the list */
if (request_list == e) {
request_list = e->next;
} else {
tmp = request_list;
}
}
}
free(e);
break;
}
}
}
int status;
struct header *h, *t;
return;
}
status = 503;
}
}
}
}
}
int status;
struct header *h, *t;
status = 503;
}
/* pass backend response status to the caller */
}
if (h->type != AM_SUCCESS) continue;
if (!h->unset) continue;
}
}
}
}
}
static void make_key() {
}
}
}
if (settings) {
if (n_init++ == 0) {
}
} else {
}
return 0;
}