示例#1
0
文件: xmlfile.cpp 项目: crazii/mameui
void xml_data_node::write_recursive(int indent, util::core_file &file) const
{
	/* output this tag */
	file.printf("%*s<%s", indent, "", get_name());

	/* output any attributes */
	for (attribute_node const &anode : m_attributes)
		file.printf(" %s=\"%s\"", anode.name, anode.value);

	if (!get_first_child() && !get_value())
	{
		/* if there are no children and no value, end the tag here */
		file.printf(" />\n");
	}
	else
	{
		/* otherwise, close this tag and output more stuff */
		file.printf(">\n");

		/* if there is a value, output that here */
		if (get_value())
			file.printf("%*s%s\n", indent + 4, "", get_value());

		/* loop over children and output them as well */
		if (get_first_child())
		{
			for (xml_data_node const *child = this->get_first_child(); child; child = child->get_next_sibling())
				child->write_recursive(indent + 4, file);
		}

		/* write a closing tag */
		file.printf("%*s</%s>\n", indent, "", get_name());
	}
}
示例#2
0
	void DomDocument::clear_all()
	{
		while (!get_first_child().is_null())
		{
			DomNode node = get_first_child();
			remove_child(node);
		}
	}
示例#3
0
文件: player_ai.cpp 项目: rolfrm/bbe2
void player_ai::handleKeyEvent(keyEvent evt) {
	int value;
	if (evt.state == KEYDOWN) {
		if (evt.button == KEY_BACKSPACE) {
			print_children();
		}
		value = 1;
		if (evt.button == KEY_CTRL) {
			inventory_active = !inventory_active;
			eventMaster * anim = (eventMaster*) get_first_child(
					"sprite.dw_anim_fisher");
			anim->handleCustomEvent(customEvent("hide", SINGLE, "", 1));
		}
	} else {
		value = 0;
	}

	if (evt.button == KEY_D) {
		d_down = value;
	} else if (evt.button == KEY_A) {
		a_down = value;
	} else if (evt.button == KEY_UP) {
		up_down = value;
	} else if (evt.button == KEY_DOWN) {
		down_down = value;
	} else if (evt.button == KEY_LEFT) {
		left_down = value;
	} else if (evt.button == KEY_RIGHT) {
		right_down = value;
	}
}
示例#4
0
static void
widget_overlay_add (GtkContainer *container, GtkWidget *widget)
{
	WidgetOverlay *ovl = WIDGET_OVERLAY (container);
	ChildData *cd;

	cd = g_new0 (ChildData, 1);
	gtk_widget_set_parent (widget, GTK_WIDGET (ovl));
	cd->ovl = ovl;
	cd->child = widget;
	cd->halign = WIDGET_OVERLAY_ALIGN_CENTER;
	cd->valign = WIDGET_OVERLAY_ALIGN_END;
	cd->alpha = 1.;
	cd->scale = 1.;
	cd->ignore_events = FALSE;
	cd->is_tooltip = FALSE;
	
	ovl->priv->children = g_list_append (ovl->priv->children, cd);

	if (ovl->priv->scale_child) {
		ChildData *fcd;
		fcd = get_first_child (ovl);
		if (cd == fcd)
			gtk_range_set_value (ovl->priv->scale_range, cd->scale);

		ovl->priv->children = g_list_remove (ovl->priv->children, ovl->priv->scale_child);
		ovl->priv->children = g_list_append (ovl->priv->children, ovl->priv->scale_child);
	}
}
示例#5
0
bool contains_reference_to_tree( Node* n, BehaviorTree* tree )
{
  if( !n )
    return false;

  Node* it;

  if( n->m_Grist.m_Type == E_GRIST_TREE )
  {
    if( n->m_Grist.m_Tree.m_Tree == tree )
      return true;

    if( !n->m_Grist.m_Tree.m_Tree )
      return false;

    it = n->m_Grist.m_Tree.m_Tree->m_Root;
    while( it )
    {
      if( contains_reference_to_tree( it, tree ) )
        return true;
      it = it->m_Next;
    }
  }

  it = get_first_child( n );
  while( it )
  {
    if( contains_reference_to_tree( it, tree ) )
      return true;
    it = it->m_Next;
  }
  return false;
}
示例#6
0
文件: cpl_run.c 项目: 2pac/kamailio
/* UPDATED + CHECKED
 */
static inline char *run_cpl_node( struct cpl_interpreter *intr )
{
	char *kid;
	unsigned char start;
	int i;

	start = (intr->flags&CPL_RUN_INCOMING)?INCOMING_NODE:OUTGOING_NODE;
	/* look for the starting node (incoming or outgoing) */
	for(i=0;i<NR_OF_KIDS(intr->ip);i++) {
		kid= intr->ip + KID_OFFSET(intr->ip,i);
		if ( NODE_TYPE(kid)==start ) {
			return get_first_child(kid);
		} else
		if (NODE_TYPE(kid)==SUBACTION_NODE ||
		NODE_TYPE(kid)==ANCILLARY_NODE ||
		NODE_TYPE(kid)==INCOMING_NODE  ||
		NODE_TYPE(kid)==OUTGOING_NODE ) {
			continue;
		} else {
			LM_ERR("unknown child type (%d) "
				"for CPL node!!\n",NODE_TYPE(kid));
			return CPL_SCRIPT_ERROR;
		}
	}

	LM_DBG("CPL node has no %d subnode -> default\n", start);
	return DEFAULT_ACTION;
}
示例#7
0
CL_DomElement CL_DomElement::get_first_child_element() const
{
	CL_DomNode node = get_first_child();
	while (!node.is_null() && !node.is_element())
		node = node.get_next_sibling();
	return node.to_element();
}
示例#8
0
文件: player_ai.cpp 项目: rolfrm/bbe2
void player_ai::handleTurnEvent(turnEvent evt) {
	sendCustomEvent("inventory_sprite","show",1,SINGLE);
	if(!inited){
		gamepart = (sprite *) get_first_child("sprite");
		inited = true;
	}
	if (down_down) {
		graphics_core->cam.Pos.y += 10;
	}
	if (up_down) {
		graphics_core->cam.Pos.y -= 10;
	}
	if (left_down) {
		graphics_core->cam.Pos.x -= 10;
	}
	if (right_down) {
		graphics_core->cam.Pos.x += 10;
	}
	if (d_down) {
		//get_first_child("");
	}
	if (selected_sprite != NULL) {
		selected_sprite->set_velocity(event_core->pointer_game
				- selected_sprite->Pos);
	}
}
示例#9
0
static void
scale_value_changed_cb (GtkRange *range, WidgetOverlay *ovl)
{
	ChildData *cd;
	cd = get_first_child (ovl);
	if (!cd)
		return;
	change_widget_scale (ovl, cd, gtk_range_get_value (range));
}
示例#10
0
void GridObject::on_render(clan::Canvas &canvas, const clan::Rect &update_rect)
{
	// Do a fill rect for otherwise transparent components:
	std::string type = get_first_child()->get_tag_name();
	if (type == "toolbar" || type == "menubar" /*|| type == "label"*/)
	{
		clan::Rect child_geom = get_first_child()->get_geometry();
		get_canvas().fill_rect(child_geom, clan::Colorf(0.35f, 0.498f, 0.603f, 0.2f));
	}

	/*  DON'T DELETE THIS COMMENTED CODE!
	clan::Point tl = get_geometry().get_top_left();
	clan::Point tl_win = component_to_window_coords(tl);
	canvas.set_font(font);
	canvas.draw_text(20,24, clan::string_format("%1, %2", tl.x, tl.y), clan::Colorf::red);
	canvas.draw_text(60,24, clan::string_format("%1, %2", tl_win.x, tl_win.y), clan::Colorf::blue);
	*/
 }
示例#11
0
文件: xmlfile.cpp 项目: crazii/mameui
int xml_data_node::count_children() const
{
	int count = 0;

	/* loop over children and count */
	for (xml_data_node const *node = get_first_child(); node; node = node->get_next_sibling())
		count++;
	return count;
}
示例#12
0
	DomNode DomNode::named_item(const DomString &name) const
	{
		DomNode node = get_first_child();
		while (node.is_null() == false)
		{
			if (node.get_node_name() == name) return node;
			node = node.get_next_sibling();
		}
		return DomNode();
	}
示例#13
0
void set_parent_on_children( Node* n )
{
  Node* c = get_first_child( n );
  while( c )
  {
    c->m_Pare.m_Type = E_NP_NODE;
    c->m_Pare.m_Node = n;
    c = c->m_Next;
  }
}
示例#14
0
int count_children( Node* n )
{
  Node* c = get_first_child( n );
  int retval = 0;
  while( c )
  {
    c = c->m_Next;
    ++retval;
  }
  return retval;
}
示例#15
0
	DomElement DomDocument::get_document_element()
	{
		DomNode cur = get_first_child();
		while (!cur.is_null())
		{
			if (cur.is_element())
				return cur.to_element();
			cur = cur.get_next_sibling();
		}
		return DomElement();
	}
示例#16
0
	DomNodeList DomNode::get_child_nodes() const
	{
		DomNodeList list;
		DomNode node = get_first_child();
		while (!node.is_null())
		{
			list.add_item(node);
			node = node.get_next_sibling();
		}
		return list;
	}
示例#17
0
/* UPDATED + CHECKED
 */
static inline char *run_sub( struct cpl_interpreter *intr )
{
	char  *p;
	unsigned short offset;
	unsigned short attr_name;
	int i;

	/* sanity check */
	if (NR_OF_KIDS(intr->ip)!=0) {
		LOG(L_ERR,"ERROR:cpl_c:run_sub: SUB node doesn't suppose to have any "
			"sub-nodes. Found %d!\n",NR_OF_KIDS(intr->ip));
		goto script_error;
	}

	/* check the number of attr */
	i = NR_OF_ATTR( intr->ip );
	if (i!=1) {
		LOG(L_ERR,"ERROR:cpl_c:run_sub: incorrect nr. of attr. %d (<>1) in "
			"SUB node\n",i);
		goto script_error;
	}
	/* get attr's name */
	p = ATTR_PTR(intr->ip);
	get_basic_attr( p, attr_name, offset, intr, script_error);
	if (attr_name!=REF_ATTR) {
		LOG(L_ERR,"ERROR:cpl_c:run_sub: invalid attr. %d (expected %d)in "
			"SUB node\n", attr_name, REF_ATTR);
		goto script_error;
	}
	/* make the jump */
	p = intr->ip - offset;
	/* check the destination pointer -> are we still inside the buffer ;-) */
	if (((char*)p)<intr->script.s) {
		LOG(L_ERR,"ERROR:cpl_c:run_sub: jump offset lower than the script "
			"beginning -> underflow!\n");
		goto script_error;
	}
	check_overflow_by_ptr( p+SIMPLE_NODE_SIZE(intr->ip), intr, script_error);
	/* check to see if we hit a subaction node */
	if ( NODE_TYPE(p)!=SUBACTION_NODE ) {
		LOG(L_ERR,"ERROR:cpl_c:run_sub: sub. jump hit a nonsubaction node!\n");
		goto script_error;
	}
	if ( NR_OF_ATTR(p)!=0 ) {
		LOG(L_ERR,"ERROR:cpl_c:run_sub: inavlid subaction node reached "
		"(attrs=%d); expected (0)!\n",NR_OF_ATTR(p));
		goto script_error;
	}

	return get_first_child(p);
script_error:
	return CPL_SCRIPT_ERROR;
}
示例#18
0
	DomNode DomNode::named_item_ns(
		const DomString &namespace_uri,
		const DomString &local_name) const
	{
		DomNode node = get_first_child();
		while (node.is_null() == false)
		{
			if (node.get_namespace_uri() == namespace_uri && node.get_local_name() == local_name)
				return node;
			node = node.get_next_sibling();
		}
		return DomNode();
	}
示例#19
0
文件: xmlfile.cpp 项目: crazii/mameui
void xml_data_node::file_write(util::core_file &file) const
{
	/* ensure this is a root node */
	if (get_name())
		return;

	/* output a simple header */
	file.printf("<?xml version=\"1.0\"?>\n");
	file.printf("<!-- This file is autogenerated; comments and unknown tags will be stripped -->\n");

	/* loop over children of the root and output */
	for (xml_data_node const *node = get_first_child(); node; node = node->get_next_sibling())
		node->write_recursive(0, file);
}
示例#20
0
/* UPDATED + CHECKED
 */
static inline char *run_remove_location( struct cpl_interpreter *intr )
{
	unsigned short attr_name;
	unsigned short n;
	char *p;
	str url;
	int i;

	url.s = (char*)UNDEF_CHAR;

	/* sanity check */
	if (NR_OF_KIDS(intr->ip)>1) {
		LOG(L_ERR,"ERROR:cpl_c:run_remove_location: REMOVE_LOCATION node "
			"suppose to have max one child, not %d!\n",
			NR_OF_KIDS(intr->ip));
		goto script_error;
	}

	/* dirty hack to speed things up in when loc set is already empty */
	if (intr->loc_set==0)
		goto done;

	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
		get_basic_attr(p,attr_name,n,intr,script_error);
		switch (attr_name) {
			case LOCATION_ATTR:
				url.len = n;
				get_str_attr( p, url.s, url.len, intr, script_error,1);
				break;
			default:
				LOG(L_ERR,"ERROR:run_remove_location: unknown attribute "
					"(%d) in REMOVE_LOCATION node\n",attr_name);
				goto script_error;
		}
	}

	if (url.s==(char*)UNDEF_CHAR) {
		DBG("DEBUG:run_remove_location: remove all locs from loc_set\n");
		empty_location_set( &(intr->loc_set) );
	} else {
		remove_location( &(intr->loc_set), url.s, url.len );
	}
	/* set the flag for modifing the location set */
	intr->flags |= CPL_LOC_SET_MODIFIED;

done:
	return get_first_child(intr->ip);
script_error:
	return CPL_SCRIPT_ERROR;
}
示例#21
0
Node* get_first_child( const NodeParent& p )
{
  switch( p.m_Type )
  {
  case E_NP_NODE:
    return get_first_child( p.m_Node );
    break;
  case E_NP_TREE:
    return p.m_Tree->m_Root;
    break;
  case E_NP_UNKOWN:
  case E_MAX_NODE_PARENT_TYPES:
    break;
  }
  return 0x0;
}
示例#22
0
CL_String CL_DomElement::get_text() const
{
	CL_String str;
	if (has_child_nodes() == false)
		return str;

	CL_DomNode cur = get_first_child();
	while (!cur.is_null())
	{
		if (cur.is_text() || cur.is_cdata_section())
			str.append(cur.get_node_value());
		if (cur.is_element())
			str.append(cur.to_element().get_text());
		cur = cur.get_next_sibling();
	}
	return str;
}
示例#23
0
CL_GUIComponent *CL_GUIComponent::get_next_component_in_tree()
{
	if (has_child_components())
		return get_first_child();

	if (impl->next_sibling)
		return impl->next_sibling;

	CL_GUIComponent *parent = impl->parent;
	while (parent)
	{
		if (parent->get_next_sibling())
			return parent->get_next_sibling();
		parent = parent->get_parent_component();
	}

	// Reached end of tree. Return first item.
	return get_top_level_component();
}
示例#24
0
void unlink_from_parent_and_siblings( Node* n )
{
  switch( n->m_Pare.m_Type )
  {
  case E_NP_NODE:
    if( get_first_child( n->m_Pare.m_Node ) == n )
      set_first_child( n->m_Pare.m_Node, n->m_Next );
    break;
  case E_NP_TREE:
    if( n->m_Pare.m_Tree->m_Root == n )
      n->m_Pare.m_Tree->m_Root = n->m_Next;
    break;
  case E_NP_UNKOWN:
  case E_MAX_NODE_PARENT_TYPES:
    break;
  }
  unlink_from_siblings( n );
  n->m_Pare.m_Type = E_NP_UNKOWN;
  n->m_Pare.m_Node = 0x0;
}
示例#25
0
int ListViewItem::get_child_count(bool recursive, bool recurse_only_into_open_items)
{
	int num_children = 0;
	ListViewItem i = get_first_child();
	while (i.is_item())
	{
		num_children++;
		if (recursive && i.has_children())
		{
			if (recurse_only_into_open_items)
			{
				if (i.is_open())
					num_children += i.get_child_count(recursive, recurse_only_into_open_items);
			}
			else
			{
				num_children += i.get_child_count(recursive, recurse_only_into_open_items);
			}
		}
		i = i.get_next_sibling();
	}

	return num_children;
}
示例#26
0
文件: cpl_run.c 项目: 2pac/kamailio
/* UPDATED + CHECKED
 */
static inline char *run_mail( struct cpl_interpreter *intr )
{
	unsigned short attr_name;
	unsigned short n;
	char  *p;
	str subject = {0,0};
	str body    = {0,0};
	str to      = {0,0};
	int i;

	/* sanity check */
	if (NR_OF_KIDS(intr->ip)>1) {
		LM_ERR("MAIL node suppose to have max one"
			" child, not %d!\n",NR_OF_KIDS(intr->ip));
		goto script_error;
	}

	/* read the attributes of the MAIL node*/
	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
		get_basic_attr(p, attr_name, n, intr, script_error);
		switch (attr_name) {
			case TO_ATTR:
				get_str_attr(p, to.s, n, intr, script_error,0);
				to.len = n;
				break;
			case SUBJECT_ATTR:
				get_str_attr(p, subject.s, n, intr, script_error,0);
				subject.len = n;
				break;
			case BODY_ATTR:
				get_str_attr(p, body.s, n, intr, script_error,0);
				body.len = n;
				break;
			default:
				LM_ERR("unknown attribute (%d) in MAIL node\n",attr_name);
				goto script_error;
		}
	}

	if (to.len==0) {
		LM_ERR("email has an empty TO hdr!\n");
		goto script_error;
	}
	if (body.len==0 && subject.len==0) {
		LM_WARN("I refuse to send email with no "
			"body and no subject -> skipping...\n");
		goto done;
	}

	/* duplicate the attrs in shm memory */
	p = (char*)shm_malloc( to.len + subject.len + body.len );
	if (!p) {
		LM_ERR("no more shm memory!\n");
		goto runtime_error;
	}
	/* copy the TO */
	memcpy( p, to.s, to.len );
	to.s = p;
	p += to.len;
	/* copy the subject */
	if (subject.len) {
		memcpy( p, subject.s, subject.len );
		subject.s = p;
		p += subject.len;
	}
	/* copy the body */
	if (body.len) {
		memcpy( p, body.s, body.len );
		body.s = p;
		p += body.len;
	}

	/* send the command */
	write_cpl_cmd( CPL_MAIL_CMD, &to, &subject, &body);

done:
	return get_first_child(intr->ip);
runtime_error:
	return CPL_RUNTIME_ERROR;
script_error:
	return CPL_SCRIPT_ERROR;
}
示例#27
0
文件: cpl_run.c 项目: 2pac/kamailio
/* UPDATED + CHECKED
 */
static inline char *run_log( struct cpl_interpreter *intr )
{
	char  *p;
	unsigned short attr_name;
	unsigned short n;
	str name    = {0,0};
	str comment = {0,0};
	str user;
	int i;

	/* sanity check */
	if (NR_OF_KIDS(intr->ip)>1) {
		LM_ERR("LOG node suppose to have max one child"
			", not %d!\n",NR_OF_KIDS(intr->ip));
		goto script_error;
	}

	/* is logging enabled? */
	if ( cpl_env.log_dir==0 )
		goto done;

	/* read the attributes of the LOG node*/
	p = ATTR_PTR(intr->ip);
	for( i=NR_OF_ATTR(intr->ip); i>0 ; i-- ) {
		get_basic_attr( p, attr_name, n, intr, script_error);
		switch (attr_name) {
			case NAME_ATTR:
				get_str_attr( p, name.s, n, intr, script_error,1);
				name.len = n;
				break;
			case COMMENT_ATTR:
				get_str_attr( p, comment.s, n, intr, script_error,1);
				comment.len = n;
				break;
			default:
				LM_ERR("unknown attribute "
					"(%d) in LOG node\n",attr_name);
				goto script_error;
		}
	}

	if (comment.len==0) {
		LM_NOTICE("LOG node has no comment attr -> skipping\n");
		goto done;
	}

	user.len = intr->user.len + name.len + comment.len;
	/* duplicate the attrs in shm memory */
	user.s = p = (char*)shm_malloc( user.len );
	if (!user.s) {
		LM_ERR("no more shm memory!\n");
		goto runtime_error;
	}
	/* copy the user name */
	memcpy( p, intr->user.s, intr->user.len);
	user.len = intr->user.len;
	p += intr->user.len;
	/* copy the log name */
	if (name.len) {
		memcpy( p, name.s, name.len );
		name.s = p;
		p += name.len;
	}
	/* copy the comment */
	memcpy( p, comment.s, comment.len);
	comment.s = p;

	/* send the command */
	write_cpl_cmd( CPL_LOG_CMD, &user, &name, &comment );

done:
	return get_first_child(intr->ip);
runtime_error:
	return CPL_RUNTIME_ERROR;
script_error:
	return CPL_SCRIPT_ERROR;
}
示例#28
0
文件: cpl_run.c 项目: 2pac/kamailio
/* UPDATED + CHECKED
 */
static inline char *run_location( struct cpl_interpreter *intr )
{
	unsigned short attr_name;
	unsigned short n;
	char  *p;
	unsigned char  prio;
	unsigned char  clear;
	str url;
	int i;

	clear = NO_VAL;
	prio = 10;
	url.s = (char*)UNDEF_CHAR;
	url.len = 0;

	/* sanity check */
	if (NR_OF_KIDS(intr->ip)>1) {
		LM_ERR("LOCATION node suppose to have max "
			"one child, not %d!\n",NR_OF_KIDS(intr->ip));
		goto script_error;
	}

	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
		get_basic_attr(p,attr_name,n,intr,script_error);
		switch (attr_name) {
			case URL_ATTR:
				url.len = n;
				get_str_attr( p, url.s, url.len, intr, script_error,1);
				break;
			case PRIORITY_ATTR:
				if ( n>10)
					LM_WARN("invalid value (%u) found"
						" for param. PRIORITY in LOCATION node -> using "
						"default (%u)!\n",n,prio);
				else
					prio = n;
				break;
			case CLEAR_ATTR:
				if (n!=YES_VAL && n!=NO_VAL)
					LM_WARN("invalid value (%u) found"
						" for param. CLEAR in LOCATION node -> using "
						"default (%u)!\n",n,clear);
				else
					clear = n;
				break;
			default:
				LM_ERR("unknown attribute (%d) in "
					"LOCATION node\n",attr_name);
				goto script_error;
		}
	}

	if (url.s==(char*)UNDEF_CHAR) {
		LM_ERR("param. URL missing in LOCATION node\n");
		goto script_error;
	}

	if (clear)
		empty_location_set( &(intr->loc_set) );
	if (add_location( &(intr->loc_set), &url, 0, prio, 0/*no dup*/ )==-1) {
		LM_ERR("unable to add location to set :-(\n");
		goto runtime_error;
	}
	/* set the flag for modifying the location set */
	intr->flags |= CPL_LOC_SET_MODIFIED;

	return get_first_child(intr->ip);
runtime_error:
	return CPL_RUNTIME_ERROR;
script_error:
	return CPL_SCRIPT_ERROR;
}
示例#29
0
文件: cpl_run.c 项目: 2pac/kamailio
/* UPDATED + CHECKED
 */
static inline char *run_lookup( struct cpl_interpreter *intr )
{
	unsigned short attr_name;
	unsigned short n;
	unsigned char  clear;
	char *p;
	char *kid;
	char *failure_kid = 0;
	char *success_kid = 0;
	char *notfound_kid = 0;
	int  i;
	time_t      tc;
	urecord_t*  r;
	ucontact_t* contact;

	clear = NO_VAL;

	/* check the params */
	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
		get_basic_attr(p,attr_name,n,intr,script_error);
		switch (attr_name) {
			case CLEAR_ATTR:
				if (n!=YES_VAL && n!=NO_VAL)
					LM_WARN("invalid value (%u) found"
						" for param. CLEAR in LOOKUP node -> using "
						"default (%u)!\n",n,clear);
				else
					clear = n;
				break;
			default:
				LM_ERR("unknown attribute (%d) in LOOKUP node\n",attr_name);
				goto script_error;
		}
	}

	/* check the kids */
	for( i=0 ; i<NR_OF_KIDS(intr->ip) ; i++ ) {
		kid = intr->ip + KID_OFFSET(intr->ip,i);
		check_overflow_by_ptr( kid+SIMPLE_NODE_SIZE(kid), intr, script_error);
		switch ( NODE_TYPE(kid) ) {
			case SUCCESS_NODE :
				success_kid = kid;
				break;
			case NOTFOUND_NODE:
				notfound_kid = kid;
				break;
			case FAILURE_NODE:
				failure_kid = kid;
				break;
			default:
				LM_ERR("unknown output node type"
					" (%d) for LOOKUP node\n",NODE_TYPE(kid));
				goto script_error;
		}
	}

	kid = failure_kid;

	if (cpl_env.lu_domain) {
		/* fetch user's contacts via usrloc */
		tc = time(0);
		cpl_fct.ulb.lock_udomain( cpl_env.lu_domain, &intr->user );
		i = cpl_fct.ulb.get_urecord( cpl_env.lu_domain, &intr->user, &r);
		if (i < 0) {
			/* failure */
			LM_ERR("failed to query usrloc\n");
			cpl_fct.ulb.unlock_udomain( cpl_env.lu_domain, &intr->user );
		} else if (i > 0) {
			/* not found */
			LM_DBG("'%.*s' Not found in usrloc\n",
				intr->user.len, intr->user.s);
			cpl_fct.ulb.unlock_udomain( cpl_env.lu_domain, &intr->user );
			kid = notfound_kid;
		} else {
			contact = r->contacts;
			/* skip expired contacts */
			while ((contact) && (contact->expires <= tc))
				contact = contact->next;
			/* any contacts left? */
			if (contact) {
				/* clear loc set if requested */
				if (clear)
					empty_location_set( &(intr->loc_set) );
				/* start adding locations to set */
				do {
					LM_DBG("adding <%.*s>q=%d\n",
						contact->c.len,contact->c.s,(int)(10*contact->q));
					if (add_location( &(intr->loc_set), &contact->c, 
					&contact->received, (int)(10*contact->q),
					CPL_LOC_DUPL|
						((contact->cflags&cpl_fct.ulb.nat_flag)?CPL_LOC_NATED:0)
					)==-1) {
						LM_ERR("unable to add location to set :-(\n");
						cpl_fct.ulb.unlock_udomain( cpl_env.lu_domain, &intr->user );
						goto runtime_error;
					}
					contact = contact->next;
				}while( contact && cpl_env.lu_append_branches);
				/* set the flag for modifying the location set */
				intr->flags |= CPL_LOC_SET_MODIFIED;
				/* we found a valid contact */
				kid = success_kid;
			} else {
				/* no valid contact found */
				kid = notfound_kid;
			}
			cpl_fct.ulb.unlock_udomain( cpl_env.lu_domain, &intr->user );
		}

	}

	if (kid)
		return get_first_child(kid);
	return DEFAULT_ACTION;
runtime_error:
	return CPL_RUNTIME_ERROR;
script_error:
	return CPL_SCRIPT_ERROR;
}
示例#30
0
clan::DomElement GridObject::to_element(clan::DomDocument &doc)
{
	clan::GUIComponent *comp = get_first_child();

	std::string type = comp->get_tag_name();

	clan::DomElement e = doc.create_element(comp->get_tag_name());
	std::string comp_class;
	comp->get_class(comp_class);

	e.set_attribute("class", comp_class);
	e.set_attribute("id", comp->get_id());
	e.set_attribute_bool("enabled", comp->is_enabled());

	if (!pos_equation_x.empty())
		e.set_attribute("eq-x", pos_equation_x);
	if (!pos_equation_y.empty())
		e.set_attribute("eq-y", pos_equation_y);
	if (!pos_equation_x2.empty())
		e.set_attribute("eq-x2", pos_equation_x2);
	if (!pos_equation_y2.empty())
		e.set_attribute("eq-y2", pos_equation_y2);

	if (type == "button")
	{
		clan::PushButton *co = dynamic_cast<clan::PushButton*>(comp);
		e.set_attribute("text", co->get_text());
	}
	else if (comp->get_tag_name() == "checkbox")
	{
		clan::CheckBox *co = dynamic_cast<clan::CheckBox*>(comp);
		e.set_attribute("text", co->get_text());
	}
	else if (comp->get_tag_name() == "radiobutton")
	{
		clan::RadioButton *co = dynamic_cast<clan::RadioButton*>(comp);
		e.set_attribute("text", co->get_text());
		e.set_attribute("group", co->get_group_name());
	}
	else if (comp->get_tag_name() == "label")
	{
		clan::Label *co = dynamic_cast<clan::Label*>(comp);
		e.set_attribute("text", co->get_text());
	}
	else if (comp->get_tag_name() == "lineedit")
	{
		clan::LineEdit *co = dynamic_cast<clan::LineEdit*>(comp);
		e.set_attribute("text", co->get_text());
	}
	else if (comp->get_tag_name() == "textedit")
	{
		clan::TextEdit *co = dynamic_cast<clan::TextEdit*>(comp);
		e.set_attribute("text", co->get_text());
	}
	else if (comp->get_tag_name() == "menubar")
	{
		// clan::MenuBar *co = dynamic_cast<clan::MenuBar*>(comp);
	}
	else if (comp->get_tag_name() == "statusbar")
	{
		// clan::StatusBar *co = dynamic_cast<clan::StatusBar*>(comp);
	}
	else if (comp->get_tag_name() == "toolbar")
	{
		// clan::ToolBar *co = dynamic_cast<clan::ToolBar*>(comp);
	}
	else if (comp->get_tag_name() == "imageview")
	{
		// clan::ImageView *co = dynamic_cast<clan::ImageView*>(comp);
	}
	else if (comp->get_tag_name() == "listview")
	{
		clan::ListView *co = dynamic_cast<clan::ListView*>(comp);
		save_listview(e, co);
	}
	else if (comp->get_tag_name() == "slider")
	{
		clan::Slider *co = dynamic_cast<clan::Slider*>(comp);
		e.set_attribute("min", clan::StringHelp::int_to_text(co->get_min()));
		e.set_attribute("max", clan::StringHelp::int_to_text(co->get_max()));
		e.set_attribute("ticks", clan::StringHelp::int_to_text(co->get_tick_count()));
		e.set_attribute("page_step", clan::StringHelp::int_to_text(co->get_page_step()));
	}
	else if (comp->get_tag_name() == "tab")
	{
		clan::Tab *co = dynamic_cast<clan::Tab*>(comp);

		clan::GUIComponent *child = co->get_first_child();
		while (child != 0)
		{
			if (child->get_tag_name() == "tabpage")
			{
				clan::TabPage *tab_page = dynamic_cast<clan::TabPage*>(child);
				clan::DomElement tabpage_element = doc.create_element("tabpage");
				tabpage_element.set_attribute("label", tab_page->get_label());

				clan::GUIComponent *tabpage_child = child->get_first_child();
				while (tabpage_child != 0)
				{
					if (tabpage_child->get_tag_name() == "object")
					{
						GridObject *object_comp = dynamic_cast<GridObject*>(tabpage_child);
						clan::DomElement tabpage_child_element = object_comp->to_element(doc);
						tabpage_element.append_child(tabpage_child_element);
					}

					tabpage_child = tabpage_child->get_next_sibling();
				}

				e.append_child(tabpage_element);
			}

			child = child->get_next_sibling();
		}
		
	}
	else if (comp->get_tag_name() == "frame")
	{
		clan::Frame *co = dynamic_cast<clan::Frame*>(comp);
		e.set_attribute("text", co->get_header_text());

		clan::GUIComponent *child = co->get_first_child();
		while (child != 0)
		{
			if (child->get_tag_name() == "object")
			{
				GridObject *object_comp = dynamic_cast<GridObject*>(child);
				clan::DomElement frame_child_element = object_comp->to_element(doc);
				e.append_child(frame_child_element);
			}

			child = child->get_next_sibling();
		}

	}
	else if (comp->get_tag_name() == "spin")
	{
		// clan::Spin *co = dynamic_cast<clan::Spin*>(comp);
	}
	else if (comp->get_tag_name() == "combobox")
	{
		// clan::ComboBox *co = dynamic_cast<clan::ComboBox*>(comp);
	}
	else // custom component
	{
		// CustomComponent *co = dynamic_cast<CustomComponent*>(comp);
	}

	save_anchors(e,comp);
	save_geometry(e,comp); // write geom="..." attribute

	return e;
}