Github user SolidWallOfCode commented on a diff in the pull request:

    https://github.com/apache/trafficserver/pull/843#discussion_r74175735
  
    --- Diff: plugins/experimental/carp/CarpConfig.cc ---
    @@ -0,0 +1,581 @@
    +/** @file
    +
    +  Loads the CARP configuration
    +
    +  @section license License
    +
    +  Licensed to the Apache Software Foundation (ASF) under one
    +  or more contributor license agreements.  See the NOTICE file
    +  distributed with this work for additional information
    +  regarding copyright ownership.  The ASF licenses this file
    +  to you under the Apache License, Version 2.0 (the
    +  "License"); you may not use this file except in compliance
    +  with the License.  You may obtain a copy of the License at
    +
    +      http://www.apache.org/licenses/LICENSE-2.0
    +
    +  Unless required by applicable law or agreed to in writing, software
    +  distributed under the License is distributed on an "AS IS" BASIS,
    +  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +  See the License for the specific language governing permissions and
    +  limitations under the License.
    + */
    +
    +//////////////////////////////////////////////////////////////
    +// Read CARP configuration file
    +// [Servers]
    +// host1.yahoo.com:4080 weight=2      # port 4080 on host1.yahoo.com with 
weight factor of 2
    +// host2.yahoo.com                    # port 80 on host2.yahoo.com with 
(default) weight factor of 1
    +// 
    +// [Values]
    +// healthcheck={host}:8001/status.html
    +// healthfreq=30
    +// global=on
    +//
    +
    +#include <stdlib.h> 
    +#include <stdio.h> 
    +#include <memory.h> 
    +#include <ts/ts.h>
    +#include <sys/time.h>
    +
    +#include <sstream>
    +
    +#include "CarpConfig.h"
    +#include "Common.h"
    +#include "CarpConfigPool.h"
    +
    +using namespace std;
    +
    +#define DEFAULT_HEALTH_CHECK_FREQ 30  // 30 second period for health checks
    +#define DEFAULT_HEALTH_CHECK_PORT 80  // default to makeing healthcheck 
requests against port 80
    +#define DEFAULT_CONFIG_RELOAD_FREQ 30 // 30 seconds used in TSContSchedule
    +#define DEFAULT_PORT 80  // default to makeing requests against port 80
    +#define DEFAULT_WEIGHT 1  // default weight
    +#define DEFAULT_SCHEME "http"
    +#define DEFAULT_REPLICATION_FACTOR 1
    +
    +// config section headers
    +static const char *const SECTION_SERVERS_STR = "[Servers]";
    +static const char *const SECTION_VALUES_STR = "[Values]";
    +
    +// key strings
    +static const char *const KEY_HEALTHCHECK_STR = "healthcheck";
    +static const char *const KEY_HEALTHFREQ_STR = "healthfreq";
    +static const char *const KEY_RELOADFREQ_STR = "reloadfreq";
    +static const char *const KEY_HCTIMEOUT_STR =  "hctimeout";
    +static const char *const KEY_BLACKLIST_STR = "blacklist";
    +static const char *const KEY_WHITELIST_STR = "whitelist";
    +static const char *const KEY_MODE_STR = "mode";
    +static const char *const KEY_ALLOWFWDPORT_STR = "allowfwdport";
    +static const char *const KEY_REPLICATIONFACTOR_STR = "replicationfactor";
    +
    +// parameter strings
    +static const char *const WEIGHT_EQUALS_STRING = "weight=";
    +static const char *const GROUP_EQUALS_STRING = "group=";
    +static const char *const KEY_MODE_PREREMAP_STR = "pre-remap";
    +static const char *const KEY_MODE_POSTREMAP_STR = "post-remap";
    +
    +
    +/**********************************************************/
    +bool
    +getInt(char** pptr, int *val)
    +{
    +  bool bReturn = false;
    +  int v=0;
    +  
    +  char* ptr = *pptr;
    +  // skip white space if any
    +  while (*ptr && isspace(*ptr)) ++ptr; 
    +  // get digits
    +  if (*ptr) {
    +    while (*ptr && isdigit(*ptr)) {
    +      v *= 10;
    +      v += (*ptr)-'0';
    +      ++ptr;
    +      bReturn = true;
    +    }
    +  }
    +  if (bReturn) {
    +    *pptr = ptr;
    +    *val = v;
    +  }
    +
    +  return bReturn;
    +}
    +
    +/**********************************************************/
    +// [http[s]://]host[:port]/path
    +bool
    +getHostAndPort(char** pptr,string* sHost,int* iPort, string* sScheme)
    +{
    +  bool bReturn = false;
    +  char* ptr = *pptr;
    +
    +  *iPort = 80;
    +  *sScheme = DEFAULT_SCHEME;
    +  if(strncmp(*pptr,"https",5) == 0) {
    --- End diff --
    
    Strings like `https` should be compile time constants so that you don't 
need to use magic constants like `5` later.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to