utilities.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <stdlib.h>
00041 #include <string.h>
00042
00043 #include "utilities.h"
00044
00045 #include "../../str.h"
00046 #include "../../locking.h"
00047 #include "../../mem/mem.h"
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 int convertStrToCharString(str *strToConvert, char **copiedString)
00058 {
00059
00060 *copiedString = shm_malloc(sizeof(char) * (strToConvert->len + 1));
00061
00062 if (*copiedString == NULL)
00063 {
00064 return 0;
00065 }
00066
00067 memcpy(*copiedString, strToConvert->s, strToConvert->len);
00068 (*copiedString)[strToConvert->len] = '\0';
00069
00070 return 1;
00071 }
00072
00073
00074
00075
00076 int stringHandlerSanityCheck( modparam_t type, void *val, char *parameterName)
00077 {
00078 char *theString = (char *)val;
00079
00080
00081 if (type != STR_PARAM) {
00082 LM_ERR("the %s parameter was assigned a type %d instead of %d\n",
00083 parameterName, type, STR_PARAM);
00084 return 0;
00085 }
00086
00087
00088 if (theString==0 || (theString[0])==0) {
00089 LM_ERR("the %s parameter was specified with an empty string\n",
00090 parameterName);
00091 return 0;
00092 }
00093
00094 return 1;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104 int get_statistic(char *statName)
00105 {
00106 int result = 0;
00107
00108 str theStr;
00109
00110 theStr.s = statName;
00111 theStr.len = strlen(statName);
00112
00113 stat_var *theVar = get_stat(&theStr);
00114
00115 if (theVar==0) {
00116 LM_INFO("failed to retrieve statistics for %s\n", statName);
00117 } else {
00118 result = get_stat_val(theVar);
00119 }
00120
00121 return result;
00122 }
00123
00124
00125
00126
00127 char * convertTMToSNMPDateAndTime(struct tm *timeStructure)
00128 {
00129 static char dateAndTime[8];
00130
00131
00132
00133 int currentYear = timeStructure->tm_year + 1900;
00134
00135
00136 dateAndTime[0] = (char) ((currentYear & 0xFF00) >> 8);
00137 dateAndTime[1] = (char) currentYear & 0xFF;
00138 dateAndTime[2] = (char) timeStructure->tm_mon + 1;
00139 dateAndTime[3] = (char) timeStructure->tm_mday;
00140 dateAndTime[4] = (char) timeStructure->tm_hour;
00141 dateAndTime[5] = (char) timeStructure->tm_min;
00142 dateAndTime[6] = (char) timeStructure->tm_sec;
00143 dateAndTime[7] = 0;
00144
00145 return dateAndTime;
00146 }