Example #1
0
/** Returns an address for the specified host name.
 *
 * @param[in] host - A pointer to hostname to resolve.
 * @param[out] addr - The address of storage for the returned address 
 *    data.
 *
 * @return Zero on success, or non-zero on error.
 *
 * @remarks This routine returns address data of unspecified family, so 
 *    the output buffer is purposely defined as a sockaddr_storage buffer.
 */
int SLPNetResolveHostToAddr(const char * host, 
      struct sockaddr_storage * addr)
{
   struct sockaddr_in6 * a6 = (struct sockaddr_in6 *)addr;
   struct sockaddr_in  * a4 = (struct sockaddr_in  *)addr;

   /*Clear out the addr, because resolve won't fill in everything*/
   memset(addr, 0, sizeof(struct sockaddr_storage));

   /* Quick check for dotted quad IPv4 address. */
   if (resolveHost(AF_INET, host, a4) == 1)
   {
      addr->ss_family = AF_INET;
#ifdef HAVE_SOCKADDR_STORAGE_SS_LEN
      addr->ss_len = sizeof(struct sockaddr_in);
#endif
      return 0;
   }

   /* Try an IPv6 address. */
   if (resolveHost(AF_INET6, host, a6) == 1)
   {
      addr->ss_family = AF_INET6;
#ifdef HAVE_SOCKADDR_STORAGE_SS_LEN
      addr->ss_len = sizeof(struct sockaddr_in6);
#endif
      return 0;
   }
   return -1;
}
Example #2
0
int
_rsProcStat (rsComm_t *rsComm, procStatInp_t *procStatInp,
             genQueryOut_t **procStatOut)
{
    int status;
    rodsServerHost_t *rodsServerHost;
    int remoteFlag;
    rodsHostAddr_t addr;
    procStatInp_t myProcStatInp;
    char *tmpStr;

    if (getValByKey (&procStatInp->condInput, ALL_KW) != NULL) {
        status = _rsProcStatAll (rsComm, procStatInp, procStatOut);
        return status;
    }
    if (getValByKey (&procStatInp->condInput, EXEC_LOCALLY_KW) != NULL) {
        status = localProcStat (rsComm, procStatInp, procStatOut);
        return status;
    }

    bzero (&addr, sizeof (addr));
    bzero (&myProcStatInp, sizeof (myProcStatInp));
    if (*procStatInp->addr != '\0') {	/* given input addr */
        rstrcpy (addr.hostAddr, procStatInp->addr, LONG_NAME_LEN);
        remoteFlag = resolveHost (&addr, &rodsServerHost);
    } else if ((tmpStr = getValByKey (&procStatInp->condInput, RESC_NAME_KW))
               != NULL) {
        rescGrpInfo_t *rescGrpInfo = NULL;
        status = _getRescInfo (rsComm, tmpStr, &rescGrpInfo);
        if (status < 0) {
            rodsLog (LOG_ERROR,
                     "_rsProcStat: _getRescInfo of %s error. stat = %d",
                     tmpStr, status);
            return status;
        }
        rstrcpy (procStatInp->addr, rescGrpInfo->rescInfo->rescLoc, NAME_LEN);
        rodsServerHost = (rodsServerHost_t*)rescGrpInfo->rescInfo->rodsServerHost;
        if (rodsServerHost == NULL) {
            remoteFlag = SYS_INVALID_SERVER_HOST;
        } else {
            remoteFlag = rodsServerHost->localFlag;
        }
    } else {
        /* do the IES server */
        remoteFlag = getRcatHost (MASTER_RCAT, NULL, &rodsServerHost);
    }
    if (remoteFlag < 0) {
        rodsLog (LOG_ERROR,
                 "_rsProcStat: getRcatHost() failed. erro=%d", remoteFlag);
        return (remoteFlag);
    } else if (remoteFlag == REMOTE_HOST) {
        addKeyVal (&myProcStatInp.condInput, EXEC_LOCALLY_KW, "");
        status = remoteProcStat (rsComm, &myProcStatInp, procStatOut,
                                 rodsServerHost);
        rmKeyVal (&myProcStatInp.condInput, EXEC_LOCALLY_KW);
    } else {
        status = localProcStat (rsComm, procStatInp, procStatOut);
    }
    return status;
}
int
rsSubStructFileClosedir (rsComm_t *rsComm, subStructFileFdOprInp_t *subStructFileClosedirInp)
{
    rodsServerHost_t *rodsServerHost;
    int remoteFlag;
    int status;

    remoteFlag = resolveHost (&subStructFileClosedirInp->addr, &rodsServerHost);

    if (remoteFlag == LOCAL_HOST) {
        status = _rsSubStructFileClosedir (rsComm, subStructFileClosedirInp);
    } else if (remoteFlag == REMOTE_HOST) {
        status = remoteSubStructFileClosedir (rsComm, subStructFileClosedirInp,
          rodsServerHost);
    } else {
        if (remoteFlag < 0) {
            return (remoteFlag);
        } else {
            rodsLog (LOG_NOTICE,
              "rsSubStructFileClosedir: resolveHost returned unrecognized value %d",
               remoteFlag);
            return (SYS_UNRECOGNIZED_REMOTE_FLAG);
        }
    }

    return (status);
}
Example #4
0
int
rsFileGet (rsComm_t *rsComm, fileOpenInp_t *fileGetInp, 
bytesBuf_t *fileGetOutBBuf)
{
    rodsServerHost_t *rodsServerHost;
    int remoteFlag;
    int status;

    remoteFlag = resolveHost (&fileGetInp->addr, &rodsServerHost);
    if (remoteFlag == LOCAL_HOST) {
        status = _rsFileGet (rsComm, fileGetInp, fileGetOutBBuf);
    } else if (remoteFlag == REMOTE_HOST) {
        status = remoteFileGet (rsComm, fileGetInp, fileGetOutBBuf, 
          rodsServerHost);
    } else {
        if (remoteFlag < 0) {
            return (remoteFlag);
        } else {
            rodsLog (LOG_NOTICE,
              "rsFileGet: resolveHost returned unrecognized value %d",
               remoteFlag);
            return (SYS_UNRECOGNIZED_REMOTE_FLAG);
        }
    }

    return (status);
}
Example #5
0
int
rsFileStage (rsComm_t *rsComm, fileStageInp_t *fileStageInp)
{
    rodsServerHost_t *rodsServerHost;
    int remoteFlag;
    int status;

    remoteFlag = resolveHost (&fileStageInp->addr, &rodsServerHost);
    if (remoteFlag == LOCAL_HOST) {
        status = _rsFileStage (rsComm, fileStageInp);
    } else if (remoteFlag == REMOTE_HOST) {
        status = remoteFileStage (rsComm, fileStageInp, rodsServerHost);
    } else {
        if (remoteFlag < 0) {
            return (remoteFlag);
        } else {
            rodsLog (LOG_NOTICE,
              "rsFileStage: resolveHost returned unrecognized value %d",
               remoteFlag);
            return (SYS_UNRECOGNIZED_REMOTE_FLAG);
        }
    }

      /* Manually insert call-specific code here */

    return (status);
}
Example #6
0
Server::Server(const string &listenAddr, unsigned short port):
            _fd(-1)
{
  _connectionString =listenAddr;
  _connectionString+=":";
  char portString[6];               // temporary...
  sprintf(portString, "%d", port);  // for this!
  _connectionString+=portString;

  sockaddr_in addr;     // our listen-on address

  addr=resolveHost(listenAddr, port);

  _fd=socket(AF_INET, SOCK_STREAM, 0);
  if(_fd==-1)
    throw Exception("Server::Server(): socket() failed");

  // bind address with socket
  if( bind(_fd, (sockaddr*)&addr, sizeof(addr) )==-1 )
  {
    close(_fd);
    throw Exception("Server::Server(): bind() failed");
  };

  int listenQueueLen=1;     // we process only one host in most cases...
  if( listen(_fd, listenQueueLen)==-1 )
  {
    close(_fd);
    throw Exception("Server::Server(): listen() failed");
  };
};
int
rsSubStructFileRead (rsComm_t *rsComm, subStructFileFdOprInp_t *subStructFileReadInp,
bytesBuf_t *subStructFileReadOutBBuf)
{
    rodsServerHost_t *rodsServerHost;
    int remoteFlag;
    int status;

    remoteFlag = resolveHost (&subStructFileReadInp->addr, &rodsServerHost);

    if (subStructFileReadInp->len > 0) {
        if (subStructFileReadOutBBuf->buf == NULL)
            subStructFileReadOutBBuf->buf = malloc (subStructFileReadInp->len);
    } else {
        return (0);
    }

    if (remoteFlag == LOCAL_HOST) {
        status = _rsSubStructFileRead (rsComm, subStructFileReadInp, subStructFileReadOutBBuf);
    } else if (remoteFlag == REMOTE_HOST) {
        status = remoteSubStructFileRead (rsComm, subStructFileReadInp, subStructFileReadOutBBuf, 
	  rodsServerHost);
    } else {
        if (remoteFlag < 0) {
            return (remoteFlag);
        } else {
            rodsLog (LOG_NOTICE,
              "rsSubStructFileRead: resolveHost returned unrecognized value %d",
               remoteFlag);
            return (SYS_UNRECOGNIZED_REMOTE_FLAG);
        }
    }

    return (status);
}
Example #8
0
/* get hostname and host socket */
void
getHostName(char *prompt, char **hostName, Sockaddr *hostAddr)
{
	char		buf[128];
	Sockaddr	*AddrTemp;

	buf[0] = '\0';
	for (AddrTemp = (Sockaddr *)NULL; AddrTemp == (Sockaddr *)NULL; )
	  {
		printf("%s %s: " , prompt, "(CR for any host)");
		fgets(buf, sizeof(buf)-1, stdin);
		if (strlen(buf) == 0)
			break;
		*hostName = (char*)malloc((unsigned) (strlen(buf) + 1));
		if (*hostName == NULL)
			MWError("no mem for hostName");
		strcpy(*hostName, buf);

		/* check for valid maze name */
		AddrTemp = resolveHost(*hostName);
		if (AddrTemp== (Sockaddr *) NULL) {
			printf("Don't know host %s\n", *hostName);
			free(*hostName);
			*hostName = NULL;
		}
	}
	if ((*hostName != NULL) &&
	    (strlen(*hostName) != 0))
		bcopy((char *) AddrTemp, (char *) hostAddr, sizeof(Sockaddr));
}
Example #9
0
/**
 * The connect function will call takes a server host name or IP address string
 * and the server listening port as arguments. The server struct sockaddr_in,
 * sin_family is set to PF_INET and the sin_port is set to the TCPPort on which
 * the server is listening for connections
 */
TCPStream* TCPConnector::connect(const char* server, int port) {
    struct sockaddr_in address;

    memset(&address, 0, sizeof(address));

    address.sin_family = AF_INET;
    address.sin_port   = htons(port);
    
    // Call resolveHost to convert the DNS host name string to an IP address
    // If this call fails the assumption is made the server string contains 
    // an IP address and it is converted to an IP address in network byte 
    // order.
    if (resolveHost(server, &(address.sin_addr)) != 0) {
        inet_pton(PF_INET, server, &(address.sin_addr));
    }

    int sd = socket(AF_INET, SOCK_STREAM, 0);

    // We call ::connect() passing it the socket descriptor, pointer to the server
    // struct sockaddr_in structure, cast to a struct sockaddr pointer, and the lengh
    // of the server address structure. The ::connect() call is prefeced with the 
    // :: qualifier so the compliler does not confuse this function with 
    // TCPConnector::connect(). if ::connect() succeeds and TCPStream object is
    // created with the connected socket descriptor and the server socket address 
    // information and a pointer to the TCPStream object is returned to the called.
    if (::connect(sd, (struct sockaddr*)&address, sizeof(address)) != 0) {
        return NULL;
    }
    return new TCPStream(sd, &address);
}
Example #10
0
int
rsSubStructFileCreate( rsComm_t *rsComm, subFile_t *subFile ) {
    rodsServerHost_t *rodsServerHost;
    int remoteFlag;
    int fd;

    remoteFlag = resolveHost( &subFile->addr, &rodsServerHost );

    if ( remoteFlag == LOCAL_HOST ) {
        fd = _rsSubStructFileCreate( rsComm, subFile );
    }
    else if ( remoteFlag == REMOTE_HOST ) {
        fd = remoteSubStructFileCreate( rsComm, subFile, rodsServerHost );
    }
    else {
        if ( remoteFlag < 0 ) {
            return remoteFlag;
        }
        else {
            rodsLog( LOG_NOTICE,
                     "rsSubStructFileCreate: resolveHost returned unrecognized value %d",
                     remoteFlag );
            return SYS_UNRECOGNIZED_REMOTE_FLAG;
        }
    }

    return fd;
}
Example #11
0
int handleRequest(struct dnsServer *srv, int len)
{
	struct DNSHeader head;
	struct DNSQuestion question;
	struct DNSAnswer answer;
	int8_t *ptr = srv->buffer;
	char *addr, *buf = NULL;
	uint16_t size;
	uint8_t found = 0;
	ptr = readDNSHeader(&head, ptr);
	ptr = readDNSQuestion(&question, ptr);
	if (question.qtype == TYPE_A)
		addr = resolveHost(question.qname);
	else if (question.qtype = TYPE_PTR)
		addr = resolveAddress(question.qname);
#if DEBUG == 1
		printf("Received packet from %s:%d\tID: %04x\n",
			inet_ntoa(srv->client.sin_addr), ntohs(srv->client.sin_port), head.id);
		printf("NAME TO RESOLVE: %s\t%s\n", question.qname, addr);
#endif
	if ((question.qtype != TYPE_A && question.qtype != TYPE_PTR || question.qclass != CLASS_IN) ||
	    addr == NULL)
	{
		passthrough(srv, len);
	}
	else
	{
		answer = createDNSAnswer(&question, addr, question.qtype == TYPE_A);
		createDNSResponse(&head, &question, &answer, (void **)&buf, &size);
		sendto(srv->sock, buf, size, 0, (struct sockaddr*)&srv->client, sizeof(srv->client));
	}
	return 0; //packet sent
}
Example #12
0
bool CNFSConnection::Connect(VFSURL* url, std::string& relativePath)
{
  PLATFORM::CLockObject lock(*this);
  bool ret = false;
  int nfsRet = 0;
  std::string exportPath;

  resolveHost(url->hostname);
  ret = splitUrlIntoExportAndPath(url->hostname, url->filename, exportPath, relativePath);
  
  if( (ret && (exportPath != m_exportPath  || 
      m_hostName != url->hostname))    ||
      (PLATFORM::GetTimeMs() - m_lastAccessedTime) > CONTEXT_TIMEOUT )
  {
    int contextRet = getContextForExport(std::string(url->hostname) + exportPath);
    
    if(contextRet == CONTEXT_INVALID)//we need a new context because sharename or hostname has changed
    {
      return false;
    }
    
    if(contextRet == CONTEXT_NEW) //new context was created - we need to mount it
    {
      //we connect to the directory of the path. This will be the "root" path of this connection then.
      //So all fileoperations are relative to this mountpoint...
      nfsRet = nfs_mount(m_pNfsContext, m_resolvedHostName.c_str(), exportPath.c_str());

      if(nfsRet != 0) 
      {
        XBMC->Log(ADDON::LOG_ERROR,"NFS: Failed to mount nfs share: %s %s (%s)\n", m_resolvedHostName.c_str(), exportPath.c_str(), nfs_get_error(m_pNfsContext));
        destroyContext(std::string(url->hostname) + exportPath);
        return false;
      }
      XBMC->Log(ADDON::LOG_DEBUG,"NFS: Connected to server %s and export %s\n", url->hostname, exportPath.c_str());
    }
    m_exportPath = exportPath;
    m_hostName = url->hostname;
    //read chunksize only works after mount
    m_readChunkSize = nfs_get_readmax(m_pNfsContext);
    m_writeChunkSize =nfs_get_writemax(m_pNfsContext);

    if(contextRet == CONTEXT_NEW)
    {
      XBMC->Log(ADDON::LOG_DEBUG,"NFS: chunks: r/w %i/%i\n", (int)m_readChunkSize,(int)m_writeChunkSize);
    }
  }
  return ret; 
}
Example #13
0
int
isLocalHost( const char *hostAddr ) {
    int remoteFlag;
    rodsServerHost_t *rodsServerHost;
    rodsHostAddr_t addr;

    bzero( &addr, sizeof( addr ) );
    rstrcpy( addr.hostAddr, hostAddr, NAME_LEN );
    remoteFlag = resolveHost( &addr, &rodsServerHost );
    if ( remoteFlag == LOCAL_HOST ) {
        return 1;
    }
    else {
        return 0;
    }
}
Example #14
0
int
getRemoteZoneHost( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
                   rodsServerHost_t **rodsServerHost, char *remoteZoneOpr ) {
    int status;
    rodsServerHost_t *icatServerHost = NULL;
    rodsHostAddr_t *rescAddr = NULL;

    status = getRcatHost( MASTER_RCAT, dataObjInp->objPath, &icatServerHost );

    if ( status < 0 || NULL == icatServerHost ) { // JMC cppcheck - nullptr
        return status;
    }

    if ( icatServerHost->rcatEnabled != REMOTE_ICAT ) {
        /* local zone. nothing to do */
        return LOCAL_HOST;
    }

    status = svrToSvrConnect( rsComm, icatServerHost );

    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "getRemoteZoneHost: svrToSvrConnect to %s failed, status = %d",
                 icatServerHost->hostName->name, status );
        status = convZoneSockError( status );
        return status;
    }

    addKeyVal( &dataObjInp->condInput, REMOTE_ZONE_OPR_KW, remoteZoneOpr );

    status = rcGetRemoteZoneResc( icatServerHost->conn, dataObjInp, &rescAddr );
    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "getRemoteZoneHost: rcGetRemoteZoneResc for %s failed, status = %d",
                 dataObjInp->objPath, status );
        return status;
    }

    status = resolveHost( rescAddr, rodsServerHost );

    free( rescAddr );

    return status;
}
Example #15
0
BOOL CRegFinishDlg::OnSetActive() 
{
	CRegWizard *wiz = (CRegWizard *) GetParent();
	wiz->getData(&icqLink->myInfo, &icqLink->options);
	wiz->qid.uin = 0;

	CString str;
	str.LoadString(IDS_PLEASE_WAIT);
	SetDlgItemText(IDC_STATUS, str);
	str.LoadString(IDS_REG_REGISTERING);
	SetDlgItemText(IDC_STATUS_DETAIL, str);
	wiz->SetWizardButtons(PSWIZB_DISABLEDFINISH);

	m_faceLabel.start();

	resolveHost();

	return CPropertyPage::OnSetActive();
}
Example #16
0
int
resoAndConnHostByDataObjInfo( rsComm_t *rsComm, dataObjInfo_t *dataObjInfo,
                              rodsServerHost_t **rodsServerHost ) {
    int status;
    rodsHostAddr_t addr;
    int remoteFlag;
    if ( dataObjInfo == NULL ) {
        rodsLog( LOG_NOTICE,
                 "resoAndConnHostByDataObjInfo: NULL dataObjInfo" );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    // =-=-=-=-=-=-=-
    // extract the host location from the resource hierarchy
    std::string location;
    irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location );
    if ( !ret.ok() ) {
        irods::log( PASSMSG( "resoAndConnHostByDataObjInfo - failed in get_loc_for_hier_string", ret ) );
        return ret.code();
    }


    memset( &addr, 0, sizeof( addr ) );
    rstrcpy( addr.hostAddr, location.c_str(), NAME_LEN );

    remoteFlag = resolveHost( &addr, rodsServerHost );

    if ( remoteFlag == REMOTE_HOST ) {
        status = svrToSvrConnect( rsComm, *rodsServerHost );
        if ( status < 0 ) {
            rodsLog( LOG_ERROR,
                     "resAndConnHostByDataObjInfo: svrToSvrConnect to %s failed",
                     ( *rodsServerHost )->hostName->name );
        }
    }
    return remoteFlag;
}
Example #17
0
int
rsFileOpendir (rsComm_t *rsComm, fileOpendirInp_t *fileOpendirInp)
{
    rodsServerHost_t *rodsServerHost;
    int remoteFlag;
    int fileInx;
    int status;
    void *dirPtr = NULL;

    remoteFlag = resolveHost (&fileOpendirInp->addr, &rodsServerHost);

    if (remoteFlag == LOCAL_HOST) {
	status = _rsFileOpendir (rsComm, fileOpendirInp, &dirPtr);
    } else if (remoteFlag == REMOTE_HOST) {
        status = remoteFileOpendir (rsComm, fileOpendirInp, rodsServerHost);
    } else {
	if (remoteFlag < 0) {
	    return (remoteFlag);
	} else {
	    rodsLog (LOG_NOTICE,
	      "rsFileOpendir: resolveHost returned unrecognized value %d",
	       remoteFlag);
	    return (SYS_UNRECOGNIZED_REMOTE_FLAG);
	}
    }

    if (status < 0) {
	return (status);
    }

    fileInx = allocAndFillFileDesc (rodsServerHost, fileOpendirInp->dirName,
      fileOpendirInp->fileType, status, 0);
    FileDesc[fileInx].driverDep = dirPtr;

    return (fileInx);
}
Example #18
0
int CNFSConnection::stat(VFSURL* url, struct stat *statbuff)
{
  PLATFORM::CLockObject lock(*this);
  int nfsRet = 0;
  std::string exportPath;
  std::string relativePath;
  struct nfs_context *pTmpContext = NULL;
  
  resolveHost(url->hostname);
  
  if(splitUrlIntoExportAndPath(url->hostname, url->filename, exportPath, relativePath))
  {    
    pTmpContext = nfs_init_context();
    
    if(pTmpContext)
    {  
      //we connect to the directory of the path. This will be the "root" path of this connection then.
      //So all fileoperations are relative to this mountpoint...
      nfsRet = nfs_mount(pTmpContext, m_resolvedHostName.c_str(), exportPath.c_str());
      
      if(nfsRet == 0) 
      {
        nfsRet = nfs_stat(pTmpContext, relativePath.c_str(), statbuff);      
      }
      else
      {
        XBMC->Log(ADDON::LOG_ERROR,"NFS: Failed to mount nfs share: %s (%s)\n", exportPath.c_str(), nfs_get_error(m_pNfsContext));
      }
      
      nfs_destroy_context(pTmpContext);
      XBMC->Log(ADDON::LOG_DEBUG,"NFS: Connected to server %s and export %s in tmpContext\n", url->hostname, exportPath.c_str());
    }
  }

  return nfsRet;
}
Example #19
0
/* This will presumably be modified by you.
   It is here to provide an example of how to open a UDP port.
   You might choose to use a different strategy
 */
void
netInit()
{
	bool		joinGame();
	Sockaddr	nullAddr;
	Sockaddr	*thisHost;
	char		buf[128];
	int		reuse;
	u_char          ttl;
	struct ip_mreq  mreq;

	/* MAZEPORT will be assigned by the TA to each team */
	M->mazePortIs(htons(MAZEPORT));

	gethostname(buf, sizeof(buf));
	if ((thisHost = resolveHost(buf)) == (Sockaddr *) NULL)
	  MWError("who am I?");
	bcopy((caddr_t) thisHost, (caddr_t) (M->myAddr()), sizeof(Sockaddr));

	M->theSocketIs(socket(AF_INET, SOCK_DGRAM, 0));
	if (M->theSocket() < 0)
	  MWError("can't get socket");

	/* SO_REUSEADDR allows more than one binding to the same
	   socket - you cannot have more than one player on one
	   machine without this */
	reuse = 1;
	if (setsockopt(M->theSocket(), SOL_SOCKET, SO_REUSEADDR, &reuse,
		   sizeof(reuse)) < 0) {
		MWError("setsockopt failed (SO_REUSEADDR)");
	}

	nullAddr.sin_family = AF_INET;
	nullAddr.sin_addr.s_addr = htonl(INADDR_ANY);
	nullAddr.sin_port = M->mazePort();
	if (bind(M->theSocket(), (struct sockaddr *)&nullAddr,
		 sizeof(nullAddr)) < 0)
	  MWError("netInit binding");

	/* Multicast TTL:
	   0 restricted to the same host
	   1 restricted to the same subnet
	   32 restricted to the same site
	   64 restricted to the same region
	   128 restricted to the same continent
	   255 unrestricted

	   DO NOT use a value > 32. If possible, use a value of 1 when
	   testing.
	*/

	ttl = 32;
	if (setsockopt(M->theSocket(), IPPROTO_IP, IP_MULTICAST_TTL, &ttl,
		   sizeof(ttl)) < 0) {
		MWError("setsockopt failed (IP_MULTICAST_TTL)");
	}

	/* uncomment the following if you do not want to receive messages that
	   you sent out - of course, you cannot have multiple players on the
	   same machine if you do this */
#if 0
	{
	  u_char loop = 0;
	  if (setsockopt(M->theSocket(), IPPROTO_IP, IP_MULTICAST_LOOP, &loop,
	             sizeof(loop)) < 0) {
		MWError("setsockopt failed (IP_MULTICAST_LOOP)");
	  }
	}
#endif

	/* join the multicast group */
	mreq.imr_multiaddr.s_addr = htonl(MAZEGROUP);
	mreq.imr_interface.s_addr = htonl(INADDR_ANY);
	if (setsockopt(M->theSocket(), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)
		   &mreq, sizeof(mreq)) < 0) {
		MWError("setsockopt failed (IP_ADD_MEMBERSHIP)");
	}

	/*
	 * Now we can try to find a game to join; if none, start one.
	 */

	/* I haven't implemented joinGame or startGame in this sample */
	/*
	if (!joinGame())
		startGame();
        */
	printf("\n");

	/* set up some stuff strictly for this local sample */
	M->myRatIdIs(0);
	M->scoreIs(0);
	SetMyRatIndexType(0);

	/* Get the multi-cast address ready to use in SendData()
           calls. */
	memcpy(&groupAddr, &nullAddr, sizeof(Sockaddr));
	groupAddr.sin_addr.s_addr = htonl(MAZEGROUP);

	mws_set_addr(M->state, (struct sockaddr *)&groupAddr, M->theSocket());
}
Example #20
0
int csocket::connect( const char* remoteHost, unsigned int remotePort )
{
    if ( m_socketState != CLOSED ) 
    {
        return ERROR_INAPPROPRIATE_STATE;
    }

    struct hostent *pHostEnt = NULL;
    int status = resolveHost(remoteHost, &pHostEnt);
    if (status == FAILURE || !pHostEnt) 
    {
        return FAILURE;
    }

    m_strRemoteHost = remoteHost;
    m_remotePort = remotePort;

    m_remoteSocketAddr.sin_family = pHostEnt->h_addrtype;
    memcpy((char *) &m_remoteSocketAddr.sin_addr.s_addr,
        pHostEnt->h_addr_list[0], 
        pHostEnt->h_length);

    m_remoteSocketAddr.sin_port = htons(m_remotePort);


#ifdef WIN32
    m_socket = WSASocket(AF_INET, SOCK_STREAM, 
        IPPROTO_TCP, 0 , 0 , 0);

    if (m_socket == INVALID_SOCKET)
    {
        return FAILURE;
    }
#else
    m_socket = socket(AF_INET, SOCK_STREAM, 0);
#endif

    if (m_socket < 0) 
    {
        return FAILURE;
    }

    m_localSocketAddr.sin_family = AF_INET;

    m_localSocketAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    
    int         iRecvTimeout = 1;
    setsockopt(m_socket, SOL_SOCKET, SO_RCVTIMEO, 
        (char*) &iRecvTimeout, sizeof(iRecvTimeout) );

    m_localSocketAddr.sin_port = htons(0);

    status = bind( m_socket, 
        (const sockaddr*)&(m_localSocketAddr),  
        sizeof(struct sockaddr) );

    if (status < 0) 
    {
        return FAILURE;
    }

#ifdef WIN32 
    int set = 1;
    setsockopt(m_socket, IPPROTO_TCP, TCP_NODELAY,  (char*) &set, sizeof(set) );
#endif

    m_remoteSocketAddr.sin_family = pHostEnt->h_addrtype;

    memcpy(&(m_remoteSocketAddr.sin_addr), 
                pHostEnt->h_addr, 
                pHostEnt->h_length);

    m_remoteSocketAddr.sin_port = htons( m_remotePort );

    status = ::connect(m_socket, 
                    (const sockaddr*)&(m_remoteSocketAddr), 
                    sizeof(m_remoteSocketAddr)  );

    if (status < 0) 
    {
        return FAILURE;
    }

    m_socketState = CONNECTED;

    return SUCCESS;
}
Example #21
0
int
rsPhyBundleColl( rsComm_t*                 rsComm,
                 structFileExtAndRegInp_t* phyBundleCollInp ) {
    int               status         = -1;
    specCollCache_t*  specCollCache  = 0;
    char*             destRescName   = 0;

    resolveLinkedPath( rsComm, phyBundleCollInp->objPath, &specCollCache,
                       &phyBundleCollInp->condInput );

    resolveLinkedPath( rsComm, phyBundleCollInp->collection,
                       &specCollCache, NULL );

    if ( ( destRescName = getValByKey( &phyBundleCollInp->condInput,
                                       DEST_RESC_NAME_KW ) ) == NULL ) {
        return USER_NO_RESC_INPUT_ERR;
    }

    if ( isLocalZone( phyBundleCollInp->collection ) == 0 ) {
        /* can only do local zone */
        return SYS_INVALID_ZONE_NAME;
    }

    // =-=-=-=-=-=-=-
    // working on the "home zone", determine if we need to redirect to a different
    // server in this zone for this operation.  if there is a RESC_HIER_STR_KW then
    // we know that the redirection decision has already been made
    dataObjInp_t      data_inp;
    bzero( &data_inp, sizeof( data_inp ) );
    rstrcpy( data_inp.objPath, phyBundleCollInp->objPath, MAX_NAME_LEN );
    bzero( &data_inp.condInput, sizeof( data_inp.condInput ) );
    addKeyVal( &data_inp.condInput, DEST_RESC_NAME_KW, destRescName );

    std::string       hier;
    char* hier_kw = getValByKey( &phyBundleCollInp->condInput, RESC_HIER_STR_KW );
    if ( hier_kw == NULL ) {
        irods::error ret = irods::resolve_resource_hierarchy( irods::CREATE_OPERATION, rsComm,
                           &data_inp, hier );
        if ( !ret.ok() ) {
            std::stringstream msg;
            msg << "failed in irods::resolve_resource_hierarchy for [";
            msg << data_inp.objPath << "]";
            irods::log( PASSMSG( msg.str(), ret ) );
            return ret.code();
        }

        // =-=-=-=-=-=-=-
        // we resolved the redirect and have a host, set the hier str for subsequent
        // api calls, etc.
        addKeyVal( &phyBundleCollInp->condInput, RESC_HIER_STR_KW, hier.c_str() );

    }
    else {
        hier = hier_kw;

    }

    // =-=-=-=-=-=-=-
    // extract the host location from the resource hierarchy
    std::string location;
    irods::error ret = irods::get_loc_for_hier_string( hier, location );
    if ( !ret.ok() ) {
        irods::log( PASSMSG( "rsPhyBundleColl - failed in get_loc_for_hier_string", ret ) );
        return -1;
    }



    rodsHostAddr_t rescAddr;
    bzero( &rescAddr, sizeof( rescAddr ) );

    rstrcpy( rescAddr.hostAddr, location.c_str(), NAME_LEN );
    rodsServerHost_t* rodsServerHost = 0;
    int remoteFlag = resolveHost( &rescAddr, &rodsServerHost );



    if ( remoteFlag == LOCAL_HOST ) {
        status = _rsPhyBundleColl( rsComm, phyBundleCollInp, destRescName );
    }
    else if ( remoteFlag == REMOTE_HOST ) {
        status = remotePhyBundleColl( rsComm, phyBundleCollInp, rodsServerHost );
    }
    else if ( remoteFlag < 0 ) {
        status = remoteFlag;
    }


    return status;
}
Example #22
0
int
irsPhyPathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp)
{
    int status;
    rescGrpInfo_t *rescGrpInfo = NULL;
    rodsServerHost_t *rodsServerHost = NULL;
    int remoteFlag;
    int rescCnt;
    rodsHostAddr_t addr;
    char *tmpStr = NULL;
    char *rescGroupName = NULL;
    rescInfo_t *tmpRescInfo = NULL;

    if ((tmpStr = getValByKey (&phyPathRegInp->condInput,
      COLLECTION_TYPE_KW)) != NULL && strcmp (tmpStr, UNMOUNT_STR) == 0) {
        status = unmountFileDir (rsComm, phyPathRegInp);
        return (status);
    } else if (tmpStr != NULL && (strcmp (tmpStr, HAAW_STRUCT_FILE_STR) == 0 ||
      strcmp (tmpStr, TAR_STRUCT_FILE_STR) == 0)) {
	status = structFileReg (rsComm, phyPathRegInp);
        return (status);
    } else if (tmpStr != NULL && strcmp (tmpStr, LINK_POINT_STR) == 0) {
        status = linkCollReg (rsComm, phyPathRegInp);
        return (status);
    }

    status = getRescInfo (rsComm, NULL, &phyPathRegInp->condInput,
      &rescGrpInfo);

    if (status < 0) {
	rodsLog (LOG_ERROR,
	  "rsPhyPathReg: getRescInfo error for %s, status = %d",
	  phyPathRegInp->objPath, status);
	return (status);
    }

    rescCnt = getRescCnt (rescGrpInfo);

    if (rescCnt != 1) {
        rodsLog (LOG_ERROR,
          "rsPhyPathReg: The input resource is not unique for %s",
          phyPathRegInp->objPath);
        return (SYS_INVALID_RESC_TYPE);
    }

    if ((rescGroupName = getValByKey (&phyPathRegInp->condInput,
      RESC_GROUP_NAME_KW)) != NULL) {
        status = getRescInGrp (rsComm, rescGrpInfo->rescInfo->rescName, 
	  rescGroupName, &tmpRescInfo);
	if (status < 0) {
            rodsLog (LOG_ERROR,
              "rsPhyPathReg: resc %s not in rescGrp %s for %s",
              rescGrpInfo->rescInfo->rescName, rescGroupName,
	      phyPathRegInp->objPath);
            return SYS_UNMATCHED_RESC_IN_RESC_GRP;
	}
    }

    memset (&addr, 0, sizeof (addr));
    
    rstrcpy (addr.hostAddr, rescGrpInfo->rescInfo->rescLoc, LONG_NAME_LEN);
    remoteFlag = resolveHost (&addr, &rodsServerHost);

    if (remoteFlag == LOCAL_HOST) {
        status = _rsPhyPathReg (rsComm, phyPathRegInp, rescGrpInfo, 
	  rodsServerHost);
    } else if (remoteFlag == REMOTE_HOST) {
        status = remotePhyPathReg (rsComm, phyPathRegInp, rodsServerHost);
    } else {
        if (remoteFlag < 0) {
            return (remoteFlag);
        } else {
            rodsLog (LOG_ERROR,
              "rsPhyPathReg: resolveHost returned unrecognized value %d",
               remoteFlag);
            return (SYS_UNRECOGNIZED_REMOTE_FLAG);
        }
    }

    return (status);
}
Example #23
0
void ClientUDP::run()
{
	//init();
	assert(init());

	//open();
	assert(open());

	//resolveHost();
	assert(resolveHost());

	//allocatePacket();
	assert(allocatePacket());

	//SDL_CreateWindow("Client Window", 0, 0, 100, 100, SDL_WINDOW_OPENGL);

	/* Main loop */
	m_quit = 0;
	while (!m_quit)
	{
		//while (SDL_PollEvent(&m_evt))
		//{
		//	m_clientPackage->e = m_evt;

		//	switch (m_clientPackage->e.type)
		//	{
		//	case SDL_KEYDOWN:
		//		printf("Key press detected\n");
		//		break;

		//	case SDL_KEYUP:
		//		printf("Key release detected\n");
		//		break;

		//	case SDL_MOUSEMOTION:
		//		printf("Mouse Moved\n");
		//		break;

		//	default:
		//		break;
		//	}
		//}

		//m_packet->len = (sizeof(Package));
		//m_packet->address.host = m_srvadd.host;	/* Set the destination host */
		//m_packet->address.port = m_srvadd.port;	/* And destination port */

		printf("Type Message: \n>");
		//scanf("%s", (char *)m_packet->data);

		std::getline(std::cin, m_input);

		m_packet->address.host = m_srvadd.host;	/* Set the destination host */
		m_packet->address.port = m_srvadd.port;	/* And destination port */

		m_packet->len = m_input.length() + 256;
		
		memcpy(m_packet->data, m_input.c_str(), m_packet->len);

		//memcpy(m_packet->data, m_clientPackage->data, sizeof(Package));

		if (!(SDLNet_UDP_Send(m_socketDescriptor, -1, m_packet) > 0))
		{
			printf("SDLNet_UDP_Send failed...\n");
		}
	}

	freePacket(*m_packet);
	SDLNet_Quit();
}
Example #24
0
/**
 * Same as eConnect() except you may the specify address family here (default is
 * AF_UNSPEC).
 * We couldn't just add the new family arg to eConnect because the original one
 * is pure virtual declared in EClientSocketBase. Thanks C++ design crap ...
 */
bool EPosixClientSocket::eConnect2( const char *host, unsigned int port,
	int clientId, int family )
{
	// already connected?
	if( m_fd >= 0) {
		assert(false); // for now we don't allow that
		return true;
	}

	// initialize Winsock DLL (only for Windows)
	if ( !SocketsInit())	{
		// Does this set errno?
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(),
			"Initializing Winsock DLL failed.");
		return false;
	}

	// use local machine if no host passed in
	if ( !( host && *host)) {
		host = "127.0.0.1";
	}

	// starting to connect to server
	struct addrinfo *aitop;

	int s = resolveHost( host, port, family, &aitop );
	if( s != 0 ) {
		SocketsDestroy();
		const char *err;
#ifdef HAVE_GETADDRINFO
		err = gai_strerror(s);
#else
		err = "Invalid address, hostname resolving not supported.";
#endif
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), err );
		return false;
	}

	int con_errno = 0;
	for( struct addrinfo *ai = aitop; ai != NULL; ai = ai->ai_next ) {

		// create socket
		m_fd = socket(ai->ai_family, ai->ai_socktype, 0);
		if( m_fd < 0) {
			con_errno = errno;
			continue;
		}

		/* Set socket O_NONBLOCK. If wanted we could handle errors
		   (portability!) We could even make O_NONBLOCK optional. */
		int sn = set_socket_nonblock( m_fd );
		assert( sn == 0 );

		// try to connect
		if( timeout_connect( m_fd, ai->ai_addr, ai->ai_addrlen ) < 0 ) {
			con_errno = errno;
			SocketClose(m_fd);
			m_fd = -1;
			continue;
		}
		/* successfully  connected */
		break;
	}

	freeaddrinfo(aitop);

	/* connection failed, tell the error which happened in our last try  */
	if( m_fd < 0 ) {
		const char *err = strerror(con_errno);
		SocketsDestroy();
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), err );
		return false;
	}

	// set client id
	setClientId( clientId);

	errno = 0;
	onConnectBase();
	if( !isOutBufferEmpty() ) {
		/* For now we consider it as error if it's not possible to send an
		   integer string within a single tcp packet. Here we don't know weather
		   ::send() really failed or not. If so then we hopefully still have
		   it's errno set.*/
		const char *err = (errno != 0) ? strerror(errno)
			: "Sending client id failed.";
		eDisconnect();
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), err );
		return false;
	}

	if( wait_socket( m_fd, WAIT_READ ) <= 0 ) {
		const char *err = (errno != 0) ? strerror(errno) : strerror(ENODATA);
		eDisconnect();
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), err );
		return false;
	}

	while( !isConnected() ) {
		assert( isSocketOK() ); // need to be handled if send() would destroy it
		if ( !checkMessagesConnect()) {
			const char *err = (errno != 0) ? strerror(errno)
				: "The remote host closed the connection.";
			eDisconnect();
			getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), err );
			return false;
		}
	}
	// successfully connected
	return true;
}
Example #25
0
// =-=-=-=-=-=-=-
// public - initialize the special local file system resource
    error resource_manager::init_local_file_system_resource( void ) {
        // =-=-=-=-=-=-=-
        // init the local fs resource
        resource_ptr resc;
        error err = init_from_type( LOCAL_USE_ONLY_RESOURCE_TYPE,
                                    LOCAL_USE_ONLY_RESOURCE,
                                    LOCAL_USE_ONLY_RESOURCE,
                                    "",
                                    resc );
        // =-=-=-=-=-=-=-
        // error check
        if ( !err.ok() ) {
            std::stringstream msg;
            msg << "resource_manager::init_local_file_system_resource - failed to create resource";
            return PASSMSG( msg.str(), err );
        }

        // =-=-=-=-=-=-=-
        // get the zone info for the local zone
        zoneInfo_t* zone_info = 0;
        getLocalZoneInfo( &zone_info );

        // =-=-=-=-=-=-=-
        // build a host addr struct to get the server host info
        char host_name[ MAX_NAME_LEN ];
        gethostname( host_name, MAX_NAME_LEN );

        rodsHostAddr_t addr;
        rstrcpy( addr.hostAddr, host_name, LONG_NAME_LEN );
        rstrcpy( addr.zoneName, const_cast<char*>( zone_info->zoneName ), NAME_LEN );

        rodsServerHost_t* tmpRodsServerHost = 0;
        if ( resolveHost( &addr, &tmpRodsServerHost ) < 0 ) {
            rodsLog( LOG_NOTICE, "procAndQueRescResult: resolveHost error for %s",
                     addr.hostAddr );
        }

        resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, tmpRodsServerHost );

        // =-=-=-=-=-=-=-
        // start filling in the properties
        resc->set_property<long>( RESOURCE_ID, 999 );
        resc->set_property<long>( RESOURCE_FREESPACE, 999 );
        resc->set_property<long>( RESOURCE_QUOTA, RESC_QUOTA_UNINIT );

        resc->set_property<std::string>( RESOURCE_ZONE,      zone_info->zoneName );
        resc->set_property<std::string>( RESOURCE_NAME,      LOCAL_USE_ONLY_RESOURCE );
        resc->set_property<std::string>( RESOURCE_LOCATION,  "localhost" );
        resc->set_property<std::string>( RESOURCE_TYPE,      LOCAL_USE_ONLY_RESOURCE_TYPE );
        resc->set_property<std::string>( RESOURCE_CLASS,     "cache" );
        resc->set_property<std::string>( RESOURCE_PATH,      LOCAL_USE_ONLY_RESOURCE_VAULT );
        resc->set_property<std::string>( RESOURCE_INFO,      "info" );
        resc->set_property<std::string>( RESOURCE_COMMENTS,  "comments" );
        resc->set_property<std::string>( RESOURCE_CREATE_TS, "999" );
        resc->set_property<std::string>( RESOURCE_MODIFY_TS, "999" );
        resc->set_property<std::string>( RESOURCE_CHILDREN,  "" );
        resc->set_property<std::string>( RESOURCE_PARENT,    "" );
        resc->set_property<std::string>( RESOURCE_CONTEXT,   "" );
        resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_UP );

        // =-=-=-=-=-=-=-
        // assign to the map
        resources_[ LOCAL_USE_ONLY_RESOURCE ] = resc;

        return SUCCESS();

    } // init_local_file_system_resource
Example #26
0
// =-=-=-=-=-=-=-
// public - take results from genQuery, extract values and create resources
    error resource_manager::process_init_results( genQueryOut_t* _result ) {
        // =-=-=-=-=-=-=-
        // extract results from query
        if ( !_result ) {
            return ERROR( SYS_INVALID_INPUT_PARAM, "_result parameter is null" );
        }

        // =-=-=-=-=-=-=-
        // values to extract from query
        sqlResult_t *rescId       = 0, *rescName      = 0, *zoneName   = 0, *rescType   = 0, *rescClass = 0;
        sqlResult_t *rescLoc      = 0, *rescVaultPath = 0, *freeSpace  = 0, *rescInfo   = 0;
        sqlResult_t *rescComments = 0, *rescCreate    = 0, *rescModify = 0, *rescStatus = 0;
        sqlResult_t *rescChildren = 0, *rescContext   = 0, *rescParent = 0, *rescObjCount = 0;

        // =-=-=-=-=-=-=-
        // extract results from query
        if ( ( rescId = getSqlResultByInx( _result, COL_R_RESC_ID ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_ID failed" );
        }

        if ( ( rescName = getSqlResultByInx( _result, COL_R_RESC_NAME ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_NAME failed" );
        }

        if ( ( zoneName = getSqlResultByInx( _result, COL_R_ZONE_NAME ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_ZONE_NAME failed" );
        }

        if ( ( rescType = getSqlResultByInx( _result, COL_R_TYPE_NAME ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_TYPE_NAME failed" );
        }

        if ( ( rescClass = getSqlResultByInx( _result, COL_R_CLASS_NAME ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_CLASS_NAME failed" );
        }

        if ( ( rescLoc = getSqlResultByInx( _result, COL_R_LOC ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_LOC failed" );
        }

        if ( ( rescVaultPath = getSqlResultByInx( _result, COL_R_VAULT_PATH ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_VAULT_PATH failed" );
        }

        if ( ( freeSpace = getSqlResultByInx( _result, COL_R_FREE_SPACE ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_FREE_SPACE failed" );
        }

        if ( ( rescInfo = getSqlResultByInx( _result, COL_R_RESC_INFO ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_INFO failed" );
        }

        if ( ( rescComments = getSqlResultByInx( _result, COL_R_RESC_COMMENT ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_COMMENT failed" );
        }

        if ( ( rescCreate = getSqlResultByInx( _result, COL_R_CREATE_TIME ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_CREATE_TIME failed" );
        }

        if ( ( rescModify = getSqlResultByInx( _result, COL_R_MODIFY_TIME ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_MODIFY_TIME failed" );
        }

        if ( ( rescStatus = getSqlResultByInx( _result, COL_R_RESC_STATUS ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_STATUS failed" );
        }

        if ( ( rescChildren = getSqlResultByInx( _result, COL_R_RESC_CHILDREN ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_CHILDREN failed" );
        }

        if ( ( rescContext = getSqlResultByInx( _result, COL_R_RESC_CONTEXT ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_CONTEXT failed" );
        }

        if ( ( rescParent = getSqlResultByInx( _result, COL_R_RESC_PARENT ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_PARENT failed" );
        }

        if ( ( rescObjCount = getSqlResultByInx( _result, COL_R_RESC_OBJCOUNT ) ) == NULL ) {
            return ERROR( UNMATCHED_KEY_OR_INDEX, "getSqlResultByInx for COL_R_RESC_OBJCOUNT failed" );
        }

        // =-=-=-=-=-=-=-
        // iterate through the rows, initialize a resource for each entry
        for ( int i = 0; i < _result->rowCnt; ++i ) {
            // =-=-=-=-=-=-=-
            // extract row values
            std::string tmpRescId        = &rescId->value[ rescId->len * i ];
            std::string tmpRescLoc       = &rescLoc->value[ rescLoc->len * i ];
            std::string tmpRescName      = &rescName->value[ rescName->len * i ];
            std::string tmpZoneName      = &zoneName->value[ zoneName->len * i ];
            std::string tmpRescType      = &rescType->value[ rescType->len * i ];
            std::string tmpRescInfo      = &rescInfo->value[ rescInfo->len * i ];
            std::string tmpFreeSpace     = &freeSpace->value[ freeSpace->len * i ];
            std::string tmpRescClass     = &rescClass->value[ rescClass->len * i ];
            std::string tmpRescCreate    = &rescCreate->value[ rescCreate->len * i ];
            std::string tmpRescModify    = &rescModify->value[ rescModify->len * i ];
            std::string tmpRescStatus    = &rescStatus->value[ rescStatus->len * i ];
            std::string tmpRescComments  = &rescComments->value[ rescComments->len * i ];
            std::string tmpRescVaultPath = &rescVaultPath->value[ rescVaultPath->len * i ];
            std::string tmpRescChildren  = &rescChildren->value[ rescChildren->len * i ];
            std::string tmpRescContext   = &rescContext->value[ rescContext->len * i ];
            std::string tmpRescParent    = &rescParent->value[ rescParent->len * i ];
            std::string tmpRescObjCount  = &rescObjCount->value[ rescObjCount->len * i ];

            // =-=-=-=-=-=-=-
            // create the resource and add properties for column values
            resource_ptr resc;
            error ret = load_resource_plugin( resc, tmpRescType, tmpRescName, tmpRescContext );
            if ( !ret.ok() ) {
                return PASSMSG( "Failed to load Resource Plugin", ret );
            }

            // =-=-=-=-=-=-=-
            // resolve the host name into a rods server host structure
            if ( tmpRescLoc != irods::EMPTY_RESC_HOST ) {
                rodsHostAddr_t addr;
                rstrcpy( addr.hostAddr, const_cast<char*>( tmpRescLoc.c_str() ), LONG_NAME_LEN );
                rstrcpy( addr.zoneName, const_cast<char*>( tmpZoneName.c_str() ), NAME_LEN );

                rodsServerHost_t* tmpRodsServerHost = 0;
                if ( resolveHost( &addr, &tmpRodsServerHost ) < 0 ) {
                    rodsLog( LOG_NOTICE, "procAndQueRescResult: resolveHost error for %s",
                             addr.hostAddr );
                }

                resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, tmpRodsServerHost );

            }
            else {
                resc->set_property< rodsServerHost_t* >( RESOURCE_HOST, 0 );
            }

            resc->set_property<long>( RESOURCE_ID, strtoll( tmpRescId.c_str(), 0, 0 ) );
            resc->set_property<long>( RESOURCE_FREESPACE, strtoll( tmpFreeSpace.c_str(), 0, 0 ) );
            resc->set_property<long>( RESOURCE_QUOTA, RESC_QUOTA_UNINIT );

            resc->set_property<std::string>( RESOURCE_ZONE,      tmpZoneName );
            resc->set_property<std::string>( RESOURCE_NAME,      tmpRescName );
            resc->set_property<std::string>( RESOURCE_LOCATION,  tmpRescLoc );
            resc->set_property<std::string>( RESOURCE_TYPE,      tmpRescType );
            resc->set_property<std::string>( RESOURCE_CLASS,     tmpRescClass );
            resc->set_property<std::string>( RESOURCE_PATH,      tmpRescVaultPath );
            resc->set_property<std::string>( RESOURCE_INFO,      tmpRescInfo );
            resc->set_property<std::string>( RESOURCE_COMMENTS,  tmpRescComments );
            resc->set_property<std::string>( RESOURCE_CREATE_TS, tmpRescCreate );
            resc->set_property<std::string>( RESOURCE_MODIFY_TS, tmpRescModify );
            resc->set_property<std::string>( RESOURCE_CHILDREN,  tmpRescChildren );
            resc->set_property<std::string>( RESOURCE_PARENT,    tmpRescParent );
            resc->set_property<std::string>( RESOURCE_CONTEXT,   tmpRescContext );
            resc->set_property<std::string>( RESOURCE_OBJCOUNT,  tmpRescObjCount );

            if ( tmpRescStatus == std::string( RESC_DOWN ) ) {
                resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_DOWN );
            }
            else {
                resc->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_UP );
            }

            // =-=-=-=-=-=-=-
            // add new resource to the map
            resources_[ tmpRescName ] = resc;

        } // for i


        return SUCCESS();

    } // process_init_results
Example #27
0
int
rsGetHostForGet (rsComm_t *rsComm, dataObjInp_t *dataObjInp,
char **outHost)
{
    int status;
    rescInfo_t *myRescInfo;
    char *myResc;
    rodsServerHost_t *rodsServerHost;
    rodsHostAddr_t addr;
    specCollCache_t *specCollCache = NULL;
    char *myHost;
    int remoteFlag;

    *outHost = NULL;

#if 0
    if (isLocalZone (dataObjInp->objPath) == 0) {
	/* it is a remote zone. better connect to this host */
	*outHost = strdup (THIS_ADDRESS);
	return 0;
    }
#endif

    resolveLinkedPath (rsComm, dataObjInp->objPath, &specCollCache, NULL);
    if (isLocalZone (dataObjInp->objPath) == 0) {
#if 0
        /* it is a remote zone. better connect to this host */
        *outHost = strdup (THIS_ADDRESS);
        return 0;
#else
        resolveLinkedPath (rsComm, dataObjInp->objPath, &specCollCache,
          &dataObjInp->condInput);
        remoteFlag = getAndConnRcatHost (rsComm, SLAVE_RCAT, 
	  dataObjInp->objPath, &rodsServerHost);
        if (remoteFlag < 0) {
            return (remoteFlag);
        } else if (remoteFlag == LOCAL_HOST) {
	    *outHost = strdup (THIS_ADDRESS);
            return 0;
	} else {
            status = rcGetHostForGet (rodsServerHost->conn, dataObjInp, 
	      outHost);
	    if (status >= 0 && *outHost != NULL && 
	      strcmp (*outHost, THIS_ADDRESS) == 0) {
		free (*outHost);
		*outHost = strdup (rodsServerHost->hostName->name);
	    }
            return (status);
	}
#endif
    }
    status = getSpecCollCache (rsComm, dataObjInp->objPath, 0, &specCollCache);
    if (status >= 0) {
	if (specCollCache->specColl.collClass == MOUNTED_COLL) {
            status = resolveResc (specCollCache->specColl.resource, 
	      &myRescInfo);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "rsGetHostForGet: resolveResc error for %s, status = %d",
                 specCollCache->specColl.resource, status);
		return status;
            }
	    /* mounted coll will fall through with myRescInfo */
        } else {
            *outHost = strdup (THIS_ADDRESS);
            return 0;
	}
    } else if ((myResc = getValByKey (&dataObjInp->condInput, RESC_NAME_KW)) 
      != NULL && resolveResc (myResc, &myRescInfo) >= 0) {
	/* user specified a resource. myRescInfo set and fall through */
    } else {
	/* normal type */
        status = getBestRescForGet (rsComm, dataObjInp, &myRescInfo);
	if (myRescInfo == NULL) {
	    *outHost = strdup (THIS_ADDRESS);
            return status;
	}
    }

    /* get down here when we got a valid myRescInfo */

    if (getRescClass (myRescInfo) == COMPOUND_CL) {
        *outHost = strdup (THIS_ADDRESS);
        return 0;
    }

    bzero (&addr, sizeof (addr));
    rstrcpy (addr.hostAddr, myRescInfo->rescLoc, NAME_LEN);
    status = resolveHost (&addr, &rodsServerHost);
    if (status < 0) return status;
    if (rodsServerHost->localFlag == LOCAL_HOST) {
        *outHost = strdup (THIS_ADDRESS);
        return 0;
    }

    myHost = getSvrAddr (rodsServerHost);
    if (myHost != NULL) {
	*outHost = strdup (myHost);
        return 0;
    } else {
        *outHost = NULL;
	return SYS_INVALID_SERVER_HOST;
    }
}
Example #28
0
int
initZone( rsComm_t *rsComm ) {
    rodsServerHost_t *tmpRodsServerHost;
    rodsServerHost_t *masterServerHost = NULL;
    rodsServerHost_t *slaveServerHost = NULL;
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    int status, i;
    sqlResult_t *zoneName, *zoneType, *zoneConn, *zoneComment;
    char *tmpZoneName, *tmpZoneType, *tmpZoneConn;//, *tmpZoneComment;

    irods::server_properties& props = irods::server_properties::getInstance();
    irods::error ret = props.capture_if_needed();
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    std::string zone_name;
    ret = props.get_property <
          std::string > (
              irods::CFG_ZONE_NAME,
              zone_name );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();

    }

    /* configure the local zone first or rsGenQuery would not work */

    tmpRodsServerHost = ServerHostHead;
    while ( tmpRodsServerHost != NULL ) {
        if ( tmpRodsServerHost->rcatEnabled == LOCAL_ICAT ) {
            tmpRodsServerHost->zoneInfo = ZoneInfoHead;
            masterServerHost = tmpRodsServerHost;
        }
        else if ( tmpRodsServerHost->rcatEnabled == LOCAL_SLAVE_ICAT ) {
            tmpRodsServerHost->zoneInfo = ZoneInfoHead;
            slaveServerHost = tmpRodsServerHost;
        }
        tmpRodsServerHost = tmpRodsServerHost->next;
    }
    ZoneInfoHead->masterServerHost = masterServerHost;
    ZoneInfoHead->slaveServerHost = slaveServerHost;

    memset( &genQueryInp, 0, sizeof( genQueryInp ) );
    addInxIval( &genQueryInp.selectInp, COL_ZONE_NAME, 1 );
    addInxIval( &genQueryInp.selectInp, COL_ZONE_TYPE, 1 );
    addInxIval( &genQueryInp.selectInp, COL_ZONE_CONNECTION, 1 );
    addInxIval( &genQueryInp.selectInp, COL_ZONE_COMMENT, 1 );
    genQueryInp.maxRows = MAX_SQL_ROWS;

    status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );

    clearGenQueryInp( &genQueryInp );

    if ( status < 0 ) {
        freeGenQueryOut( &genQueryOut );
        rodsLog( LOG_NOTICE,
                 "initZone: rsGenQuery error, status = %d", status );
        return status;
    }

    if ( genQueryOut == NULL ) {
        rodsLog( LOG_NOTICE,
                 "initZone: NULL genQueryOut" );
        return CAT_NO_ROWS_FOUND;
    }

    if ( ( zoneName = getSqlResultByInx( genQueryOut, COL_ZONE_NAME ) ) == NULL ) {
        rodsLog( LOG_NOTICE,
                 "initZone: getSqlResultByInx for COL_ZONE_NAME failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }
    if ( ( zoneType = getSqlResultByInx( genQueryOut, COL_ZONE_TYPE ) ) == NULL ) {
        rodsLog( LOG_NOTICE,
                 "initZone: getSqlResultByInx for COL_ZONE_TYPE failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }
    if ( ( zoneConn = getSqlResultByInx( genQueryOut, COL_ZONE_CONNECTION ) ) == NULL ) {
        rodsLog( LOG_NOTICE,
                 "initZone: getSqlResultByInx for COL_ZONE_CONNECTION failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }
    if ( ( zoneComment = getSqlResultByInx( genQueryOut, COL_ZONE_COMMENT ) ) == NULL ) {
        rodsLog( LOG_NOTICE,
                 "initZone: getSqlResultByInx for COL_ZONE_COMMENT failed" );
        return UNMATCHED_KEY_OR_INDEX;
    }

    for ( i = 0; i < genQueryOut->rowCnt; i++ ) {
        rodsHostAddr_t addr;

        tmpZoneName = &zoneName->value[zoneName->len * i];
        tmpZoneType = &zoneType->value[zoneType->len * i];
        tmpZoneConn = &zoneConn->value[zoneConn->len * i];
        //tmpZoneComment = &zoneComment->value[zoneComment->len * i];
        if ( strcmp( tmpZoneType, "local" ) == 0 ) {
            if ( strcmp( zone_name.c_str(), tmpZoneName ) != 0 ) {
                rodsLog( LOG_ERROR,
                         "initZone: zoneName in env %s does not match %s in icat ",
                         zone_name.c_str(), tmpZoneName );
            }
            /* fillin rodsZone if it is not defined */
            if ( strlen( rsComm->proxyUser.rodsZone ) == 0 ) {
                rstrcpy( rsComm->proxyUser.rodsZone, tmpZoneName, NAME_LEN );
            }
            if ( strlen( rsComm->clientUser.rodsZone ) == 0 ) {
                rstrcpy( rsComm->clientUser.rodsZone, tmpZoneName, NAME_LEN );
            }
            continue;
        }
        else if ( strlen( tmpZoneConn ) <= 0 ) {
            rodsLog( LOG_ERROR,
                     "initZone: connection info for zone %s not configured",
                     tmpZoneName );
            continue;
        }

        memset( &addr, 0, sizeof( addr ) );
        /* assume address:port */
        parseHostAddrStr( tmpZoneConn, &addr );
        if ( addr.portNum == 0 ) {
            addr.portNum = ZoneInfoHead->portNum;
        }
        rstrcpy( addr.zoneName, tmpZoneName, NAME_LEN ); // JMC - bacport 4562
        status = resolveHost( &addr, &tmpRodsServerHost );
        if ( status < 0 ) {
            rodsLog( LOG_ERROR,
                     "initZone: resolveHost error for %s for zone %s. status = %d",
                     addr.hostAddr, tmpZoneName, status );
            continue;
        }
        if ( tmpRodsServerHost->rcatEnabled == LOCAL_ICAT ) {
            rodsLog( LOG_ERROR,
                     "initZone: address %s for remote zone %s already in use",
                     tmpZoneConn, tmpZoneName );
            continue;
        }

        tmpRodsServerHost->rcatEnabled = REMOTE_ICAT;
        /* REMOTE_ICAT is always on a remote host even if it is one the same
         * host, but will be on different port */
        tmpRodsServerHost->localFlag = REMOTE_HOST; // JMC - bacport 4562
        queZone( tmpZoneName, addr.portNum, tmpRodsServerHost, NULL );
    }

    freeGenQueryOut( &genQueryOut );

    return 0;
}
// =-=-=-=-=-=-=-
// plugin - resolve resource plugin for this object
    error structured_object::resolve(
        const std::string& _interface,
        plugin_ptr&        _ptr ) {
        // =-=-=-=-=-=-=-
        // check to see if this is for a resource plugin
        // resolution, otherwise it is an error
        if ( RESOURCE_INTERFACE != _interface ) {
            std::stringstream msg;
            msg << "structured_object does not support a [";
            msg << _interface;
            msg << "] for plugin resolution";
            return ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
        }

        // =-=-=-=-=-=-=-
        // we now support tar file ( structfile ) and
        // msso file types.  this needs to be moved out
        std::string plugin_type;
        if ( TAR_STRUCT_FILE_T == spec_coll_type_ ) {
            plugin_type = "structfile";

        }
        else if ( MSSO_STRUCT_FILE_T == spec_coll_type_ ) {
            plugin_type = "mssofile";

        }
        else {
            std::stringstream msg;
            msg << "unsupported structured type: "
                << spec_coll_type_;
            return ERROR(
                       SYS_INVALID_INPUT_PARAM,
                       msg.str() );
        }

        // =-=-=-=-=-=-=-
        // try to find the resource based on the type
        resource_ptr resc_ptr;
        irods::error err = resc_mgr.resolve(
                               plugin_type,
                               resc_ptr );
        if ( err.ok() ) {
            _ptr = boost::dynamic_pointer_cast< resource >( resc_ptr );
            return SUCCESS();

        }
        else {
            // =-=-=-=-=-=-=-
            // otherwise create a resource and add properties from this object
            error init_err = resc_mgr.init_from_type(
                                 plugin_type,        // type
                                 plugin_type,        // key
                                 "struct_file_inst", // inst name
                                 "empty context",    // context
                                 resc_ptr );
            if ( !init_err.ok() ) {
                return PASSMSG( "failed to load resource plugin", init_err );

            }

        } // if !ok

        // =-=-=-=-=-=-=-
        // found ourselves a plugin, fill in the properties
        rodsServerHost_t* tmpRodsServerHost = 0;
        int status = resolveHost( &addr_, &tmpRodsServerHost );
        if ( status < 0 ) {
            std::stringstream msg;
            msg << "resolveHost error for [";
            msg << addr_.hostAddr;
            return ERROR( status, msg.str() );
        }

        resc_ptr->set_property< rodsServerHost_t* >( RESOURCE_HOST, tmpRodsServerHost );

        resc_ptr->set_property<long>( RESOURCE_ID, -1 );
        resc_ptr->set_property<long>( RESOURCE_FREESPACE, -1 );
        resc_ptr->set_property<long>( RESOURCE_QUOTA, -1 );

        resc_ptr->set_property<int>( RESOURCE_STATUS, INT_RESC_STATUS_UP );

        resc_ptr->set_property<std::string>( RESOURCE_ZONE,      addr_.zoneName );
        resc_ptr->set_property<std::string>( RESOURCE_NAME,      plugin_type );
        resc_ptr->set_property<std::string>( RESOURCE_LOCATION,  addr_.hostAddr );
        resc_ptr->set_property<std::string>( RESOURCE_TYPE,      plugin_type );
        resc_ptr->set_property<std::string>( RESOURCE_CLASS,     "cache" );
        resc_ptr->set_property<std::string>( RESOURCE_PATH,      physical_path_ );
        resc_ptr->set_property<std::string>( RESOURCE_INFO,      "blank info" );
        resc_ptr->set_property<std::string>( RESOURCE_COMMENTS,  "blank comments" );
        resc_ptr->set_property<std::string>( RESOURCE_CREATE_TS, "create?" );
        resc_ptr->set_property<std::string>( RESOURCE_MODIFY_TS, "modify?" );

        _ptr = boost::dynamic_pointer_cast< resource >( resc_ptr );
        return SUCCESS();

    } // resolve
Example #30
0
int
initRcatServerHostByFile() {
    typedef irods::configuration_parser::object_t object_t;
    typedef irods::configuration_parser::array_t  array_t;

    irods::server_properties& props = irods::server_properties::getInstance();
    irods::error ret = props.capture_if_needed();
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    array_t prop_arr;
    ret = props.get_property <
          array_t > (
              irods::CFG_RE_RULEBASE_SET_KW,
              prop_arr );

    std::string prop_str;
    if ( ret.ok() ) {
        std::string rule_arr;
        for ( size_t i = 0;
                i < prop_arr.size();
                ++i ) {
            try {
                rule_arr += boost::any_cast< std::string >(
                                prop_arr[i][ irods::CFG_FILENAME_KW ] );
            }
            catch ( boost::bad_any_cast& _e ) {
                rodsLog(
                    LOG_ERROR,
                    "initRcatServerHostByFile - failed to cast rule base file name entry to string" );
                continue;
            }
            rule_arr += prop_str + ",";
        }

        rule_arr = rule_arr.substr( 0, rule_arr.size() - 1 );

        snprintf(
            reRuleStr,
            sizeof( reRuleStr ),
            "%s",
            rule_arr.c_str() );

    }
    else {
        std::string prop_str;
        ret = props.get_property< std::string >(
                  RE_RULESET_KW,
                  prop_str );
        if ( ret.ok() ) {
            snprintf(
                reRuleStr,
                sizeof( reRuleStr ),
                "%s",
                prop_str.c_str() );

        }
        else {
            irods::log( PASS( ret ) );
            return ret.code();
        }

    }

    ret = props.get_property <
          array_t > (
              irods::CFG_RE_FUNCTION_NAME_MAPPING_SET_KW,
              prop_arr );
    if ( ret.ok() ) {
        std::string rule_arr;
        for ( size_t i = 0;
                i < prop_arr.size();
                ++i ) {
            try {
                rule_arr += boost::any_cast< std::string >(
                                prop_arr[i][ irods::CFG_FILENAME_KW ] );
            }
            catch ( boost::bad_any_cast& _e ) {
                rodsLog(
                    LOG_ERROR,
                    "initRcatServerHostByFile - failed to cast rule function file name entry to string" );
                continue;
            }
            rule_arr += prop_str + ",";
        }

        rule_arr = rule_arr.substr( 0, rule_arr.size() - 1 );

        snprintf(
            reFuncMapStr,
            sizeof( reFuncMapStr ),
            "%s",
            rule_arr.c_str() );

    }
    else {
        ret = props.get_property< std::string >(
                  RE_FUNCMAPSET_KW,
                  prop_str );
        if ( ret.ok() ) {
            snprintf(
                reFuncMapStr,
                sizeof( reFuncMapStr ),
                "%s",
                prop_str.c_str() );

        }
        else {
            irods::log( PASS( ret ) );
            return ret.code();
        }
    }

    ret = props.get_property <
          array_t > (
              irods::CFG_RE_DATA_VARIABLE_MAPPING_SET_KW,
              prop_arr );
    if ( ret.ok() ) {
        std::string rule_arr;
        for ( size_t i = 0;
                i < prop_arr.size();
                ++i ) {
            try {
                rule_arr += boost::any_cast< std::string >(
                                prop_arr[i][ irods::CFG_FILENAME_KW ] );
            }
            catch ( boost::bad_any_cast& _e ) {
                rodsLog(
                    LOG_ERROR,
                    "initRcatServerHostByFile - failed to cast rule data variable file name entry to string" );
                continue;
            }
            rule_arr += prop_str + ",";
        }

        rule_arr = rule_arr.substr( 0, rule_arr.size() - 1 );

        snprintf(
            reVariableMapStr,
            sizeof( reVariableMapStr ),
            "%s",
            rule_arr.c_str() );

    }
    else {
        ret = props.get_property< std::string >(
                  RE_VARIABLEMAPSET_KW,
                  prop_str );
        if ( ret.ok() ) {
            snprintf(
                reVariableMapStr,
                sizeof( reVariableMapStr ),
                "%s",
                prop_str.c_str() );

        }
        else {
            irods::log( PASS( ret ) );
            return ret.code();
        }
    }

    ret = props.get_property< std::string >(
              KERBEROS_NAME_KW,
              prop_str );
    if ( ret.ok() ) {
        snprintf(
            KerberosName,
            sizeof( KerberosName ),
            "%s",
            prop_str.c_str() );

    }

    ret = props.get_property< std::string >(
              ICAT_HOST_KW,
              prop_str );
    if ( ret.ok() ) {
        rodsHostAddr_t    addr;
        memset( &addr, 0, sizeof( addr ) );
        rodsServerHost_t* tmp_host = 0;
        snprintf(
            addr.hostAddr,
            sizeof( addr.hostAddr ),
            "%s",
            prop_str.c_str() );
        int rem_flg = resolveHost(
                          &addr,
                          &tmp_host );
        if ( rem_flg < 0 ) {
            rodsLog( LOG_SYS_FATAL,
                     "initRcatServerHostByFile: resolveHost error for %s, status = %d",
                     addr.hostAddr,
                     rem_flg );
            return rem_flg;
        }
        tmp_host->rcatEnabled = LOCAL_ICAT;

    }
    else {
        irods::log( PASS( ret ) );
        return ret.code();
    }

    // re host
    // xmsg host
    ret = props.get_property< std::string >(
              irods::CFG_IRODS_XMSG_HOST_KW,
              prop_str );
    if ( ret.ok() ) {
        rodsHostAddr_t    addr;
        memset( &addr, 0, sizeof( addr ) );
        rodsServerHost_t* tmp_host = 0;
        snprintf(
            addr.hostAddr,
            sizeof( addr.hostAddr ),
            "%s",
            prop_str.c_str() );
        int rem_flg = resolveHost(
                          &addr,
                          &tmp_host );
        if ( rem_flg < 0 ) {
            rodsLog( LOG_SYS_FATAL,
                     "initRcatServerHostByFile: resolveHost error for %s, status = %d",
                     addr.hostAddr,
                     rem_flg );
            return rem_flg;
        }
        tmp_host->xmsgHostFlag = 1;
    }

    // slave icat host

    ret = props.get_property< std::string >(
              irods::CFG_ZONE_KEY_KW,
              prop_str );
    if ( ret.ok() ) {
        snprintf( localSID, sizeof( localSID ), "%s", prop_str.c_str() );
    }
    else {
        ret = props.get_property< std::string >(
                  LOCAL_ZONE_SID_KW,
                  prop_str );
        if ( ret.ok() ) {
            snprintf( localSID, sizeof( localSID ), "%s", prop_str.c_str() );
        }
        else {
            irods::log( PASS( ret ) );
            return ret.code();
        }
    }

    // try for new federation config
    std::string neg_key;
    ret = props.get_property <
          std::string > (
              irods::CFG_NEGOTIATION_KEY_KW,
              neg_key );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
        return ret.code();
    }
    array_t fed_arr;
    ret = props.get_property <
          array_t > (
              irods::CFG_FEDERATION_KW,
              fed_arr );
    if ( ret.ok() ) {
        for ( size_t i = 0; i < fed_arr.size(); ++i ) {
            object_t& obj = fed_arr[ i ];
            std::string fed_zone_key, fed_zone_name, fed_zone_negotiation_key;
            try {
                fed_zone_key = boost::any_cast< std::string >(
                                   obj[ irods::CFG_ZONE_KEY_KW ] );
                fed_zone_name = boost::any_cast< std::string >(
                                    obj[irods::CFG_ZONE_NAME_KW ] );
                fed_zone_negotiation_key = boost::any_cast< std::string >(
                                               obj[ irods::CFG_NEGOTIATION_KEY_KW ] );
            }
            catch ( boost::bad_any_cast& _e ) {
                rodsLog(
                    LOG_ERROR,
                    "initRcatServerHostByFile - failed to cast federation entry to string" );
                continue;
            }

            // store in remote_SID_key_map
            remote_SID_key_map[fed_zone_name] = std::make_pair( fed_zone_key, fed_zone_negotiation_key );

        } // for i
    }
    else {
        // try the old remote sid config
        std::vector< std::string > rem_sids;
        ret = props.get_property <
              std::vector< std::string > > (
                  REMOTE_ZONE_SID_KW,
                  rem_sids );
        if ( ret.ok() ) {
            for ( size_t i = 0; i < rem_sids.size(); ++i ) {
                // legacy format should be zone_name-SID
                size_t pos = rem_sids[i].find( "-" );
                if ( pos == std::string::npos ) {
                    rodsLog( LOG_ERROR, "initRcatServerHostByFile - Unable to parse remote SID %s", rem_sids[i].c_str() );
                }
                else {
                    // store in remote_SID_key_map
                    std::string fed_zone_name = rem_sids[i].substr( 0, pos );
                    std::string fed_zone_key = rem_sids[i].substr( pos + 1 );
                    // use our negotiation key for the old configuration
                    remote_SID_key_map[fed_zone_name] = std::make_pair( fed_zone_key, neg_key );
                }
            }
        }

    } // else

    return 0;
}