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

Definition at line 1650 of file webDid.c.

References addJSONChildEnd(), addJSONChildStart(), addJSONEnd(), addJSONNodeEnd(), addJSONNodeStart(), addJSONStart(), item::busy, find_node(), find_service_pattern(), Memory::free(), getNodeLabel(), bitem::JSONSmiBuffer, JSONSmiBuffer, bitem::JSONSmiBufferSize, JSONSmiBufferSize, 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 getJSONSmiBuffer().

1651 {
1652  char *ptr;
1653  NODE *nodep;
1654  SERVER *servp;
1655  char str[256], aux[128];
1656  int selective = 0;
1657  int n_nodes, tot_n_nodes;
1658  int n_servers, tot_n_servers;
1659  int ret, n_found = 0;
1660  char pattern[256] = {'\0'};
1661  char *sptr;
1662 
1663  if(browserp)
1664  {
1665  if(browserp->pattern[0] != '\0')
1666  {
1667  selective = 1;
1668  strcpy(pattern, browserp->pattern);
1669  }
1670 // else
1671 // return(0);
1672  }
1673 // selective = 1;
1674 // strcpy(pattern,"SMI/*");
1675  if(!selective)
1676  {
1677  if(JSONSmiBufferSize == 0)
1678  {
1679  JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
1680  }
1681  else if (JSONSmiBufferSize < N_nodes*128+N_servers*128)
1682  {
1684  JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
1685  }
1686  ptr = JSONSmiBuffer;
1687  }
1688  else
1689  {
1690  if(browserp->JSONSmiBufferSize == 0)
1691  {
1692  browserp->JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
1693  }
1694  else if (browserp->JSONSmiBufferSize < N_nodes*128+N_servers*128)
1695  {
1696  free(browserp->JSONSmiBuffer);
1697  browserp->JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
1698  }
1699  ptr = browserp->JSONSmiBuffer;
1700  }
1701  *ptr = '\0';
1702  if(!strcmp(node, "src"))
1703  {
1704  ptr = addJSONStart(ptr);
1705  ptr = addJSONNodeStart(ptr,"children");
1706  sprintf(str,"text: \"%s\", id: \"Nodes\", expanded: false", Title);
1707  ptr = addJSONChildStart(ptr,str,1);
1708  ptr = addJSONNodeStart(ptr,"children");
1709  nodep = Node_head;
1710  tot_n_nodes = 0;
1711  while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
1712  {
1713  nodep->match = 1;
1714  if(selective)
1715  {
1716  if(!(ret = find_service_pattern(nodep, 0, pattern, &tot_n_servers)))
1717  {
1718  nodep->match = 0;
1719  continue;
1720  }
1721  else
1722  {
1723  n_found += ret;
1724  }
1725  }
1726  tot_n_nodes++;
1727  }
1728  n_nodes = 0;
1729  nodep = Node_head;
1730  while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
1731  {
1732  if(!nodep->match)
1733  continue;
1734  getNodeLabel(nodep->name, aux);
1735  sprintf(str,"text: \"%s\", id: \"%s\", qtip: \"%s\"",
1736  aux, nodep->name, nodep->name);
1737  ptr = addJSONChildStart(ptr,str,0);
1738  n_nodes++;
1739 if(WebDID_Debug)
1740  printf("adding %s %d %d\n",nodep->name, n_nodes, tot_n_nodes);
1741  if(n_nodes < tot_n_nodes)
1742  ptr = addJSONChildEnd(ptr,1);
1743  else
1744  ptr = addJSONChildEnd(ptr,0);
1745  }
1746  ptr = addJSONNodeEnd(ptr);
1747  ptr = addJSONChildEnd(ptr,0);
1748  ptr = addJSONNodeEnd(ptr);
1749  ptr = addJSONEnd(ptr);
1750  if(selective)
1751  {
1752  browserp->n_services = n_found;
1753  browserp->n_servers = tot_n_servers;
1754  browserp->n_nodes = tot_n_nodes;
1755  }
1756  }
1757  else
1758  {
1759  if((nodep = find_node(node)))
1760  {
1761  ptr = addJSONStart(ptr);
1762  ptr = addJSONNodeStart(ptr,"children");
1763  servp = nodep->server_head;
1764  tot_n_servers = 0;
1765  while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
1766  {
1767  servp->match = 1;
1768  if(servp->busy != 1)
1769  {
1770  servp->match = 0;
1771  continue;
1772  }
1773  if(selective)
1774  {
1775  if(!(ret = find_service_pattern(nodep, servp, pattern, 0)))
1776  {
1777  servp->match = 0;
1778  continue;
1779  }
1780  else
1781  {
1782  n_found += ret;
1783  }
1784  }
1785  tot_n_servers++;
1786  }
1787  n_servers = 0;
1788  servp = nodep->server_head;
1789  while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
1790  {
1791  if(!servp->match)
1792  continue;
1793  strcpy(aux, servp->name);
1794  sptr = strstr(aux,"_SMI");
1795  if(sptr)
1796  *sptr = '\0';
1797  sprintf(str,"text: \"%s\", id: \"%d\", leaf: true, icon: \"server.png\", name: \"%s\"",aux, servp->server.pid, servp->name);
1798  ptr = addJSONChildStart(ptr,str,0);
1799  n_servers++;
1800  if(n_servers < tot_n_servers)
1801  ptr = addJSONChildEnd(ptr,1);
1802  else
1803  ptr = addJSONChildEnd(ptr,0);
1804  }
1805  ptr = addJSONNodeEnd(ptr);
1806  ptr = addJSONEnd(ptr);
1807  }
1808  }
1809  /*
1810 if(!selective)
1811 printf(" Nodes&Servers %s\n",JSONBuffer);
1812 else
1813 printf(" Nodes&Servers %s\n",browserp->JSONBuffer);
1814  */
1815 printf("%s\n",browserp->JSONSmiBuffer);
1816  return(1);
1817 }
NODE * Node_head
Definition: webDid.c:28
char * addJSONNodeEnd(char *ptr)
Definition: webDid.c:1380
Definition: dns.c:26
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
int JSONSmiBufferSize
Definition: webDid.c:77
Definition: did.h:42
char str[80]
Definition: test_client.c:7
void * malloc()
Definition: EventBuilder.cc:99
char * addJSONChildEnd(char *ptr, int sep)
Definition: webDid.c:1401
int getNodeLabel(char *name, char *label)
Definition: webDid.c:1475
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
int JSONSmiBufferSize
Definition: webDid.c:96
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
char * JSONSmiBuffer
Definition: webDid.c:76
void free(void *mem)
char * addJSONStart(char *ptr)
Definition: webDid.c:1353
int n_nodes
Definition: webDid.c:72
NODE * find_node(char *node)
Definition: webDid.c:174
int N_nodes
Definition: webDid.c:104
sprintf(name1,"NewService%d", i)
char * JSONSmiBuffer
Definition: webDid.c:95
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: