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
12 // Disable the code in this file if NSS is not available
32 cs_protocol_version::~cs_protocol_version ()
35 free ((void*)this->v
);
38 const cs_protocol_version
&
39 cs_protocol_version::operator= (const char *v
)
42 free ((void *)this->v
);
48 cs_protocol_version::operator< (const cs_protocol_version
&that
) const
50 // Compare the levels of each version in turn.
51 vector
<string
> these_tokens
;
52 tokenize (this->v
, these_tokens
, ".");
53 vector
<string
> those_tokens
;
54 tokenize (that
.v
, those_tokens
, ".");
56 unsigned this_limit
= these_tokens
.size ();
57 unsigned that_limit
= those_tokens
.size ();
59 for (i
= 0; i
< this_limit
&& i
< that_limit
; ++i
)
62 unsigned long this_level
= strtoul (these_tokens
[i
].c_str (), & e
, 0);
64 unsigned long that_level
= strtoul (those_tokens
[i
].c_str (), & e
, 0);
66 if (this_level
> that_level
)
68 if (this_level
< that_level
)
72 // If the other version has more components, then this one is less than that one.
75 assert (i
== this_limit
);
78 // This version is greater than or equal to that one.
83 read_from_file (const string
&fname
, cs_protocol_version
&data
)
85 // C++ streams may not set errno in the even of a failure. However if we
86 // set it to 0 before each operation and it gets set during the operation,
87 // then we can use its value in order to determine what happened.
90 ifstream
f (fname
.c_str ());
93 clog
<< _F("Unable to open file '%s' for reading: ", fname
.c_str());
102 clog
<< _F("Unable to read from file '%s': ", fname
.c_str());
106 data
= dataStr
.c_str ();
108 // NB: not necessary to f.close ();
113 clog
<< strerror (errno
) << endl
;
115 clog
<< _("unknown error") << endl
;
119 string
get_cert_serial_number (const CERTCertificate
*cert
)
121 ostringstream serialNumber
;
122 serialNumber
<< hex
<< setfill('0') << right
;
123 for (unsigned i
= 0; i
< cert
->serialNumber
.len
; ++i
)
127 serialNumber
<< setw(2) << (unsigned)cert
->serialNumber
.data
[i
];
129 return serialNumber
.str ();
131 #endif /* HAVE_NSS */