Пример #1
0
/* Parse one line of text */
void parse (char string[]) {
  struct node *list_ptr /*, *node_ptr */;
  static int vartype = NOP, state = NOP;
  char *ptr = string, *title_ptr, *temp;

  if (((string[0] == ' ') && (strlen(string) > 6)) ||
      ((string[0] == '\t') && (strlen(string) > 2))) {
    /* The current line is not a comment */
    if (string[0] == '\t') ptr++;
    else ptr += 5;
    if ((isspace (*ptr)) || ((state != COMMON_CONTINUE) && (state != REGISTER_CONTINUE))) {
      ptr = skip_blanks (ptr);
      vartype = determine_type (ptr);
      state = vartype;
      if (strncmp_i("double precision", ptr, 16) == 0)
	ptr = skip_blanks (skip_nonblanks (ptr));
    }
    if ((vartype != NOP) && (vartype != PARAMETER) && (vartype != EQUIV)) {
      /* The current line is a list of variables */
      if (state == COMMON_CONTINUE) {
	/* The current line is the continuation of a common block */
	list_ptr = common_start;
	ptr++;
      }
      else if (state == COMMON) {
	/* The current line is a common block */
	list_ptr = common_start;
	ptr = find_char (find_char (ptr, '/'), '/');
	state = COMMON_CONTINUE;
      }
      else if (state == REGISTER_CONTINUE) {
	/* The current line is the continuation of a register statement */
	list_ptr = register_start;
	ptr++;
      }
      else {
	/* The current line contains variables to be registered */
	list_ptr = register_start;
	ptr = skip_nonblanks (ptr);
	state = REGISTER_CONTINUE;
      }
      ptr = skip_blanks (ptr);

      /* Obtain the title string */
      title_ptr = string;
      if (find_char (ptr, ',') > find_char (ptr, '!')) {
	while (*title_ptr != '!') title_ptr++;
	title_ptr = skip_blanks (title_ptr+1);
	if (*title_ptr == '\0') title_ptr = NULL;
      }
      else title_ptr = NULL;
      /* Convert ' to '' in title string */
      if (title_ptr != NULL) {
	temp = title_ptr;
	while (*temp != '\0') {
	  if (*temp == '\'') shift_left (temp++);
	  temp++;
	}
      }

      /* Add each variable to the linked list */
      while ((ptr < find_char (string, '!')) && (*ptr != '!')) {
	if ((find_char (ptr, '(') < find_char (ptr, ',')) &&
	    (find_char (ptr, '(') < find_char (ptr, '!'))) {
	  /* The variable is an array */
	  create (list_ptr, vartype, ptr, title_ptr);
	  if (vartype >= 0) array_flags[current_calltype][vartype] = 1;
	  ptr = skip_blanks (find_char (find_char (ptr, ')'), ','));
	}
	else {
	  /* The variable is not an array */
	  create (list_ptr, vartype, ptr, title_ptr);
	  if (vartype >=0) variable_flags[current_calltype][vartype] = 1;
	  ptr = skip_blanks (find_char (ptr, ','));
	}
      }
    }
    if (vartype == PARAMETER)
      /* If the line is a parameter statement, then ignore the variable */
      mark_node (register_start, skip_blanks(find_char (ptr, '(')), IGNORE);
    if (vartype == EQUIV) {
      /* If the line is an equivalence statement, then skip the variables */
      ptr = skip_blanks (find_char (ptr, '('));
      mark_node (register_start, ptr, SKIP);
      if (find_char(ptr,'(') < find_char(ptr,',')) ptr = find_char(ptr,')');
      ptr = skip_blanks (find_char (ptr, ','));
      mark_node (register_start, ptr, SKIP);
    }
  }
}
	void QPBO<REAL>::TransformToSecondStage(bool copy_trees)
{
	// add non-submodular edges
	Node* i[2];
	Node* j[2];
	Arc* a[2];

	memset(nodes[1], 0, node_num*sizeof(Node));
	node_last[1] = nodes[1] + node_num;

	if (!copy_trees)
	{
		for (i[0]=nodes[0], i[1]=nodes[1]; i[0]<node_last[0]; i[0]++, i[1]++)
		{
			i[1]->first = NULL;
			i[1]->tr_cap = -i[0]->tr_cap;
		}

		for (a[0]=arcs[0], a[1]=arcs[1]; a[0]<arc_max[0]; a[0]+=2, a[1]+=2)
		{
			if (!a[0]->sister) continue;

			code_assert(IsNode0(a[0]->sister->head));
			SET_SISTERS(a[1], a[1]+1);
			if (IsNode0(a[0]->head))
			{
				i[1] = GetMate0(a[0]->sister->head);
				j[1] = GetMate0(a[0]->head);

				SET_FROM(a[1],         j[1]);
				SET_FROM(a[1]->sister, i[1]);
				SET_TO(a[1],         i[1]);
				SET_TO(a[1]->sister, j[1]);
			}
			else
			{
				i[0] = a[0]->sister->head;
				i[1] = GetMate0(i[0]);
				j[1] = a[0]->head;
				j[0] = GetMate1(j[1]);

				SET_FROM(a[0],         i[0]);
				SET_FROM(a[0]->sister, j[1]);
				SET_FROM(a[1],         j[0]);
				SET_FROM(a[1]->sister, i[1]);
				SET_TO(a[1],         i[1]);
				SET_TO(a[1]->sister, j[0]);
			}
			a[1]->r_cap = a[0]->r_cap;
			a[1]->sister->r_cap = a[0]->sister->r_cap;
		}
	}
	else
	{
		for (i[0]=nodes[0], i[1]=nodes[1]; i[0]<node_last[0]; i[0]++, i[1]++)
		{
			i[1]->first = NULL;
			i[1]->tr_cap = -i[0]->tr_cap;
			i[1]->is_sink = i[0]->is_sink ^ 1;
			i[1]->DIST = i[0]->DIST;
			i[1]->TS = i[0]->TS;

			if (i[0]->parent == NULL || i[0]->parent == QPBO_MAXFLOW_TERMINAL) i[1]->parent = i[0]->parent;
			else i[1]->parent = GetMate0(i[0]->parent->sister);
		}

		for (a[0]=arcs[0], a[1]=arcs[1]; a[0]<arc_max[0]; a[0]+=2, a[1]+=2)
		{
			if (!a[0]->sister) continue;

			code_assert(IsNode0(a[0]->sister->head));
			SET_SISTERS(a[1], a[1]+1);
			if (IsNode0(a[0]->head))
			{
				i[1] = GetMate0(a[0]->sister->head);
				j[1] = GetMate0(a[0]->head);

				SET_FROM(a[1],         j[1]);
				SET_FROM(a[1]->sister, i[1]);
				SET_TO(a[1],         i[1]);
				SET_TO(a[1]->sister, j[1]);
			}
			else
			{
				i[0] = a[0]->sister->head;
				i[1] = GetMate0(i[0]);
				j[1] = a[0]->head;
				j[0] = GetMate1(j[1]);

				SET_FROM(a[0],         i[0]);
				SET_FROM(a[0]->sister, j[1]);
				SET_FROM(a[1],         j[0]);
				SET_FROM(a[1]->sister, i[1]);
				SET_TO(a[1],         i[1]);
				SET_TO(a[1]->sister, j[0]);

				mark_node(i[0]);
				mark_node(i[1]);
				mark_node(j[0]);
				mark_node(j[1]);
			}
			a[1]->r_cap = a[0]->r_cap;
			a[1]->sister->r_cap = a[0]->sister->r_cap;
		}
	}

	stage = 1;
}
Пример #3
0
int pike_check_req(struct sip_msg *msg)
{
	struct ip_node *node;
	struct ip_node *father;
	unsigned char flags;
	struct ip_addr* ip;


#ifdef _test
	/* get the ip address from second via */
	if (parse_headers(msg, HDR_VIA1_F, 0)!=0 )
		return -1;
	if (msg->via1==0 )
		return -1;
	/* convert from string to ip_addr */
	ip = str2ip( &msg->via1->host );
	if (ip==0)
		return -1;
#else
	ip = &(msg->rcv.src_ip);
#endif


	/* first lock the proper tree branch and mark the IP with one more hit*/
	lock_tree_branch( ip->u.addr[0] );
	node = mark_node( ip->u.addr, ip->len, &father, &flags);
	if (node==0) {
		unlock_tree_branch( ip->u.addr[0] );
		/* even if this is an error case, we return true in script to avoid
		 * considering the IP as marked (bogdan) */
		return 1;
	}

	LM_DBG("src IP [%s],node=%p; hits=[%d,%d],[%d,%d] node_flags=%d"
		" func_flags=%d\n", ip_addr2a( ip ), node,
		node->hits[PREV_POS],node->hits[CURR_POS],
		node->leaf_hits[PREV_POS],node->leaf_hits[CURR_POS],
		node->flags, flags);

	/* update the timer */
	lock_get(timer_lock);
	if ( flags&NEW_NODE ) {
		/* put this node into the timer list and remove its
		   father only if this has one kid and is not a LEAF_NODE*/
		node->expires =  get_ticks() + timeout;
		append_to_timer( timer, &(node->timer_ll) );
		node->flags |= NODE_INTIMER_FLAG;
		if (father) {
			LM_DBG("father %p: flags=%d kids->next=%p\n",
				father,father->flags,father->kids->next);
			if (!(father->flags&NODE_IPLEAF_FLAG) && !father->kids->next){
				/* debug */
				assert( has_timer_set(&(father->timer_ll))
					&& (father->flags&(NODE_EXPIRED_FLAG|NODE_INTIMER_FLAG)) );
				/* if the node is maked as expired by timer, let the timer
				 * to finish and remove the node */
				if ( !(father->flags&NODE_EXPIRED_FLAG) ) {
					remove_from_timer( timer, &(father->timer_ll) );
					father->flags &= ~NODE_INTIMER_FLAG;
				} else {
					father->flags &= ~NODE_EXPIRED_FLAG;
				}
			}
		}
	} else {
		/* update the timer -> in timer can be only nodes
		 * as IP-leaf(complete address) or tree-leaf */
		if (node->flags&NODE_IPLEAF_FLAG || node->kids==0) {
			/* tree leafs which are not potential red nodes are not update in
			 * order to make them to expire */
			/* debug */
			assert( has_timer_set(&(node->timer_ll))
				&& (node->flags&(NODE_EXPIRED_FLAG|NODE_INTIMER_FLAG)) );
			/* if node exprired, ignore the current hit and let is
			 * expire in timer process */
			if ( !(flags&NO_UPDATE) && !(node->flags&NODE_EXPIRED_FLAG) ) {
				node->expires = get_ticks() + timeout;
				update_in_timer( timer, &(node->timer_ll) );
			}
		} else {
			/* debug */
			assert( !has_timer_set(&(node->timer_ll))
				&& !(node->flags&(NODE_INTIMER_FLAG|NODE_EXPIRED_FLAG)) );
			/* debug */
			assert( !(node->flags&NODE_IPLEAF_FLAG) && node->kids );
		}
	}
	/*print_timer_list( timer );*/ /* debug*/
	lock_release(timer_lock);

	unlock_tree_branch( ip->u.addr[0] );
	/*print_tree( 0 );*/ /* debug */

	if (flags&RED_NODE) {
		if (flags&NEWRED_NODE) {
			LM_GEN1( pike_log_level,
				"PIKE - BLOCKing ip %s, node=%p\n",ip_addr2a(ip),node);
			pike_raise_event(ip_addr2a(ip));
			return -2;
		}
		return -1;
	}
	return 1;
}
Пример #4
0
void mark_nodes(Sig_tree * tree) {
	for(int i = tree->sig_cnt-1; i>=0; i--) {
		mark_node(tree, i);
	}
}