• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Version.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #include "libts.h"
00025 
00026 AppVersionInfo::AppVersionInfo()
00027 {
00028   defined = 0;
00029   ink_strlcpy(PkgStr, "?", sizeof(PkgStr));
00030   ink_strlcpy(AppStr, "?", sizeof(AppStr));
00031   ink_strlcpy(VersionStr, "?", sizeof(VersionStr));
00032   ink_strlcpy(BldNumStr, "?", sizeof(BldNumStr));
00033   ink_strlcpy(BldTimeStr, "?", sizeof(BldTimeStr));
00034   ink_strlcpy(BldDateStr, "?", sizeof(BldDateStr));
00035   ink_strlcpy(BldMachineStr, "?", sizeof(BldMachineStr));
00036   ink_strlcpy(BldPersonStr, "?", sizeof(BldPersonStr));
00037   ink_strlcpy(BldCompileFlagsStr, "?", sizeof(BldCompileFlagsStr));
00038   ink_strlcpy(FullVersionInfoStr, "?", sizeof(FullVersionInfoStr));
00039   // coverity[uninit_member]
00040 }
00041 
00042 
00043 void
00044 AppVersionInfo::setup(const char *pkg_name, const char *app_name, const char *app_version,
00045                       const char *build_date, const char *build_time, const char *build_machine,
00046                       const char *build_person, const char *build_cflags)
00047 {
00048   char month_name[8];
00049   int year, month, day, hour, minute, second;
00050 
00051   static const char *months[] = {
00052     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
00053     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"
00054   };
00055 
00056   // coverity[secure_coding]
00057   sscanf(build_time, "%d:%d:%d", &hour, &minute, &second);
00058   // coverity[secure_coding]
00059   sscanf(build_date, "%3s %d %d", month_name, &day, &year);
00060 
00061   for (month = 0; month < 11; month++) {
00062     if (strcasecmp(months[month], month_name) == 0)
00063       break;
00064   }
00065 
00066   ///////////////////////////////////////////
00067   // now construct the version information //
00068   ///////////////////////////////////////////
00069   ink_strlcpy(PkgStr, pkg_name, sizeof(PkgStr));
00070   ink_strlcpy(AppStr, app_name, sizeof(AppStr));
00071   snprintf(VersionStr, sizeof(VersionStr), "%s", app_version);
00072 
00073   // If the builder set a build number, use that. Otherwise take the build timestamp.
00074   if (strlen(BUILD_NUMBER) == 0) {
00075     snprintf(BldNumStr, sizeof(BldNumStr), "%d%d%d", month, day, hour);
00076   } else {
00077     snprintf(BldNumStr, sizeof(BldNumStr), "%s", BUILD_NUMBER);
00078   }
00079 
00080   snprintf(BldTimeStr, sizeof(BldTimeStr), "%s", build_time);
00081   snprintf(BldDateStr, sizeof(BldDateStr), "%s", build_date);
00082   snprintf(BldMachineStr, sizeof(BldMachineStr), "%s", build_machine);
00083   snprintf(BldPersonStr, sizeof(BldPersonStr), "%s", build_person);
00084   snprintf(BldCompileFlagsStr, sizeof(BldCompileFlagsStr), "%s", build_cflags);
00085 
00086   /////////////////////////////////////////////////////////////
00087   // the manager doesn't like empty strings, so prevent them //
00088   /////////////////////////////////////////////////////////////
00089   if (PkgStr[0] == '\0')
00090     ink_strlcpy(PkgStr, "?", sizeof(PkgStr));
00091   if (AppStr[0] == '\0')
00092     ink_strlcpy(AppStr, "?", sizeof(AppStr));
00093   if (VersionStr[0] == '\0')
00094     ink_strlcpy(VersionStr, "?", sizeof(VersionStr));
00095   if (BldNumStr[0] == '\0')
00096     ink_strlcpy(BldNumStr, "?", sizeof(BldNumStr));
00097   if (BldTimeStr[0] == '\0')
00098     ink_strlcpy(BldTimeStr, "?", sizeof(BldTimeStr));
00099   if (BldDateStr[0] == '\0')
00100     ink_strlcpy(BldDateStr, "?", sizeof(BldDateStr));
00101   if (BldMachineStr[0] == '\0')
00102     ink_strlcpy(BldMachineStr, "?", sizeof(BldMachineStr));
00103   if (BldPersonStr[0] == '\0')
00104     ink_strlcpy(BldPersonStr, "?", sizeof(BldPersonStr));
00105   if (BldCompileFlagsStr[0] == '\0')
00106     ink_strlcpy(BldCompileFlagsStr, "?", sizeof(BldCompileFlagsStr));
00107   if (FullVersionInfoStr[0] == '\0')
00108     ink_strlcpy(FullVersionInfoStr, "?", sizeof(FullVersionInfoStr));
00109 
00110   snprintf(FullVersionInfoStr, sizeof(FullVersionInfoStr),
00111            "%s - %s - %s - (build # %s on %s at %s)",
00112            PkgStr, AppStr, VersionStr, BldNumStr, BldDateStr, BldTimeStr);
00113 
00114   defined = 1;
00115 }

Generated by  doxygen 1.7.1