void SetProxyPref(const nsAString& aHostPort, const char* aPref,
                  const char* aPortPref, nsIPrefBranch* aPrefs)
{
  nsCOMPtr<nsIURI> uri;
  nsAutoCString host;
  int32_t portValue;

  // try parsing it as a URI first
  if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), aHostPort)) &&
      NS_SUCCEEDED(uri->GetHost(host)) &&
      !host.IsEmpty() &&
      NS_SUCCEEDED(uri->GetPort(&portValue))) {
    SetUnicharPref(aPref, NS_ConvertUTF8toUTF16(host), aPrefs);
    aPrefs->SetIntPref(aPortPref, portValue);
  }
  else {
    nsAutoString hostPort(aHostPort);
    int32_t portDelimOffset = hostPort.RFindChar(':');
    if (portDelimOffset > 0) {
      SetUnicharPref(aPref, Substring(hostPort, 0, portDelimOffset), aPrefs);
      nsAutoString port(Substring(hostPort, portDelimOffset + 1));
      nsresult error;
      portValue = port.ToInteger(&error);
      aPrefs->SetIntPref(aPortPref, portValue);
    }
    else
      SetUnicharPref(aPref, hostPort, aPrefs);
  }
}
Пример #2
0
void IcyConnector::ProcessHeaders(const QString &hdrs)
{
    QStringList f0;
    QStringList f1;
    QString txt;

    f0=hdrs.split("\r\n");
    if(f0[0]!="OK2") {
        Log(LOG_WARNING,
            QString().sprintf("login to \"%s:%d\" rejected: %s",
                              (const char *)hostHostname().toUtf8(),
                              0xFFFF&hostPort(),
                              (const char *)f0[0].toUtf8()));
        return;
    }
    icy_authenticated=true;
    WriteHeader("icy-name: "+streamName());
    WriteHeader("icy-genre: "+streamGenre());
    WriteHeader("icy-pub: "+QString().sprintf("%d",streamPublic()));
    WriteHeader("icy-br: "+QString().sprintf("%u",audioBitrate()));
    if(icy_protocol_version==1) {
        WriteHeader("icy-url: "+streamUrl());
    }
    WriteHeader("icy-irc: "+streamIrc());
    WriteHeader("icy-icq: "+streamIcq());
    WriteHeader("icy-aim: "+streamAim());
    WriteHeader("Content-Type: "+contentType());
    WriteHeader("");

    setConnected(true);
}
Пример #3
0
const char* Client::connect(const char* httpURL)
{
  if(nullptr != httpURL)
    {
      connect(std::string(httpURL));
    }
  return hostPort();
}
Пример #4
0
void dumpCollection(Parameters& params) {
	DBClientConnection c;
	string hostPort(params.getHost());
	if (hostPort.find(':') == string::npos) {
		hostPort += ":";
		hostPort += to_string(params.getPort());
	}
	c.connect(hostPort);
	time_t t;
	time(&t);

	int documentCount = c.count(params.getDbCollection());

	if (params.isDebug()) {
		cout << "{ " << params.getDbCollection() << ".count: "
			<< documentCount << " }\n";
	}

	string docPrefixString(params.getDbCollection());
//	docIndex += "{";
//	docIndex += to_string(i++);
//	docIndex += "}";

	unique_ptr<DBClientCursor> cursor = c.query(params.getDbCollection(), BSONObj());

	unique_ptr<IBSONRenderer> renderer;
	switch (params.getStyle()) {
	case STYLE_DOTTED:
		renderer = unique_ptr<IBSONRenderer>(new BSONDotNotationDump(params, docPrefixString));
		break;
	case STYLE_TREE:
		renderer = unique_ptr<IBSONRenderer>(new BSONObjectTypeDump(params, docPrefixString));
		break;
	case STYLE_JSON:
	case STYLE_JSONPACKED:
		renderer = unique_ptr<IBSONRenderer>(new JSONDump(params, "  "));
		break;
	default:
		throw std::logic_error("ISE: Undefined STYLE!");
		break;
	}
	if (renderer) {
		renderer->setOutputStream(cout);
		renderer->begin(NULL);
		int documentIndex = 0;
		while (cursor->more()) {
			const BSONObj& o = cursor->next(); // Get the BSON Object
			renderer->render(o, documentIndex++, documentCount);
		}
		renderer->end(NULL);
	} else {
		throw std::logic_error("ISE: Undefined renderer!");
	}
}
Пример #5
0
void IcyConnector::socketDisconnectedData()
{
    if(!icy_authenticated) {
        Log(LOG_WARNING,
            QString().sprintf("login to \"%s:%d\" rejected: bad password",
                              (const char *)hostHostname().toUtf8(),
                              0xFFFF&hostPort()));
    }
    icy_authenticated=false;
    setConnected(false);
}
Пример #6
0
void
nsCertOverrideService::GetHostWithPort(const nsACString & aHostName, PRInt32 aPort, nsACString& _retval)
{
    nsCAutoString hostPort(aHostName);
    if (aPort == -1) {
        aPort = 443;
    }
    if (!hostPort.IsEmpty()) {
        hostPort.AppendLiteral(":");
        hostPort.AppendInt(aPort);
    }
    _retval.Assign(hostPort);
}
Пример #7
0
void IcyConnector::socketReadyReadData()
{
    char data[1501];
    int64_t n;

    while((n=icy_socket->read(data,1500))>0) {
        data[n]=0;
        for(int64_t i=0; i<n; i++) {
            switch(0xFF&data[i]) {
            case 10:
                if((icy_recv_buffer.length()>=2)&&
                        (icy_recv_buffer.toUtf8().at(icy_recv_buffer.length()-3)==13)) {
                    icy_recv_buffer=icy_recv_buffer.left(icy_recv_buffer.length()-1);
                    ProcessHeaders(icy_recv_buffer);
                    icy_recv_buffer="";
                }
                else {
                    icy_recv_buffer+=data[i];
                }
                break;

            case 13:
                if(QString(icy_recv_buffer)=="invalid password") {
                    Log(LOG_WARNING,
                        QString().sprintf("login to \"%s:%d\" rejected: invalid password",
                                          (const char *)hostHostname().toUtf8(),
                                          0xFFFF&hostPort()));
                }
                else {
                    icy_recv_buffer+=data[i];
                }
                break;

            default:
                icy_recv_buffer+=data[i];
                break;
            }
        }
    }
}
Пример #8
0
BOOL LLURI::defaultPort() const
{
	return isDefault(mScheme, hostPort());
}
Пример #9
0
void HlsConnector::RotateMediaFile()
{
  //
  // Update working files
  //
  fclose(hls_media_handle);
  hls_media_datetimes[hls_sequence_back]=
    QDateTime(QDate::currentDate(),QTime::currentTime());
  hls_media_durations[hls_sequence_back]=
    (double)hls_media_frames/(double)audioSamplerate();
  if((hls_sequence_back-hls_sequence_head)>=HLS_MINIMUM_SEGMENT_QUAN) {
    // Schedule garbage collection
    hls_media_killtimes[hls_sequence_head++]=hls_total_media_frames+
      (HLS_MINIMUM_SEGMENT_QUAN+1)*HLS_SEGMENT_SIZE*audioSamplerate();
  }
  WritePlaylistFile();

  //
  // HTTP Uploads
  //
  hls_conveyor->push(this,hls_temp_dir->path()+"/"+hls_media_filename,
		     "http://"+hostHostname()+
		     QString().sprintf(":%u",hostPort())+
		     hls_put_directory+"/",ConveyorEvent::PutMethod);
  unlink((hls_temp_dir->path()+"/"+hls_media_filename).toUtf8());
  hls_conveyor->push(this,hls_playlist_filename,
		     "http://"+hostHostname()+hls_put_directory+"/",
		     ConveyorEvent::PutMethod);
  unlink(hls_playlist_filename.toUtf8());

  //
  // Take out the trash
  //
  std::map<int,uint64_t>::iterator ci=hls_media_killtimes.begin();
  while(ci!=hls_media_killtimes.end()) {
    if(ci->second<hls_total_media_frames) {
      std::map<int,double>::iterator cj=hls_media_durations.begin();
      while(cj!=hls_media_durations.end()) {
	if(cj->first==ci->first) {
	  hls_media_durations.erase(cj++);
	}
	else {
	  ++cj;
	}
      }
      std::map<int,QDateTime>::iterator dj=hls_media_datetimes.begin();
      while(dj!=hls_media_datetimes.end()) {
	if(dj->first==ci->first) {
	  hls_media_datetimes.erase(dj++);
	}
	else {
	  ++dj;
	}
      }
      hls_conveyor->push(this,"","http://"+hostHostname()+hls_put_directory+"/"+
			 GetMediaFilename(ci->first),
			 ConveyorEvent::DeleteMethod);
      hls_media_killtimes.erase(ci++);
    }
    else {
      ++ci;
    }
  }

  //
  // Initialize for next segment
  //
  hls_sequence_back++;
  hls_media_frames=0;
  //hls_media_killname=hls_media_filename;
  hls_media_filename=GetMediaFilename(hls_sequence_back);
  if((hls_media_handle=
      fopen((hls_temp_dir->path()+"/"+hls_media_filename).toUtf8(),"w"))==
     NULL) {
    Log(LOG_WARNING,
	QString().sprintf("unable to write media data to \"%s\" [%s]",
	   (const char *)(hls_temp_dir->path()+"/"+hls_media_filename).toUtf8(),
			  strerror(errno)));
  }
#ifndef HLS_OMIT_ID3_TIMESTAMPS
  uint8_t id3_header[HLS_ID3_HEADER_SIZE];
  GetStreamTimestamp(id3_header,hls_total_media_frames);
  fwrite(id3_header,1,HLS_ID3_HEADER_SIZE,hls_media_handle);
#endif  // HLS_OMIT_ID3_TIMESTAMPS
}