Esempio n. 1
0
/*
 * call-seq:
 *    document.compression = num
 *
 * Set this document's compression mode.
 */
static VALUE rxml_document_compression_set(VALUE self, VALUE num)
{
#ifdef HAVE_ZLIB_H
  xmlDocPtr xdoc;

  int compmode;
  Check_Type(num, T_FIXNUM);
  Data_Get_Struct(self, xmlDoc, xdoc);

  if (xdoc == NULL)
  {
    return(Qnil);
  }
  else
  {
    xmlSetDocCompressMode(xdoc, NUM2INT(num));

    compmode = xmlGetDocCompressMode(xdoc);
    if (compmode == -1)
    return(Qnil);
    else
    return(INT2NUM(compmode));
  }
#else
  rb_warn("libxml compiled without zlib support");
  return (Qfalse);
#endif
}
Esempio n. 2
0
int find_expired_probes(struct dbspec *dbspec)
{
  xmlDocPtr doc;
  xmlNodePtr probe;
  dbi_result result;
  dbi_conn conn;
  int count = 0;
  char buf[10];

  sprintf(buf, "%d", dbspec->port);

  conn = open_database(OPT_ARG(DBTYPE), dbspec->host, buf, dbspec->db,
                     dbspec->user, dbspec->password);
  if (!conn) return 0;

  doc = UpwatchXmlDoc("result", NULL);

  // find all expired probes, but skip those for which processing
  // has been stopped for some reason
  result = db_query(conn, 0, "select probe.name, pr_status.probe, " 
                             "       pr_status.server, pr_status.color, "
                             "       pr_status.expires "
                             "from   pr_status, probe "
                             "where  probe.id = pr_status.class and color <> 400 "
                             "       and expires < UNIX_TIMESTAMP()-30 "
                             "       and expires < probe.lastseen"
                             "       and probe.expiry = 'yes'");
  if (!result) goto errexit;

  while (dbi_result_next_row(result)) {
    char buffer[256];
    time_t now = time(NULL);

    probe = xmlNewChild(xmlDocGetRootElement(doc), NULL, dbi_result_get_string(result, "name"), NULL);
    xmlSetProp(probe, "realm", dbspec->realm);
    xmlSetProp(probe, "id", dbi_result_get_string(result, "probe"));
    xmlSetProp(probe, "server", dbi_result_get_string(result, "server"));
    sprintf(buffer, "%u", (int) now);	xmlSetProp(probe, "date", buffer);
    xmlSetProp(probe, "expires", dbi_result_get_string(result, "expires"));

    xmlNewChild(probe, NULL, "color", "400");  // PURPLE
    xmlNewChild(probe, NULL, "prevcolor", dbi_result_get_string(result, "color"));

    LOG(LOG_INFO, "%s: purpled %s %d", dbspec->realm, dbi_result_get_string(result, "name"), 
                                                      dbi_result_get_uint(result, "probe"));
    count++;
  }
  if (count) {
    xmlSetDocCompressMode(doc, OPT_VALUE_COMPRESS);
    spool_result(OPT_ARG(SPOOLDIR), OPT_ARG(OUTPUT), doc, NULL);
    LOG(LOG_INFO, "%s: purpled %u probes", dbspec->realm, count);
  }

errexit:
  if (result) dbi_result_free(result);
  if (conn) close_database(conn);
  if (doc) xmlFreeDoc(doc);
  return count;
}
Esempio n. 3
0
static void
end_render(DiaRenderer *self)
{
  DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self);
  g_free(renderer->linestyle);

  xmlSetDocCompressMode(renderer->doc, 0);
  xmlDiaSaveFile(renderer->filename, renderer->doc);
  g_free(renderer->filename);
  xmlFreeDoc(renderer->doc);
}
Esempio n. 4
0
// schematic_write_xml
//
// Save a Sheet to an XML file.
gint
schematic_write_xml (Schematic *sm, GError **error)
{
	int ret = -1;
	xmlDocPtr xml;
	parseXmlContext ctxt;
	GError *internal_error = NULL;

	g_return_val_if_fail (sm != NULL, FALSE);

	// Create the tree.
	xml = xmlNewDoc (BAD_CAST "1.0");
	if (xml == NULL) {
		return FALSE;
	}

	ctxt.ns = NULL;
	ctxt.doc = xml;

	xmlDocSetRootElement (xml, write_xml_schematic (&ctxt, sm, &internal_error));

	if (internal_error) {
		g_propagate_error (error, internal_error);
		return FALSE;
	}

	// Dump the tree.
	xmlSetDocCompressMode (xml, oregano.compress_files ? 9 : 0);

	{
		char *s =schematic_get_filename (sm);
		if (s != NULL) {
			ret = xmlSaveFormatFile (s, xml, 1);
		}
		else {
			g_warning ("Schematic has no filename!!\n");
		}
	}

	if (xml != NULL) {
		xmlFreeDoc (xml);
	}
	else {
		g_warning ("XML object is NULL\n");
	}

	if (ret < 0)
		return FALSE;
	return TRUE;
}
Esempio n. 5
0
void write_results(void)
{
  int ct  = STACKCT_OPT(OUTPUT);
  char **output = (char **) &STACKLST_OPT(OUTPUT);
  int i;
  xmlDocPtr doc;

  doc = UpwatchXmlDoc("result", NULL);

  g_hash_table_foreach(cache, write_probe, doc);
  xmlSetDocCompressMode(doc, OPT_VALUE_COMPRESS);
  for (i=0; i < ct; i++) {
    spool_result(OPT_ARG(SPOOLDIR), output[i], doc, NULL);
  }
  xmlFreeDoc(doc);
}
Esempio n. 6
0
static void
end_render(DiaRenderer *self)
{
  DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self);
  g_free(renderer->linestyle);

  /* handle potential patterns */
  if (renderer->patterns) {
    xmlNodePtr root = xmlDocGetRootElement (renderer->doc);
    xmlNodePtr defs = xmlNewNode (renderer->svg_name_space, (const xmlChar *)"defs");
    GradientData gd = { renderer, defs };
    g_hash_table_foreach (renderer->patterns, _gradient_do, &gd);
    xmlAddPrevSibling (root->children, defs);
    g_hash_table_destroy (renderer->patterns);
    renderer->patterns = NULL;
  }
  xmlSetDocCompressMode(renderer->doc, 0);
  xmlDiaSaveFile(renderer->filename, renderer->doc);
  g_free(renderer->filename);
  xmlFreeDoc(renderer->doc);
}
Esempio n. 7
0
/* full overwrite */
static void
end_render(DiaRenderer *self)
{
  DiaSvgRenderer *renderer = DIA_SVG_RENDERER (self);
  int old_blanks_default = pretty_formated_xml;

  /* FIXME HACK: we always want nice readable shape files,
   *  but toggling it by a global var is ugly   --hb 
   */
  pretty_formated_xml = TRUE;

  g_free(renderer->linestyle);
  renderer->linestyle = NULL;
  
  xmlSetDocCompressMode(renderer->doc, 0);
  xmlDiaSaveFile(renderer->filename, renderer->doc);
  g_free(renderer->filename);
  renderer->filename = NULL;
  xmlFreeDoc(renderer->doc);
  pretty_formated_xml = old_blanks_default;
}
Esempio n. 8
0
void
gpinstruct_parser_save_to_file (GPInstructParser *parser,
                                GPInstructProject *project,
                                const gchar *file,
                                GError **error)
{
	xmlDocPtr doc = create_xml_document_from_project (project);

	if (!doc)
	{
		g_set_error (error, GPINSTRUCT_PARSER_ERROR, GPINSTRUCT_PARSER_ERROR_PARSE,
		             _("Failed to create an XML document from project."));
		return;
	}

	xmlIndentTreeOutput = 1;
	xmlTreeIndentString = "\t";
	xmlSetDocCompressMode (doc, 9);
	xmlSaveFormatFileEnc (file, doc, "UTF-8", 1);
	xmlFreeDoc (doc);
}
void filterSaveXml(char *docname,uint8_t silent)
{
 xmlDocPtr xdoc;
 xmlNodePtr node;
 xmlAttrPtr attr;
 char tmpstring[1024];
VF_FILTERS tag;
int max;
		UNUSED_ARG(silent);
		if( ! (xdoc = xmlNewDoc((const xmlChar *)"1.0")) ) {printf("Problem creating xml doc\n");	return ;}
		if( ! (xdoc->children = xmlNewNode(NULL,(xmlChar *)"filters")) )
			{
				xmlFreeDoc(xdoc);
				xdoc = NULL;
				return ;
			}
		// we add # of filteras as attribute to the first children
		max=nb_active_filter;
		if(max) max--;
		sprintf(tmpstring,"%d",max);
		attr=xmlNewProp(xdoc->children,(xmlChar *)"FilterNumber",(xmlChar *)tmpstring);
		if(max)
		for(uint32_t curFilter=1;curFilter<nb_active_filter;curFilter++)
		{
			// for each filter we create a new node

			node= xmlNewChild(xdoc->children,NULL,(xmlChar *)"Filter",NULL );

			tag=videofilters[curFilter].tag;

			// and fill-up some informations
			sprintf(tmpstring,"%d",tag);
			attr=xmlNewProp(node,(xmlChar *)"Tag",(xmlChar *)tmpstring);

			attr=xmlNewProp(node,(xmlChar *)"Conf",(xmlChar *)videofilters[curFilter].filter->printConf());

			// now we create a child containing the config
			CONFcouple *setup;

			if( videofilters[curFilter].filter->getCoupledConf(&setup))
			{
				// we create a new child parameters with # of parameter as attribute
				 xmlNodePtr nodeConf; //,tmpnode;
// 				 xmlAttrPtr attrConf;


				 char *nm,*val;

					nodeConf= xmlNewChild(node,NULL,(xmlChar *)"Parameters",NULL );
					sprintf(tmpstring,"%lu",setup->getNumber());
					xmlNewProp(nodeConf,(xmlChar *)"Number",(xmlChar *)tmpstring);

					// and write each attribute
					for(uint32_t i=0;i<setup->getNumber();i++)
					{
						assert(setup->getEntry(i,&nm,&val));
						xmlNewChild(nodeConf,NULL,(xmlChar *)nm,(xmlChar *)val );
					}
				delete setup;
			}

		}

		xmlSetDocCompressMode(xdoc,0);  // we want pure text
		if( xmlSaveFormatFile(docname,xdoc,1) == -1 )
		{
			GUI_Alert("Error writing XML file");
			return ;
		}
		xmlFreeDoc(xdoc);
	return ;
}
Esempio n. 10
0
int preferences::save_xml_to_file(){
   char *dir_adm;
   char *rcfile;
   char *rcfilenew;

        dir_adm=ADM_getBaseDir();
        if(!dir_adm) return RC_FAILED;

        rcfile=new char[strlen(dir_adm)+4+strlen(CONFIG)];
        strcpy(rcfile,dir_adm);
        strcat(rcfile,"/");
        strcat(rcfile,CONFIG);


#if defined(__MINGW32__)
	xmlSetDocCompressMode(xdoc,9);
	if( xmlSaveFormatFile(rcfile,xdoc,1) == -1 ){
           fprintf(stderr,"\ncan't save xml tree to file. Filesystem full?\n\n");
           delete [] rcfile;
	   return RC_FAILED;
	}
        delete [] rcfile;
	return RC_OK;

#else
	
        
         rcfilenew=new char[strlen(rcfile)+5];
        strcpy(rcfilenew,rcfile);
        strcat(rcfilenew,".new");
        if( unlink(rcfilenew) == -1 && errno != ENOENT ){
           fprintf(stderr,"can't unlink(%s): %d (%s)\n",
                   rcfilenew, errno, strerror(errno));
           delete [] rcfilenew;
           return RC_FAILED;
        }
	xmlSetDocCompressMode(xdoc,9);
	if( qxmlSaveFormatFile(rcfilenew,xdoc,1) == -1 ){
           delete [] rcfilenew;
           delete [] rcfile;
	   return RC_FAILED;
	}

        if( unlink(rcfile) == -1 && errno != ENOENT ){
           fprintf(stderr,"can't unlink(%s): %d (%s)\n",
                   rcfile, errno, strerror(errno));
           delete [] rcfilenew;
           delete [] rcfile;
           return RC_FAILED;
        }
        if( link(rcfilenew,rcfile) == -1 ){
           fprintf(stderr,"can't create \"%s\": %d (%s)\n",
                   rcfile, errno, strerror(errno));
           delete [] rcfilenew;
           delete [] rcfile;
           return RC_FAILED;
        }
        unlink(rcfilenew); // rc/errno handling is done on next call ;-)
        delete [] rcfilenew;
        delete [] rcfile;
	return RC_OK;
#endif
}
Esempio n. 11
0
int run(void)
{
  xmlDocPtr doc;
  xmlNodePtr node;
  int ct  = STACKCT_OPT(OUTPUT);
  char **output = (char **) &STACKLST_OPT(OUTPUT);
  GString *log;
  int i;
  int color;
  int highest_color = STAT_GREEN;
  char buf[24];
extern int forever;

  uw_setproctitle("sleeping");
  for (i=0; i < OPT_VALUE_INTERVAL; i++) { // wait some minutes
    sleep(1);
    if (!forever)  {
      return(0);
    }
  }

  uw_setproctitle("getting system statistics");
  get_stats();
  doc = UpwatchXmlDoc("result", NULL);
  xmlSetDocCompressMode(doc, OPT_VALUE_COMPRESS);

  // do the sysstat
  node = (xmlNodePtr) newnode(doc, "sysstat");
  add_loadavg(node);
  add_cpu(node);
  add_paging(node);
  add_blockio(node);
  add_swap(node);
  add_memory(node);
  add_systemp(node);
  add_sysstat_info(node);
  color = xmlGetPropInt(node, "color");
  if (color > highest_color) highest_color = color;
#if USE_XMBMON|| defined (__OpenBSD__)
  if (OPT_VALUE_HWSTATS ) { 
    // do the hwstat
    get_hwstats();
    node = (xmlNodePtr) newnode(doc, "hwstat");
    add_hwstat(node);
    color = xmlGetPropInt(node, "color");
    if (color > highest_color) highest_color = color;
  }
#endif
  if (OPT_VALUE_LOCALCHECKS ) { 
   // do the local checks
    color = do_local((xmlNodePtr) doc);
    if (color > highest_color) highest_color = color;
  }

#if HAVE_LIBPCRE
  // do the errlog
  node = (xmlNodePtr) newnode(doc, "errlog");
  log = check_logs(&color);
  if (color > highest_color) highest_color = color;
  sprintf(buf, "%u", color);
  xmlSetProp(node, "color", buf);
  if (log) {
    if (log->str && strlen(log->str) > 0) {
      xmlNewTextChild(node, NULL, "info", log->str);
    }
    g_string_free(log, TRUE);
  }
#endif

  // do the diskfree
  uw_setproctitle("checking diskspace");
  node = (xmlNodePtr) newnode(doc, "diskfree");
  add_diskfree_info(node);
  color = xmlGetPropInt(node, "color");

  if (color > highest_color) highest_color = color;

  if (HAVE_OPT(HPQUEUE) && (highest_color != prv_highest_color)) {
    // if status changed, it needs to be sent immediately. So drop into
    // the high priority queue. Else just drop in the normal queue where
    // uw_send in batched mode will pick it up later
    spool_result(OPT_ARG(SPOOLDIR), OPT_ARG(HPQUEUE), doc, NULL);
  } else {
    for (i=0; i < ct; i++) {
      spool_result(OPT_ARG(SPOOLDIR), output[i], doc, NULL);
    }
  }
  prv_highest_color = highest_color; // remember for next time
  xmlFreeDoc(doc);
  return 0;
}