2 Compile-server and client common functions
3 Copyright (C) 2011 Red Hat Inc.
5 This file is part of systemtap, and is free software. You can
6 redistribute it and/or modify it under the terms of the GNU General
7 Public License (GPL); either version 2, or (at your option) any
30 cs_protocol_version::~cs_protocol_version ()
33 free ((void*)this->v
);
36 const cs_protocol_version
&
37 cs_protocol_version::operator= (const char *v
)
40 free ((void *)this->v
);
46 cs_protocol_version::operator< (const cs_protocol_version
&that
) const
48 // Compare the levels of each version in turn.
49 vector
<string
> these_tokens
;
50 tokenize (this->v
, these_tokens
, ".");
51 vector
<string
> those_tokens
;
52 tokenize (that
.v
, those_tokens
, ".");
54 unsigned this_limit
= these_tokens
.size ();
55 unsigned that_limit
= those_tokens
.size ();
57 for (i
= 0; i
< this_limit
&& i
< that_limit
; ++i
)
60 unsigned long this_level
= strtoul (these_tokens
[i
].c_str (), & e
, 0);
62 unsigned long that_level
= strtoul (those_tokens
[i
].c_str (), & e
, 0);
64 if (this_level
> that_level
)
66 if (this_level
< that_level
)
70 // If the other version has more components, then this one is less than that one.
73 assert (i
== this_limit
);
76 // This version is greater than or equal to that one.
82 read_from_file (const string
&fname
, cs_protocol_version
&data
)
84 // C++ streams may not set errno in the even of a failure. However if we
85 // set it to 0 before each operation and it gets set during the operation,
86 // then we can use its value in order to determine what happened.
89 ifstream
f (fname
.c_str ());
92 clog
<< _F("Unable to open file '%s' for reading: ", fname
.c_str());
101 clog
<< _F("Unable to read from file '%s': ", fname
.c_str());
105 data
= dataStr
.c_str ();
107 // NB: not necessary to f.close ();
112 clog
<< strerror (errno
) << endl
;
114 clog
<< _("unknown error") << endl
;
118 string
get_cert_serial_number (const CERTCertificate
*cert
)
120 ostringstream serialNumber
;
121 serialNumber
<< hex
<< setfill('0') << right
;
122 for (unsigned i
= 0; i
< cert
->serialNumber
.len
; ++i
)
126 serialNumber
<< setw(2) << (unsigned)cert
->serialNumber
.data
[i
];
128 return serialNumber
.str ();
130 #endif /* HAVE_NSS */