Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "AclFiltering.h"
00025 #include "Main.h"
00026 #include "Error.h"
00027 #include "HTTP.h"
00028
00029
00030
00031
00032
00033 void
00034 acl_filter_rule::reset(void)
00035 {
00036 int i;
00037 for (i = (argc = 0); i < ACL_FILTER_MAX_ARGV; i++) {
00038 argv[i] = (char *)ats_free_null(argv[i]);
00039 }
00040 method_restriction_enabled = false;
00041 for (i = 0; i < HTTP_WKSIDX_METHODS_CNT; i++) {
00042 standard_method_lookup[i] = false;
00043 }
00044 nonstandard_methods.clear();
00045 for (i = (src_ip_cnt = 0); i < ACL_FILTER_MAX_SRC_IP; i++) {
00046 src_ip_array[i].reset();
00047 }
00048 src_ip_valid = 0;
00049 }
00050
00051 acl_filter_rule::acl_filter_rule():next(NULL), filter_name_size(0), filter_name(NULL), allow_flag(1),
00052 src_ip_valid(0), active_queue_flag(0), argc(0)
00053 {
00054 standard_method_lookup.resize(HTTP_WKSIDX_METHODS_CNT);
00055 ink_zero(argv);
00056 reset();
00057 }
00058
00059 acl_filter_rule::~acl_filter_rule()
00060 {
00061 reset();
00062 name();
00063 }
00064
00065 int
00066 acl_filter_rule::add_argv(int _argc, char *_argv[])
00067 {
00068 int real_cnt = 0;
00069 if (likely(_argv)) {
00070 for (int i = 0; i < _argc && argc < ACL_FILTER_MAX_ARGV; i++) {
00071 if (likely(_argv[i] && (argv[argc] = ats_strdup(_argv[i])) != NULL)) {
00072 real_cnt++;
00073 argc++;
00074 }
00075 }
00076 }
00077 return real_cnt;
00078 }
00079
00080 int
00081 acl_filter_rule::name(const char *_name)
00082 {
00083 filter_name_size = 0;
00084 filter_name = (char *)ats_free_null(filter_name);
00085 if (_name && _name[0] && (filter_name = ats_strdup(_name)) != NULL) {
00086 filter_name_size = strlen(filter_name);
00087 }
00088 return filter_name_size;
00089 }
00090
00091 void
00092 acl_filter_rule::print(void)
00093 {
00094 int i;
00095 printf("-----------------------------------------------------------------------------------------\n");
00096 printf("Filter \"%s\" status: allow_flag=%d, src_ip_valid=%d, active_queue_flag=%d\n",
00097 filter_name ? filter_name : "<NONAME>", (int) allow_flag,
00098 (int) src_ip_valid, (int) active_queue_flag);
00099 printf("standard methods=");
00100 for (i = 0; i < HTTP_WKSIDX_METHODS_CNT; i++) {
00101 if (standard_method_lookup[i]) {
00102 printf("0x%x ", HTTP_WKSIDX_CONNECT + i);
00103 }
00104 }
00105 printf("nonstandard methods=");
00106 for (MethodMap::iterator iter = nonstandard_methods.begin(), end = nonstandard_methods.end(); iter != end; ++iter) {
00107 printf("%s ", iter->c_str());
00108 }
00109 printf("\n");
00110 printf("src_ip_cnt=%d\n", src_ip_cnt);
00111 for (i = 0; i < src_ip_cnt; i++) {
00112 ip_text_buffer b1, b2;
00113 printf("%s - %s"
00114 , ats_ip_ntop(&src_ip_array[i].start.sa, b1, sizeof(b1))
00115 , ats_ip_ntop(&src_ip_array[i].end.sa, b2, sizeof(b2))
00116 );
00117 }
00118 for (i = 0; i < argc; i++) {
00119 printf("argv[%d] = \"%s\"\n", i, argv[i]);
00120 }
00121 }
00122
00123 acl_filter_rule *
00124 acl_filter_rule::find_byname(acl_filter_rule *list, const char *_name)
00125 {
00126 int _name_size = 0;
00127 acl_filter_rule *rp = 0;
00128 if (likely(list && _name && (_name_size = strlen(_name)) > 0)) {
00129 for (rp = list; rp; rp = rp->next) {
00130 if (rp->filter_name_size == _name_size && !strcasecmp(rp->filter_name, _name))
00131 break;
00132 }
00133 }
00134 return rp;
00135 }
00136
00137 void
00138 acl_filter_rule::delete_byname(acl_filter_rule **rpp, const char *_name)
00139 {
00140 int _name_size = 0;
00141 acl_filter_rule *rp;
00142 if (likely(rpp && _name && (_name_size = strlen(_name)) > 0)) {
00143 for (; (rp = *rpp) != NULL; rpp = &rp->next) {
00144 if (rp->filter_name_size == _name_size && !strcasecmp(rp->filter_name, _name)) {
00145 *rpp = rp->next;
00146 delete rp;
00147 break;
00148 }
00149 }
00150 }
00151 }
00152
00153 void
00154 acl_filter_rule::requeue_in_active_list(acl_filter_rule **list, acl_filter_rule *rp)
00155 {
00156 if (likely(list && rp)) {
00157 if (rp->active_queue_flag == 0) {
00158 acl_filter_rule *r, **rpp;
00159 for (rpp = list; ((r = *rpp) != NULL); rpp = &(r->next)) {
00160 if (r == rp) {
00161 *rpp = r->next;
00162 break;
00163 }
00164 }
00165 for (rpp = list; ((r = *rpp) != NULL); rpp = &(r->next)) {
00166 if (r->active_queue_flag == 0)
00167 break;
00168 }
00169 (*rpp = rp)->next = r;
00170 rp->active_queue_flag = 1;
00171 }
00172 }
00173 }
00174
00175 void
00176 acl_filter_rule::requeue_in_passive_list(acl_filter_rule **list, acl_filter_rule *rp)
00177 {
00178 if (likely(list && rp)) {
00179 if (rp->active_queue_flag) {
00180 acl_filter_rule **rpp;
00181 for (rpp = list; *rpp; rpp = &((*rpp)->next)) {
00182 if (*rpp == rp) {
00183 *rpp = rp->next;
00184 break;
00185 }
00186 }
00187 for (rpp = list; *rpp; rpp = &((*rpp)->next));
00188 (*rpp = rp)->next = NULL;
00189 rp->active_queue_flag = 0;
00190 }
00191 }
00192 }