void parse_refreshCheckHelper(refresh_check_helper ** ptr) { refresh_check_helper *a; char *token; refresh_check_format **p; if (*ptr) self_destruct(); CBDATA_INIT_TYPE_FREECB(refresh_check_helper, free_refresh_check_helper); CBDATA_INIT_TYPE_FREECB(refresh_check_format, free_refresh_check_format); a = cbdataAlloc(refresh_check_helper); a->children = DEFAULT_REFRESH_CHECK_CHILDREN; /* Parse options */ while ((token = strtok(NULL, w_space)) != NULL) { if (strncmp(token, "children=", 9) == 0) { a->children = atoi(token + 9); } else if (strncmp(token, "concurrency=", 12) == 0) { a->concurrency = atoi(token + 12); } else { break; } } /* Parse format */ p = &a->format; while (token) { refresh_check_format *format; /* stop on first non-format token found */ if (*token != '%') break; format = cbdataAlloc(refresh_check_format); if (strncmp(token, "%RES{", 5) == 0) { /* header format */ char *header, *member, *end; header = token + 5; end = strchr(header, '}'); /* cut away the terminating } */ if (end && strlen(end) == 1) *end = '\0'; else self_destruct(); member = strchr(header, ':'); if (member) { /* Split in header and member */ *member++ = '\0'; if (!xisalnum(*member)) format->separator = *member++; else format->separator = ','; format->member = xstrdup(member); format->type = REFRESH_CHECK_RESP_HEADER_MEMBER; } else { format->type = REFRESH_CHECK_RESP_HEADER; } format->header = xstrdup(header); format->header_id = httpHeaderIdByNameDef(header, strlen(header)); if (format->header_id != -1) { if (member) format->type = REFRESH_CHECK_RESP_HEADER_ID_MEMBER; else format->type = REFRESH_CHECK_RESP_HEADER_ID; } } else if (strcmp(token, "%URI") == 0) format->type = REFRESH_CHECK_URI; else if (strcmp(token, "%URL") == 0) format->type = REFRESH_CHECK_URI; else if (strcmp(token, "%CACHE_URI") == 0) format->type = REFRESH_CHECK_URI; else if (strcmp(token, "%AGE") == 0) format->type = REFRESH_CHECK_AGE; else { self_destruct(); } *p = format; p = &format->next; token = strtok(NULL, w_space); } /* There must be at least one format token */ if (!a->format) self_destruct(); /* helper */ if (!token) self_destruct(); wordlistAdd(&a->cmdline, token); /* arguments */ parse_wordlist(&a->cmdline); *ptr = a; }
void parse_externalAclHelper(external_acl ** list) { external_acl *a; char *token; external_acl_format **p; CBDATA_INIT_TYPE_FREECB(external_acl, free_external_acl); CBDATA_INIT_TYPE_FREECB(external_acl_format, free_external_acl_format); a = cbdataAlloc(external_acl); a->ttl = DEFAULT_EXTERNAL_ACL_TTL; a->negative_ttl = -1; a->children = DEFAULT_EXTERNAL_ACL_CONCURRENCY; token = strtok(NULL, w_space); if (!token) self_destruct(); a->name = xstrdup(token); token = strtok(NULL, w_space); /* Parse options */ while (token) { if (strncmp(token, "ttl=", 4) == 0) { a->ttl = atoi(token + 4); } else if (strncmp(token, "negative_ttl=", 13) == 0) { a->negative_ttl = atoi(token + 13); } else if (strncmp(token, "children=", 9) == 0) { a->children = atoi(token + 9); } else if (strncmp(token, "concurrency=", 12) == 0) { a->children = atoi(token + 12); } else if (strncmp(token, "cache=", 6) == 0) { a->cache_size = atoi(token + 6); } else { break; } token = strtok(NULL, w_space); } if (a->negative_ttl == -1) a->negative_ttl = a->ttl; /* Parse format */ p = &a->format; while (token) { external_acl_format *format; /* stop on first non-format token found */ if (*token != '%') break; format = cbdataAlloc(external_acl_format); if (strncmp(token, "%{", 2) == 0) { /* header format */ char *header, *member, *end; header = token + 2; end = strchr(header, '}'); /* cut away the terminating } */ if (end && strlen(end) == 1) *end = '\0'; else self_destruct(); member = strchr(header, ':'); if (member) { /* Split in header and member */ *member++ = '\0'; if (!isalnum(*member)) format->separator = *member++; else format->separator = ','; format->member = xstrdup(member); format->type = EXT_ACL_HEADER_MEMBER; } else { format->type = EXT_ACL_HEADER; } format->header = xstrdup(header); format->header_id = httpHeaderIdByNameDef(header, strlen(header)); if (format->header_id != -1) { if (member) format->type = EXT_ACL_HEADER_ID_MEMBER; else format->type = EXT_ACL_HEADER_ID; } } else if (strcmp(token, "%LOGIN") == 0) { format->type = EXT_ACL_LOGIN; a->require_auth = 1; } #if USE_IDENT else if (strcmp(token, "%IDENT") == 0) format->type = EXT_ACL_IDENT; #endif else if (strcmp(token, "%SRC") == 0) format->type = EXT_ACL_SRC; else if (strcmp(token, "%DST") == 0) format->type = EXT_ACL_DST; else if (strcmp(token, "%PROTO") == 0) format->type = EXT_ACL_PROTO; else if (strcmp(token, "%PORT") == 0) format->type = EXT_ACL_PORT; else if (strcmp(token, "%METHOD") == 0) format->type = EXT_ACL_METHOD; else { self_destruct(); } *p = format; p = &format->next; token = strtok(NULL, w_space); } /* There must be at least one format token */ if (!a->format) self_destruct(); /* helper */ if (!token) self_destruct(); wordlistAdd(&a->cmdline, token); /* arguments */ parse_wordlist(&a->cmdline); while (*list) list = &(*list)->next; *list = a; }
/* *?????Ǵ????ġ?????һ??header?Ĵ??�?? */ static int modifyHeader3(struct action_part* acp, HttpReply* reply) { assert(acp); assert(reply); int flag = 0; int act = acp->action; struct header_info* hdr = acp->hdr; HttpHeaderEntry e; //HttpHeaderEntry *mye; int i; HttpHeaderEntry *myheader; HttpHeaderPos pos = HttpHeaderInitPos + HDR_ENUM_END; e.name = stringDup(&hdr->header); e.value = stringDup(&hdr->value); i = httpHeaderIdByNameDef(strBuf(hdr->header), strLen(hdr->header)); e.id = i; if(i == -1) { e.id = HDR_OTHER; if(0 == act) { httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e)); } else if(2 == act) { while ((myheader = httpHeaderGetEntryPlus(&reply->header, &pos))) { if (myheader->id == HDR_OTHER && strCaseCmp(myheader->name, strBuf(hdr->header)) == 0) { debug(98, 3)("%s is myheader->value,%s is hdr->value\n",strBuf(myheader->value), strBuf(hdr->value)); stringReset(&myheader->value, strBuf(hdr->value)); } } } else if(1 == act) { httpHeaderDelByName(&reply->header,strBuf(hdr->header)); } else if(3 == act) { while ((myheader = httpHeaderGetEntryPlus(&reply->header, &pos))) { if (myheader->id == HDR_OTHER && strCaseCmp(myheader->name, strBuf(hdr->header)) == 0) { debug(98, 3)("%s is myheader->value,%s is hdr->value\n",strBuf(myheader->value), strBuf(hdr->value)); flag = 1; stringReset(&myheader->value, strBuf(hdr->value)); } } if(!flag) httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e)); } } else { //mye = httpHeaderFindEntry2(&reply->header, i); //debug(98, 3) ("%d is i\n", i); if(0 == act) { httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e)); } else if(2 == act) { if(httpHeaderDelByName(&reply->header,strBuf(hdr->header))) { httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e)); } //mye = httpHeaderFindEntry2(&reply->header, i); //debug(98, 3)("%s is newvalue\n",strBuf(mye->value)); } else if(1 == act) { httpHeaderDelByName(&reply->header,strBuf(hdr->header)); } else if(3 == act) { httpHeaderDelByName(&reply->header,strBuf(hdr->header)); httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e)); } } stringClean(&e.name); stringClean(&e.value); return 0; }