Annotation of embedaddon/strongswan/src/conftest/hooks/set_critical.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2010 Martin Willi
! 3: * Copyright (C) 2010 revosec AG
! 4: *
! 5: * This program is free software; you can redistribute it and/or modify it
! 6: * under the terms of the GNU General Public License as published by the
! 7: * Free Software Foundation; either version 2 of the License, or (at your
! 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 9: *
! 10: * This program is distributed in the hope that it will be useful, but
! 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 13: * for more details.
! 14: */
! 15:
! 16: #include "hook.h"
! 17:
! 18: #include <encoding/payloads/unknown_payload.h>
! 19:
! 20: typedef struct private_set_critical_t private_set_critical_t;
! 21:
! 22: /**
! 23: * Private data of an set_critical_t object.
! 24: */
! 25: struct private_set_critical_t {
! 26:
! 27: /**
! 28: * Implements the hook_t interface.
! 29: */
! 30: hook_t hook;
! 31:
! 32: /**
! 33: * Alter requests or responses?
! 34: */
! 35: bool req;
! 36:
! 37: /**
! 38: * ID of message to alter.
! 39: */
! 40: int id;
! 41:
! 42: /**
! 43: * Payload types, space separated
! 44: */
! 45: char *payloads;
! 46: };
! 47:
! 48: METHOD(listener_t, message, bool,
! 49: private_set_critical_t *this, ike_sa_t *ike_sa, message_t *message,
! 50: bool incoming, bool plain)
! 51: {
! 52: if (!incoming && plain &&
! 53: message->get_request(message) == this->req &&
! 54: message->get_message_id(message) == this->id)
! 55: {
! 56: enumerator_t *msg, *types;
! 57: payload_t *payload;
! 58: payload_type_t type;
! 59: bool *critical;
! 60: char *name;
! 61:
! 62: types = enumerator_create_token(this->payloads, " ", "");
! 63: while (types->enumerate(types, &name))
! 64: {
! 65: type = atoi(name);
! 66: if (!type)
! 67: {
! 68: if (!enum_from_name(payload_type_short_names, name, &type))
! 69: {
! 70: DBG1(DBG_CFG, "invalid payload name '%s'", name);
! 71: break;
! 72: }
! 73: }
! 74: msg = message->create_payload_enumerator(message);
! 75: while (msg->enumerate(msg, &payload))
! 76: {
! 77: if (type == payload->get_type(payload))
! 78: {
! 79: critical = payload_get_field(payload, FLAG, 0);
! 80: if (critical)
! 81: {
! 82: *critical = TRUE;
! 83: }
! 84: }
! 85: }
! 86: msg->destroy(msg);
! 87: }
! 88: types->destroy(types);
! 89: }
! 90: return TRUE;
! 91: }
! 92:
! 93: METHOD(hook_t, destroy, void,
! 94: private_set_critical_t *this)
! 95: {
! 96: free(this);
! 97: }
! 98:
! 99: /**
! 100: * Create the IKE_AUTH fill hook
! 101: */
! 102: hook_t *set_critical_hook_create(char *name)
! 103: {
! 104: private_set_critical_t *this;
! 105:
! 106: INIT(this,
! 107: .hook = {
! 108: .listener = {
! 109: .message = _message,
! 110: },
! 111: .destroy = _destroy,
! 112: },
! 113: .req = conftest->test->get_bool(conftest->test,
! 114: "hooks.%s.request", TRUE, name),
! 115: .id = conftest->test->get_int(conftest->test,
! 116: "hooks.%s.id", 0, name),
! 117: .payloads = conftest->test->get_str(conftest->test,
! 118: "hooks.%s.payloads", "", name),
! 119: );
! 120:
! 121: return &this->hook;
! 122: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>