<commit_before>/**
 * @file gexec_funcs.c Functions to support gexec, gstat et al
 */
/* $Id$ */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <expat.h>

#include "ganglia_gexec.h"
#include "ganglia_priv.h"
#include "net.h"
#include "llist.h"
#include "hash.h"

int gexec_errno = 0;

static void
start (void *data, const char *el, const char **attr)
{
   int n;
   gexec_cluster_t *cluster = (gexec_cluster_t *)data;
   char *p;

   if (! strcmp("CLUSTER", el))
      {
         strncpy( cluster->name, attr[1], 256 );
         for(n=0; attr[n] && strcmp(attr[n], "LOCALTIME"); n+=2){}
         cluster->localtime = atol(attr[n+1]);
      }
   else if (! strcmp("HOST",el))
      {
         cluster->host = (gexec_host_t *)calloc(1, sizeof(gexec_host_t) );
         if ( cluster->host == NULL )
            {
               /* We'll catch this error later */
               cluster->malloc_error = 1;
               gexec_errno = 1;
               return;
            } 

         if(! strcmp( attr[1], attr[3]))
            {
               /* The IP address did not resolve at all */
               cluster->host->name_resolved = 0;
               strcpy(cluster->host->name,   attr[1]);
               strcpy(cluster->host->domain, "unresolved");
            }
         else
            {
               cluster->host->name_resolved = 1;
               p = strchr( attr[1], '.' );
               if( p )
                  {
                     /* The IP DID resolve AND we have a domainname */
                     n = p - attr[1];
                     strncpy(cluster->host->name, attr[1], n);
                     cluster->host->name[n] = '\0';
                     p++;
                     strncpy(cluster->host->domain, p, GEXEC_HOST_STRING_LEN);
                  }
               else
                  {
                     /* The IP DID resolve BUT we DON'T have a domainname */
                     strncpy(cluster->host->name, attr[1], GEXEC_HOST_STRING_LEN);
                     strcpy(cluster->host->domain, "unspecified");
                  }
            }

         strcpy(cluster->host->ip, attr[3]);
         cluster->host->last_reported = atol(attr[5]);

         if( abs(cluster->localtime - cluster->host->last_reported) < GEXEC_TIMEOUT )
            {
               cluster->host_up = 1;
            }<commit_msg>Patch from <NAME> to unbreak gstat with new ganglia release. ( http://www.mail-archive.com/<EMAIL>/msg05898.html )<commit_after>/**
 * @file gexec_funcs.c Functions to support gexec, gstat et al
 */
/* $Id$ */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <expat.h>

#include "ganglia_gexec.h"
#include "ganglia_priv.h"
#include "net.h"
#include "llist.h"
#include "hash.h"

int gexec_errno = 0;

static void
start (void *data, const char *el, const char **attr)
{
   int n;
   gexec_cluster_t *cluster = (gexec_cluster_t *)data;
   char *p;

   if (! strcmp("CLUSTER", el))
      {
         strncpy( cluster->name, attr[1], 256 );
         for(n=0; attr[n] && strcmp(attr[n], "LOCALTIME"); n+=2){}
         cluster->localtime = atol(attr[n+1]);
      }
   else if (! strcmp("HOST",el))
      {
         cluster->host = (gexec_host_t *)calloc(1, sizeof(gexec_host_t) );
         if ( cluster->host == NULL )
            {
               /* We'll catch this error later */
               cluster->malloc_error = 1;
               gexec_errno = 1;
               return;
            } 

         if(! strcmp( attr[1], attr[3]))
            {
               /* The IP address did not resolve at all */
               cluster->host->name_resolved = 0;
               strcpy(cluster->host->name,   attr[1]);
               strcpy(cluster->host->domain, "unresolved");
            }
         else
            {
               cluster->host->name_resolved = 1;
               p = strchr( attr[1], '.' );
               if( p )
                  {
                     /* The IP DID resolve AND we have a domainname */
                     n = p - attr[1];
                     strncpy(cluster->host->name, attr[1], n);
                     cluster->host->name[n] = '\0';
                     p++;
                     strncpy(cluster->host->domain, p, GEXEC_HOST_STRING_LEN);
                  }
               else
                  {
                     /* The IP DID resolve BUT we DON'T have a domainname */
                     strncpy(cluster->host->name, attr[1], GEXEC_HOST_STRING_LEN);
                     strcpy(cluster->host->domain, "unspecified");
                  }
            }

         strcpy(cluster->host->ip, attr[3]);
         cluster->host->last_reported = atol(attr[7]);

         if( abs(cluster->localtime - cluster->host->last_reported) < GEXEC_TIMEOUT )
            {
               cluster->host_up = 1;
            }
{'fraction_non_alphanumeric': 0.1431215299198026, 'fraction_numerical': 0.01089862224964014, 'mean_word_length': 1.5046343975283214, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5164881', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1462, 'n_words': 331}