예제 #1
0
파일: EventChannel.cpp 프로젝트: CCJY/ATCD
void
TAO_Notify_EventChannel::save_attrs(TAO_Notify::NVPList& attrs)
{
  TAO_Notify_Object::save_attrs(attrs);
  add_attr(attrs, this->admin_properties().max_global_queue_length());
  add_attr(attrs, this->admin_properties().max_consumers());
  add_attr(attrs, this->admin_properties().max_suppliers());
  add_attr(attrs, this->admin_properties().reject_new_events());
}
예제 #2
0
파일: ipset.c 프로젝트: ANGERofWaR/dnsmasq
static int new_add_to_ipset(const char *setname, const struct all_addr *ipaddr, int af, int remove)
{
  struct nlmsghdr *nlh;
  struct nfgenmsg *nfg;
  struct nlattr *nested[2];
  uint8_t proto;
  int addrsz = INADDRSZ;
  ssize_t rc;

#ifdef HAVE_IPV6
  if (af == AF_INET6)
    addrsz = IN6ADDRSZ;
#endif
    
  if (strlen(setname) >= IPSET_MAXNAMELEN) 
    {
      errno = ENAMETOOLONG;
      return -1;
    }
  
  memset(buffer, 0, BUFF_SZ);

  nlh = (struct nlmsghdr *)buffer;
  nlh->nlmsg_len = NL_ALIGN(sizeof(struct nlmsghdr));
  nlh->nlmsg_type = (remove ? IPSET_CMD_DEL : IPSET_CMD_ADD) | (NFNL_SUBSYS_IPSET << 8);
  nlh->nlmsg_flags = NLM_F_REQUEST;
  
  nfg = (struct nfgenmsg *)(buffer + nlh->nlmsg_len);
  nlh->nlmsg_len += NL_ALIGN(sizeof(struct nfgenmsg));
  nfg->nfgen_family = af;
  nfg->version = NFNETLINK_V0;
  nfg->res_id = htons(0);
  
  proto = IPSET_PROTOCOL;
  add_attr(nlh, IPSET_ATTR_PROTOCOL, sizeof(proto), &proto);
  add_attr(nlh, IPSET_ATTR_SETNAME, strlen(setname) + 1, setname);
  nested[0] = (struct nlattr *)(buffer + NL_ALIGN(nlh->nlmsg_len));
  nlh->nlmsg_len += NL_ALIGN(sizeof(struct nlattr));
  nested[0]->nla_type = NLA_F_NESTED | IPSET_ATTR_DATA;
  nested[1] = (struct nlattr *)(buffer + NL_ALIGN(nlh->nlmsg_len));
  nlh->nlmsg_len += NL_ALIGN(sizeof(struct nlattr));
  nested[1]->nla_type = NLA_F_NESTED | IPSET_ATTR_IP;
  add_attr(nlh, 
	   (af == AF_INET ? IPSET_ATTR_IPADDR_IPV4 : IPSET_ATTR_IPADDR_IPV6) | NLA_F_NET_BYTEORDER,
	   addrsz, &ipaddr->addr);
  nested[1]->nla_len = (void *)buffer + NL_ALIGN(nlh->nlmsg_len) - (void *)nested[1];
  nested[0]->nla_len = (void *)buffer + NL_ALIGN(nlh->nlmsg_len) - (void *)nested[0];
	
  while ((rc = sendto(ipset_sock, buffer, nlh->nlmsg_len, 0,
		      (struct sockaddr *)&snl, sizeof(snl))) == -1 && retry_send());
  return rc;
}
예제 #3
0
파일: xml.cpp 프로젝트: 2202877/acl
xml_node& xml_node::add_attr(const char* name, size_t n)
{
	char buf[32];

	safe_snprintf(buf, sizeof(buf), "%lu", (unsigned long) n);
	return add_attr(name, buf);
}
예제 #4
0
파일: xml.cpp 프로젝트: SmartPeach/acl
xml_node& xml_node::add_attr(const char* name, int n)
{
	char buf[32];

	safe_snprintf(buf, sizeof(buf), "%d", n);
	return add_attr(name, buf);
}
예제 #5
0
void Metalink4Writer::write_piece_hash(const MetalinkFile& file)
{
    if(file.get_piece_hashes().empty()) return;
    if(file.get_piece_hash_type().empty()) return;
    start(wxT("pieces"));
    add_attr(wxT("length"),
             wxString::Format(wxT("%lu"), file.get_piece_length()));
    add_attr(wxT("type"), file.get_piece_hash_type());
    close_start();
    const std::vector<wxString>& hashes = file.get_piece_hashes();
    for(std::vector<wxString>::const_iterator i = hashes.begin(),
            eoi = hashes.end(); i != eoi; ++i) {
        add_element(wxT("hash"), *i);
    }
    end(wxT("pieces"));
}
예제 #6
0
파일: znl2.c 프로젝트: elambert/honeycomb
attrp_t make_attr_raw(ptr_t buf, int bufsize, int type, ptr_t data, int len)
{
    uint32_t l;

    if ((l = add_attr(buf, bufsize, type, data, len)) < 0)
        return NULL;

    return (attrp_t) buf;
}
예제 #7
0
void Metalink3Writer::write_metalink()
{
    write_text(wxString(wxT("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")), true);
    start(wxT("metalink"));
    add_attr(wxT("version"), wxT("3.0"));
    add_attr(wxT("generator"), get_generator());
    add_attr(wxT("xmlns"), wxT("http://www.metalinker.org/"));
    close_start();
    start(wxT("files"));
    close_start();
    const std::vector<MetalinkFile>& files = metalink_.get_files();
    for(std::vector<MetalinkFile>::const_iterator i = files.begin(),
            eoi = files.end(); i != eoi; ++i) {
        write_file(*i);
    }
    end(wxT("files"));
    end(wxT("metalink"));
}
예제 #8
0
void Metalink3Writer::write_piece_hashes(const MetalinkFile& file)
{
    if(!has_piece_hashes(file)) return;
    start(wxT("pieces"));
    add_attr(wxT("length"),
             wxString::Format(wxT("%lu"), file.get_piece_length()));
    add_attr(wxT("type"), file.get_piece_hash_type());
    close_start();
    const std::vector<wxString>& hashes = file.get_piece_hashes();
    long index = 0;
    for(std::vector<wxString>::const_iterator i = hashes.begin(),
            eoi = hashes.end(); i != eoi; ++i) {
        start(wxT("hash"));
        add_attr(wxT("piece"), wxString::Format(wxT("%ld"), index));
        end(wxT("hash"), *i);
        index++;
    }
    end(wxT("pieces"));
}
예제 #9
0
파일: xml.cpp 프로젝트: 2202877/acl
xml_node& xml_node::add_attr(const char* name, acl_int64 n)
{
	char buf[32];
#ifdef WIN32
	safe_snprintf(buf, sizeof(buf), "%I64d", n);
#else
	safe_snprintf(buf, sizeof(buf), "%lld", n);
#endif
	return add_attr(name, buf);
}
예제 #10
0
void Metalink4Writer::write_hashes(const MetalinkFile& file)
{
    const std::vector<MetalinkHash>& hashes = file.get_file_hashes();
    for(std::vector<MetalinkHash>::const_iterator i = hashes.begin(),
            eoi = hashes.end(); i != eoi; ++i) {
        start(wxT("hash"));
        add_attr(wxT("type"), (*i).type);
        end(wxT("hash"), (*i).value);
    }
}
예제 #11
0
void Metalink4Writer::write_source(const MetalinkSource& source)
{
    if(source.is_torrent()) {
        start(wxT("metaurl"));
        add_attr(wxT("mediatype"), wxT("torrent"));
        if(!source.get_prioritystr().empty()) {
            add_attr(wxT("priority"), source.get_prioritystr());
        }
        end(wxT("metaurl"), source.get_uri());
    } else {
        start(wxT("url"));
        if(!source.get_prioritystr().empty()) {
            add_attr(wxT("priority"), source.get_prioritystr());
        }
        if(!source.get_location().empty()) {
            add_attr(wxT("location"), source.get_location());
        }
        end(wxT("url"), source.get_uri());
    }
}
예제 #12
0
파일: znl2.c 프로젝트: elambert/honeycomb
attrp_t nl2m_addattr(znl2msghdr *hdr, int maxlen, int type, ptr_t data, int len)
{
    uint32_t l;

    ptr_t tail = (ptr_t)hdr + hdr->znl2msg_len;
    maxlen -= hdr->znl2msg_len;

    if ((l = add_attr(tail, maxlen, type, data, len)) < 0)
        return NULL;

    hdr->znl2msg_len += l;
    return (attrp_t) tail;
}
예제 #13
0
static void add_attribute( char *attribute, int type, P_Void_ptr value )
/* This method adds an attribute-value pair to the gob's attribute list.
 * Note that it does not make a new copy of the attribute or value info.
 */
{
  P_Gob *self= (P_Gob *)po_this;
  METHOD_IN

  ger_debug("gob_mthd: add_attribute");
  
  self->attr= add_attr( self->attr, attribute, type, value );

  METHOD_OUT
}
예제 #14
0
void Metalink4Writer::write_metalink()
{
    write_text(wxT("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"));
    start(wxT("metalink"));
    add_attr(wxT("xmlns"), wxT("urn:ietf:params:xml:ns:metalink"));
    close_start();
    add_element(wxT("generator"), get_generator());
    const std::vector<MetalinkFile>& files = metalink_.get_files();
    for(std::vector<MetalinkFile>::const_iterator i = files.begin(),
            eoi = files.end(); i != eoi; ++i) {
        write_file(*i);
    }
    end(wxT("metalink"));
}
예제 #15
0
void Metalink4Writer::write_file(const MetalinkFile& file)
{
    start(wxT("file"));
    add_attr(wxT("name"), file.get_filename());
    close_start();
    add_element(wxT("identity"), file.get_identity());
    add_element(wxT("description"), file.get_description());
    add_element(wxT("version"), file.get_version());
    add_element(wxT("size"), file.get_size());
    write_hashes(file);
    write_piece_hash(file);
    const std::vector<MetalinkSource>& sources = file.get_sources();
    for(std::vector<MetalinkSource>::const_iterator i = sources.begin(),
            eoi = sources.end(); i != eoi; ++i) {
        write_source(*i);
    }
    end(wxT("file"));
}
예제 #16
0
/*
 * Gathers basic MPI information; sets up reader CM.
 */
int
adios_read_flexpath_init_method (MPI_Comm comm, PairStruct* params)
{    
    setenv("CMSelfFormats", "1", 1);
    fp_read_data = malloc(sizeof(flexpath_read_data));     
    if(!fp_read_data) {
        adios_error(err_no_memory, "Cannot allocate memory for flexpath.");
        return -1;
    }
    memset(fp_read_data, 0, sizeof(flexpath_read_data));
    
    fp_read_data->CM_TRANSPORT = attr_atom_from_string("CM_TRANSPORT");
    attr_list listen_list = NULL;
    char * transport = NULL;
    transport = getenv("CMTransport");

    // setup MPI stuffs
    fp_read_data->fp_comm = comm;
    MPI_Comm_size(fp_read_data->fp_comm, &(fp_read_data->fp_comm_size));
    MPI_Comm_rank(fp_read_data->fp_comm, &(fp_read_data->fp_comm_rank));

    fp_read_data->fp_cm = CManager_create();
    if(transport == NULL){
	if(CMlisten(fp_read_data->fp_cm) == 0) {
	    fprintf(stderr, "Flexpath ERROR: reader %d unable to initialize connection manager.\n",
		fp_read_data->fp_comm_rank);
	}
    }else{
	listen_list = create_attr_list();
	add_attr(listen_list, fp_read_data->CM_TRANSPORT, Attr_String, 
		 (attr_value)strdup(transport));
	CMlisten_specific(fp_read_data->fp_cm, listen_list);
    }
    int forked = CMfork_comm_thread(fp_read_data->fp_cm);
    if(!forked) {
	fprintf(stderr, "reader %d failed to fork comm_thread.\n", fp_read_data->fp_comm_rank);
	/*log_debug( "forked\n");*/
    }
    return 0;
}
예제 #17
0
/* This function is used by gtk_text_cell_accessible_get_offset_at_point()
 * and gtk_text_cell_accessible_get_character_extents(). There is no
 * cached PangoLayout so we must create a temporary one using this function.
 */
static PangoLayout *
create_pango_layout (GtkTextCellAccessible *text)
{
  GdkRGBA *foreground_rgba;
  PangoAttrList *attr_list, *attributes;
  PangoLayout *layout;
  PangoUnderline uline, underline;
  PangoFontMask mask;
  PangoFontDescription *font_desc;
  gboolean foreground_set, strikethrough_set, strikethrough;
  gboolean scale_set, underline_set, rise_set;
  gchar *renderer_text;
  gdouble scale;
  gint rise;
  GtkRendererCellAccessible *gail_renderer;
  GtkCellRendererText *gtk_renderer;

  gail_renderer = GTK_RENDERER_CELL_ACCESSIBLE (text);
  gtk_renderer = GTK_CELL_RENDERER_TEXT (gail_renderer->renderer);

  g_object_get (gtk_renderer,
                "text", &renderer_text,
                "attributes", &attributes,
                "foreground-set", &foreground_set,
                "foreground-rgba", &foreground_rgba,
                "strikethrough-set", &strikethrough_set,
                "strikethrough", &strikethrough,
                "font-desc", &font_desc,
                "scale-set", &scale_set,
                "scale", &scale,
                "underline-set", &underline_set,
                "underline", &underline,
                "rise-set", &rise_set,
                "rise", &rise,
                NULL);

  layout = gtk_widget_create_pango_layout (get_widget (text), renderer_text);

  if (attributes)
    attr_list = pango_attr_list_copy (attributes);
  else
    attr_list = pango_attr_list_new ();

  if (foreground_set)
    {
      add_attr (attr_list, pango_attr_foreground_new (foreground_rgba->red * 65535,
                                                      foreground_rgba->green * 65535,
                                                      foreground_rgba->blue * 65535));
    }

  if (strikethrough_set)
    add_attr (attr_list,
              pango_attr_strikethrough_new (strikethrough));

  mask = pango_font_description_get_set_fields (font_desc);

  if (mask & PANGO_FONT_MASK_FAMILY)
    add_attr (attr_list,
      pango_attr_family_new (pango_font_description_get_family (font_desc)));

  if (mask & PANGO_FONT_MASK_STYLE)
    add_attr (attr_list, pango_attr_style_new (pango_font_description_get_style (font_desc)));

  if (mask & PANGO_FONT_MASK_VARIANT)
    add_attr (attr_list, pango_attr_variant_new (pango_font_description_get_variant (font_desc)));

  if (mask & PANGO_FONT_MASK_WEIGHT)
    add_attr (attr_list, pango_attr_weight_new (pango_font_description_get_weight (font_desc)));

  if (mask & PANGO_FONT_MASK_STRETCH)
    add_attr (attr_list, pango_attr_stretch_new (pango_font_description_get_stretch (font_desc)));

  if (mask & PANGO_FONT_MASK_SIZE)
    add_attr (attr_list, pango_attr_size_new (pango_font_description_get_size (font_desc)));

  if (scale_set && scale != 1.0)
    add_attr (attr_list, pango_attr_scale_new (scale));

  if (underline_set)
    uline = underline;
  else
    uline = PANGO_UNDERLINE_NONE;

  if (uline != PANGO_UNDERLINE_NONE)
    add_attr (attr_list,
              pango_attr_underline_new (underline));

  if (rise_set)
    add_attr (attr_list, pango_attr_rise_new (rise));

  pango_layout_set_attributes (layout, attr_list);
  pango_layout_set_width (layout, -1);
  pango_attr_list_unref (attr_list);

  pango_font_description_free (font_desc);
  pango_attr_list_unref (attributes);
  g_free (renderer_text);
  gdk_rgba_free (foreground_rgba);

  return layout;
}
예제 #18
0
파일: isakmp.c 프로젝트: hydromet/libreswan
/*
 *	make_trans -- Construct a single transform payload
 *
 *	Inputs:
 *
 *	length	(output) length of entire transform payload.
 *	next    Next Payload Type (3 = More transforms; 0=No more transforms)
 *	number	Transform number
 *	cipher	The encryption algorithm
 *	keylen	Key length for variable length keys (0=fixed key length)
 *	hash	Hash algorithm
 *	auth	Authentication method
 *	group	DH Group number
 *	lifetime	Lifetime in seconds (0=no lifetime)
 *	lifesize	Life in kilobytes (0=no life)
 *
 *	Returns:
 *
 *	Pointer to transform payload.
 *
 *	This constructs a single transform payload.
 *	Most of the values are defined in RFC 2409 Appendix A.
 */
unsigned char*make_trans(size_t *length, unsigned next, unsigned number,
			 unsigned cipher,
			 unsigned keylen, unsigned hash, unsigned auth,
			 unsigned group,
			 unsigned lifetime, unsigned lifesize, int gss_id_flag,
			 unsigned char *gss_data, size_t gss_data_len)
{

	struct isakmp_transform* hdr;   /* Transform header */
	unsigned char *payload;
	unsigned char *attr;
	unsigned char *cp;
	size_t attr_len;                /* Attribute Length */
	size_t len;                     /* Payload Length */

/* Allocate and initialise the transform header */

	hdr = Malloc(sizeof(struct isakmp_transform));
	memset(hdr, '\0', sizeof(struct isakmp_transform));

	hdr->isat_np = next;            /* Next payload type */
	hdr->isat_transnum = number;    /* Transform Number */
	hdr->isat_transid = KEY_IKE;

/* Allocate and initialise the mandatory attributes */

	add_attr(0, NULL, 'B', OAKLEY_ENCRYPTION_ALGORITHM, 0, cipher, NULL);
	add_attr(0, NULL, 'B', OAKLEY_HASH_ALGORITHM, 0, hash, NULL);
	add_attr(0, NULL, 'B', OAKLEY_AUTHENTICATION_METHOD, 0, auth, NULL);
	add_attr(0, NULL, 'B', OAKLEY_GROUP_DESCRIPTION, 0, group, NULL);

/* Allocate and initialise the optional attributes */

	if (keylen)
		add_attr(0, NULL, 'B', OAKLEY_KEY_LENGTH, 0, keylen, NULL);

	if (lifetime) {
		uint32_t lifetime_n = htonl(lifetime);

		add_attr(0, NULL, 'B', OAKLEY_LIFE_TYPE, 0,
			 SA_LIFE_TYPE_SECONDS, NULL);
		add_attr(0, NULL, 'V', OAKLEY_LIFE_DURATION, 4, 0,
			 &lifetime_n);
	}

	if (lifesize) {
		uint32_t lifesize_n = htonl(lifesize);

		add_attr(0, NULL, 'B', OAKLEY_LIFE_TYPE, 0,
			 SA_LIFE_TYPE_KBYTES, NULL);
		add_attr(0, NULL, 'V', OAKLEY_LIFE_DURATION, 4, 0,
			 &lifesize_n);
	}

	if (gss_id_flag)
		add_attr(0, NULL, 'V', OAKLEY_GSS_ID, gss_data_len, 0,
			 gss_data);

/* Finalise attributes and fill in length value */

	attr = add_attr(1, &attr_len, '\0', 0, 0, 0, NULL);
	len = attr_len + sizeof(struct isakmp_transform);
	hdr->isat_length = htons(len);  /* Transform length */
	*length = len;

/* Allocate memory for payload and copy structures to payload */

	payload = Malloc(len);

	cp = payload;
	memcpy(cp, hdr, sizeof(struct isakmp_transform));
	free(hdr);
	cp += sizeof(struct isakmp_transform);
	memcpy(cp, attr, attr_len);
	free(attr);

	return payload;
}
예제 #19
0
    /* Build link connections */
    v_iterate(links, iter) {
        link = vl_iter_pval(iter);

        if (vh_iget(link, "NOLINK"))
            continue;

        if (vh_iget(link, "NOPATH"))
            continue;

        oneway = vh_iget(link, "ONEWAY");
        len = vh_iget(link, "LEN");
        if (len)
            uselen++;

        from = vh_pget(link, "FROM");
        to = vh_pget(link, "TO");

        /* From -> to */
        reach = vh_create();

        cmd = NULL;
        goflag = vh_iget(link, "GO");
        dir = vh_iget(link, "TO_DIR");
        if ((cmdto = vh_pget(link, "TO_CMD")) != NULL) {
            vh_pstore(reach, "CMD", cmdto);
        } else {
            if (goflag)
                cmd = dirinfo[goflag].sname;
            if (cmd == NULL)
                cmd = dirinfo[dir].sname;
            add_attr(reach, "CMD", cmd);
        }

        vh_pstore(reach, "FROM", from);
        vh_pstore(reach, "TO", to);
        vh_pstore(reach, "NEED", vh_pget(link, "NEED"));
        vh_pstore(reach, "BEFORE", vh_pget(link, "BEFORE"));
        vh_pstore(reach, "AFTER", vh_pget(link, "AFTER"));
        vh_istore(reach, "LEN", V_MAX(len, 1));
        vh_pstore(reach, "LEAVE", vh_pget(link, "LEAVE"));
        vh_istore(reach, "LEAVEALL", vh_iget(link, "LEAVEALL"));

        link_rooms(from, to, reach);

        if (TASK_VERBOSE) {
            indent(1);
            list = vh_pget(reach, "CMD");
            printf("link '%s' to '%s' (%s)",
                   vh_sgetref(from, "DESC"),
                   vh_sgetref(to, "DESC"),
                   vl_join(list, ". "));
            if (len > 1)
                printf(" (dist %d)", len);
            printf("\n");
        }

        /* To -> from if not one-way */
        if (!oneway) {
            reach = vh_create();

            cmd = NULL;
            goflag = dirinfo[goflag].odir;
            dir = vh_iget(link, "FROM_DIR");
            if ((cmdfrom = vh_pget(link, "FROM_CMD")) != NULL) {
                vh_pstore(reach, "CMD", cmdfrom);
            } else if (cmdto != NULL) {
                vh_pstore(reach, "CMD", cmdto);
            } else {
                if (goflag)
                    cmd = dirinfo[goflag].sname;
                if (cmd == NULL)
                    cmd = dirinfo[dir].sname;
                add_attr(reach, "CMD", cmd);
            }

            vh_pstore(reach, "FROM", to);
            vh_pstore(reach, "TO", from);
            vh_pstore(reach, "NEED", vh_pget(link, "NEED"));
            vh_pstore(reach, "BEFORE", vh_pget(link, "BEFORE"));
            vh_pstore(reach, "AFTER", vh_pget(link, "AFTER"));
            vh_pstore(reach, "LEAVE", vh_pget(link, "LEAVE"));
            vh_istore(reach, "LEAVEALL", vh_iget(link, "LEAVEALL"));
            vh_istore(reach, "LEN", V_MAX(len, 1));

            link_rooms(to, from, reach);

            if (TASK_VERBOSE) {
                indent(1);
                list = vh_pget(reach, "CMD");
                printf("link '%s' to '%s' (%s)",
                       vh_sgetref(to, "DESC"),
                       vh_sgetref(from, "DESC"),
                       vl_join(list, ". "));
                if (len > 1)
                    printf(" (dist %d)", len);
                printf("\n");
            }
        }
    }
예제 #20
0
/* 
    adds different types of attributes to an object.
	
	returns the number of attributes added to the objects.
 */
int add_attrs(hid_t oid, int idx) 
{
    char name[32];
    int i0, i1, i2, j, nattrs=0;
	hid_t aid, tid, tid1, sid;
    hvl_t               i_vlen[4];
	hobj_ref_t          ref;
	zipcode_t            cmp_data[4];
    unsigned int        i = 0xffffffff;
    long long           l = -2147483647;
    float               f = 123456789.987654321;
    double              d = 987654321.123456789;
    char                *s[7] = {"Parting", "is such", "sweeter", "sorrow."};
    float               f_array[4] = {1.0, 2.22, 3.333, 4.444};
    char                *s_vlen[4] = {"Parting", "is such", "sweet", "sorrow."};
	hsize_t             dims1[1]={1}, dims2[1]={4}, dims3[2]={3,5};
	int                 int3d[4][3][5];
	 size_t             offset = 0;
	
	for (i0=0; i0<4; i0++) {
	    i_vlen[i0].len = (i0+1);
		i_vlen[i0].p = (int *)calloc(i_vlen[i0].len, sizeof(int));
		for (j=0; j<i_vlen[i0].len; j++)
		    ((int *)i_vlen[i0].p)[j] = i0*100+j;
	    for (i1=0; i1<3; i1++) {
	        for (i2=0; i2<5; i2++)
	            int3d[i0][i1][i2] = i0*i1-i1*i2+i0*i2;
		}
    }

	cmp_data[0].zipcode = 01001;
    cmp_data[0].city = "Agawam, Massachusetts";
    cmp_data[1].zipcode = 99950;
    cmp_data[1].city = "Ketchikan, Alaska";
    cmp_data[2].zipcode = 00501;
    cmp_data[2].city = "Holtsville, New York";
    cmp_data[3].zipcode = 61820;
    cmp_data[3].city = "Champaign, Illinois";
	
	/* 1 scalar point */
	sid = H5Screate (H5S_SCALAR);
	sprintf(name, "%05d scalar int", idx);
    nattrs += add_attr(oid, name, H5T_NATIVE_UINT, sid, &i);	
	sprintf(name, "%05d scalar ulong", idx);
    nattrs += add_attr(oid, name, H5T_NATIVE_INT64, sid, &l);	
	sprintf(name, "%05d scalar str", idx);
	tid =  H5Tcopy (H5T_C_S1);
    H5Tset_size (tid, H5T_VARIABLE);
    nattrs += add_attr(oid, name, tid, sid, &s[2]);	
	H5Tclose(tid);
	H5Sclose(sid);

	/* 4 single point */
	sid = H5Screate_simple (1, dims1, NULL);
    H5Rcreate(&ref, oid, ".", H5R_OBJECT, -1);
	sprintf(name, "%05d single float", idx);
    nattrs += add_attr(oid, name, H5T_NATIVE_FLOAT, sid, &f);	
	sprintf(name, "%05d single double", idx);
    nattrs += add_attr(oid, name, H5T_NATIVE_DOUBLE, sid, &d);	
	sprintf(name, "%05d single obj_ref", idx);
    nattrs += add_attr(oid, name, H5T_STD_REF_OBJ, sid, &ref);	
	H5Sclose(sid);
	
	/* 7 fixed length 1D array */
	sid = H5Screate_simple (1, dims1, NULL);
	tid = H5Tarray_create (H5T_NATIVE_FLOAT, 1, dims2);
	sprintf(name, "%05d array float", idx);
    nattrs += add_attr(oid, name, tid, sid, &f_array[0]);
	H5Tclose(tid);
	tid =  H5Tcopy (H5T_C_S1);
    H5Tset_size (tid, strlen(s[0])+1);	
	tid1 = H5Tarray_create (tid, 1, dims2);
	sprintf(name, "%05d array str", idx);
    nattrs += add_attr(oid, name, tid1, sid, s);	
	H5Tclose(tid1);	
	H5Tclose(tid);	
	H5Sclose(sid);

	/* 9 fixed length 2D int arrays */
	sid = H5Screate_simple (1, dims2, NULL);
	tid = H5Tarray_create (H5T_NATIVE_INT, 2, dims3);
	sprintf(name, "%05d array int 2D", idx);
    nattrs += add_attr(oid, name, tid, sid, int3d[0][0]);
	H5Tclose(tid);
	H5Sclose(sid);
	
	/* 10 variable length arrays */
	sid = H5Screate_simple (1, dims2, NULL);
	tid = H5Tcopy (H5T_C_S1);
	H5Tset_size (tid, H5T_VARIABLE);
	sprintf(name, "%05d vlen strings", idx);
    nattrs += add_attr(oid, name, tid, sid, s_vlen);
	H5Tclose(tid);	
	tid = H5Tvlen_create (H5T_NATIVE_INT);;
	sprintf(name, "%05d vlen int array", idx);
    nattrs += add_attr(oid, name, tid, sid, i_vlen);
	H5Tclose(tid);
	H5Sclose(sid);

	/* 12 compound data */
	sid = H5Screate_simple (1, dims2, NULL);
	tid = H5Tcreate (H5T_COMPOUND, sizeof (zipcode_t));
	tid1 = H5Tcopy (H5T_C_S1);
	H5Tset_size (tid1, H5T_VARIABLE);	
    H5Tinsert (tid, "zip code", 0, H5T_NATIVE_INT); offset += sizeof(H5T_NATIVE_INT);
    H5Tinsert (tid, "City", offset, tid1); offset += sizeof(char *);
	sprintf(name, "%05d compound data", idx);
    nattrs += add_attr(oid, name, tid, sid, cmp_data);
	H5Tclose(tid1);	
	H5Tclose(tid);	
	H5Sclose(sid);

	for (i0=0; i0<4; i0++) 
	    free(i_vlen[i0].p);
		
	return nattrs;
}
예제 #21
0
파일: pool.c 프로젝트: FancyFon/strongswan
static void do_args(int argc, char *argv[])
{
	char *name = "", *value = "", *filter = "";
	char *pool = NULL, *identity = NULL, *addresses = NULL;
	value_type_t value_type = VALUE_NONE;
	int timeout = 0;
	bool utc = FALSE, hexout = FALSE;

	enum {
		OP_UNDEF,
		OP_USAGE,
		OP_STATUS,
		OP_STATUS_ATTR,
		OP_ADD,
		OP_ADD_ATTR,
		OP_DEL,
		OP_DEL_ATTR,
		OP_SHOW_ATTR,
		OP_RESIZE,
		OP_LEASES,
		OP_PURGE,
		OP_BATCH
	} operation = OP_UNDEF;

	/* reinit getopt state */
	optind = 0;

	while (TRUE)
	{
		int c;

		struct option long_opts[] = {
			{ "help", no_argument, NULL, 'h' },

			{ "utc", no_argument, NULL, 'u' },
			{ "status", no_argument, NULL, 'w' },
			{ "add", required_argument, NULL, 'a' },
			{ "replace", required_argument, NULL, 'c' },
			{ "del", required_argument, NULL, 'd' },
			{ "resize", required_argument, NULL, 'r' },
			{ "leases", no_argument, NULL, 'l' },
			{ "purge", required_argument, NULL, 'p' },
			{ "statusattr", no_argument, NULL, '1' },
			{ "addattr", required_argument, NULL, '2' },
			{ "delattr", required_argument, NULL, '3' },
			{ "showattr", no_argument, NULL, '4' },
			{ "batch", required_argument, NULL, 'b' },

			{ "start", required_argument, NULL, 's' },
			{ "end", required_argument, NULL, 'e' },
			{ "addresses", required_argument, NULL, 'y' },
			{ "timeout", required_argument, NULL, 't' },
			{ "filter", required_argument, NULL, 'f' },
			{ "addr", required_argument, NULL, 'v' },
			{ "mask", required_argument, NULL, 'v' },
			{ "server", required_argument, NULL, 'v' },
			{ "subnet", required_argument, NULL, 'n' },
			{ "string", required_argument, NULL, 'g' },
			{ "hex", required_argument, NULL, 'x' },
			{ "hexout", no_argument, NULL, '5' },
			{ "pool", required_argument, NULL, '6' },
			{ "identity", required_argument, NULL, '7' },
			{ 0,0,0,0 }
		};

		c = getopt_long(argc, argv, "", long_opts, NULL);
		switch (c)
		{
			case EOF:
				break;
			case 'h':
				operation = OP_USAGE;
				break;
			case 'w':
				operation = OP_STATUS;
				break;
			case '1':
				operation = OP_STATUS_ATTR;
				break;
			case 'u':
				utc = TRUE;
				continue;
			case 'c':
				replace_pool = TRUE;
				/* fallthrough */
			case 'a':
				name = optarg;
				operation = is_attribute(name) ? OP_ADD_ATTR : OP_ADD;
				if (replace_pool && operation == OP_ADD_ATTR)
				{
					fprintf(stderr, "invalid pool name: "
									"reserved for '%s' attribute.\n", optarg);
					usage();
					exit(EXIT_FAILURE);
				}
				continue;
			case '2':
				name = optarg;
				operation = OP_ADD_ATTR;
				continue;
			case 'd':
				name = optarg;
				operation = is_attribute(name) ? OP_DEL_ATTR : OP_DEL;
				continue;
			case '3':
				name = optarg;
				operation = OP_DEL_ATTR;
				continue;
			case '4':
				operation = OP_SHOW_ATTR;
				continue;
			case 'r':
				name = optarg;
				operation = OP_RESIZE;
				continue;
			case 'l':
				operation = OP_LEASES;
				continue;
			case 'p':
				name = optarg;
				operation = OP_PURGE;
				continue;
			case 'b':
				name = optarg;
				if (operation == OP_BATCH)
				{
					fprintf(stderr, "--batch commands can not be nested\n");
					exit(EXIT_FAILURE);
				}
				operation = OP_BATCH;
				continue;
			case 's':
				DESTROY_IF(start);
				start = host_create_from_string(optarg, 0);
				if (start == NULL)
				{
					fprintf(stderr, "invalid start address: '%s'.\n", optarg);
					usage();
					exit(EXIT_FAILURE);
				}
				continue;
			case 'e':
				DESTROY_IF(end);
				end = host_create_from_string(optarg, 0);
				if (end == NULL)
				{
					fprintf(stderr, "invalid end address: '%s'.\n", optarg);
					usage();
					exit(EXIT_FAILURE);
				}
				continue;
			case 't':
				timeout = atoi(optarg);
				if (timeout == 0 && strcmp(optarg, "0") != 0)
				{
					fprintf(stderr, "invalid timeout '%s'.\n", optarg);
					usage();
					exit(EXIT_FAILURE);
				}
				continue;
			case 'f':
				filter = optarg;
				continue;
			case 'y':
				addresses = optarg;
				continue;
			case 'g':
				value_type = VALUE_STRING;
				value = optarg;
				continue;
			case 'n':
				value_type = VALUE_SUBNET;
				value = optarg;
				continue;
			case 'v':
				value_type = VALUE_ADDR;
				value = optarg;
				continue;
			case 'x':
				value_type = VALUE_HEX;
				value = optarg;
				continue;
			case '5':
				hexout = TRUE;
				continue;
			case '6':
				pool = optarg;
				continue;
			case '7':
				identity = optarg;
				continue;
			default:
				usage();
				exit(EXIT_FAILURE);
				break;
		}
		break;
	}

	switch (operation)
	{
		case OP_USAGE:
			usage();
			break;
		case OP_STATUS:
			status();
			break;
		case OP_STATUS_ATTR:
			status_attr(hexout);
			break;
		case OP_ADD:
			if (addresses != NULL)
			{
				add_addresses(name, addresses, timeout);
			}
			else if (start != NULL && end != NULL)
			{
				add(name, start, end, timeout);
			}
			else
			{
				fprintf(stderr, "missing arguments.\n");
				usage();
				exit(EXIT_FAILURE);
			}
			break;
		case OP_ADD_ATTR:
			if (value_type == VALUE_NONE)
			{
				fprintf(stderr, "missing arguments.\n");
				usage();
				exit(EXIT_FAILURE);
			}
			if (identity && !pool)
			{
				fprintf(stderr, "--identity option can't be used without --pool.\n");
				usage();
				exit(EXIT_FAILURE);
			}
			add_attr(name, pool, identity, value, value_type);
			break;
		case OP_DEL:
			del(name);
			break;
		case OP_DEL_ATTR:
			if (identity && !pool)
			{
				fprintf(stderr, "--identity option can't be used without --pool.\n");
				usage();
				exit(EXIT_FAILURE);
			}
			del_attr(name, pool, identity, value, value_type);
			break;
		case OP_SHOW_ATTR:
			show_attr();
			break;
		case OP_RESIZE:
			if (end == NULL)
			{
				fprintf(stderr, "missing arguments.\n");
				usage();
				exit(EXIT_FAILURE);
			}
			resize(name, end);
			break;
		case OP_LEASES:
			leases(filter, utc);
			break;
		case OP_PURGE:
			purge(name);
			break;
		case OP_BATCH:
			if (name == NULL)
			{
				fprintf(stderr, "missing arguments.\n");
				usage();
				exit(EXIT_FAILURE);
			}
			batch(argv[0], name);
			break;
		default:
			usage();
			exit(EXIT_FAILURE);
	}
}
예제 #22
0
/* 
 * This function is used by gail_text_cell_get_offset_at_point()
 * and gail_text_cell_get_character_extents(). There is no 
 * cached PangoLayout for gailtextcell so we must create a temporary
 * one using this function.
 */ 
static PangoLayout*
create_pango_layout(GtkCellRendererText *gtk_renderer,
                    GtkWidget           *widget)
{
  PangoAttrList *attr_list;
  PangoLayout *layout;
  PangoUnderline uline;
  PangoFontMask mask;

  layout = gtk_widget_create_pango_layout (widget, gtk_renderer->text);

  if (gtk_renderer->extra_attrs)
    attr_list = pango_attr_list_copy (gtk_renderer->extra_attrs);
  else
    attr_list = pango_attr_list_new ();

  if (gtk_renderer->foreground_set)
    {
      PangoColor color;
      color = gtk_renderer->foreground;
      add_attr (attr_list, pango_attr_foreground_new (color.red,
                                                      color.green, color.blue));
    }

  if (gtk_renderer->strikethrough_set)
    add_attr (attr_list,
              pango_attr_strikethrough_new (gtk_renderer->strikethrough));

  mask = pango_font_description_get_set_fields (gtk_renderer->font);

  if (mask & PANGO_FONT_MASK_FAMILY)
    add_attr (attr_list,
      pango_attr_family_new (pango_font_description_get_family (gtk_renderer->font)));

  if (mask & PANGO_FONT_MASK_STYLE)
    add_attr (attr_list, pango_attr_style_new (pango_font_description_get_style (gtk_renderer->font)));

  if (mask & PANGO_FONT_MASK_VARIANT)
    add_attr (attr_list, pango_attr_variant_new (pango_font_description_get_variant (gtk_renderer->font)));

  if (mask & PANGO_FONT_MASK_WEIGHT)
    add_attr (attr_list, pango_attr_weight_new (pango_font_description_get_weight (gtk_renderer->font)));

  if (mask & PANGO_FONT_MASK_STRETCH)
    add_attr (attr_list, pango_attr_stretch_new (pango_font_description_get_stretch (gtk_renderer->font)));

  if (mask & PANGO_FONT_MASK_SIZE)
    add_attr (attr_list, pango_attr_size_new (pango_font_description_get_size (gtk_renderer->font)));

  if (gtk_renderer->scale_set &&
      gtk_renderer->font_scale != 1.0)
    add_attr (attr_list, pango_attr_scale_new (gtk_renderer->font_scale));

  if (gtk_renderer->underline_set)
    uline = gtk_renderer->underline_style;
  else
    uline = PANGO_UNDERLINE_NONE;

  if (uline != PANGO_UNDERLINE_NONE)
    add_attr (attr_list,
      pango_attr_underline_new (gtk_renderer->underline_style));

  if (gtk_renderer->rise_set)
    add_attr (attr_list, pango_attr_rise_new (gtk_renderer->rise));

  pango_layout_set_attributes (layout, attr_list);
  pango_layout_set_width (layout, -1);
  pango_attr_list_unref (attr_list);

  return layout;
}