- Timestamp:
- 06/23/07 10:44:30 (6 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- e6e297e
- Parents:
- 6c5375b
- Location:
- include
- Files:
-
- 4 edited
-
EnumNtSrv.cpp (modified) (3 diffs)
-
EnumNtSrv.h (modified) (2 diffs)
-
PDHCounter.h (modified) (1 diff)
-
Socket.h (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
include/EnumNtSrv.cpp
r6817602 re4d3f23 177 177 } 178 178 179 #define SC_BUF_LEN 1024179 #define SC_BUF_LEN 4096 180 180 TNtServiceInfo TNtServiceInfo::GetService(std::string name) 181 181 { … … 189 189 if (!sh) { 190 190 DWORD bufLen = SC_BUF_LEN; 191 TCHAR *buf = new TCHAR[bufLen ];192 if (!GetServiceKeyName(scman, name.c_str(), buf, &bufLen)) {193 throw NTServiceException(name, "Could not open Service", GetLastError());191 TCHAR *buf = new TCHAR[bufLen+1]; 192 std::cout << "name: '" << name << "'" << std::endl; 193 if (GetServiceKeyName(scman, name.c_str(), buf, &bufLen) == 0) { 194 194 ::CloseServiceHandle(scman); 195 } 195 throw NTServiceException(name, "GetServiceKeyName: Could not translate service name", GetLastError()); 196 } 197 /* 198 Why does this not work? (a bug in the API? says it should return the correct size?) 196 199 if (bufLen >= SC_BUF_LEN) { 197 throw NTServiceException(name, "Could not open Service", GetLastError());198 200 ::CloseServiceHandle(scman); 201 throw NTServiceException(name, "Service name to long to handle", GetLastError()); 199 202 } 200 203 buf[bufLen] = 0; 201 SC_HANDLE sh = ::OpenService(scman,buf,SERVICE_QUERY_STATUS);202 if (!sh) {203 throw NTServiceException(name, "Could not open Service", GetLastError());204 */ 205 sh = ::OpenService(scman,buf,SERVICE_QUERY_STATUS); 206 if (sh == NULL) { 204 207 ::CloseServiceHandle(scman); 208 throw NTServiceException(name, "OpenService: Could not open Service", GetLastError()); 205 209 } 206 210 } … … 210 214 info.m_dwServiceType = state.dwServiceType; 211 215 } else { 212 info.m_dwCurrentState = -1; 213 info.m_dwServiceType = -1; 216 ::CloseServiceHandle(sh); 217 ::CloseServiceHandle(scman); 218 throw NTServiceException(name, "QueryServiceStatus: Could not query service status", GetLastError()); 214 219 } 215 220 // TODO: Get more info here -
include/EnumNtSrv.h
re26cfe0 re4d3f23 25 25 #include <list> 26 26 #include <string> 27 #include <strEx.h> 27 28 28 29 class TNtServiceInfo; … … 44 45 45 46 std::string getError() { 46 return "Service: " + name_ + " caused: " + msg_ ;47 return "Service: " + name_ + " caused: " + msg_ + "(" + strEx::itos(error_) + ")"; 47 48 } 48 49 }; -
include/PDHCounter.h
rdc65e35 re4d3f23 326 326 LPTSTR szInstanceBuffer = NULL; 327 327 status = PdhEnumObjectItems(NULL, NULL, (*it).name.c_str(), szCounterBuffer, &dwCounterBufLen, szInstanceBuffer, &dwInstanceBufLen, dwDetailLevel, 0); 328 if (status != PDH_MORE_DATA)329 throw PDHException("PdhEnumObjectItems failed when trying to retrieve size for " + (*it).name, status);330 szCounterBuffer = new char[dwCounterBufLen+1024];331 szInstanceBuffer = new char[dwInstanceBufLen+1024];332 status = PdhEnumObjectItems(NULL, NULL, (*it).name.c_str(), szCounterBuffer, &dwCounterBufLen, szInstanceBuffer, &dwInstanceBufLen, dwDetailLevel, 0);333 if (status != ERROR_SUCCESS)334 throw PDHException("PdhEnumObjectItems failed when trying to retrieve buffer for " + (*it).name, status); 335 336 if (dwCounterBufLen > 0) {337 cp=szCounterBuffer;338 while(*cp != '\0') {339 Counter o;340 o.name = cp;341 (*it).counters.push_back(o);342 cp += lstrlen(cp)+1;328 if (status == PDH_MORE_DATA) { 329 szCounterBuffer = new char[dwCounterBufLen+1024]; 330 szInstanceBuffer = new char[dwInstanceBufLen+1024]; 331 status = PdhEnumObjectItems(NULL, NULL, (*it).name.c_str(), szCounterBuffer, &dwCounterBufLen, szInstanceBuffer, &dwInstanceBufLen, dwDetailLevel, 0); 332 if (status != ERROR_SUCCESS) 333 throw PDHException("PdhEnumObjectItems failed when trying to retrieve buffer for " + (*it).name, status); 334 335 if (dwCounterBufLen > 0) { 336 cp=szCounterBuffer; 337 while(*cp != '\0') { 338 Counter o; 339 o.name = cp; 340 (*it).counters.push_back(o); 341 cp += lstrlen(cp)+1; 342 } 343 343 } 344 if (dwInstanceBufLen > 0) { 345 cp=szInstanceBuffer; 346 while(*cp != '\0') { 347 Instance o; 348 o.name = cp; 349 (*it).instances.push_back(o); 350 cp += lstrlen(cp)+1; 351 } 352 } 353 delete [] szCounterBuffer; 354 delete [] szInstanceBuffer; 355 //throw PDHException("PdhEnumObjectItems failed when trying to retrieve size for " + (*it).name, status); 344 356 } 345 if (dwInstanceBufLen > 0) {346 cp=szInstanceBuffer;347 while(*cp != '\0') {348 Instance o;349 o.name = cp;350 (*it).instances.push_back(o);351 cp += lstrlen(cp)+1;352 }353 }354 delete [] szCounterBuffer;355 delete [] szInstanceBuffer;356 357 } 357 358 return ret; -
include/Socket.h
rdc65e35 re4d3f23 47 47 } 48 48 DataBuffer(const DataBuffer &other) { 49 buffer_ = new char[other.getLength() ];50 memcpy(buffer_, other.getBuffer(), other.getLength() );49 buffer_ = new char[other.getLength()+2]; 50 memcpy(buffer_, other.getBuffer(), other.getLength()+1); 51 51 length_ = other.getLength(); 52 52 } … … 54 54 delete [] buffer_; 55 55 length_ = 0; 56 buffer_ = NULL; 56 57 } 57 58 void append(const char* buffer, const unsigned int length) { 58 char *tBuf = new char[length_+length+ 1];59 char *tBuf = new char[length_+length+2]; 59 60 memcpy(tBuf, buffer_, length_); 60 61 memcpy(&tBuf[length_], buffer, length); … … 62 63 buffer_ = tBuf; 63 64 length_ += length; 64 } 65 buffer_[length_+1] = 0; 66 } 67 /** 68 * returns a const reference to the internal buffer 69 * Use with care! 70 * 71 * @access public 72 * @returns const char * 73 * @qualifier const 74 */ 65 75 const char * getBuffer() const { 66 76 return buffer_; … … 69 79 return length_; 70 80 } 81 /** 82 * Eats a specified number of bytes from the beginning of the buffer 83 * @access public 84 * @returns void 85 * @qualifier 86 * @param const unsigned int length the amount of bytes to eat 87 */ 71 88 void nibble(const unsigned int length) { 72 89 if (length > length_) 73 90 return; 74 91 unsigned int newLen = length_-length; 75 char *tBuf = new char[newLen+ 1];76 memcpy(tBuf, &buffer_[length], newLen );92 char *tBuf = new char[newLen+2]; 93 memcpy(tBuf, &buffer_[length], newLen+1); 77 94 char *oldBuf = buffer_; 78 95 buffer_ = tBuf; … … 87 104 ret.copyFrom(buffer_, length); 88 105 unsigned int newLen = length_-length; 89 char *tBuf = new char[newLen+ 1];90 memcpy(tBuf, &buffer_[length], newLen );106 char *tBuf = new char[newLen+2]; 107 memcpy(tBuf, &buffer_[length], newLen+1); 91 108 char *oldBuf = buffer_; 92 109 buffer_ = tBuf; … … 107 124 void copyFrom(const char* buffer, const unsigned int length) { 108 125 delete [] buffer_; 109 buffer_ = new char[length+ 1];126 buffer_ = new char[length+2]; 110 127 memcpy(buffer_, buffer, length); 111 128 length_ = length; 129 buffer_[length_+1] = 0; 112 130 } 113 131 };
Note: See TracChangeset
for help on using the changeset viewer.








