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

    https://github.com/apache/trafficserver/pull/106#discussion_r17050782
  
    --- Diff: proxy/http/HttpSM.cc ---
    @@ -371,6 +392,107 @@ HttpSM::destroy()
       httpSMAllocator.free(this);
     }
     
    +#ifdef TS_HAS_UUID
    +void
    +HttpSM::init_uuid_config()
    +{
    +  // Lazy init: Trying to register and read the config on the constructor 
won't work,
    +  // so we've postponed it until now, when the instance is to be used for 
the first time.
    +  // As use_uuid is static, this will happen only once (this variable has 
been set on the
    +  // preamble of this file.) Also, if we're using OSSP and a generator 
could not be
    +  // initialized on the constructor, then this block won't be used.
    +  RecRegisterConfigInt(RECT_CONFIG,    "proxy.config.http.use_uuid",       
      0,            RECU_DYNAMIC, RECC_NULL, NULL);
    +  RecRegisterConfigInt(RECT_CONFIG,    
"proxy.config.http.add_uuid_to_request",  0,            RECU_DYNAMIC, 
RECC_NULL, NULL);
    +  RecRegisterConfigInt(RECT_CONFIG,    
"proxy.config.http.add_uuid_to_response", 0,            RECU_DYNAMIC, 
RECC_NULL, NULL);
    +  RecRegisterConfigString(RECT_CONFIG, 
"proxy.config.http.uuid_header_name",     "x-ats-uuid", RECU_DYNAMIC, 
RECC_NULL, NULL);
    +
    +  if ( RecGetRecordInt("proxy.config.http.use_uuid", &use_uuid, false) != 
REC_ERR_OKAY ) {
    +    DebugSM("http", "Could not read config [proxy.config.http.use_uuid].");
    +  } else {
    +    DebugSM("http", "Read [proxy.config.http.use_uuid] == [%d].", (int) 
use_uuid);
    +
    +    RecGetRecordInt("proxy.config.http.add_uuid_to_request", 
&add_to_request, false);
    +    DebugSM("http", "Read [proxy.config.http.add_uuid_to_request] == 
[%d].", (int) add_to_request);
    +
    +    RecGetRecordInt("proxy.config.http.add_uuid_to_response", 
&add_to_response, false);
    +    DebugSM("http", "Read [proxy.config.http.add_uuid_to_response] == 
[%d].", (int) add_to_response);
    +
    +    char tmp_header_name[128];
    +
    +    RecGetRecordString("proxy.config.http.uuid_header_name", 
tmp_header_name, sizeof(tmp_header_name), false);
    +    DebugSM("http", "Read [proxy.config.http.uuid_header_name] == [%s].", 
tmp_header_name);
    +
    +    header_name = std::string(tmp_header_name);
    +  }
    +}
    +
    +void
    +HttpSM::generate_uuid()
    +{
    +#ifdef HAS_BOOST_UUID
    +  uuid           uuid = gen();
    +  unsigned char *puuid = (unsigned char *) &uuid;
    +  char          *ptr;
    +  int            i;
    +  char           str_uuid[37];
    +
    +  for (ptr=str_uuid, i=0; i < 16; ++i) {
    +    sprintf(ptr, "%02x", *(puuid + i));
    +    ptr += 2;
    +
    +    if ( i == 3 || i == 5 || i == 7 || i == 9 )
    +     *ptr++ = '-';
    +
    +    if ( i == 15 )
    +     *ptr = '\0';
    +  }
    +
    +  id((char *) str_uuid);
    +
    +#else // HAS_OSSP_UUID
    +  char *vp = NULL;
    +  size_t n;
    +
    +  if ( _uuid != NULL ) {
    +   if ( uuid_make(_uuid, UUID_MAKE_V4) == UUID_RC_OK ) {
    +     uuid_export(_uuid, UUID_FMT_STR, &vp, &n);
    +     id = std::string(vp);
    +     free(vp);
    +   } else {
    +     DebugSM("http", "Could not generate UUID.");
    +   }
    +  }
    +#endif
    +
    +  if ( id.size() > 0 )
    +   DebugSM("http", UUID_FMT "UUID generated.", UUID_VAL);
    +}
    +
    +bool
    +HttpSM::should_add_uuid_to_request(void) const
    +{
    +  return ( HttpSM::add_to_request == 1 );
    +}
    +
    +bool
    +HttpSM::should_add_uuid_to_response(void) const
    +{
    +  return ( HttpSM::add_to_response == 1 );
    +}
    +
    +void
    +HttpSM::add_uuid_header(HTTPHdr *hdr) const
    +{
    +  const char *hdr_name = header_name.c_str();
    --- End diff --
    
    Please look at the scoped resource helper classes in lib/ts/ink_memory.h.


---
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