src/client_list.c
int addToList( wrp_msg_t **msg)
{   
    //new_node indicates the new clients which needs to be added to list
    int rc = -1;
    int sock;
    int retStatus = -1;

    sock = nn_socket( AF_SP, NN_PUSH );
    ParodusPrint("sock created for adding entries to list: %d\n", sock);
    if(sock >= 0)
    {
            int t = NANO_SOCKET_SEND_TIMEOUT_MS;
            rc = nn_setsockopt(sock, NN_SOL_SOCKET, NN_SNDTIMEO, &t, sizeof(t));
            if(rc < 0)
            {
                ParodusError ("Unable to set socket timeout (errno=%d, %s)\n",errno, strerror(errno));
            }
            
            rc = nn_connect(sock, (*msg)->u.reg.url);
            if(rc < 0)
            {
                ParodusError ("Unable to connect socket (errno=%d, %s)\n",errno, strerror(errno));
		if (nn_close (sock) < 0)
                {
                   ParodusError ("nn_close socket=%d (err=%d, %s)\n", 
			sock, errno, strerror(errno));
		}
                
            }
            else
            {
            	reg_list_item_t *new_node = NULL;
		new_node=(reg_list_item_t *)malloc(sizeof(reg_list_item_t));
		if(new_node)
		{
    			memset( new_node, 0, sizeof( reg_list_item_t ) );
    			new_node->sock = sock;
                        new_node->endpoint = rc;
    			ParodusPrint("new_node->sock is %d\n", new_node->sock);
    			
    			
	                ParodusPrint("(*msg)->u.reg.service_name is %s\n", (*msg)->u.reg.service_name);
	                ParodusPrint("(*msg)->u.reg.url is %s\n", (*msg)->u.reg.url);

	                parStrncpy(new_node->service_name, (*msg)->u.reg.service_name, sizeof(new_node->service_name));
	                parStrncpy(new_node->url, (*msg)->u.reg.url, sizeof(new_node->url));
	                new_node->next=NULL;
	                 
	                if (g_head == NULL) //adding first client
	                {
	                        ParodusInfo("Adding first client to list\n");
	                        g_head = new_node;
	                }
	                else   //client2 onwards           
	                {
	                        reg_list_item_t *temp = NULL;
	                        ParodusInfo("Adding clients to list\n");
	                        temp = g_head;

	                        while(temp->next !=NULL)
	                        {
		                        temp=temp->next;
	                        }

	                        temp->next=new_node;
	                }

	                ParodusPrint("client is added to list\n");
	                ParodusInfo("client service %s is added to list with url: %s\n", new_node->service_name, new_node->url);
	                if((strcmp(new_node->service_name, (*msg)->u.reg.service_name)==0)&& (strcmp(new_node->url, (*msg)->u.reg.url)==0))
	                {
	                	numOfClients = numOfClients + 1;
	                        ParodusInfo("sending auth status to reg client\n");
	                        retStatus = sendAuthStatus(new_node);
	                }
	                else
	                {
	                        ParodusError("nanomsg client registration failed\n");
	                        
	                }
	            }
            }
    }
    else
    {
            ParodusError("Unable to create socket (errno=%d, %s)\n",errno, strerror(errno));
            
    }
    ParodusPrint("addToList return %d\n", retStatus);
    return retStatus;
   
}
/** To add clients to registered list ***/
To add clients to registered list
To add clients to registered list
int addToList( wrp_msg_t **msg)
{   
    int rc = -1;
    int sock;
    int retStatus = -1;
    sock = nn_socket( AF_SP, NN_PUSH );
    ParodusPrint("sock created for adding entries to list: %d\n", sock);
    if(sock >= 0)
    {
            int t = NANO_SOCKET_SEND_TIMEOUT_MS;
            rc = nn_setsockopt(sock, NN_SOL_SOCKET, NN_SNDTIMEO, &t, sizeof(t));
            if(rc < 0)
            {
                ParodusError ("Unable to set socket timeout (errno=%d, %s)\n",errno, strerror(errno));
            }
            rc = nn_connect(sock, (*msg)->u.reg.url);
            if(rc < 0)
            {
                ParodusError ("Unable to connect socket (errno=%d, %s)\n",errno, strerror(errno));
		if (nn_close (sock) < 0)
                {
                   ParodusError ("nn_close socket=%d (err=%d, %s)\n", 
			sock, errno, strerror(errno));
		}
            }
            else
            {
            	reg_list_item_t *new_node = NULL;
		new_node=(reg_list_item_t *)malloc(sizeof(reg_list_item_t));
		if(new_node)
		{
    			memset( new_node, 0, sizeof( reg_list_item_t ) );
    			new_node->sock = sock;
                        new_node->endpoint = rc;
    			ParodusPrint("new_node->sock is %d\n", new_node->sock);
	                ParodusPrint("(*msg)->u.reg.service_name is %s\n", (*msg)->u.reg.service_name);
	                ParodusPrint("(*msg)->u.reg.url is %s\n", (*msg)->u.reg.url);
	                parStrncpy(new_node->service_name, (*msg)->u.reg.service_name, sizeof(new_node->service_name));
	                parStrncpy(new_node->url, (*msg)->u.reg.url, sizeof(new_node->url));
	                new_node->next=NULL;
	                if (g_head == NULL) 
	                {
	                        ParodusInfo("Adding first client to list\n");
	                        g_head = new_node;
	                }
	                else   
	                {
	                        reg_list_item_t *temp = NULL;
	                        ParodusInfo("Adding clients to list\n");
	                        temp = g_head;
	                        while(temp->next !=NULL)
	                        {
		                        temp=temp->next;
	                        }
	                        temp->next=new_node;
	                }
	                ParodusPrint("client is added to list\n");
	                ParodusInfo("client service %s is added to list with url: %s\n", new_node->service_name, new_node->url);
	                if((strcmp(new_node->service_name, (*msg)->u.reg.service_name)==0)&& (strcmp(new_node->url, (*msg)->u.reg.url)==0))
	                {
	                	numOfClients = numOfClients + 1;
	                        ParodusInfo("sending auth status to reg client\n");
	                        retStatus = sendAuthStatus(new_node);
	                }
	                else
	                {
	                        ParodusError("nanomsg client registration failed\n");
	                }
	            }
            }
    }
    else
    {
            ParodusError("Unable to create socket (errno=%d, %s)\n",errno, strerror(errno));
    }
    ParodusPrint("addToList return %d\n", retStatus);
    return retStatus;
}
int addToList ( wrp_msg_t * * msg ) { int rc = -1 ; int sock ; int retStatus = -1 ; sock = nn_socket ( AF_SP , NN_PUSH ) ; ParodusPrint ( " \n " , sock ) ; if ( sock >= 0 ) { int t = NANO_SOCKET_SEND_TIMEOUT_MS ; rc = nn_setsockopt ( sock , NN_SOL_SOCKET , NN_SNDTIMEO , & t , sizeof ( t ) ) ; if ( rc < 0 ) { ParodusError ( " \n " , errno , strerror ( errno ) ) ; } rc = nn_connect ( sock , ( * msg ) -> u . reg . url ) ; if ( rc < 0 ) { ParodusError ( " \n " , errno , strerror ( errno ) ) ; if ( nn_close ( sock ) < 0 ) { ParodusError ( " \n " , sock , errno , strerror ( errno ) ) ; } } else { reg_list_item_t * new_node = NULL ; new_node = ( reg_list_item_t * ) malloc ( sizeof ( reg_list_item_t ) ) ; if ( new_node ) { memset ( new_node , 0 , sizeof ( reg_list_item_t ) ) ; new_node -> sock = sock ; new_node -> endpoint = rc ; ParodusPrint ( " \n " , new_node -> sock ) ; ParodusPrint ( " \n " , ( * msg ) -> u . reg . service_name ) ; ParodusPrint ( " \n " , ( * msg ) -> u . reg . url ) ; parStrncpy ( new_node -> service_name , ( * msg ) -> u . reg . service_name , sizeof ( new_node -> service_name ) ) ; parStrncpy ( new_node -> url , ( * msg ) -> u . reg . url , sizeof ( new_node -> url ) ) ; new_node -> next = NULL ; if ( g_head == NULL ) { ParodusInfo ( " \n " ) ; g_head = new_node ; } else { reg_list_item_t * temp = NULL ; ParodusInfo ( " \n " ) ; temp = g_head ; while ( temp -> next != NULL ) { temp = temp -> next ; } temp -> next = new_node ; } ParodusPrint ( " \n " ) ; ParodusInfo ( " \n " , new_node -> service_name , new_node -> url ) ; if ( ( strcmp ( new_node -> service_name , ( * msg ) -> u . reg . service_name ) == 0 ) && ( strcmp ( new_node -> url , ( * msg ) -> u . reg . url ) == 0 ) ) { numOfClients = numOfClients + 1 ; ParodusInfo ( " \n " ) ; retStatus = sendAuthStatus ( new_node ) ; } else { ParodusError ( " \n " ) ; } } } } else { ParodusError ( " \n " , errno , strerror ( errno ) ) ; } ParodusPrint ( " \n " , retStatus ) ; return retStatus ; }
To add clients to registered list
To add clients to registered list
//new_node indicates the new clients which needs to be added to list //adding first client //client2 onwards           