8 #define SCARAB_API_EXPORTS 20 #include <mach-o/dyld.h> 32 LOGGER( slog,
"version_semantic" );
63 combine( a_maj_ver, a_min_ver, a_patch_ver );
89 f_package( a_orig.f_package ),
90 f_commit( a_orig.f_commit ),
91 f_exe_name( a_orig.f_exe_name ),
92 f_hostname( a_orig.f_hostname ),
93 f_username( a_orig.f_username )
108 f_package = a_orig.f_package;
109 f_commit = a_orig.f_commit;
110 f_exe_name = a_orig.f_exe_name;
111 f_hostname = a_orig.f_hostname;
112 f_username = a_orig.f_username;
145 if( a_ver.empty() || a_ver ==
"unknown" )
155 if( a_ver[0] ==
'v' )
159 size_t t_delim_pos_1 = a_ver.find(
s_delimeter, 0 );
160 if( t_delim_pos_1 == std::string::npos )
162 LERROR( slog,
"version string <" << a_ver <<
"> is not in the right format (did not find first delimeter)" );
165 std::stringstream t_maj_ver_str;
166 t_maj_ver_str << a_ver.substr( t_start, t_delim_pos_1 );
168 size_t t_delim_pos_2 = a_ver.find(
s_delimeter, t_delim_pos_1 + 1 );
169 if( t_delim_pos_2 == std::string::npos )
171 LERROR( slog,
"version string <" << a_ver <<
"> is not in the right format (did not find second delimeter)" );
174 std::stringstream t_min_ver_str;
175 t_min_ver_str << a_ver.substr(t_delim_pos_1 + 1, t_delim_pos_2 );
177 std::stringstream t_patch_ver;
178 t_patch_ver << a_ver.substr( t_delim_pos_2 + 1 );
190 std::stringstream t_ver_str;
198 const size_t t_bufsize = 1024;
202 char t_username_buf[ t_bufsize ];
203 DWORD t_bufsize_win = t_bufsize;
204 if( GetUserName( t_username_buf, &t_bufsize_win ) )
206 f_username = string( t_username_buf );
212 passwd* t_passwd = getpwuid( getuid() );
213 if( t_passwd !=
nullptr )
215 f_username = string( t_passwd->pw_name );
219 LWARN( slog,
"Error reported while getting passwd info: " << strerror( errno ) );
221 LWARN( slog,
"Unable to get the username" );
225 char t_hostname_buf[ t_bufsize ];
228 WSAStartup( MAKEWORD( 2, 2 ), &wsaData );
231 if( gethostname( t_hostname_buf, t_bufsize ) == 0 )
233 f_hostname = string( t_hostname_buf );
237 LWARN( slog,
"Unable to get the hostname" );
246 TCHAR t_exe_buf[ MAX_PATH ];
247 if( ! GetModuleFileName( NULL, t_exe_buf, MAX_PATH ) )
249 char t_exe_buf[ 2048 ];
250 uint32_t t_exe_bufsize =
sizeof( t_exe_buf );
251 if( _NSGetExecutablePath( t_exe_buf, &t_exe_bufsize ) != 0 )
253 const size_t t_exe_bufsize = 2048;
254 char t_exe_buf[ t_exe_bufsize ];
255 ssize_t t_exe_name_len = readlink(
"/proc/self/exe", t_exe_buf, t_exe_bufsize );
256 if( t_exe_name_len >= 0 )
258 t_exe_buf[t_exe_name_len] =
'\0';
264 LWARN( slog,
"Could not retrieve executable file name" );
266 LWARN( slog,
"Executable name buffer is too small; needs size %u\n" << t_bufsize );
269 f_exe_name = string( t_exe_buf );
276 std::stringstream t_info_stream;
277 path t_exe_path( f_exe_name );
278 t_info_stream <<
"Executable: " << t_exe_path.filename() <<
'\n';
279 t_info_stream <<
"Location: " << t_exe_path.parent_path() <<
'\n';
280 t_info_stream <<
"Built with " << f_package <<
" version " <<
f_version <<
'\n';
281 t_info_stream <<
"Git commit: " << f_commit;
282 std::string t_version_info( t_info_stream.str() );
283 return t_version_info;
version_ifc & operator=(const version_ifc &)
bool operator>(const version_semantic &a_other)
Greater-than operator to compare version information only.
bool update_exe_host_user()
bool combine(unsigned a_maj_ver, unsigned a_min_ver, unsigned a_patch_ver)
LOGGER(mtlog, "authentication")
virtual std::string version_info_string() const
bool operator<(const version_semantic &a_other)
Less-than operator to compare version information only.
version_semantic & operator=(const version_semantic &a_orig)
Contains the logger class and macros, based on Kasper's KLogger class.
bool operator==(const version_semantic &a_other)
Equality operator to compare version information only.
bool parse(const std::string &a_ver)