-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.h
More file actions
157 lines (134 loc) · 5.71 KB
/
utils.h
File metadata and controls
157 lines (134 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* \file utils.h
* This file contains the declarations of some helper methods for ApMon.
*/
/*
* ApMon - Application Monitoring Tool
*
* Copyright (C) 2006 California Institute of Technology
*
* Permission is hereby granted, free of charge, to use, copy and modify
* this software and its documentation (the "Software") for any
* purpose, provided that existing copyright notices are retained in
* all copies and that this notice is included verbatim in any distributions
* or substantial portions of the Software.
* This software is a part of the MonALISA framework (http://monalisa.cacr.caltech.edu).
* Users of the Software are asked to feed back problems, benefits,
* and/or suggestions about the software to the MonALISA Development Team
* (developers@monalisa.cern.ch). Support for this software - fixing of bugs,
* incorporation of new features - is done on a best effort basis. All bug
* fixes and enhancements will be made available under the same terms and
* conditions as the original software,
* IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
* EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS
* PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS.
*/
#ifdef _WIN32
// FIXME: (MCl) the following warning tells that the usage of throw
// declaration may cause trouble with VC > 7.1
// Disable warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#pragma warning ( disable : 4290 )
#endif
#ifndef apmon_utils_h
#define apmon_utils_h
#include <stdexcept>
#include <ctype.h>
#define FATAL 0 /**< Logging level with minimum number of messages. */
#define WARNING 1 /**< Intermediate logging level. */
#define INFO 2 /**< Intermediate logging level. */
#define FINE 3 /**< Logging level with detailed information. */
#define DEBUG 4 /**< Logging level for debugging. */
using namespace std;
namespace apmon_utils {
/**
* Returns true if the page with the specified URL was modified since the
* last check.
* @param url The address of the page.
* @param lastModified The "Last-Modified" header that was received last time
* the page was requested.
*/
bool urlModified(char *url, char *lastModified);
/**
* Performs a HTTP request and puts the result into a temporary file.
* @param url The address of the web page.
* @param reqType The type of the request (GET, POST, HEAD).
* @param temp_filename The name of the temporary file.
* @return The size of the response received from the server, in bytes.
*/
int httpRequest(char *url, const char *reqType, char *temp_filename);
/**
* If "address" is a hostname, it returns the corresponding IP address;
* if "address" is an IP address, it just returns a copy of the address.
*/
char *findIP(char *address);
/**
* Parses an URL and determines the hostname, the port and the file name.
* It is used for the URLs given in the configuration file.
* @param url The URL string.
* @param hostname The determined hostname (this is an output parameter).
* @param port The determined port (also an output parameter).
* @param identifier The determined file name (also an output parameter).
*/
void parse_URL(char *url, char *hostname, int *port, char *identifier);
/**
* Frees the memory for a 2-dimensional character array.
* @param mat The array to be freed.
* @param nRows The number of rows in the arrray.
*/
void freeMat(char **mat, int nRows);
/**
* Removes the leading and trailing white spaces from a string and puts the
* result into a malloc'ed string.
* @param s The input string (which is not modified).
* @return The trimmed string.
*/
char *trimString(char *s);
/**
* Determines the size of the XDR representation for a data item.
* @param type The type of the data item (see the constants XDR_STRING,
* XDR_INT32, ... defined above).
* @param value The value of the data item (only used when dealing with
* strings).
*/
int xdrSize(int type, char *value);
/**
* Determines the size of a data item.
* @param type The type of the data item (see the constants XDR_STRING,
* XDR_INT32, ... defined above).
* @param value The value of the data item (only used when dealing with
* strings).
*/
int sizeEval(int type, char *value);
/**
* Logs the parameters included in a datagram.
*/
void logParameters(int level, int nParams, char **paramNames,
int *valueTypes, char **paramValues);
/**
* Verifies whether an IP address is private.
*/
bool isPrivateAddress(char *addr);
/**
* Finds the index of a string in a string array.
* @param item The string that is searched in the array.
* @param vect The string array.
* @param vectDim The number of strings in the array.
* @return The index of the string or -1 if the string is not found.
*/
int getVectIndex(const char *item, char **vect, int vectDim);
/** If the newLevel parameter is not specified, log the message given as
* argument if the current logging level is greater than or equal to
* msgLevel.
* If the newLevel parameter is specified, set the current logging level to
* newLevel and ignore the first two parameters.
*/
void logger(int msgLevel, const char *msg, int newLevel = -1);
}
#endif