Exemple #1
0
bool MainWindow::initializeSettings()
{
    bool status=false;

    logger(alert, "\nAlert:\tProgram Starting\n");

    //Check configfile exists if not, note and move on.
    if (!(QFile(userHomeDir + ".config/sign/sign.conf").exists()))
    {
        logger(error,"ERROR:\tMissing config file. Does ~/.config/sign/sign.conf exist?");
        return false;
    }

    //Go get the config settings
    QSettings appSettings;
    serverUrl = appSettings.value("serverUrl").toString();
    defaultPage = appSettings.value("defaultPage").toString();
    defaultPageDuration = appSettings.value("defaultDuration").toInt();
    serverConf = appSettings.value("serverConf").toString();
    logLevel = appSettings.value("logLevel").toInt();
    logToFile = appSettings.value("logToFile").toBool();

    //Read the server Config
    if(readServerConfig())
    {
        status=true;
    }

    return status;
}
int main()
{
	// Initialize the winsock library
	MyTcpSocket::initialize();
        
	// get client's information (assume neither the name nor the address is given)
	winLog << endl;
	winLog << "Retrieve the localHost [CLIENT] name and address:" << endl;
	winLog.flush();

	//以下是客户端程序,所有服务器IP从配置文件中读取
	//*********************************************************************************
	//  【①】   客户端HostInfo(hostent)
    MyHostInfo clientInfo;
	string clientName = clientInfo.getHostName();
    string clientIPAddress = clientInfo.getHostIPAddress();
    cout << "Name: " << clientName << endl;
    cout << "Address: " << clientIPAddress << endl;
	winLog << "		==> Name: " << clientName << endl;
	winLog << "		==> Address: " << clientIPAddress << endl;

	//*********************************************************************************
	// get server's IP address and name 【服务器IP,从配置文件读取】
	string serverIPAddress = "";
	readServerConfig(serverIPAddress);
	winLog << endl;
	winLog << "Retrieve the remoteHost [SERVER] name and address:" << endl;
	winLog << "		==> the given address is " << serverIPAddress << endl;

	//  【②】   服务器端HostInfo(hostent)
    MyHostInfo serverInfo(serverIPAddress,ADDRESS);	
	string serverName = serverInfo.getHostName();
    cout << "Name: " << serverName << endl;
    cout << "Address: " << serverIPAddress << endl;
	winLog << "		==> Name: " << serverName << endl;
	winLog << "		==> Address: " << serverIPAddress << endl;

	//*********************************************************************************
    // create the socket for client
    MyTcpSocket myClient(PORTNUM);
	cout << myClient;
	winLog << "client configuation: " << endl;
	winLog << myClient;

	//*********************************************************************************
    // connect to the server.
	cout   << "connecting to the server [" << serverName << "] ... " << endl;
	winLog << "connecting to the server [" << serverName << "] ... " << endl;
	myClient.connectToServer(serverIPAddress,ADDRESS);

	int recvBytes = 0;
	while (1)
	{
		// send message to server
		char messageToServer[MAX_MSG_LEN+1];
		memset(messageToServer,0,sizeof(messageToServer));
		cout << "[SEND] ";
		cin.getline(messageToServer,MAX_MSG_LEN);

		winLog << "[SEND] " << messageToServer << endl;
		myClient.sendMessage(string(messageToServer));
		if ( !string(messageToServer).compare("Quit") || !string(messageToServer).compare("quit") ) break;

		// receive message from server
		string messageFromServer = "";
        recvBytes = myClient.recieveMessage(messageFromServer);
		if ( recvBytes == -99 ) break;

		cout   << "[RECV:" << serverName << "]: " << messageFromServer << endl;
		winLog << "[RECV:" << serverName << "]: " << messageFromServer << endl;

	}

    return EXIT_SUCCESS;
}
Exemple #3
0
int
main(int argc, char **argv) {
   int status;
   rsComm_t *Comm;
   /*   rErrMsg_t errMsg;*/
   rodsArguments_t myRodsArgs;
   char *mySubName;
   char *myName;
   int didOne;
   rodsServerConfig_t serverConfig;

   Comm = (rsComm_t*)malloc (sizeof (rsComm_t));
   memset (Comm, 0, sizeof (rsComm_t));

   parseCmdLineOpt(argc, argv, "", 0, &myRodsArgs);

   rodsLogLevel(LOG_NOTICE);

   rodsLogSqlReq(1);

   if (argc < 2) {
      printf("Usage: test_chl testName [args...]\n");
      exit(3);
   }

   status = getRodsEnv (&myEnv);
   if (status < 0) {
      rodsLog (LOG_ERROR, "main: getRodsEnv error. status = %d",
	       status);
      exit (1);
   }

   if (strstr(myEnv.rodsDebug, "CAT") != NULL) {
      chlDebug(myEnv.rodsDebug);
   }

   memset(&serverConfig, 0, sizeof(serverConfig));
   status = readServerConfig(&serverConfig);

   strncpy(Comm->clientUser.userName, myEnv.rodsUserName, 
	   sizeof Comm->clientUser.userName);

   strncpy(Comm->clientUser.rodsZone, myEnv.rodsZone, 
	   sizeof Comm->clientUser.rodsZone);

   /*
   char rodsUserName[NAME_LEN];
   char rodsZone[NAME_LEN];

     userInfo_t clientUser;
    char userName[NAME_LEN];
    char rodsZone[NAME_LEN];
   */
   if ((status = chlOpen(serverConfig.DBUsername,
			 serverConfig.DBPassword)) != 0) {
        rodsLog (LOG_SYS_FATAL,
		 "initInfoWithRcat: chlopen Error. Status = %d",
		 status);
        free(Comm); // cppcheck - Memory leak: Comm
        return (status);
   }

   didOne=0;
   if (strcmp(argv[1],"reg")==0) {
      status = testRegDataObj(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }
   if (strcmp(argv[1],"regmulti")==0) {
      status = testRegDataMulti(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   if (strcmp(argv[1],"mod")==0) {
      status = testModDataObjMeta(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"mod2")==0) {
      status = testModDataObjMeta2(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"modr")==0) {
      status = testModRuleMeta(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"modc")==0) {
      status = testModColl(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmrule")==0) {
      status = testDelRule(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"modrfs")==0) { 
      status = testModResourceFreeSpace(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"rep")==0) {
      if (argc < 6) {
	 printf("too few arguments\n");
	 exit(1);
      }
      status = testRegReplica(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   /*
   if (strcmp(argv[1],"cml")==0) {
      status = testCml(Comm);
      didOne=1;
   }
   */

   if (strcmp(argv[1],"rmuser")==0) {
      status = testDelUser(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"mkdir")==0) {
      status = testRegColl(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmdir")==0) {
      status = testDelColl(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"sql")==0) {
      status = testSimpleQ(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"rm")==0) {
      status = testDelFile(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmtrash")==0) {
      status = testDelFileTrash(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"rmpriv")==0) {
      status = testDelFilePriv(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"chmod")==0) {
      status = testChmod(Comm, argv[2], argv[3], argv[4], argv[5]);
      didOne=1;
   }

   if (strcmp(argv[1],"regrule")==0) {
      status = testRegRule(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"rename")==0) {
      status = testRename(Comm, argv[2], argv[3]);
      testCurrent(Comm);  /* exercise this as part of rename;
                             testCurrent needs a SQL context */
      didOne=1;
   }

   if (strcmp(argv[1],"login")==0) {
      status = testLogin(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"move")==0) {
      status = testMove(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"checkauth")==0) {
      status = testCheckAuth(Comm, argv[2], argv[3], argv[4]);
      didOne=1;
   }

   if (strcmp(argv[1],"temppw")==0) {
      status = testTempPw(Comm);
      didOne=1;
   }

   if (strcmp(argv[1],"tpc")==0) {
      status = testTempPwConvert(argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"tpw")==0) {
      status = testTempPwCombined(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"tpwforother")==0) {
      status = testTempPwForOther(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (strcmp(argv[1],"serverload")==0) {
      status = testServerLoad(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"purgeload")==0) {
      status = testPurgeServerLoad(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"serverdigest")==0) {
      status = testServerLoadDigest(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"purgedigest")==0) {
      status = testPurgeServerLoadDigest(Comm, argv[2]);
      didOne=1;
   }

   if (strcmp(argv[1],"checkquota")==0) {
      if (argc < 5) {
	 status = testCheckQuota(Comm, argv[2], argv[3],
				 NULL, NULL);
      }
      else {
	 status = testCheckQuota(Comm, argv[2], argv[3],
				 argv[4], argv[5]);
      }
      didOne=1;
   }

   if (strcmp(argv[1],"open")==0) {
      int i;
      for (i=0;i<3;i++) {
	 status = chlClose();
	 if (status) {
	    printf ("close %d error", i);
	 }
      
	 if ((status = chlOpen(serverConfig.DBUsername,
			       serverConfig.DBPassword)) != 0) {
	    rodsLog (LOG_SYS_FATAL,
		     "initInfoWithRcat: chlopen %d Error. Status = %d",
		     i, status);
	    return (status);
	 }
      }
      didOne=1;
   }

   if (strcmp(argv[1],"addrule")==0) {
     status = testAddRule(Comm, argv[2], argv[3],
			     argv[4], argv[5],
			  argv[6], argv[7]);
     didOne=1;
   }

   if (strcmp(argv[1],"versionrulebase")==0) {
     status = testVersionRuleBase(Comm, argv[2]);
     didOne=1;
   }

   if (strcmp(argv[1],"versiondvmbase")==0) {
     status = testVersionDvmBase(Comm, argv[2]);
     didOne=1;
   }

   if (strcmp(argv[1],"versionfnmbase")==0) {
     status = testVersionFnmBase(Comm, argv[2]);
     didOne=1;
   }

   if (strcmp(argv[1],"insfnmtable")==0) {
      status = testInsFnmTable(Comm, argv[2], argv[3], argv[4], argv[5] );
      didOne=1;
   }

   if (strcmp(argv[1],"insdvmtable")==0) {
      status = testInsDvmTable(Comm, argv[2], argv[3], argv[4], argv[5] );
      didOne=1;
   }

   if (strcmp(argv[1],"insmsrvctable")==0) {
      status = testInsMsrvcTable(Comm, argv[2], argv[3], argv[4], argv[5],
			       argv[6], argv[7], argv[8], argv[9], argv[10]);
      if (status==0) {
	/* do it a second time to test another logic path and
           different SQL.  Since no commit is part of the chl
           function, and there is not corresponding Delete call, this
           is an easy way to do this. */
	status = testInsMsrvcTable(Comm, argv[2], argv[3], argv[4], argv[5],
			   argv[6], argv[7], argv[8], argv[9], argv[10]);
      }
     didOne=1;
   }
   if (strcmp(argv[1],"getlocalzone")==0) {
      status = testGetLocalZone(Comm, argv[2]);
      didOne=1;
   }
   if (strcmp(argv[1],"getpampw")==0) {
      status = testGetPamPw(Comm, argv[2], argv[3]);
      didOne=1;
   }

   if (status != 0) {
      /*
      if (Comm->rError) {
	 rError_t *Err;
         rErrMsg_t *ErrMsg;
	 int i, len;
	 Err = Comm->rError;
	 len = Err->len;
	 for (i=0;i<len;i++) {
	    ErrMsg = Err->errMsg[i];
	    rodsLog(LOG_ERROR, "Level %d: %s",i, ErrMsg->msg);
	 }
      }
      */
      myName = rodsErrorName(status, &mySubName);
      rodsLog (LOG_ERROR, "%s failed with error %d %s %s", argv[1],
	       status, myName, mySubName);
   }
   else {
      if (didOne) printf("Completed successfully\n");
   }

   if (didOne==0) {
      printf("Unknown test type: %s\n", argv[1]);
   }

   exit(status);
}
Exemple #4
0
int
main(int argc, char **argv) {
   int mode;
   rodsServerConfig_t serverConfig;
   int status;
   rodsEnv myEnv;

   /* remove this call or change to LOG_NOTICE for more verbosity */
   rodsLogLevel(LOG_ERROR);

   /* this will cause the sql to be printed, comment this out to skip it  */
   rodsLogSqlReq(1);

   mode = 0;
   if (strcmp(argv[1],"1")==0) mode=1;
   if (strcmp(argv[1],"2")==0) mode=2;
   if (strcmp(argv[1],"3")==0) mode=3;
   if (strcmp(argv[1],"4")==0) mode=4;
   if (strcmp(argv[1],"5")==0) mode=5;
   if (strcmp(argv[1],"6")==0) mode=6;

   memset((char *)&myEnv, 0, sizeof(myEnv));
   status = getRodsEnv (&myEnv);
   if (status < 0) {
      rodsLog (LOG_ERROR, "main: getRodsEnv error. status = %d",
	       status);
      exit (1);
   }
   
   if (strstr(myEnv.rodsDebug, "CAT") != NULL) {
      chlDebug(myEnv.rodsDebug);
   }

   memset(&serverConfig, 0, sizeof(serverConfig));
   status = readServerConfig(&serverConfig);

   if ((status = chlOpen(serverConfig.DBUsername,
			 serverConfig.DBPassword)) != 0) {
      rodsLog (LOG_SYS_FATAL,
	       "chlopen Error. Status = %d",
	       status);
      return (status);
   }
   if (mode==1) {
      status = doTest1(argv[2], argv[3], argv[4], argv[5]);
      if (status <0) exit(2);
      exit(0);
   }
   if (mode==2) {
      status = doTest2(argv[2], argv[3], argv[4], argv[5]);
      if (status <0) exit(2);
      exit(0);
   }
   if (mode==3) {
      status = doTest3(argv[2], argv[3], argv[4], argv[5]);
      if (status <0) exit(2);
      exit(0);
   }
   if (mode==4) {
      status = doTest4(argv[2], argv[3], argv[4], argv[5]);
      if (status <0) exit(2);
      exit(0);
   }
   if (mode==5) {
      status = doTest5(argv[2], argv[3], argv[4], argv[5], argv[6], argv[7]);
      if (status <0) exit(2);
      exit(0);
   }
   if (mode==6) {
      status = doTest6(argv[2], argv[3], argv[4], argv[5]);
      if (status <0) exit(2);
      exit(0);
   }
   exit(0);
}