Example #1
0
nsresult
NfcConnector::CreateStreamSocket(struct sockaddr* aAddress,
                                 socklen_t* aAddressLength,
                                 int& aStreamFd)
{
  ScopedClose fd;

  nsresult rv = CreateSocket(fd.rwget());
  if (NS_FAILED(rv)) {
    return rv;
  }
  rv = SetSocketFlags(fd);
  if (NS_FAILED(rv)) {
    return rv;
  }
  if (aAddress && aAddressLength) {
    rv = CreateAddress(*aAddress, *aAddressLength);
    if (NS_FAILED(rv)) {
      return rv;
    }
  }

  aStreamFd = fd.forget();

  return NS_OK;
}
Example #2
0
nsresult
KeyStoreConnector::CreateListenSocket(struct sockaddr* aAddress,
                                      socklen_t* aAddressLength,
                                      int& aListenFd)
{
  ScopedClose fd;

  nsresult rv = CreateSocket(fd.rwget());
  if (NS_FAILED(rv)) {
    return rv;
  }
  rv = SetSocketFlags(fd);
  if (NS_FAILED(rv)) {
    return rv;
  }
  if (aAddress && aAddressLength) {
    rv = CreateAddress(*aAddress, *aAddressLength);
    if (NS_FAILED(rv)) {
      return rv;
    }
  }

  // Allow access for wpa_supplicant (different user, different group)
  //
  // TODO: Improve this by setting specific user/group for
  //       wpa_supplicant by calling |fchmod| and |fchown|.
  //
  chmod(KEYSTORE_SOCKET_PATH, S_IRUSR|S_IWUSR|
                              S_IRGRP|S_IWGRP|
                              S_IROTH|S_IWOTH);

  aListenFd = fd.forget();

  return NS_OK;
}
/***************************************************************************
 ** ReadSites --
 **    This function asks the user for the name of the data
 ** file to be used, opens it, reads the website Addresses and
 ** sorts them. The totals are then computed and the tables printed using
 ** other functions within this one.
 **      Inputs: None
 **      Outputs: 4 arrays fll of websites and printed results.
 ***************************************************************************/
void ReadSites()
{
   FILE *ifp;
   char filename[SIZE] = "cat";
   char temp[SIZE] = "dog";
   int j = 0;

   /*The  four arrays are declared*/
   WEBSITE t, comSites[SIZE], govSites[SIZE], eduSites[SIZE], netSites[SIZE];

   int TotalNonUniqueSites = 0, TotalUniqueSites = 0, TotalTimeLogged = 0;
   int TotalFunSites = 0, TotalSearchSites = 0, TotalEducationSites = 0;
   int  TotalNewsSites = 0, *pTotalNewsSites, *pTotalNonUniqueSites;
   int *pTotalUniqueSites, *pTotalTimeLogged, *pTotalFunSites; 
   int *pTotalSearchSites, *pTotalEducationSites;

   /*The pointers are set to point to the their corresponding values*/
   pTotalNonUniqueSites = &TotalNonUniqueSites;
   pTotalUniqueSites = &TotalUniqueSites;
   pTotalTimeLogged = &TotalTimeLogged;
   pTotalFunSites = &TotalFunSites;
   pTotalSearchSites = &TotalSearchSites;
   pTotalEducationSites = &TotalEducationSites;
   pTotalNewsSites = &TotalNewsSites;

   /*The are filled with dummy values*/
   FillArray(comSites);
   FillArray(netSites);
   FillArray(eduSites);
   FillArray(govSites);

   /*Asks the user for the file name*/
   fprintf(stdout, "\nPlease enter the file name: ");
   fscanf(stdin, "%s", filename);
   ifp = fopen(filename, "r");

   /*If the file cannot exit and give error message*/
   if(ifp == NULL)
   {
      fprintf(stderr, "The file could not be opened.");
      exit(-1);
   }

   /*Scans every thing in the file until it reaches the end*/
   while(fscanf(ifp, "%s %s %d", temp, t.siteType, &t.seconds) != EOF)
     {
	/*Breaks the string temp  into access code, domain name*/
	/* and domain ending and stores the in the temporary structure*/
	t.webAddress = CreateAddress(temp);
	
	/*Depending on the first letter of the domain ending, stores*/
	/*them into the appropriate array*/
	if(t.webAddress.domainEnding[0] == 'c')
	{
	   /*Finds the index of wherever the website is supposed to go*/
	   j = IsPresent(comSites, t);
	   
	   /*Stores the website in the proper location*/
	   comSites[j].webAddress = t.webAddress;
	   
	   /*Stores the siteType in the corresponding location*/
	   strcpy(comSites[j].siteType, t.siteType);
	   
	   /*Adds the number of hits and the seconds*/
	   comSites[j].hits += 1;
	   comSites[j].seconds += t.seconds;
	} 
	else if(t.webAddress.domainEnding[0] == 'g')
	{
	   j = IsPresent(govSites, t);
	   
	   govSites[j].webAddress = t.webAddress;
	   strcpy(govSites[j].siteType, t.siteType);
	   govSites[j].hits += 1;
	   govSites[j].seconds += t.seconds;
	}
	else if(t.webAddress.domainEnding[0] == 'n')
	{
	   j = IsPresent(netSites, t);
	   
	   netSites[j].webAddress = t.webAddress;
	   strcpy(netSites[j].siteType, t.siteType);
	   netSites[j].hits += 1;
	   netSites[j].seconds += t.seconds;
	 }
       else
	 {
	   j = IsPresent(eduSites, t);
	   
	   eduSites[j].webAddress = t.webAddress;
	   strcpy(eduSites[j].siteType, t.siteType);
	   eduSites[j].hits += 1;
	   eduSites[j].seconds += t.seconds;
	 } 
     }  
   
   /*Sorts the arrays*/
   SortArray(eduSites, ArrayLength(eduSites));
   SortArray(govSites, ArrayLength(govSites));
   SortArray(comSites, ArrayLength(comSites));
   SortArray(netSites, ArrayLength(netSites));
   
   /*Computes the totals using data from all the arrays*/
   ComputeTotals(comSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(eduSites, pTotalUniqueSites, pTotalNonUniqueSites, 
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(netSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   ComputeTotals(govSites, pTotalUniqueSites, pTotalNonUniqueSites,
		 pTotalTimeLogged, pTotalFunSites, pTotalSearchSites,
		 pTotalEducationSites, pTotalNewsSites);

   /*Prints the results of the read*/
   PrintTable(comSites, netSites, eduSites, govSites);
   
   /*Caclulates the percentages and prints them*/
   CalcStats(TotalUniqueSites, TotalFunSites, TotalSearchSites,
	     TotalNewsSites, TotalEducationSites, TotalTimeLogged,
	     TotalNonUniqueSites);
   
   return;
}
Example #4
0
 const Address AddressFactory::CreateAddress(const QString &surl) const
 {
   return CreateAddress(QUrl(surl));
 }