Esempio n. 1
0
void pre_pathfinding(char i[], char j[], nodes ptr)
{
 if(ptr==NULL)
 {
  printf("Podane węzły muszą istnieć!\n");
  return;
 }
 if(node_by_id(ptr,i)==NULL||node_by_id(ptr,j)==NULL)
 {
  printf("Podane węzły muszą istnieć!\n");
  return;
 }
 steps tabl=NULL;
 steps final=NULL;
 pathfinding(i,j,&tabl,&final,ptr);
 steps temp=final;
 if(temp==NULL)
 {
  printf("Brak połączenia!\n");
  return;
 }
 printf("%s", temp->id);
 temp=temp->next;
 while(temp != NULL)
 {
  printf("->%s", temp->id);
  temp=temp->next;
 }
 printf("\n");
 while(final!=NULL)
 {
  temp=final;
  final=final->next;
  free(temp);
 }
Esempio n. 2
0
/**
 * Free routine for the extended message blocks we send to the UDP layer.
 */
static void
g2_qh2_pmsg_free(pmsg_t *mb, void *arg)
{
	struct g2_qh2_pmsg_info *pmi = arg;
	gnutella_node_t *n;

	g2_qh2_pmsg_info_check(pmi);
	g_assert(pmsg_is_extended(mb));

	if (pmsg_was_sent(mb))
		goto done;

	/*
	 * Message was unsent, probably because the UDP address in the /Q2 was
	 * wrong for some reason.
	 *
	 * If we're still connected to the hub which passed us this /Q2, then
	 * we can relay back the /QH2 to the hub and it will hopefully be able
	 * to deliver it back to the querying node.
	 */

	n = node_by_id(pmi->hub_id);

	if (NULL == n) {
		if (GNET_PROPERTY(g2_debug) > 1) {
			g_debug("%s(): could not send %s, relaying hub is gone, dropping.",
				G_STRFUNC, g2_msg_infostr_mb(mb));
		}
		gnet_stats_inc_general(GNR_UDP_G2_HITS_UNDELIVERED);
		goto done;
	} else {
		pmsg_t *nmb;

		if (GNET_PROPERTY(g2_debug) > 1) {
			g_debug("%s(): could not send %s, giving back to %s for relaying",
				G_STRFUNC, g2_msg_infostr_mb(mb), node_infostr(n));
		}

		nmb = pmsg_clone_plain(mb);
		pmsg_clear_reliable(nmb);

		g2_node_send(n, nmb);
		gnet_stats_inc_general(GNR_UDP_G2_HITS_REROUTED_TO_HUB);
	}

done:
	nid_unref(pmi->hub_id);
	pmi->magic = 0;
	WFREE(pmi);
}
char* get_group_components(char* id, xmlXPathContextPtr &xpathCtx){
	xpathCtx->node = node_by_id(id, "entry", xpathCtx);
	xmlNodeSetPtr comp = xmlXPathEvalExpression( (const xmlChar *) "./component", xpathCtx ) ->nodesetval;
	int numOfcomp = (comp) ? comp->nodeNr : 0;

	string group = "";
	for (int a = 0;a < numOfcomp;a++){
		xmlNodePtr sub_node = comp->nodeTab[a];
		char* comp_id = get_attr(sub_node, "id");
		char* comp_name = comp_id ? attr_by_id(comp_id, "name", xpathCtx) : NULL;

		if(comp_name){
			if(a != 0)
				group = group + ((string)" ");

			group = group + ((string) comp_name);
		}


	}
	return(strdup(group.c_str()));
}
Esempio n. 4
0
//funkcja dodająca węzły
void insert_node(nodes *ptr, char i[])
{
 nodes nowy;
 if(*ptr != NULL)
 {
  if(node_by_id(*ptr,i)!=NULL)
  {
   printf("Węzeł o podanym id już istnieje!\n");
   return;
  }
 }
 if((nowy=(nodes)malloc(sizeof(struct Node)))==NULL)
 {
  printf("Brak wolnej pamięci\n");
  return;
 }
  strcpy(nowy->id,i);
 nowy->next=*ptr;
 nowy->outEdges=NULL;
 nowy->inEdges=NULL;
 *ptr= nowy;
 printf("Węzeł %s dodany!\n", i);
}
char* attr_by_id(char* id, const char* attr_name,xmlXPathContextPtr &xpathCtx){
	if(!id) return( NULL );

	xmlNodePtr node = node_by_id(id, "entry", xpathCtx);
	return( node? get_attr(node, attr_name) : NULL );
}