Show
Ignore:
Timestamp:
07/01/08 20:16:09 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1214943369 +0000
git-parent:

[a19b8157a03891ec782d7a880a640be1c6c98663]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1214943369 +0000
Message:

implements stratcon configuration storage in DB, refs #27

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_conf.c

    r70451c5 rdcd539d  
    462462  int len; 
    463463  int allocd; 
    464   enum { CONFIG_RAW = 0, CONFIG_COMPRESSED, CONFIG_B64 } encoded; 
     464  enum { CONFIG_RAW = 0, CONFIG_COMPRESSED, CONFIG_B64 } target, encoded; 
    465465}; 
    466466static int 
     
    494494 
    495495  if(clv->buff == NULL) { 
    496     clv->encoded = CONFIG_B64
     496    clv->encoded = clv->target
    497497    return 0; 
    498498  } 
    499499  clv->raw_len = clv->len; 
    500500  assert(clv->encoded == CONFIG_RAW); 
     501  if(clv->encoded == clv->target) return 0; 
     502 
    501503  /* Compress */ 
    502504  initial_dlen = dlen = compressBound(clv->len); 
     
    514516  clv->len = dlen; 
    515517  clv->encoded = CONFIG_COMPRESSED; 
     518  if(clv->encoded == clv->target) return 0; 
     519 
    516520  /* Encode */ 
    517521  initial_dlen = ((clv->len + 2) / 3) * 4; 
     
    528532  clv->len = dlen; 
    529533  clv->encoded = CONFIG_B64; 
    530   return 0; 
     534  if(clv->encoded == clv->target) return 0; 
     535  return -1; 
    531536} 
    532537 
     
    592597  return 0; 
    593598} 
     599char * 
     600noit_conf_xml_in_mem(size_t *len) { 
     601  struct config_line_vstr *clv; 
     602  xmlOutputBufferPtr out; 
     603  xmlCharEncodingHandlerPtr enc; 
     604  char *rv; 
     605 
     606  clv = calloc(1, sizeof(*clv)); 
     607  clv->target = CONFIG_RAW; 
     608  enc = xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8); 
     609  out = xmlOutputBufferCreateIO(noit_config_log_write_xml, 
     610                                noit_config_log_close_xml, 
     611                                clv, enc); 
     612  xmlSaveFormatFileTo(out, master_config, "utf8", 1); 
     613  if(clv->encoded != CONFIG_RAW) { 
     614    noitL(noit_error, "Error logging configuration\n"); 
     615    if(clv->buff) free(clv->buff); 
     616    free(clv); 
     617    return NULL; 
     618  } 
     619  rv = clv->buff; 
     620  *len = clv->len; 
     621  free(clv); 
     622  return rv; 
     623} 
     624 
    594625int 
    595626noit_conf_write_log() { 
     
    607638  gettimeofday(&__now, NULL); 
    608639  clv = calloc(1, sizeof(*clv)); 
     640  clv->target = CONFIG_B64; 
    609641  enc = xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8); 
    610642  out = xmlOutputBufferCreateIO(noit_config_log_write_xml,