FACT++  1.0
int prepareJSONTree ( char *  node,
BROWSER browserp 
)

Definition at line 1493 of file webDid.c.

References addJSONChildEnd(), addJSONChildStart(), addJSONEnd(), addJSONNodeEnd(), addJSONNodeStart(), addJSONStart(), item::busy, find_node(), find_service_pattern(), Memory::free(), getNodeLabel(), bitem::JSONBuffer, JSONBuffer, bitem::JSONBufferSize, JSONBufferSize, Memory::malloc(), item::match, bitem::n_nodes, N_nodes, bitem::n_servers, N_servers, bitem::n_services, item::name, Node_head, bitem::pattern, DNS_SERVER_INFO::pid, item::server, sll_get_next(), sprintf(), str, Title, and WebDID_Debug.

Referenced by find_services(), getJSONBuffer(), prepare_browser_tree(), and update_servers().

1494 {
1495  char *ptr;
1496  NODE *nodep;
1497  SERVER *servp;
1498  char str[256], aux[128];
1499  int selective = 0;
1500  int n_nodes, tot_n_nodes;
1501  int n_servers, tot_n_servers;
1502  int ret, n_found = 0;
1503 
1504  if(browserp)
1505  {
1506  if(browserp->pattern[0] != '\0')
1507  selective = 1;
1508  else
1509  return(0);
1510  }
1511  if(!selective)
1512  {
1513  if(JSONBufferSize == 0)
1514  {
1515  JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
1516  }
1517  else if (JSONBufferSize < N_nodes*128+N_servers*128)
1518  {
1519  free(JSONBuffer);
1520  JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
1521  }
1522  ptr = JSONBuffer;
1523  }
1524  else
1525  {
1526  if(browserp->JSONBufferSize == 0)
1527  {
1528  browserp->JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
1529  }
1530  else if (browserp->JSONBufferSize < N_nodes*128+N_servers*128)
1531  {
1532  free(browserp->JSONBuffer);
1533  browserp->JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
1534  }
1535  ptr = browserp->JSONBuffer;
1536  }
1537  *ptr = '\0';
1538  if(!strcmp(node, "src"))
1539  {
1540  ptr = addJSONStart(ptr);
1541  ptr = addJSONNodeStart(ptr,"children");
1542  sprintf(str,"text: \"%s\", id: \"Nodes\", expanded: false", Title);
1543  ptr = addJSONChildStart(ptr,str,1);
1544  ptr = addJSONNodeStart(ptr,"children");
1545  nodep = Node_head;
1546  tot_n_nodes = 0;
1547  while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
1548  {
1549  nodep->match = 1;
1550  if(selective)
1551  {
1552  if(!(ret = find_service_pattern(nodep, 0, browserp->pattern, &tot_n_servers)))
1553  {
1554  nodep->match = 0;
1555  continue;
1556  }
1557  else
1558  {
1559  n_found += ret;
1560  }
1561  }
1562  tot_n_nodes++;
1563  }
1564  n_nodes = 0;
1565  nodep = Node_head;
1566  while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
1567  {
1568  if(!nodep->match)
1569  continue;
1570  getNodeLabel(nodep->name, aux);
1571  sprintf(str,"text: \"%s\", id: \"%s\", qtip: \"%s\"",
1572  aux, nodep->name, nodep->name);
1573  ptr = addJSONChildStart(ptr,str,0);
1574  n_nodes++;
1575 if(WebDID_Debug)
1576  printf("adding %s %d %d\n",nodep->name, n_nodes, tot_n_nodes);
1577  if(n_nodes < tot_n_nodes)
1578  ptr = addJSONChildEnd(ptr,1);
1579  else
1580  ptr = addJSONChildEnd(ptr,0);
1581  }
1582  ptr = addJSONNodeEnd(ptr);
1583  ptr = addJSONChildEnd(ptr,0);
1584  ptr = addJSONNodeEnd(ptr);
1585  ptr = addJSONEnd(ptr);
1586  if(selective)
1587  {
1588  browserp->n_services = n_found;
1589  browserp->n_servers = tot_n_servers;
1590  browserp->n_nodes = tot_n_nodes;
1591  }
1592  }
1593  else
1594  {
1595  if((nodep = find_node(node)))
1596  {
1597  ptr = addJSONStart(ptr);
1598  ptr = addJSONNodeStart(ptr,"children");
1599  servp = nodep->server_head;
1600  tot_n_servers = 0;
1601  while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
1602  {
1603  servp->match = 1;
1604  if(servp->busy != 1)
1605  {
1606  servp->match = 0;
1607  continue;
1608  }
1609  if(selective)
1610  {
1611  if(!(ret = find_service_pattern(nodep, servp, browserp->pattern, 0)))
1612  {
1613  servp->match = 0;
1614  continue;
1615  }
1616  else
1617  {
1618  n_found += ret;
1619  }
1620  }
1621  tot_n_servers++;
1622  }
1623  n_servers = 0;
1624  servp = nodep->server_head;
1625  while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
1626  {
1627  if(!servp->match)
1628  continue;
1629  sprintf(str,"text: \"%s\", id: \"%d\", leaf: true, icon: \"server.png\"",servp->name, servp->server.pid);
1630  ptr = addJSONChildStart(ptr,str,0);
1631  n_servers++;
1632  if(n_servers < tot_n_servers)
1633  ptr = addJSONChildEnd(ptr,1);
1634  else
1635  ptr = addJSONChildEnd(ptr,0);
1636  }
1637  ptr = addJSONNodeEnd(ptr);
1638  ptr = addJSONEnd(ptr);
1639  }
1640  }
1641  /*
1642 if(!selective)
1643 printf(" Nodes&Servers %s\n",JSONBuffer);
1644 else
1645 printf(" Nodes&Servers %s\n",browserp->JSONBuffer);
1646  */
1647  return(1);
1648 }
NODE * Node_head
Definition: webDid.c:28
char * addJSONNodeEnd(char *ptr)
Definition: webDid.c:1380
Definition: dns.c:26
char * JSONBuffer
Definition: webDid.c:90
int N_servers
Definition: webDid.c:105
int n_services
Definition: webDid.c:70
char Title[128]
Definition: webDid.c:120
int busy
Definition: did.h:52
int WebDID_Debug
Definition: webServer.c:7
Definition: did.h:42
char str[80]
Definition: test_client.c:7
void * malloc()
Definition: EventBuilder.cc:99
int JSONBufferSize
Definition: webDid.c:91
char * addJSONChildEnd(char *ptr, int sep)
Definition: webDid.c:1401
int getNodeLabel(char *name, char *label)
Definition: webDid.c:1475
char * JSONBuffer
Definition: webDid.c:74
char name[132]
Definition: did.h:46
SLL * sll_get_next(SLL *item)
Definition: sll.c:50
char * addJSONChildStart(char *ptr, char *child, int sep)
Definition: webDid.c:1389
Definition: dim.h:536
int n_servers
Definition: webDid.c:71
char * addJSONEnd(char *ptr)
Definition: webDid.c:1362
char * addJSONNodeStart(char *ptr, char *node)
Definition: webDid.c:1371
DNS_SERVER_INFO server
Definition: did.h:44
int find_service_pattern(NODE *nodep, SERVER *servpp, char *pattern, int *n_servers)
Definition: webDid.c:208
void free(void *mem)
char * addJSONStart(char *ptr)
Definition: webDid.c:1353
int n_nodes
Definition: webDid.c:72
int JSONBufferSize
Definition: webDid.c:75
NODE * find_node(char *node)
Definition: webDid.c:174
int N_nodes
Definition: webDid.c:104
sprintf(name1,"NewService%d", i)
int match
Definition: webDid.c:15
char pattern[256]
Definition: webDid.c:78

+ Here is the call graph for this function:

+ Here is the caller graph for this function: