コード例 #1
0
ファイル: usbdb.cpp プロジェクト: KDE/kde-workspace
USBDB::USBDB() {
	QString db = "/usr/share/hwdata/usb.ids"; /* on Fedora */
	if (!QFile::exists(db))
		db = KStandardDirs::locate("data", "kcmusb/usb.ids");
	if (db.isEmpty())
		return;

	QFile f(db);

	if (f.open(QIODevice::ReadOnly)) {
		QTextStream ts(&f);
		ts.setCodec("UTF-8");

		QString line, name;
		int id=0, subid=0, protid=0;
		QRegExp vendor("[0-9a-fA-F]+ ");
		QRegExp product("\\s+[0-9a-fA-F]+ ");
		QRegExp cls("C [0-9a-fA-F][0-9a-fA-F]");
		QRegExp subclass("\\s+[0-9a-fA-F][0-9a-fA-F]  ");
		QRegExp prot("\\s+[0-9a-fA-F][0-9a-fA-F]  ");
		while (!ts.atEnd()) {
			line = ts.readLine();
			if (line.left(1) == "#" || line.trimmed().isEmpty())
				continue;

			// skip AT lines
			if (line.left(2) == "AT")
				continue;

			if (cls.indexIn(line) == 0 && cls.matchedLength() == 4) {
				id = line.mid(2,2).toInt(0, 16);
				name = line.mid(4).trimmed();
				_classes.insert(QString("%1").arg(id), name);
			} else if (prot.indexIn(line) == 0 && prot.matchedLength() > 5) {
				line = line.trimmed();
				protid = line.left(2).toInt(0, 16);
				name = line.mid(4).trimmed();
				_classes.insert(QString("%1-%2-%3").arg(id).arg(subid).arg(protid), name);
			} else if (subclass.indexIn(line) == 0 && subclass.matchedLength() > 4) {
				line = line.trimmed();
				subid = line.left(2).toInt(0, 16);
				name = line.mid(4).trimmed();
				_classes.insert(QString("%1-%2").arg(id).arg(subid), name);
			} else if (vendor.indexIn(line) == 0 && vendor.matchedLength() == 5) {
				id = line.left(4).toInt(0, 16);
				name = line.mid(6);
				_ids.insert(QString("%1").arg(id), name);
			} else if (product.indexIn(line) == 0 && product.matchedLength() > 5) {
				line = line.trimmed();
				subid = line.left(4).toInt(0, 16);
				name = line.mid(6);
				_ids.insert(QString("%1-%2").arg(id).arg(subid), name);
			}

		}

		f.close();
	}
}
コード例 #2
0
ファイル: PIDUtils.cpp プロジェクト: denglert/PKPCorrel
void PIDStudy::InitializeFits()
{

	for (int multBin = 0; multBin < nMultiplicityBins; multBin++)
	for (int PBin=0; PBin < nPBins_lin; PBin++)
	{	


		TF1 pion("pion", "gaus(0)", 2.0, 4.0);
		pion.SetParameter(0,10000);
		pion.SetParameter(1,2.8);
		pion.SetParameter(2,0.2);

		TF1 kaon("kaon", "gaus(0)", 3.0, 6.0);
		kaon.SetParameter(0,2000);
		kaon.SetParameter(1,4);
		kaon.SetParameter(2,0.2);

		TF1 prot("prot", "gaus(0)", 5.0, 8.0);
		prot.SetParameter(0,1000);
		prot.SetParameter(1,7);
		prot.SetParameter(2,0.4);

		// "R" means only using fit range.
		//dEdxDistr_log[multBin][PBin]->Fit(&pion, "R");
		//dEdxDistr_log[multBin][PBin]->Fit(&kaon, "R");
		//dEdxDistr_log[multBin][PBin]->Fit(&prot, "R");

		double pion_amp = pion.GetParameter(0);
		double pion_pos = pion.GetParameter(1);
		double pion_sig = pion.GetParameter(2);

		double kaon_amp = kaon.GetParameter(0);
		double kaon_pos = kaon.GetParameter(1);
		double kaon_sig = kaon.GetParameter(2);

		double prot_amp = prot.GetParameter(0);
		double prot_pos = prot.GetParameter(1);
		double prot_sig = prot.GetParameter(2);

 	   // Pion
		dEdxDistr_log_Fit[multBin][PBin]->SetParameter(0,pion_amp);
		dEdxDistr_log_Fit[multBin][PBin]->SetParameter(1,pion_pos);
		dEdxDistr_log_Fit[multBin][PBin]->SetParameter(2,pion_sig);

		dEdxDistr_log_Fit[multBin][PBin]->SetParameter(3,kaon_amp);
		dEdxDistr_log_Fit[multBin][PBin]->SetParameter(4,kaon_pos);
		dEdxDistr_log_Fit[multBin][PBin]->SetParameter(5,kaon_sig);

		dEdxDistr_log_Fit[multBin][PBin]->SetParameter(6,prot_amp);
		dEdxDistr_log_Fit[multBin][PBin]->SetParameter(7,prot_pos);
		dEdxDistr_log_Fit[multBin][PBin]->SetParameter(8,prot_sig);
	}

}
コード例 #3
0
ファイル: json.c プロジェクト: MartinNowak/GDC
void EnumMember::toJsonBuffer(OutBuffer *buf)
{
    //printf("EnumMember::toJsonBuffer()\n");
    buf->writestring("{\n");

    JsonProperty(buf, Pname, toChars());
    JsonProperty(buf, Pkind, kind());

    if (prot())
        JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);

    if (comment)
        JsonProperty(buf, Pcomment, (const char *)comment);

    if (loc.linnum)
        JsonProperty(buf, Pline, loc.linnum);

    JsonRemoveComma(buf);
    buf->writestring("}\n");
}
コード例 #4
0
int CUrlRichEditCtrl::AddProtocol(LPCTSTR szProtocol, BOOL bWantNotify)
{
	int nExist = MatchProtocol(szProtocol);
	
	if (nExist == -1)
	{
		PROTOCOL prot(szProtocol, bWantNotify);
		return m_aProtocols.Add(prot);
	}
	
	return nExist;
}
コード例 #5
0
ファイル: tree.c プロジェクト: KhasMek/android_external_tree
char *fillinfo(char *buf, struct _info *ent)
{
  int n;
  buf[n=0] = 0;
  #ifdef __USE_FILE_OFFSET64
  if (inodeflag) n += sprintf(buf," %7lld",(long long)ent->inode);
  #else
  if (inodeflag) n += sprintf(buf," %7ld",(long int)ent->inode);
  #endif
  if (devflag) n += sprintf(buf+n, " %3d", (int)ent->dev);
  #ifdef __EMX__
  if (pflag) n += sprintf(buf+n, " %s",prot(ent->attr));
  #else
  if (pflag) n += sprintf(buf+n, " %s", prot(ent->mode));
  #endif
  if (uflag) n += sprintf(buf+n, " %-8.32s", uidtoname(ent->uid));
  if (gflag) n += sprintf(buf+n, " %-8.32s", gidtoname(ent->gid));
  if (sflag) n += psize(buf+n,ent->size);
  if (Dflag) n += sprintf(buf+n, " %s", do_date(cflag? ent->ctime : ent->mtime));

  return buf;
}
コード例 #6
0
ファイル: json.c プロジェクト: 1100110/dmd
void Dsymbol::jsonProperties(JsonOut *json)
{
    if (!isTemplateDeclaration()) // TemplateDeclaration::kind() acts weird sometimes
    {
        json->property("name", toChars());
        json->property("kind", kind());
    }

    if (prot() != PROTpublic)
        json->property("protection", Pprotectionnames[prot()]);

    json->property("comment", (const char *)comment);

    json->property("line", &loc);

#if 0
    if (!isModule())
    {
        Module *module = getModule();
        if (module)
        {
            json->propertyStart("module");
            json->objectStart();
            module->jsonProperties(json);
            json->objectEnd();
        }

        Module *accessModule = getAccessModule();
        if (accessModule && accessModule != module)
        {
            json->propertyStart("accessModule");
            json->objectStart();
            accessModule->jsonProperties(json);
            json->objectEnd();
        }
    }
#endif
}
コード例 #7
0
ファイル: ws_world.cpp プロジェクト: proton/ireon
WorldMobProtPtr WSWorld::getMobPrototype(String& type)
{
   std::map<String,WorldMobProtPtr>::iterator it = m_mobPrototypesCache.find(type);
	if( it != m_mobPrototypesCache.end() )
		return (*it).second;

	WorldMobProtPtr prot(new CWorldMobPrototype);
	if(prot->load(type))
	{
		m_mobPrototypesCache.insert(std::pair<String,WorldMobProtPtr>(type,prot));
		CLog::instance()->log(CLog::msgFlagResources, CLog::msgLvlInfo,__FUNCTION__,_("Mob prototype '%s' added to cache."), type.c_str());
		return prot;
	} else {
	 	return WorldMobProtPtr();
	}
};
コード例 #8
0
ファイル: xml.c プロジェクト: execjosh/tree
void xml_fillinfo(struct _info *ent)
{
  #ifdef __USE_FILE_OFFSET64
  if (inodeflag) fprintf(outfile," inode=\"%lld\"",(long long)ent->inode);
  #else
  if (inodeflag) fprintf(outfile," inode=\"%ld\"",(long int)ent->inode);
  #endif
  if (devflag) fprintf(outfile, " dev=\"%d\"", (int)ent->dev);
  #ifdef __EMX__
  if (pflag) fprintf(outfile, " mode=\"%04o\" prot=\"%s\"",ent->attr, prot(ent->attr));
  #else
  if (pflag) fprintf(outfile, " mode=\"%04o\" prot=\"%s\"", ent->mode & (S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID|S_ISVTX), prot(ent->mode));
  #endif
  if (uflag) fprintf(outfile, " user=\"%s\"", uidtoname(ent->uid));
  if (gflag) fprintf(outfile, " group=\"%s\"", gidtoname(ent->gid));
  if (sflag) fprintf(outfile, " size=\"%lld\"", (long long int)(ent->size));
  if (Dflag) fprintf(outfile, " time=\"%s\"", do_date(cflag? ent->ctime : ent->mtime));
}
コード例 #9
0
ファイル: tocvdebug.c プロジェクト: John-Colvin/dmd
int VarDeclaration::cvMember(unsigned char *p)
{
    int nwritten = 0;

    //printf("VarDeclaration::cvMember(p = %p) '%s'\n", p, toChars());

    if (type->toBasetype()->ty == Ttuple)
        return 0;

    char *id = toChars();

    if (!p)
    {
        if (isField())
        {
            if (config.fulltypes == CV8)
                nwritten += 2;
            nwritten += 6 + cv_stringbytes(id);
            nwritten += cv4_numericbytes(offset);
        }
        else if (isStatic())
        {
            if (config.fulltypes == CV8)
                nwritten += 2;
            nwritten += 6 + cv_stringbytes(id);
        }
        nwritten = cv_align(NULL, nwritten);
    }
    else
    {
        idx_t typidx = cv_typidx(type->toCtype());
        unsigned attribute = PROTtoATTR(prot());
        assert((attribute & ~3) == 0);
        switch (config.fulltypes)
        {
            case CV8:
                if (isField())
                {
                    TOWORD(p,LF_MEMBER_V3);
                    TOWORD(p + 2,attribute);
                    TOLONG(p + 4,typidx);
                    cv4_storenumeric(p + 8, offset);
                    nwritten = 8 + cv4_numericbytes( offset);
                    nwritten += cv_namestring(p + nwritten, id);
                }
                else if (isStatic())
                {
                    TOWORD(p,LF_STMEMBER_V3);
                    TOWORD(p + 2,attribute);
                    TOLONG(p + 4,typidx);
                    nwritten = 8;
                    nwritten += cv_namestring(p + nwritten, id);
                }
                break;

            case CV4:
                if (isField())
                {
                    TOWORD(p,LF_MEMBER);
                    TOWORD(p + 2,typidx);
                    TOWORD(p + 4,attribute);
                    cv4_storenumeric(p + 6, offset);
                    nwritten = 6 + cv4_numericbytes( offset);
                    nwritten += cv_namestring(p + nwritten, id);
                }
                else if (isStatic())
                {
                    TOWORD(p,LF_STMEMBER);
                    TOWORD(p + 2,typidx);
                    TOWORD(p + 4,attribute);
                    nwritten = 6;
                    nwritten += cv_namestring(p + nwritten, id);
                }
                break;

             default:
                assert(0);
        }

        nwritten = cv_align(p + nwritten, nwritten);
#ifdef DEBUG
        assert(nwritten == cvMember(NULL));
#endif
    }
    return nwritten;
}
コード例 #10
0
ファイル: tocvdebug.c プロジェクト: John-Colvin/dmd
int FuncDeclaration::cvMember(unsigned char *p)
{
    int nwritten = 0;

    //printf("FuncDeclaration::cvMember() '%s'\n", toChars());

    if (!type)                  // if not compiled in,
        return 0;               // skip it

    char *id = toChars();

    if (!p)
    {
        nwritten = 2 + 2 + cgcv.sz_idx + cv_stringbytes(id);
        nwritten = cv_align(NULL, nwritten);
        return nwritten;
    }
    else
    {
        int count = 0;
        int mlen = 2;
        {
            if (introducing)
                mlen += 4;
            mlen += cgcv.sz_idx * 2;
            count++;
        }

        // Allocate and fill it in
        debtyp_t *d = debtyp_alloc(mlen);
        unsigned char *q = d->data;
        TOWORD(q,config.fulltypes == CV8 ? LF_METHODLIST_V2 : LF_METHODLIST);
        q += 2;
//      for (s = sf; s; s = s->Sfunc->Foversym)
        {
            unsigned attribute = PROTtoATTR(prot());

            /* 0*4 vanilla method
             * 1*4 virtual method
             * 2*4 static method
             * 3*4 friend method
             * 4*4 introducing virtual method
             * 5*4 pure virtual method
             * 6*4 pure introducing virtual method
             * 7*4 reserved
             */

            if (isStatic())
                attribute |= 2*4;
            else if (isVirtual())
            {
                if (introducing)
                {
                    if (isAbstract())
                        attribute |= 6*4;
                    else
                        attribute |= 4*4;
                }
                else
                {
                    if (isAbstract())
                        attribute |= 5*4;
                    else
                        attribute |= 1*4;
                }
            }
            else
                attribute |= 0*4;

            TOIDX(q,attribute);
            q += cgcv.sz_idx;
            TOIDX(q, cv4_memfunctypidx(this));
            q += cgcv.sz_idx;
            if (introducing)
            {   TOLONG(q, vtblIndex * Target::ptrsize);
                q += 4;
            }
        }
        assert(q - d->data == mlen);

        idx_t typidx = cv_debtyp(d);
        if (typidx)
        {
            switch (config.fulltypes)
            {
                case CV8:
                    TOWORD(p,LF_METHOD_V3);
                    goto Lmethod;
                case CV4:
                    TOWORD(p,LF_METHOD);
                Lmethod:
                    TOWORD(p + 2,count);
                    nwritten = 4;
                    TOIDX(p + nwritten, typidx);
                    nwritten += cgcv.sz_idx;
                    nwritten += cv_namestring(p + nwritten, id);
                    break;

                default:
                    assert(0);
            }
        }
        nwritten = cv_align(p + nwritten, nwritten);
#ifdef DEBUG
        assert(nwritten == cvMember(NULL));
#endif
    }
    return nwritten;
}
コード例 #11
0
int main(int argc, char **argv)
{
	try
	{
    	std::string host = "localhost";
		if (argc > 1)
			host = argv[1];

		unsigned port = 32000;
		if (argc > 2)
			port = atoi(argv[2]);


	std::cout << "Serving " << " securing " << " rpc requests at "
            << host << ":" << port << std::endl;


    std::auto_ptr<funtik::SSLConnection> conn = std::auto_ptr<funtik::SSLConnection>(new funtik::SSLConnection (false, host, port));



    ulxr::HttpProtocol prot(conn.get());
    ulxr::Requester client(&prot);

    time_t starttime = time(0);


	for(int i=0;i<4;i++)
	{
//#1 test
//disable all auth options.
	std::cout <<"Test Number: "<<++iTestNum;
	conn->disableAuth();
	doTestHandle(conn.get(),client,prot,"Without client Certificate.");

//#2 test
	std::cout <<"Test Number: "<<++iTestNum;
	conn->setCryptographyData("password", "nosignedcert.pem", "nosignedcert.pem");
	doTestHandle(conn.get(),client,prot,"Load unsigned certificate. ");

//#3 test
	std::cout <<"Test Number: "<<++iTestNum;
	conn->enableAuth(funtik::SSLConnection::MANDATORY_CLIENTCERT);
	doTestHandle(conn.get(),client,prot,"Set use unsigned certificate.");

//#4 test
	std::cout <<"Test Number: "<<++iTestNum;
	conn->setCryptographyData("", "signedcert.pem", "signedcert.pem");
	doTestHandle(conn.get(),client,prot,"Load signed revocation certificate.");


//#5 test
	std::cout <<"Test Number: "<<++iTestNum;
	conn->setCryptographyData("", "signedcert2.pem", "signedcert2.pem");
	doTestHandle(conn.get(),client,prot,"Load signed good certificate.");

//#6 test
	std::cout <<"Test Number: "<<++iTestNum;
	conn->enableAuth(funtik::SSLConnection::CA_AUTH);
        conn->setCAFile("./ca-cert.pem");
	doTestHandle(conn.get(),client,prot,"Set CA certificate checking server.");


//#7 test
	std::cout <<"Test Number: "<<++iTestNum;
	conn->enableAuth(funtik::SSLConnection::FINGERPRINT_AUTH);

	std::ifstream fsFingerprintFile("fingerprint_storage");
	if(!fsFingerprintFile)
    {
       	std::cout<<"Cannt open file"<<std::endl;
    }
	while(fsFingerprintFile.good())
    {
       	char tmp_buf[256];
		fsFingerprintFile.getline(tmp_buf,256);
		conn->addFingerprintData(tmp_buf);
	}
    fsFingerprintFile.close();
	doTestHandle(conn.get(),client,prot,"Set checking server certificate(Fingerprint only).");

//#8 test
    std::cout <<"Test Number: "<<++iTestNum;
    conn->enableAuth(funtik::SSLConnection::CHECK_REVOCATIONCERT);

    std::ifstream fsRevocationFile("revocation_storage");
    if(!fsRevocationFile)
   {
       	std::cout<<"Cannt open revocation file"<<std::endl;
    }
   	while(fsRevocationFile.good())
    {
   	    char tmp_buf[256];
       	fsRevocationFile.getline(tmp_buf,256);
		conn->addRevocationData(tmp_buf);
    }
    fsRevocationFile.close();
    doTestHandle(conn.get(),client,prot,"Set Fingerprint certificate checking server(Fingerprint and revocation).");


    time_t endtime = time(0);
    unsigned mins = (endtime - starttime) / 60;
    unsigned secs = (endtime - starttime) % 60;
    std::cout << "\nOverall time needed: " << mins << ":"
              << secs << std::endl;
  }
}//for

  catch(ulxr::Exception &ex)
  {
     std::cout << "Error occured: " << ex.why() << std::endl;
     return 1;
  }

  catch(...)
  {
     std::cout << "unknown Error occured.\n";
     return 1;
  }

  std::cout << "Well done, Ready.\n";
  return 0;
}
コード例 #12
0
int main(int argc, char **argv)
{
    try
    {
        std::string host = "localhost";
        if (argc > 1)
            host = argv[1];

        unsigned port = 32000;
        if (argc > 2)
            port = atoi(argv[2]);

        bool big = haveOption(argc, argv, "big");
        bool secure = haveOption(argc, argv, "ssl");

        std::string sec = "unsecured";
        if (secure)
            sec = "secured";

        std::cout << "Requesting " << sec << " rpc calls at "
                  << host << ":" << port << std::endl;

        std::auto_ptr<ulxr::TcpIpConnection> conn;
        if (secure)
            conn.reset(new ulxr::SSLConnection (host, port));
        else
            conn.reset(new ulxr::TcpIpConnection (host, port));

        conn->setTcpNoDelay(true);
        ulxr::HttpProtocol prot(conn.get());
        ulxr::Requester client(&prot);


        /////////////////////////////

        ulxr::MethodCall list_methods ("system.listMethods");

        ulxr::MethodCall method_help ("system.methodHelp");
        method_help.addParam(ulxr::RpcString("system.methodHelp"));

        ulxr::MethodCall method_sig ("system.methodSignature");
        method_sig.addParam(ulxr::RpcString("system.methodSignature"));

        ulxr::MethodResponse resp;

        /////////////////////////////
        //
        prot.setAcceptCookies(true);
        size_t myPayloadBytesTransferred = 0;

        // TODO: write adapters

        // Call mergeArrays
        //
        time_t starttime = time(0);
        int numCalls = 10;
        for (int i=0; i < numCalls; ++i)
        {
            std::vector<int> v1;
            v1.push_back(3); v1.push_back(1); v1.push_back(2);
            std::vector<int> v2;
            v1.push_back(4); v1.push_back(1); v1.push_back(6);

            ulxr::Array arr1, arr2;
            foreach (int val, v1)
                arr1.addItem(ulxr::Integer(val));
            foreach (int val, v2)
                arr2.addItem(ulxr::Integer(val));

            ulxr::MethodCall mergeArraysProxyFunc ("mergeArrays");
            mergeArraysProxyFunc.addParam(arr1).addParam(arr2);
            resp = client.call(mergeArraysProxyFunc, "/RPC2");
            ulxr::Array retVal = resp.getResult();
            std::vector<int> v;
            for (unsigned int i=0; i < retVal.size(); ++i)
            {
                ulxr::Integer val = retVal.getItem(i);
                v.push_back(val.getInteger());
            }

            std::vector<int> expRes;
            expRes.push_back(1); expRes.push_back(1); expRes.push_back(2);
            expRes.push_back(3); expRes.push_back(4); expRes.push_back(6);
            if (expRes != v)
                std::cerr << "Merge call produced invalid result\n";
            else
                std::cout << "Call ok" << std::endl;

            myPayloadBytesTransferred += (v1.size() + v2.size() + v.size());

        }
        time_t endtime = time(0);
        time_t totalsecs = endtime - starttime;
        std::cout << "\n" << numCalls << " remote calls to 'mergeArrays' performed\n";
        std::cout << "Time: " << totalsecs << " sec, "<< (totalsecs?numCalls/totalsecs:0) << " calls/sec\n";
        std::cout << "Transferred payload: " << myPayloadBytesTransferred/1024 << " KB, " << (totalsecs?myPayloadBytesTransferred/totalsecs:0)/1024<< " KB/sec\n";


        // Call getCert
        //
        starttime = time(0);
        numCalls = 100;
        for (int i=0; i < numCalls; ++i)
        {
            std::string myCustNameArg  = "CUST_PASSWORD";
            ulxr::MethodCall getCertProxyFunc ("getCertificate");
            getCertProxyFunc.addParam(ulxr::RpcString(myCustNameArg.c_str()));
            //std::cout << "call getCert: \n";
            //timeval startTick, endTick;
            //gettimeofday(&startTick, NULL);
            resp = client.call(getCertProxyFunc, "/RPC2");
            //gettimeofday(&endTick, NULL);

            //long secs = endTick.tv_sec - startTick.tv_sec;
            //long usecs = endTick.tv_usec - startTick.tv_usec;

            //double elapsed = (double)secs * 1000;
            //elapsed += (double)usecs/(double)1000;

            //std::cout << "call took " << elapsed << " msec\n";
            ulxr::Base64 b64 = resp.getResult();
            std::string myCert = b64.getString();
            myPayloadBytesTransferred += (myCustNameArg.size() + myCert.size());
            //std::cout <<  "getCert result: " << b64.getString() << "\n";
        }
        endtime = time(0);
        totalsecs = endtime - starttime;
        std::cout << "\n" << numCalls << "  remote calls to 'getCertificate' performed\n";
        std::cout << "Time: " << totalsecs << " sec, "<< (totalsecs?numCalls/totalsecs:0) << " calls/sec\n";
        std::cout << "Transferred payload: " << myPayloadBytesTransferred/1024 << " KB, " << (totalsecs?myPayloadBytesTransferred/totalsecs:0)/1024<< " KB/sec\n";


    }
    catch(ulxr::Exception &ex)
    {
        std::cout << "Error occured: " << ex.why() << std::endl;
        return 1;
    }

    catch(...)
    {
        std::cout << "unknown Error occured.\n";
        return 1;
    }
    return 0;
}
コード例 #13
0
ファイル: mprocess_server.cpp プロジェクト: MrMC/ulxmlrpcpp
int main(int argc, char **argv)
{
	std::string host = "localhost";
	if (argc > 1)
		host = argv[1];

	unsigned port = 32000;
	if (argc > 2)
    	port = atoi(argv[2]);


	std::cout << "Serving " << " securing " << " rpc requests at "
            << host << ":" << port << std::endl;

	try
{
    	    std::auto_ptr<ulxr::TcpIpConnection> conn = std::auto_ptr<ulxr::TcpIpConnection>(new ulxr::TcpIpConnection (true, 0, port));

	    ulxr::HttpProtocol prot(conn.get());

	    server.getDispatcher()->setProtocol(&prot);
	    ulxr::Dispatcher *dsp=server.getDispatcher();

	    struct sigaction sa;
    	sigemptyset(&sa.sa_mask);
	sa.sa_handler=sigterm_handler;
	sa.sa_flags=SA_NOCLDSTOP | SA_RESTART;
	sigaction(SIGTERM,&sa,0);


	    ulxr::Struct ulxrStruct;
	    ulxrStruct.addMember("first",ulxr::Integer());
    	    dsp->addMethod(ulxr::make_method(check),
                     ulxr::Signature() << (ulxrStruct<<ulxr::make_member("uptime",ulxr::Integer()) ),
                     "check_sig",
                     ulxr::Signature()<<  ulxr::RpcString(),
                     "Testcase return  string");

	    dsp->addMethod(ulxr::make_method(check),
                     ulxr::Signature() << ulxr::RpcString(),
                     "check",
                     ulxr::Signature() << ulxr::RpcString(),
                     "Testcase return  string");

	    dsp->addMethod(ulxr::make_method(finish_server),
                     ulxr::Signature() << ulxr::RpcString(),
                     "finish_server",
                     ulxr::Signature(),
                     "Testcase shutdown server");

	    server.setState(funtik::MultiProcessRpcServer::RUN);
   	    while((server.getState()==funtik::MultiProcessRpcServer::RUN) && sst==0)
	    {
			server.printProcess();

			if(!server.waitConnection())
			{
		    	std::cout<<"signale receive"<<std::endl;
			    continue;
			}
			try{
				server.handleRequest();
			}
			catch(ulxr::Exception& ex)
			{
		    	std::cout << "Error occured: " << ex.why() << std::endl;
			}

	    }//while
	    server.terminateAllProcess(true);
	}
	catch(ulxr::Exception& ex)
	{
		std::cout << "Error occured: " << ex.why() << std::endl;
	}
	std::cout << "Well done, Ready.\n";
	return 0;
}
コード例 #14
0
ファイル: secure_client.cpp プロジェクト: MrMC/ulxmlrpcpp
int main(int argc, char **argv)
{
  try
  {
    ulxr::intializeLogger(argv[0]);

    std::string host = "localhost";
    if (argc > 1)
      host = argv[1];

    unsigned port = 32003;
    if (argc > 2)
      port = atoi(argv[2]);

    ulxr::TcpIpConnection conn (false, host, port);
    ulxr::HttpProtocol prot(&conn);
    ulxr::Requester client(&prot);

    // prepare call
    ulxr::MethodCall secure_shutdown ("secure_shutdown");

    // put call in encrypted envelope, base64 encoded  for transmission
    ulxr::MethodCall secureDispatcher ("secureDispatcher");
    secureDispatcher.addParam(ulxr::Base64(ulxr::encodeBase64(secure_shutdown.getXml())));
    ULXR_TRACE(secure_shutdown.getXml());

    // send call
    ulxr::MethodResponse resp = client.call(secureDispatcher, "/SecureRPC", "ali-baba", "open-sesame");
    if (resp.isOK() )
    {
      // base64-decode and decrypt response
      ulxr::Base64 respdata = resp.getResult();
      ULXR_TRACE(respdata.getString());

      std::string xml_resp = ulxr::decodeBase64(respdata.getString());
      ULXR_TRACE(xml_resp);

      // parse response to access result
      ulxr::MethodResponseParser parser;
      bool done = false;
      if (!parser.parse(xml_resp.data(), xml_resp.length(), done))
      {
        throw ulxr::XmlException(parser.mapToFaultCode(parser.getErrorCode()),
                               "Problem while parsing decrypted xml request",
                               parser.getCurrentLineNumber(),
                               parser.getErrorString(parser.getErrorCode()));
      }

      resp = parser.getMethodResponse();

      std::cout << "secure call result: \n";
      std::cout << resp.getXml(0);
    }
    else
    {
      std::cout << "Error while transmitting secured method call\n";
      std::cout << "envelope call result: \n";
      std::cout << resp.getXml(0);
    }
  }
  catch(ulxr::Exception &ex)
  {
     std::cout << "Error occured: " << ex.why() << std::endl;
  }
  catch(...)
  {
     std::cout << "unknown Error occured.\n";
  }

  return 0;
}
コード例 #15
0
ファイル: tocvdebug.c プロジェクト: Geod24/dnet
int FuncDeclaration::cvMember(unsigned char *p)
{
    char *id;
    idx_t typidx;
    unsigned attribute;
    int nwritten = 0;
    debtyp_t *d;

    //printf("FuncDeclaration::cvMember() '%s'\n", toChars());

    if (!type)			// if not compiled in,
	return 0;		// skip it

    id = toChars();

    if (!p)
    {
	nwritten = 6 + cv_stringbytes(id);
    }
    else
    {
	int count;
	int mlen;
	unsigned char *q;

	count = 0;
	mlen = 2;
	{
	    if (introducing)
		mlen += 4;
	    mlen += cgcv.sz_idx * 2;
	    count++;
	}

	// Allocate and fill it in
	d = debtyp_alloc(mlen);
	q = d->data;
	TOWORD(q,LF_METHODLIST);
	q += 2;
//	for (s = sf; s; s = s->Sfunc->Foversym)
	{
	    attribute = PROTtoATTR(prot());

	    /* 0*4 vanilla method
	     * 1*4 virtual method
	     * 2*4 static method
	     * 3*4 friend method
	     * 4*4 introducing virtual method
	     * 5*4 pure virtual method
	     * 6*4 pure introducing virtual method
	     * 7*4 reserved
	     */

	    if (isStatic())
		attribute |= 2*4;
	    else if (isVirtual())
	    {
		if (introducing)
		{
		    if (isAbstract())
			attribute |= 6*4;
		    else
			attribute |= 4*4;
		}
		else
		{
		    if (isAbstract())
			attribute |= 5*4;
		    else
			attribute |= 1*4;
		}
	    }
	    else
		attribute |= 0*4;

	    TOIDX(q,attribute);
	    q += cgcv.sz_idx;
	    TOIDX(q, cv4_memfunctypidx(this));
	    q += cgcv.sz_idx;
	    if (introducing)
	    {   TOLONG(q, vtblIndex * PTRSIZE);
		q += 4;
	    }
	}
	assert(q - d->data == mlen);

	typidx = cv_debtyp(d);
	if (typidx)
	{
	    TOWORD(p,LF_METHOD);
	    TOWORD(p + 2,count);
	    nwritten = 4;
	    TOIDX(p + nwritten, typidx);
	    nwritten += cgcv.sz_idx;
	    nwritten += cv_namestring(p + nwritten, id);
	}
    }
    return nwritten;
}
コード例 #16
0
ファイル: json.c プロジェクト: MartinNowak/GDC
void AggregateDeclaration::toJsonBuffer(OutBuffer *buf)
{
    //printf("AggregateDeclaration::toJsonBuffer()\n");
    buf->writestring("{\n");

    JsonProperty(buf, Pname, toChars());
    JsonProperty(buf, Pkind, kind());

    if (prot())
        JsonProperty(buf, Pprotection, Pprotectionnames[prot()]);

    if (comment)
        JsonProperty(buf, Pcomment, (const char *)comment);

    if (loc.linnum)
        JsonProperty(buf, Pline, loc.linnum);

    ClassDeclaration *cd = isClassDeclaration();
    if (cd)
    {
        if (cd->baseClass)
        {
            JsonProperty(buf, "base", cd->baseClass->toChars());
        }
        if (cd->interfaces_dim)
        {
            JsonString(buf, "interfaces");
            buf->writestring(" : [\n");
            size_t offset = buf->offset;
            for (size_t i = 0; i < cd->interfaces_dim; i++)
            {   BaseClass *b = cd->interfaces[i];
                if (offset != buf->offset)
                {   buf->writestring(",\n");
                    offset = buf->offset;
                }
                JsonString(buf, b->base->toChars());
            }
            JsonRemoveComma(buf);
            buf->writestring("],\n");
        }
    }

    if (members)
    {
        JsonString(buf, Pmembers);
        buf->writestring(" : [\n");
        size_t offset = buf->offset;
        for (size_t i = 0; i < members->dim; i++)
        {   Dsymbol *s = (*members)[i];
            if (offset != buf->offset)
            {   buf->writestring(",\n");
                offset = buf->offset;
            }
            s->toJsonBuffer(buf);
        }
        JsonRemoveComma(buf);
        buf->writestring("]\n");
    }
    JsonRemoveComma(buf);

    buf->writestring("}\n");
}
コード例 #17
0
ファイル: json.c プロジェクト: 1100110/dmd
void Import::toJson(JsonOut *json)
{
    if (id == Id::object)
        return;

    json->objectStart();

    json->propertyStart("name");
    json->stringStart();
    if (packages && packages->dim)
    {
        for (size_t i = 0; i < packages->dim; i++)
        {   Identifier *pid = (*packages)[i];

            json->stringPart(pid->toChars());
            json->buf->writeByte('.');
        }
    }
    json->stringPart(id->toChars());
    json->stringEnd();
    json->comma();

    json->property("kind", kind());
    json->property("comment", (const char *)comment);
    json->property("line", &loc);
    if (prot() != PROTpublic)
        json->property("protection", Pprotectionnames[prot()]);
    if (aliasId)
        json->property("alias", aliasId->toChars());

    bool hasRenamed = false;
    bool hasSelective = false;
    for (size_t i = 0; i < aliases.dim; i++)
    {   // avoid empty "renamed" and "selective" sections
        if (hasRenamed && hasSelective)
            break;
        else if (aliases[i])
            hasRenamed = true;
        else
            hasSelective = true;
    }

    if (hasRenamed)
    {
        // import foo : alias1 = target1;
        json->propertyStart("renamed");
        json->objectStart();
        for (size_t i = 0; i < aliases.dim; i++)
        {
            Identifier *name = names[i];
            Identifier *alias = aliases[i];
            if (alias) json->property(alias->toChars(), name->toChars());
        }
        json->objectEnd();
    }

    if (hasSelective)
    {
        // import foo : target1;
        json->propertyStart("selective");
        json->arrayStart();
        for (size_t i = 0; i < names.dim; i++)
        {
            Identifier *name = names[i];
            if (!aliases[i]) json->item(name->toChars());
        }
        json->arrayEnd();
    }

    json->objectEnd();
}
コード例 #18
0
USBDB::USBDB()
{
#ifndef USBIDS_FILE
    QString db = "/usr/share/hwdata/usb.ids"; /* on Fedora */
    if (!QFile::exists(db))
        db = locate("data", "kcmusb/usb.ids");
#else
    QString db = USBIDS_FILE;
#endif
    if (db.isEmpty())
        return;

    _classes.setAutoDelete(true);
    _ids.setAutoDelete(true);

    QFile f(db);

    if (f.open(IO_ReadOnly))
    {
        QTextStream ts(&f);

        QString line, name;
        int id=0, subid=0, protid=0;
        QRegExp vendor("[0-9a-fA-F]+ ");
        QRegExp product("\\s+[0-9a-fA-F]+ ");
        QRegExp cls("C [0-9a-fA-F][0-9a-fA-F]");
        QRegExp subclass("\\s+[0-9a-fA-F][0-9a-fA-F]  ");
        QRegExp prot("\\s+[0-9a-fA-F][0-9a-fA-F]  ");
        while (!ts.eof())
        {
            line = ts.readLine();
            if (line.left(1) == "#" || line.stripWhiteSpace().isEmpty())
                continue;

            // skip AT lines
            if (line.left(2) == "AT")
                continue;

            if (cls.search(line) == 0 && cls.matchedLength() == 4)
            {
                id = line.mid(2,2).toInt(0, 16);
                name = line.mid(4).stripWhiteSpace();
                _classes.insert(QString("%1").arg(id), new QString(name));
            }
            else if (prot.search(line) == 0 && prot.matchedLength() > 5)
            {
                line = line.stripWhiteSpace();
                protid = line.left(2).toInt(0, 16);
                name = line.mid(4).stripWhiteSpace();
                _classes.insert(QString("%1-%2-%3").arg(id).arg(subid).arg(protid), new QString(name));
            }
            else if (subclass.search(line) == 0 && subclass.matchedLength() > 4)
            {
                line = line.stripWhiteSpace();
                subid = line.left(2).toInt(0, 16);
                name = line.mid(4).stripWhiteSpace();
                _classes.insert(QString("%1-%2").arg(id).arg(subid), new QString(name));
            }
            else if (vendor.search(line) == 0 && vendor.matchedLength() == 5)
            {
                id = line.left(4).toInt(0,16);
                name = line.mid(6);
                _ids.insert(QString("%1").arg(id), new QString(name));
            }
            else if (product.search(line) == 0 && product.matchedLength() > 5 )
            {
                line = line.stripWhiteSpace();
                subid = line.left(4).toInt(0,16);
                name = line.mid(6);
                _ids.insert(QString("%1-%2").arg(id).arg(subid), new QString(name));
            }

        }

        f.close();
    }
}
コード例 #19
0
int main(int argc, char **argv)
{
	std::string host = "localhost";
	if (argc > 1)
		host = argv[1];

	unsigned port = 32000;
	if (argc > 2)
    	port = atoi(argv[2]);


	std::cout << "Serving " << " securing " << " rpc requests at "
            << host << ":" << port << std::endl;

    std::auto_ptr<funtik::SSLConnection> conn = std::auto_ptr<funtik::SSLConnection>(new funtik::SSLConnection (true, host, port));



	ulxr::HttpProtocol prot(conn.get());
	ulxr::Dispatcher server(&prot);


	try
	{
	    server.addMethod(ulxr::make_method(checkaccess),
                     ulxr::Signature() << ulxr::RpcString(),
                     "checkaccess",
                     ulxr::Signature() << ulxr::RpcString(),
                     "Testcase return  string");

//start handle
//Check authentification options.


//without autentification.
//#1
	conn->setCryptographyData("", "sessioncert.pem", "sessioncert.pem");
	doTestHandle(conn.get(),server,"SSL server without SSL authentification. Used only session certificate.");

//#2
	conn->enableAuth(funtik::SSLConnection::CA_AUTH);
	conn->setCAFile("./ca-cert.pem");
	doTestHandle(conn.get(),server,"Set server SSL authentification via CA certificates.");

//#3
	conn->enableAuth(funtik::SSLConnection::FINGERPRINT_AUTH);

	std::ifstream fsFingerprintFile("./fingerprint_storage");
    if(!fsFingerprintFile)
   	{
       	std::cout<<"Cannt open file"<<std::endl;
   	}
    while(fsFingerprintFile.good())
   	{
       	char tmp_buf[256];
        fsFingerprintFile.getline(tmp_buf,256);
		conn->addFingerprintData(tmp_buf);
    }
   	fsFingerprintFile.close();

	doTestHandle(conn.get(),server,"Set server SSL authentification via Fingerprint of client`s certificate.");

//#4
	conn->enableAuth(funtik::SSLConnection::CHECK_REVOCATIONCERT);

    std::ifstream fsRevocationFile("./revocation_storage");
    if(!fsRevocationFile)
   	{
       	std::cout<<"Cannt open revocation file"<<std::endl;
    }
   	while(fsRevocationFile.good())
    {
   	    char tmp_buf[256];
       	fsRevocationFile.getline(tmp_buf,256);
		conn->addRevocationData(tmp_buf);
   	}
    fsRevocationFile.close();

   	doTestHandle(conn.get(),server,"Set server SSL authentification via Fingerprint of client`s certificate,check in revocation certificates.");

  }
  catch(ulxr::Exception& ex)
  {
    std::cout << "Error occured: " << ex.why() << std::endl;

  }
  std::cout << "Well done, Ready.\n";
  return 0;
}