Ejemplo n.º 1
0
void list_attributes(struct switch_dev *dev)
{
	printf("Switch %d: %s(%s), ports: %d, vlans: %d\n", dev->id, dev->dev_name, dev->name, dev->ports, dev->vlans);
	printf("     --switch\n");
	print_attrs(dev->ops);
	printf("     --vlan\n");
	print_attrs(dev->vlan_ops);
	printf("     --port\n");
	print_attrs(dev->port_ops);
}
Ejemplo n.º 2
0
Archivo: cli.c Proyecto: 4pao/openwrt
static void
list_attributes(struct switch_dev *dev)
{
	printf("%s: %s(%s), ports: %d (cpu @ %d), vlans: %d\n", dev->dev_name, dev->alias, dev->name, dev->ports, dev->cpu_port, dev->vlans);
	printf("     --switch\n");
	print_attrs(dev->ops);
	printf("     --vlan\n");
	print_attrs(dev->vlan_ops);
	printf("     --port\n");
	print_attrs(dev->port_ops);
}
Ejemplo n.º 3
0
int open_config() {
    FILE *fp = NULL;
    char *line;
    key_cmd *cmd;
    confentry *lastnode = NULL, *newnode = NULL;
    int lineno = 1, ret = 0;
    size_t n = 0;

    /* Allow the configuration file to be overridden */
    if (!config)
	config = CONFIG;

    fp = fopen(config, "r");
    if (fp == NULL) {
	lprintf("Warning: could not open the configuration file %s: %s\n", config, strerror(errno));
	return OK;
    }
    if (verbose > 1)
	lprintf("Using configuration file %s\n", config);

    while (!feof(fp) && (ret >=0)) {
	line = NULL;
	ret = getline(&line, &n, fp);
	if ((ret > 0) && (proc_config(lineno, line, &cmd) == OK)) {
	    newnode = (confentry *)(malloc(sizeof(confentry)));
	    if (newnode == NULL) {
		lprintf("Error: memory allocation failed\n");
		close_config();
		free(line);
		return MEMERR;
	    }

	    newnode->cmd = cmd;
	    newnode->next = NULL;

	    if (list == NULL) {
		list = newnode;
	    } else {
		lastnode->next = newnode;
	    }
	    lastnode = newnode;

	    if (verbose > 1) {
		lprintf("Config: ");
		lprint_mask(cmd->keys);
		lprintf(" -:- ");
		print_etype(cmd->type);
		lprintf(" -:- ");
		print_attrs(cmd);
		lprintf(" -:- %s\n", cmd->command);
	    }
	}
	free(line);
	++lineno;
    }

    fclose(fp);

    return OK;
}
Ejemplo n.º 4
0
void xlsx_workbook_context::start_element(xmlns_id_t ns, xml_token_t name, const xml_attrs_t& attrs)
{
    xml_token_pair_t parent = push_stack(ns, name);
    switch (name)
    {
        case XML_workbook:
        {
            xml_element_expected(parent, XMLNS_UNKNOWN_ID, XML_UNKNOWN_TOKEN);
            print_attrs(get_tokens(), attrs);
        }
        break;
        case XML_sheets:
            xml_element_expected(parent, NS_ooxml_xlsx, XML_workbook);
        break;
        case XML_sheet:
        {
            xml_element_expected(parent, NS_ooxml_xlsx, XML_sheets);
            workbook_sheet_attr_parser func(&get_session_context());
            func = for_each(attrs.begin(), attrs.end(), func);
            m_sheets.push_back(new xlsx_rel_sheet_info(func.get_sheet()));
            const xlsx_rel_sheet_info& info = m_sheets.back();
            m_sheet_info.insert(
                opc_rel_extras_t::value_type(func.get_rid(), &info));
        }
        break;
        default:
            warn_unhandled();
    }
}
Ejemplo n.º 5
0
void opc_relations_context::start_element(xmlns_id_t ns, xml_token_t name, const vector<xml_token_attr_t> &attrs)
{
    xml_token_pair_t parent = push_stack(ns, name);
    switch (name)
    {
        case XML_Relationships:
        {
            xml_element_expected(parent, XMLNS_UNKNOWN_ID, XML_UNKNOWN_TOKEN);
            print_attrs(get_tokens(), attrs);
        }
        break;
        case XML_Relationship:
        {
            rel_attr_parser func(&get_session_context(), &m_schema_cache);
            xml_element_expected(parent, NS_opc_rel, XML_Relationships);
            func = for_each(attrs.begin(), attrs.end(), func);
            const opc_rel_t& rel = func.get_rel();
            if (rel.type)
                m_rels.push_back(rel);
        }
        break;
        default:
            warn_unhandled();
    }
}
void find_and_print( Express model ) {
    DictionaryEntry de;
    Schema s;
    Entity e;
    DICTdo_init( model->symbol_table, &de );
    while( 0 != ( s = DICTdo( &de ) ) ) {
        printf( "Schema %s\n", s->symbol.name );
        e = DICTlookup( s->symbol_table, entityName );
        if( e ) {
            print_attrs( e );
        }
    }
}
Ejemplo n.º 7
0
void opc_content_types_context::start_element(xmlns_id_t ns, xml_token_t name, const::std::vector<xml_token_attr_t> &attrs)
{
    xml_token_pair_t parent = push_stack(ns, name);
    switch (name)
    {
        case XML_Types:
        {
            xml_element_expected(parent, XMLNS_UNKNOWN_ID, XML_UNKNOWN_TOKEN);

            print_attrs(get_tokens(), attrs);
        }
        break;
        case XML_Override:
        {
            xml_element_expected(parent, NS_opc_ct, XML_Types);
            part_ext_attr_parser func(&m_ct_cache, XML_PartName);
            func = for_each(attrs.begin(), attrs.end(), func);

            // We need to use allocated strings for part names here because
            // the part names need to survive after the [Content_Types].xml
            // stream is destroyed.
            pstring part_name = get_session_context().m_string_pool.intern(func.get_name()).first;
            m_parts.push_back(
                xml_part_t(part_name, func.get_content_type()));
        }
        break;
        case XML_Default:
        {
            xml_element_expected(parent, NS_opc_ct, XML_Types);
            part_ext_attr_parser func(&m_ct_cache, XML_Extension);
            func = for_each(attrs.begin(), attrs.end(), func);

            // Like the part names, we need to use allocated strings for
            // extension names.
            pstring ext_name = get_session_context().m_string_pool.intern(func.get_name()).first;
            m_ext_defaults.push_back(
                xml_part_t(ext_name, func.get_content_type()));
        }
        break;
        default:
            warn_unhandled();
    }
}
Ejemplo n.º 8
0
static int alerter_alert(const entry_id_t *p_entry_id, attr_set_t *p_attrs,
                         const action_params_t *params, post_action_e *after,
                         db_cb_func_t db_cb_fn, void *db_cb_arg)
{
    char *str_id = NULL;
    bool  str_is_alloc = false;
    GString *gs = g_string_new(NULL);

    /* build alert string */
    if (ATTR_MASK_TEST(p_attrs, fullpath))
    {
        str_id = ATTR(p_attrs, fullpath);
    }
    else
    {
        asprintf(&str_id, DFID, PFID(p_entry_id));
        str_is_alloc = true;
    }

    /** TODO build specific parameter that represents the alert rule */
    #if 0
    rc = BoolExpr2str(&entry_proc_conf.alert_list[i].boolexpr, stralert, 2*RBH_PATH_MAX);
    if ( rc < 0 )
        strcpy( stralert, "Error building alert string" );
    #endif

    /** TODO build specific parameter that represents attr mask for the rule (alert mask) */

    print_attrs(gs, p_attrs, null_mask, 0);

    /* title: alert rule name */
    RaiseEntryAlert(rbh_param_get(params, "title"), "entry matches alert rule",
                    str_id, gs->str);

    g_string_free(gs, TRUE);
    if (str_is_alloc)
        free(str_id);

    return 0;
}
Ejemplo n.º 9
0
static int process(const struct sockaddr_nl *who, struct nlmsghdr *n,
		   void *arg)
{
	struct genlmsghdr *ghdr;
	struct rtattr *attrs[MACSEC_ATTR_MAX + 1];
	struct rtattr *attrs_secy[MACSEC_SECY_ATTR_MAX + 1];
	int len = n->nlmsg_len;
	int ifindex;
	__u64 sci;
	__u8 encoding_sa;

	if (n->nlmsg_type != genl_family)
		return -1;

	len -= NLMSG_LENGTH(GENL_HDRLEN);
	if (len < 0)
		return -1;

	ghdr = NLMSG_DATA(n);
	if (ghdr->cmd != MACSEC_CMD_GET_TXSC)
		return 0;

	parse_rtattr(attrs, MACSEC_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len);
	if (!validate_dump(attrs)) {
		fprintf(stderr, "incomplete dump message\n");
		return -1;
	}

	ifindex = rta_getattr_u32(attrs[MACSEC_ATTR_IFINDEX]);
	parse_rtattr_nested(attrs_secy, MACSEC_SECY_ATTR_MAX + 1,
			    attrs[MACSEC_ATTR_SECY]);

	if (!validate_secy_dump(attrs_secy)) {
		fprintf(stderr, "incomplete dump message\n");
		return -1;
	}

	sci = rta_getattr_u64(attrs_secy[MACSEC_SECY_ATTR_SCI]);
	encoding_sa = rta_getattr_u8(attrs_secy[MACSEC_SECY_ATTR_ENCODING_SA]);

	if (filter.ifindex && ifindex != filter.ifindex)
		return 0;

	if (filter.sci && sci != filter.sci)
		return 0;

	open_json_object(NULL);
	print_uint(PRINT_ANY, "ifindex", "%u: ", ifindex);
	print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname",
			   "%s: ", ll_index_to_name(ifindex));

	print_attrs(attrs_secy);

	print_tx_sc("    ", sci, encoding_sa,
		    attrs[MACSEC_ATTR_TXSC_STATS],
		    attrs[MACSEC_ATTR_SECY_STATS],
		    attrs[MACSEC_ATTR_TXSA_LIST]);

	if (attrs[MACSEC_ATTR_RXSC_LIST])
		print_rxsc_list(attrs[MACSEC_ATTR_RXSC_LIST]);

	close_json_object();

	return 0;
}
Ejemplo n.º 10
0
/* create an array of str's for accounting using a formatting string;
 * this is the heart of the accounting module -- it prints whatever
 * requested in a way, that can be used for syslog, radius,
 * sql, whatsoever
 * tm sip_msg_clones does not clone (shmmem-zed) parsed fields, other then Via1,2. Such fields clone now or use from rq_rp
 */
static int fmt2strar(char *fmt,             /* what would you like to account ? */
		     struct sip_msg *rq,    /* accounted message */
		     str* ouri,             /* Outbound Request-URI */
		     struct hdr_field *to,
		     unsigned int code,
		     time_t req_time)       /* Timestamp of the request */
{
	int cnt;
	struct to_body* from, *pto;
	str *cr, *at;
	struct cseq_body *cseq;

	cnt = 0;

	     /* we don't care about parsing here; either the function
	      * was called from script, in which case the wrapping function
	      * is supposed to parse, or from reply processing in which case
	      * TM should have preparsed from REQUEST_IN callback; what's not
	      * here is replaced with NA
	      */
	while(*fmt) {
		if (cnt == ALL_LOG_FMT_LEN) {
			LOG(L_ERR, "ERROR:acc:fmt2strar: Formatting string is too long\n");
			return 0;
		}

		switch(*fmt) {
		case 'a': /* attr */
			at = print_attrs(avps, avps_n, 0);
			if (!at) {
				vals[cnt].nul = 1;
			} else {
				vals[cnt].val.str_val = *at;
			}
			break;

		case 'c': /* sip_callid */
			if (rq->callid && rq->callid->body.len) {
				vals[cnt].val.str_val = rq->callid->body;
			} else {
				vals[cnt].nul = 1;
			}
			break;

		case 'd': /* to_tag */
			if (to && (pto = (struct to_body*)(to->parsed)) && pto->tag_value.len) {
				vals[cnt].val.str_val = pto->tag_value;
			} else {
				vals[cnt].nul = 1;
			}
			break;

		case 'f': /* sip_from */
			if (rq->from && rq->from->body.len) {
				vals[cnt].val.str_val = rq->from->body;
			} else {
				vals[cnt].nul = 1;
			}
			break;

		case 'g': /* flags */
			vals[cnt].val.int_val = rq->flags;
			break;

		case 'i': /* inbound_ruri */
			vals[cnt].val.str_val = rq->first_line.u.request.uri;
			break;

		case 'm': /* sip_method */
			vals[cnt].val.str_val = rq->first_line.u.request.method;
			break;

		case 'n': /* sip_cseq */
			if (rq->cseq && (cseq = get_cseq(rq)) && cseq->number.len) {
				str2int(&cseq->number, (unsigned int*)&vals[cnt].val.int_val);
			} else {
				vals[cnt].nul = 1;
			}
			break;

		case 'o': /* outbound_ruri */
		        vals[cnt].val.str_val = *ouri;
			break;

		case 'p':
			vals[cnt].val.int_val = rq->rcv.src_ip.u.addr32[0];
			break;
			break;

		case 'r': /* from_tag */
			if (rq->from && (from = get_from(rq)) && from->tag_value.len) {
				vals[cnt].val.str_val = from->tag_value;
			} else {
				vals[cnt].nul = 1;
			}
			break;

		case 't': /* sip_to */
			if (to && to->body.len) vals[cnt].val.str_val = to->body;
			else vals[cnt].nul = 1;
			break;

		case 'u': /* digest_username */
			cr = cred_user(rq);
			if (cr) vals[cnt].val.str_val = *cr;
			else vals[cnt].nul = 1;
			break;

		case 'x': /* request_timestamp */
			vals[cnt].val.time_val = req_time;
			break;

		case 'D': /* to_did */
			vals[cnt].nul = 1;
			break;

		case 'F': /* from_uri */
			if (rq->from && (from = get_from(rq)) && from->uri.len) {
				vals[cnt].val.str_val = from->uri;
			} else vals[cnt].nul = 1;
			break;

		case 'I': /* from_uid */
			if (get_from_uid(&vals[cnt].val.str_val, rq) < 0) {
				vals[cnt].nul = 1;
			}
			break;

		case 'M': /* from_did */
			vals[cnt].nul = 1;
			break;

		case 'P': /* source_port */
			vals[cnt].val.int_val = rq->rcv.src_port;
			break;

		case 'R': /* digest_realm */
			cr = cred_realm(rq);
			if (cr) vals[cnt].val.str_val = *cr;
			else vals[cnt].nul = 1;
			break;

		case 'S': /* sip_status */
			if (code > 0) vals[cnt].val.int_val = code;
			else vals[cnt].nul = 1;
			break;

		case 'T': /* to_uri */
			if (rq->to && (pto = get_to(rq)) && pto->uri.len) vals[cnt].val.str_val = pto->uri;
			else vals[cnt].nul = 1;
			break;

		case 'U': /* to_uid */
			if (get_to_uid(&vals[cnt].val.str_val, rq) < 0) {
				vals[cnt].nul = 1;
			}
			break;

		case 'X': /* response_timestamp */
			vals[cnt].val.time_val = time(0);
			break;

		default:
			LOG(L_CRIT, "BUG:acc:fmt2strar: unknown char: %c\n", *fmt);
			return 0;
		} /* switch (*fmt) */

		fmt++;
		cnt++;
	} /* while (*fmt) */

	return cnt;
}
int main() {
  fsal_path_t path;
  int rc,fd,status, i, memsz, mempos, memval;
  fsal_op_context_t op_context;
  struct statfs stat_buf;
  gpfsfsal_export_context_t *p_export_context = calloc(0, sizeof(gpfsfsal_export_context_t));
  fsal_handle_t object_handle;
  fsal_handle_t object_handle_garbled;
  gpfsfsal_xstat_t buffstat;
  fsal_name_t file_name;
  unsigned char *handle_ptr;

  char *TESTDIR = "/ibm/gpfs0";
  char *TESTFILE = "invalid_getattrs_example";
  char *TESTFILE_PATH = "/ibm/gpfs0/invalid_getattrs_example";
  char *CREATETESTFILE = "mknod /ibm/gpfs0/invalid_getattrs_example u 1 1";
  char *REMOVETESTFILE = "ssh int001st001 rm -rf /ibm/gpfs0/invalid_getattrs_example";

  printf("Creating test file: %s\n", TESTFILE);
  system(CREATETESTFILE);

  strcpy(path.path, TESTDIR);
  path.len = strlen(TESTDIR);

  strcpy(file_name.name, TESTFILE);
  file_name.len = strlen(TESTFILE);

  fd = open(path.path, O_RDONLY | O_DIRECTORY);
  if(fd < 0) {
    printf("Couldn't open directory.\n");
    return 0;
  }
  p_export_context->mount_root_fd = fd;

  rc = statfs(path.path, &stat_buf);
  if(rc) {
    printf ("statfs call failed on file %s: %d", path.path, rc);
    return 0;
  }
  
 p_export_context->fsid[0] = stat_buf.f_fsid.__val[0];
 p_export_context->fsid[1] = stat_buf.f_fsid.__val[1];
 
 /* Get file handle to root of GPFS share */
 op_context.export_context = p_export_context;

 status = fsal_internal_get_handle(&op_context,
				   &path,
				   (fsal_handle_t *)(&(p_export_context->mount_root_handle)));
 if (status)
   printf("fsal_internal_get_handle() failed\n");

 /* Now show the error for when we use a nonsense file handle. */
 /* printf("USING AN UNINITIALIZED FILE HANDLE FOR GETATTR ...\n");
 fsal_get_xstat_by_handle(&op_context, &object_handle, &buffstat);
 printf("\n");
 */
 /* Get handle of file */
 fsal_internal_get_handle_at(fd, &file_name, &object_handle);

 /* Getattrs of file */
 printf("USING A CORRECT FILE HANDLE FOR GETATTR ...\n");
 handle_ptr = ((gpfsfsal_handle_t *)&object_handle)->data.handle.f_handle;
 printf("handle: ");
 for(i=0; i < OPENHANDLE_HANDLE_LEN; i++)
   printf("%02x", (unsigned char)handle_ptr[i]);
 printf("\n");

 fsal_get_xstat_by_handle(&op_context, &object_handle, &buffstat);

 /* print attrs */
 print_attrs(&buffstat);
 printf("\n");

 /* Getattrs of file */
 /*
 printf("USING A FILE HANDLE THAT HAS BEEN MEMSET at 4th BYTE FOR GETATTR ...\n");
 memcpy(&object_handle_garbled, &object_handle, sizeof(fsal_handle_t));
 handle_ptr = ((gpfsfsal_handle_t *)&object_handle_garbled)->data.handle.f_handle;
 memset(handle_ptr+3, 4, 1); 

 printf("handle: ");
 for(i=0; i < OPENHANDLE_HANDLE_LEN; i++)
   printf("%02x", (unsigned char)handle_ptr[i]);
 printf("\n");

 fsal_get_xstat_by_handle(&op_context, &object_handle_garbled, &buffstat);
 printf("\n");
 */
 /* Getattrs of file */
 /*
 printf("USING A FILE HANDLE THAT HAS BEEN MEMSET at 2nd BYTE FOR GETATTR ...\n");
 memcpy(&object_handle_garbled, &object_handle, sizeof(fsal_handle_t));
 handle_ptr = ((gpfsfsal_handle_t *)&object_handle_garbled)->data.handle.f_handle;
 memset(handle_ptr+1, 4, 1); 

 printf("handle: ");
 for(i=0; i < OPENHANDLE_HANDLE_LEN; i++)
   printf("%02x", (unsigned char)handle_ptr[i]);
 printf("\n");

 fsal_get_xstat_by_handle(&op_context, &object_handle_garbled, &buffstat);
 printf("\n");
 */
 /* Getattrs of file */
 /*
 printf("USING FILE HANDLEs THAT HAVE BEEN MEMSET\n");
 for(memsz=0; memsz <= OPENHANDLE_HANDLE_LEN; memsz++) {
   for(mempos=0; mempos <= OPENHANDLE_HANDLE_LEN-memsz; mempos++) {
     for(memval=0; memval <= 255; memval++) {
       memcpy(&object_handle_garbled, &object_handle, sizeof(fsal_handle_t));
       handle_ptr = ((gpfsfsal_handle_t *)&object_handle_garbled)->data.handle.f_handle;
       memset(handle_ptr+mempos, memval, memsz); 
       
       printf("handle: ");
       for(i=0; i < OPENHANDLE_HANDLE_LEN; i++)
         printf("%02x", (unsigned char)handle_ptr[i]);
       printf("\n");
       
       fsal_get_xstat_by_handle(&op_context, &object_handle_garbled, &buffstat);
     }
   }
 }
 */
 /* delete file */
 printf("Removing test file: %s\n", TESTFILE);
 system(REMOVETESTFILE);

 /* Now show the INTERRUPT error. */
 printf("USING A FILE HANDLE FROM A DELETED FILE FOR GETATTR ...\n");
 fsal_get_xstat_by_handle(&op_context, &object_handle, &buffstat);
 printf("\n");

 close(fd);

 return 0;
}
Ejemplo n.º 12
0
/* create an array of str's for accounting using a formatting string;
 * this is the heart of the accounting module -- it prints whatever
 * requested in a way, that can be used for syslog, radius,
 * sql, whatsoever
 * tm sip_msg_clones does not clone (shmmem-zed) parsed fields, other then Via1,2. Such fields clone now or use from rq_rp
 */
static int fmt2rad(char *fmt,
		   struct sip_msg *rq,
		   str* ouri,
		   struct hdr_field *to,
		   unsigned int code,
		   VALUE_PAIR** send,
		   time_t req_time)       /* Timestamp of the request */
{
	static unsigned int cseq_num, src_port, src_ip;
	static time_t rq_time, rs_time;
	int cnt;
	struct to_body* from, *pto;
	str val, *cr, *at;
	struct cseq_body *cseq;
	struct attr* attr;
	int dir;

	cnt = 0;
	dir = -2;

	     /* we don't care about parsing here; either the function
	      * was called from script, in which case the wrapping function
	      * is supposed to parse, or from reply processing in which case
	      * TM should have preparsed from REQUEST_IN callback.
	      */
	while(*fmt) {
		if (cnt == ALL_LOG_FMT_LEN) {
			LOG(L_ERR, "ERROR:acc:fmt2rad: Formatting string is too long\n");
			return 0;
		}

		attr = 0;
		switch(*fmt) {
		case 'a': /* attr */
			at = print_attrs(avps, avps_n, 0);
			if (at) {
				attr = &attrs[A_SER_ATTR];
				val = *at;
			}
			break;

		case 'c': /* sip_callid */
			if (rq->callid && rq->callid->body.len) {
				attr = &attrs[A_ACCT_SESSION_ID];
				val = rq->callid->body;
			}
			break;

		case 'd': /* to_tag */
			if (swap_dir && dir == -2) dir = get_direction(rq);
			if (dir <= 0) {
				if (to && (pto = (struct to_body*)(to->parsed)) && pto->tag_value.len) {
					attr = &attrs[A_SIP_TO_TAG];
					val = pto->tag_value;
				}
			} else {
				if (rq->from && (from = get_from(rq)) && from->tag_value.len) {
					attr = &attrs[A_SIP_TO_TAG];
					val = from->tag_value;
				}
			}
			break;

		case 'f': /* sip_from */
			if (rq->from && rq->from->body.len) {
				attr = &attrs[A_SER_FROM];
				val = rq->from->body;
			}
			break;

		case 'g': /* flags */
			attr = &attrs[A_SER_FLAGS];
			val.s = (char*)&rq->flags;
			val.len = sizeof(unsigned int);
			break;

		case 'i': /* inbound_ruri */
			attr = &attrs[A_SER_ORIGINAL_REQUEST_ID];
			val = rq->first_line.u.request.uri;
			break;

		case 'm': /* sip_method */
			attr = &attrs[A_SIP_METHOD];
			val = rq->first_line.u.request.method;
			break;

		case 'n': /* sip_cseq */
			if (rq->cseq && (cseq = get_cseq(rq)) && cseq->number.len) {
				attr = &attrs[A_SIP_CSEQ];
				str2int(&cseq->number, &cseq_num);
				val.s = (char*)&cseq_num;
				val.len = sizeof(unsigned int);
			}
			break;

		case 'o': /* outbound_ruri */
			attr = &attrs[A_SIP_TRANSLATED_REQUEST_ID];
			val = *ouri;
			break;

		case 'p': /* Source IP address */
			attr = &attrs[A_SIP_SOURCE_IP_ADDRESS];
			src_ip = ntohl(rq->rcv.src_ip.u.addr32[0]);
			val.s = (char*)&src_ip;
			val.len = sizeof(src_ip);
			break;

		case 'r': /* from_tag */
			if (swap_dir && dir == -2) dir = get_direction(rq);
			if (dir <= 0) {
				if (rq->from && (from = get_from(rq)) && from->tag_value.len) {
					attr = &attrs[A_SIP_FROM_TAG];
					val = from->tag_value;
				}
			} else {
				if (to && (pto = (struct to_body*)(to->parsed)) && pto->tag_value.len) {
					attr = &attrs[A_SIP_FROM_TAG];
					val = pto->tag_value;
				}
			}
			break;

		case 's': /* server_id */
			attr = &attrs[A_SER_SERVER_ID];
			val.s = (char*)&server_id;
			val.len = sizeof(int);
			break;

		case 't': /* sip_to */
			if (to && to->body.len) {
				attr = &attrs[A_SER_TO];
				val = to->body;
			}
			break;

		case 'u': /* digest_username */
			cr = cred_user(rq);
			if (cr) {
				attr = &attrs[A_SER_DIGEST_USERNAME];
				val = *cr;
			}
			break;

		case 'x': /* request_timestamp */
			attr = &attrs[A_SER_REQUEST_TIMESTAMP];
			rq_time = req_time;
			val.s = (char*)&rq_time;
			val.len = sizeof(time_t);
			break;

		case 'D': /* to_did */
			break;

		case 'F': /* from_uri */
			if (swap_dir && dir == -2) dir = get_direction(rq);
			if (dir <= 0) {
				if (rq->from && (from = get_from(rq)) && from->uri.len) {
					attr = &attrs[A_CALLING_STATION_ID];
					val = from->uri;
				}
			} else {
				if (rq->to && (pto = get_to(rq)) && pto->uri.len) {
					attr = &attrs[A_CALLING_STATION_ID];
					val = pto->uri;
				}
			}
			break;

		case 'I': /* from_uid */
			if (get_from_uid(&val, rq) < 0) {
				attr = &attrs[A_SER_FROM_UID];
			}
			break;

		case 'M': /* from_did */
			break;

		case 'P': /* Source port */
			attr = &attrs[A_SIP_SOURCE_PORT];
			src_port = rq->rcv.src_port;
			val.s = (char*)&src_port;
			val.len = sizeof(unsigned int);
			break;

		case 'R': /* digest_realm */
			cr = cred_realm(rq);
			if (cr) {
				attr = &attrs[A_SER_DIGEST_REALM];
				val = *cr;
			}
			break;

		case 'S': /* sip_status */
			attr = &attrs[A_SIP_RESPONSE_CODE];
			val.s = (char*)&code;
			val.len = sizeof(unsigned int);
			break;

		case 'T': /* to_uri */
			if (swap_dir && dir == -2) dir = get_direction(rq);
			if (dir <= 0) {
				if (rq->to && (pto = get_to(rq)) && pto->uri.len) {
					attr = &attrs[A_CALLED_STATION_ID];
					val = pto->uri;
				}
			} else {
				if (rq->from && (from = get_from(rq)) && from->uri.len) {
					attr = &attrs[A_CALLED_STATION_ID];
					val = from->uri;
				}
			}
			break;

		case 'U': /* to_uid */
			if (get_from_uid(&val, rq) < 0) {
				attr = &attrs[A_SER_TO_UID];
			}
			break;

		case 'X': /* response_timestamp */
			attr = &attrs[A_SER_RESPONSE_TIMESTAMP];
			rs_time = time(0);
			val.s = (char*)&rs_time;
			val.len = sizeof(time_t);
			break;

		default:
			LOG(L_CRIT, "BUG:acc:fmt2rad: unknown char: %c\n", *fmt);
			return -1;
		} /* switch (*fmt) */

		if (attr) {
			if (!rc_avpair_add(rh, send, ATTRID(attr->v), val.s, val.len, VENDOR(attr->v))) {
				LOG(L_ERR, "ERROR:acc:fmt2rad: Failed to add attribute %s\n",
				    attr->n);
				return -1;
			}
		}

		fmt++;
		cnt++;
	} /* while (*fmt) */

	return 0;
}