/* These are a bit different since they always need to go out. */ int root_report_start(client_t *client) { int rc; if (client->http) { rc = xml_print(client, "HTTP/1.0 200 OK\r\n" "Server: gmetad/" GANGLIA_VERSION_FULL "\r\n" "Content-Type: application/xml\r\n" "Connection: close\r\n" "\r\n"); if (rc) return rc; } rc = xml_print(client, DTD); if (rc) return 1; rc = xml_print(client, "<GANGLIA_XML VERSION=\"%s\" SOURCE=\"gmetad\">\n", VERSION); rc = xml_print(client, "<GRID NAME=\"%s\" AUTHORITY=\"%s\" LOCALTIME=\"%u\">\n", gmetad_config.gridname, getfield(root.strings, root.authority_ptr), (unsigned int) time(0)); return rc; }
/*! Compare two dbs using XML. Write to file and run diff */ static int compare_xmls(cxobj *xc1, cxobj *xc2, int astext) { int fd; FILE *f; char filename1[MAXPATHLEN]; char filename2[MAXPATHLEN]; char cmd[MAXPATHLEN]; int retval = -1; cxobj *xc; snprintf(filename1, sizeof(filename1), "/tmp/cliconXXXXXX"); snprintf(filename2, sizeof(filename2), "/tmp/cliconXXXXXX"); if ((fd = mkstemp(filename1)) < 0){ clicon_err(OE_UNDEF, errno, "tmpfile: %s", strerror (errno)); goto done; } if ((f = fdopen(fd, "w")) == NULL) goto done; xc = NULL; if (astext) while ((xc = xml_child_each(xc1, xc, -1)) != NULL) xml2txt(f, xc, 0); else while ((xc = xml_child_each(xc1, xc, -1)) != NULL) xml_print(f, xc); fclose(f); close(fd); if ((fd = mkstemp(filename2)) < 0){ clicon_err(OE_UNDEF, errno, "mkstemp: %s", strerror (errno)); goto done; } if ((f = fdopen(fd, "w")) == NULL) goto done; xc = NULL; if (astext) while ((xc = xml_child_each(xc2, xc, -1)) != NULL) xml2txt(f, xc, 0); else while ((xc = xml_child_each(xc2, xc, -1)) != NULL) xml_print(f, xc); fclose(f); close(fd); snprintf(cmd, sizeof(cmd), "/usr/bin/diff -dU 1 %s %s | grep -v @@ | sed 1,2d", filename1, filename2); if (system(cmd) < 0) goto done; retval = 0; done: unlink(filename1); unlink(filename2); return retval; }
int source_report_end(Generic_t *self, client_t *client, void *arg) { if (self->id == CLUSTER_NODE) return xml_print(client, "</CLUSTER>\n"); else return xml_print(client, "</GRID>\n"); }
static int metric_summary(datum_t *key, datum_t *val, void *arg) { client_t *client = (client_t*) arg; char *name = (char*) key->data; char *type; char sum[256]; Metric_t *metric = (Metric_t*) val->data; struct type_tag *tt; int rc,i; type = getfield(metric->strings, metric->type); tt = in_type_list(type, strlen(type)); if (!tt) return 0; /* We sum everything in double to properly combine integer sources (3.0) with float sources (3.1). This also avoids wraparound errors: for example memory KB exceeding 4TB. */ switch (tt->type) { case INT: case UINT: sprintf(sum, "%.f", metric->val.d); break; case FLOAT: sprintf(sum, "%.*f", (int) metric->precision, metric->val.d); break; default: break; } rc = xml_print(client, "<METRICS NAME=\"%s\" SUM=\"%s\" NUM=\"%u\" " "TYPE=\"%s\" UNITS=\"%s\" SLOPE=\"%s\" SOURCE=\"%s\">\n", name, sum, metric->num, "double", /* we always report double sums */ getfield(metric->strings, metric->units), getfield(metric->strings, metric->slope), getfield(metric->strings, metric->source)); rc = xml_print(client, "<EXTRA_DATA>\n"); for (i=0; !rc && i<metric->ednameslen; i++) { rc=xml_print(client, "<EXTRA_ELEMENT NAME=\"%s\" VAL=\"%s\"/>\n", getfield(metric->strings, metric->ednames[i]), getfield(metric->strings, metric->edvalues[i])); } rc = xml_print(client, "</EXTRA_DATA>\n"); rc=xml_print(client, "</METRICS>\n"); return rc; }
int main(int argc,char *argv[]) { FILE *f=fopen(argv[1],"r"); // Parse XML file struct foo *b=(struct foo *)xml_parse(f,"root",&myschema,metafind(&myschema, "foo"),1); struct item *i; // Access values in foo printf("root->val = %d\n",b->val); printf("root->val_name = %s\n",b->val_name); printf("root->items->val = %d\n",b->items->val); printf("root->items->next->val = %d\n",b->items->next->val); printf("root->items->next->next->val = %d\n",b->items->next->next->val); // Print in various formats xml_print(stdout,"root",0,(struct base *)b); lisp_print(stdout,"root",0,(struct base *)b); lisp_print_untagged(stdout,"root",0,(struct base *)b); indent_print(stdout,"root",0,(struct base *)b); indent_print_untagged(stdout,"root",0,(struct base *)b); json_print(stdout,NULL,0,(struct base *)b,0); // Create a database within C b=mk(&myschema, "foo"); b->val=10; b->val_name=strdup("Hello"); // Build list i=b->items=mk(&myschema, "item"); i->val=7; i=i->next=mk(&myschema, "item"); i->val=8; i=i->next=mk(&myschema, "item"); i->val=9; // Print it xml_print(stdout,"root",0,(struct base *)b); return 0; }
int metric_report_start(Generic_t *self, datum_t *key, client_t *client, void *arg) { int rc, i; char *name = (char*) key->data; Metric_t *metric = (Metric_t*) self; long tn = 0; tn = client->now.tv_sec - metric->t0.tv_sec; if (tn<0) tn = 0; if (metric->dmax && metric->dmax < tn) return 0; rc=xml_print(client, "<METRIC NAME=\"%s\" VAL=\"%s\" TYPE=\"%s\" " "UNITS=\"%s\" TN=\"%u\" TMAX=\"%u\" DMAX=\"%u\" SLOPE=\"%s\" " "SOURCE=\"%s\">\n", name, getfield(metric->strings, metric->valstr), getfield(metric->strings, metric->type), getfield(metric->strings, metric->units), (unsigned int) tn, metric->tmax, metric->dmax, getfield(metric->strings, metric->slope), getfield(metric->strings, metric->source)); rc = xml_print(client, "<EXTRA_DATA>\n"); for (i=0; !rc && i<metric->ednameslen; i++) { rc=xml_print(client, "<EXTRA_ELEMENT NAME=\"%s\" VAL=\"%s\"/>\n", getfield(metric->strings, metric->ednames[i]), getfield(metric->strings, metric->edvalues[i])); } rc = xml_print(client, "</EXTRA_DATA>\n"); rc=xml_print(client, "</METRIC>\n"); return rc; }
int source_report_start(Generic_t *self, datum_t *key, client_t *client, void *arg) { int rc; char *name = (char*) key->data; Source_t *source = (Source_t*) self; if (self->id == CLUSTER_NODE) { rc=xml_print(client, "<CLUSTER NAME=\"%s\" LOCALTIME=\"%u\" OWNER=\"%s\" " "LATLONG=\"%s\" URL=\"%s\">\n", name, source->localtime, getfield(source->strings, source->owner), getfield(source->strings, source->latlong), getfield(source->strings, source->url)); } else { rc=xml_print(client, "<GRID NAME=\"%s\" AUTHORITY=\"%s\" " "LOCALTIME=\"%u\">\n", name, getfield(source->strings, source->authority_ptr), source->localtime); } return rc; }
static int source_summary(Source_t *source, client_t *client) { int rc; rc=xml_print(client, "<HOSTS UP=\"%u\" DOWN=\"%u\" SOURCE=\"gmetad\"/>\n", source->hosts_up, source->hosts_down); if (rc) return 1; pthread_mutex_lock(source->sum_finished); rc = hash_foreach(source->metric_summary, metric_summary, (void*) client); pthread_mutex_unlock(source->sum_finished); return rc; }
int host_report_start(Generic_t *self, datum_t *key, client_t *client, void *arg) { int rc; char *name = (char*) key->data; Host_t *host = (Host_t*) self; long tn = 0; tn = client->now.tv_sec - host->t0.tv_sec; if (tn<0) tn = 0; /* Note the hash key is the host's IP address. */ rc = xml_print(client, "<HOST NAME=\"%s\" IP=\"%s\" REPORTED=\"%u\" " "TN=\"%u\" TMAX=\"%u\" DMAX=\"%u\" LOCATION=\"%s\" GMOND_STARTED=\"%u\" TAGS=\"%s\">\n", name, getfield(host->strings, host->ip), host->reported, (unsigned int) tn, host->tmax, host->dmax, getfield(host->strings, host->location), host->started, getfield(host->strings, host->tags)); return rc; }
int main(int arg, char *argv[]) { WSMMessage rxmsg; WSMIndication rxpkt; //int i, attempts = 10, drops = 0, result; int ret = 0; struct arguments arg1; rxmsg.wsmIndication = &rxpkt; /* check for the user input arguments, if it is less than 4 print the usage message */ if (arg < 4) { printf("usage: localrx [user req type<1-auto> <2-unconditional> <3-none>] [imm access] [extended access] [channel <optional>] [PROVIDER MAC <optional>]\n"); return 0; } registerLinkConfirm(confirmBeforeJoin); /* Registering the callback function */ pid = getpid(); memset(&entry, 0, sizeof(WMEApplicationRequest)); entry.psid = 10; if ((atoi(argv[1]) > USER_REQ_SCH_ACCESS_NONE) || (atoi(argv[1]) < USER_REQ_SCH_ACCESS_AUTO)) { printf("User request type invalid: setting default to auto\n"); entry.userreqtype = USER_REQ_SCH_ACCESS_AUTO; } else { entry.userreqtype = atoi(argv[1]); } if (entry.userreqtype == USER_REQ_SCH_ACCESS_AUTO_UNCONDITIONAL) { if (arg < 5) { printf("channel needed for unconditional access\n"); return 0; } else { entry.channel = atoi(argv[4]); } } entry.schaccess = atoi(argv[2]); entry.schextaccess = atoi(argv[3]); if (arg > 5) { strncpy(arg1.macaddr, argv[4], 17); set_args(entry.macaddr, &arg1, ADDR_MAC); } /* Function invokeWAVEDevice(int type, int blockflag)/invokeWAVEDriver(int blockflag) instructs the libwave * to open a connection to a wave device either on the local machine or on a remote machine. * Invoke the wave device before issuing any request to the wave device */ printf("Invoking WAVE driver \n"); if (invokeWAVEDevice(WAVEDEVICE_LOCAL, 0) < 0) { printf("Open Failed. Quitting\n"); exit(-1); } /* Registering the user to receive the data from the TX application */ printf("Registering User %d\n", entry.psid); if (registerUser(pid, &entry) < 0) { printf("Register User Failed \n"); printf("Removing user if already present %d\n", !removeUser(pid, &entry)); printf("USER Registered %d with PSID =%u \n", registerUser(pid, &entry), entry.psid); } /* catch control-c and kill signal */ signal(SIGINT, (void *) sig_int); signal(SIGTERM, (void *) sig_term); while (1) { ret = rxWSMMessage(pid, &rxmsg); /* Function to receive the Data from TX application */ if (ret > 0) { printf("Received WSMP Packet txpower= %d, rateindex=%d Packet No =#%llu#\n", rxpkt.chaninfo.txpower, rxpkt.chaninfo.rate, count++); rxWSMIdentity(&rxmsg, 0); //Identify the type of received Wave Short Message. if (!rxmsg.decode_status) { xml_print(rxmsg); /* call the parsing function to extract the contents of the received message */ } } else { blank++; } } }
int root_report_end(client_t *client) { return xml_print(client, "</GRID>\n</GANGLIA_XML>\n"); }
int host_report_end(Generic_t *self, client_t *client, void *arg) { return xml_print(client, "</HOST>\n"); }
int xml_println(xml_Text *pText) { xml_print(pText, 0 , pText->len); putchar('\n'); return 0; }