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 #include <rfb/rfb.h>
00028
00029 char *messageNameServer2Client(uint32_t type, char *buf, int len);
00030 char *messageNameClient2Server(uint32_t type, char *buf, int len);
00031 char *encodingName(uint32_t enc, char *buf, int len);
00032
00033 rfbStatList *rfbStatLookupEncoding(rfbClientPtr cl, uint32_t type);
00034 rfbStatList *rfbStatLookupMessage(rfbClientPtr cl, uint32_t type);
00035
00036 void rfbStatRecordEncodingSent(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
00037 void rfbStatRecordEncodingRcvd(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
00038 void rfbStatRecordMessageSent(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
00039 void rfbStatRecordMessageRcvd(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw);
00040 void rfbResetStats(rfbClientPtr cl);
00041 void rfbPrintStats(rfbClientPtr cl);
00042
00043
00044
00045
00046 char *messageNameServer2Client(uint32_t type, char *buf, int len) {
00047 if (buf==NULL) return "error";
00048 switch (type) {
00049 case rfbFramebufferUpdate: snprintf(buf, len, "FramebufferUpdate"); break;
00050 case rfbSetColourMapEntries: snprintf(buf, len, "SetColourMapEntries"); break;
00051 case rfbBell: snprintf(buf, len, "Bell"); break;
00052 case rfbServerCutText: snprintf(buf, len, "ServerCutText"); break;
00053 case rfbResizeFrameBuffer: snprintf(buf, len, "ResizeFrameBuffer"); break;
00054 case rfbFileTransfer: snprintf(buf, len, "FileTransfer"); break;
00055 case rfbTextChat: snprintf(buf, len, "TextChat"); break;
00056 case rfbPalmVNCReSizeFrameBuffer: snprintf(buf, len, "PalmVNCReSize"); break;
00057 case rfbXvp: snprintf(buf, len, "XvpServerMessage"); break;
00058 default:
00059 snprintf(buf, len, "svr2cli-0x%08X", 0xFF);
00060 }
00061 return buf;
00062 }
00063
00064 char *messageNameClient2Server(uint32_t type, char *buf, int len) {
00065 if (buf==NULL) return "error";
00066 switch (type) {
00067 case rfbSetPixelFormat: snprintf(buf, len, "SetPixelFormat"); break;
00068 case rfbFixColourMapEntries: snprintf(buf, len, "FixColourMapEntries"); break;
00069 case rfbSetEncodings: snprintf(buf, len, "SetEncodings"); break;
00070 case rfbFramebufferUpdateRequest: snprintf(buf, len, "FramebufferUpdate"); break;
00071 case rfbKeyEvent: snprintf(buf, len, "KeyEvent"); break;
00072 case rfbPointerEvent: snprintf(buf, len, "PointerEvent"); break;
00073 case rfbClientCutText: snprintf(buf, len, "ClientCutText"); break;
00074 case rfbFileTransfer: snprintf(buf, len, "FileTransfer"); break;
00075 case rfbSetScale: snprintf(buf, len, "SetScale"); break;
00076 case rfbSetServerInput: snprintf(buf, len, "SetServerInput"); break;
00077 case rfbSetSW: snprintf(buf, len, "SetSingleWindow"); break;
00078 case rfbTextChat: snprintf(buf, len, "TextChat"); break;
00079 case rfbPalmVNCSetScaleFactor: snprintf(buf, len, "PalmVNCSetScale"); break;
00080 case rfbXvp: snprintf(buf, len, "XvpClientMessage"); break;
00081 default:
00082 snprintf(buf, len, "cli2svr-0x%08X", type);
00083
00084
00085 }
00086 return buf;
00087 }
00088
00089
00090
00091
00092 char *encodingName(uint32_t type, char *buf, int len) {
00093 if (buf==NULL) return "error";
00094
00095 switch (type) {
00096 case rfbEncodingRaw: snprintf(buf, len, "raw"); break;
00097 case rfbEncodingCopyRect: snprintf(buf, len, "copyRect"); break;
00098 case rfbEncodingRRE: snprintf(buf, len, "RRE"); break;
00099 case rfbEncodingCoRRE: snprintf(buf, len, "CoRRE"); break;
00100 case rfbEncodingHextile: snprintf(buf, len, "hextile"); break;
00101 case rfbEncodingZlib: snprintf(buf, len, "zlib"); break;
00102 case rfbEncodingTight: snprintf(buf, len, "tight"); break;
00103 case rfbEncodingTightPng: snprintf(buf, len, "tightPng"); break;
00104 case rfbEncodingZlibHex: snprintf(buf, len, "zlibhex"); break;
00105 case rfbEncodingUltra: snprintf(buf, len, "ultra"); break;
00106 case rfbEncodingZRLE: snprintf(buf, len, "ZRLE"); break;
00107 case rfbEncodingZYWRLE: snprintf(buf, len, "ZYWRLE"); break;
00108 case rfbEncodingCache: snprintf(buf, len, "cache"); break;
00109 case rfbEncodingCacheEnable: snprintf(buf, len, "cacheEnable"); break;
00110 case rfbEncodingXOR_Zlib: snprintf(buf, len, "xorZlib"); break;
00111 case rfbEncodingXORMonoColor_Zlib: snprintf(buf, len, "xorMonoZlib"); break;
00112 case rfbEncodingXORMultiColor_Zlib: snprintf(buf, len, "xorColorZlib"); break;
00113 case rfbEncodingSolidColor: snprintf(buf, len, "solidColor"); break;
00114 case rfbEncodingXOREnable: snprintf(buf, len, "xorEnable"); break;
00115 case rfbEncodingCacheZip: snprintf(buf, len, "cacheZip"); break;
00116 case rfbEncodingSolMonoZip: snprintf(buf, len, "monoZip"); break;
00117 case rfbEncodingUltraZip: snprintf(buf, len, "ultraZip"); break;
00118
00119 case rfbEncodingXCursor: snprintf(buf, len, "Xcursor"); break;
00120 case rfbEncodingRichCursor: snprintf(buf, len, "RichCursor"); break;
00121 case rfbEncodingPointerPos: snprintf(buf, len, "PointerPos"); break;
00122
00123 case rfbEncodingLastRect: snprintf(buf, len, "LastRect"); break;
00124 case rfbEncodingNewFBSize: snprintf(buf, len, "NewFBSize"); break;
00125 case rfbEncodingKeyboardLedState: snprintf(buf, len, "LedState"); break;
00126 case rfbEncodingSupportedMessages: snprintf(buf, len, "SupportedMessage"); break;
00127 case rfbEncodingSupportedEncodings: snprintf(buf, len, "SupportedEncoding"); break;
00128 case rfbEncodingServerIdentity: snprintf(buf, len, "ServerIdentify"); break;
00129
00130
00131 case rfbEncodingCompressLevel0: snprintf(buf, len, "CompressLevel0"); break;
00132 case rfbEncodingCompressLevel1: snprintf(buf, len, "CompressLevel1"); break;
00133 case rfbEncodingCompressLevel2: snprintf(buf, len, "CompressLevel2"); break;
00134 case rfbEncodingCompressLevel3: snprintf(buf, len, "CompressLevel3"); break;
00135 case rfbEncodingCompressLevel4: snprintf(buf, len, "CompressLevel4"); break;
00136 case rfbEncodingCompressLevel5: snprintf(buf, len, "CompressLevel5"); break;
00137 case rfbEncodingCompressLevel6: snprintf(buf, len, "CompressLevel6"); break;
00138 case rfbEncodingCompressLevel7: snprintf(buf, len, "CompressLevel7"); break;
00139 case rfbEncodingCompressLevel8: snprintf(buf, len, "CompressLevel8"); break;
00140 case rfbEncodingCompressLevel9: snprintf(buf, len, "CompressLevel9"); break;
00141
00142 case rfbEncodingQualityLevel0: snprintf(buf, len, "QualityLevel0"); break;
00143 case rfbEncodingQualityLevel1: snprintf(buf, len, "QualityLevel1"); break;
00144 case rfbEncodingQualityLevel2: snprintf(buf, len, "QualityLevel2"); break;
00145 case rfbEncodingQualityLevel3: snprintf(buf, len, "QualityLevel3"); break;
00146 case rfbEncodingQualityLevel4: snprintf(buf, len, "QualityLevel4"); break;
00147 case rfbEncodingQualityLevel5: snprintf(buf, len, "QualityLevel5"); break;
00148 case rfbEncodingQualityLevel6: snprintf(buf, len, "QualityLevel6"); break;
00149 case rfbEncodingQualityLevel7: snprintf(buf, len, "QualityLevel7"); break;
00150 case rfbEncodingQualityLevel8: snprintf(buf, len, "QualityLevel8"); break;
00151 case rfbEncodingQualityLevel9: snprintf(buf, len, "QualityLevel9"); break;
00152
00153
00154 default:
00155 snprintf(buf, len, "Enc(0x%08X)", type);
00156 }
00157
00158 return buf;
00159 }
00160
00161
00162
00163
00164
00165 rfbStatList *rfbStatLookupEncoding(rfbClientPtr cl, uint32_t type)
00166 {
00167 rfbStatList *ptr;
00168 if (cl==NULL) return NULL;
00169 for (ptr = cl->statEncList; ptr!=NULL; ptr=ptr->Next)
00170 {
00171 if (ptr->type==type) return ptr;
00172 }
00173
00174 ptr = (rfbStatList *)malloc(sizeof(rfbStatList));
00175 if (ptr!=NULL)
00176 {
00177 memset((char *)ptr, 0, sizeof(rfbStatList));
00178 ptr->type = type;
00179
00180 ptr->Next = cl->statEncList;
00181 cl->statEncList = ptr;
00182 }
00183 return ptr;
00184 }
00185
00186
00187 rfbStatList *rfbStatLookupMessage(rfbClientPtr cl, uint32_t type)
00188 {
00189 rfbStatList *ptr;
00190 if (cl==NULL) return NULL;
00191 for (ptr = cl->statMsgList; ptr!=NULL; ptr=ptr->Next)
00192 {
00193 if (ptr->type==type) return ptr;
00194 }
00195
00196 ptr = (rfbStatList *)malloc(sizeof(rfbStatList));
00197 if (ptr!=NULL)
00198 {
00199 memset((char *)ptr, 0, sizeof(rfbStatList));
00200 ptr->type = type;
00201
00202 ptr->Next = cl->statMsgList;
00203 cl->statMsgList = ptr;
00204 }
00205 return ptr;
00206 }
00207
00208 void rfbStatRecordEncodingSentAdd(rfbClientPtr cl, uint32_t type, int byteCount)
00209 {
00210 rfbStatList *ptr;
00211
00212 ptr = rfbStatLookupEncoding(cl, type);
00213 if (ptr!=NULL)
00214 ptr->bytesSent += byteCount;
00215 }
00216
00217
00218 void rfbStatRecordEncodingSent(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw)
00219 {
00220 rfbStatList *ptr;
00221
00222 ptr = rfbStatLookupEncoding(cl, type);
00223 if (ptr!=NULL)
00224 {
00225 ptr->sentCount++;
00226 ptr->bytesSent += byteCount;
00227 ptr->bytesSentIfRaw += byteIfRaw;
00228 }
00229 }
00230
00231 void rfbStatRecordEncodingRcvd(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw)
00232 {
00233 rfbStatList *ptr;
00234
00235 ptr = rfbStatLookupEncoding(cl, type);
00236 if (ptr!=NULL)
00237 {
00238 ptr->rcvdCount++;
00239 ptr->bytesRcvd += byteCount;
00240 ptr->bytesRcvdIfRaw += byteIfRaw;
00241 }
00242 }
00243
00244 void rfbStatRecordMessageSent(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw)
00245 {
00246 rfbStatList *ptr;
00247
00248 ptr = rfbStatLookupMessage(cl, type);
00249 if (ptr!=NULL)
00250 {
00251 ptr->sentCount++;
00252 ptr->bytesSent += byteCount;
00253 ptr->bytesSentIfRaw += byteIfRaw;
00254 }
00255 }
00256
00257 void rfbStatRecordMessageRcvd(rfbClientPtr cl, uint32_t type, int byteCount, int byteIfRaw)
00258 {
00259 rfbStatList *ptr;
00260
00261 ptr = rfbStatLookupMessage(cl, type);
00262 if (ptr!=NULL)
00263 {
00264 ptr->rcvdCount++;
00265 ptr->bytesRcvd += byteCount;
00266 ptr->bytesRcvdIfRaw += byteIfRaw;
00267 }
00268 }
00269
00270
00271 int rfbStatGetSentBytes(rfbClientPtr cl)
00272 {
00273 rfbStatList *ptr=NULL;
00274 int bytes=0;
00275 if (cl==NULL) return 0;
00276 for (ptr = cl->statMsgList; ptr!=NULL; ptr=ptr->Next)
00277 bytes += ptr->bytesSent;
00278 for (ptr = cl->statEncList; ptr!=NULL; ptr=ptr->Next)
00279 bytes += ptr->bytesSent;
00280 return bytes;
00281 }
00282
00283 int rfbStatGetSentBytesIfRaw(rfbClientPtr cl)
00284 {
00285 rfbStatList *ptr=NULL;
00286 int bytes=0;
00287 if (cl==NULL) return 0;
00288 for (ptr = cl->statMsgList; ptr!=NULL; ptr=ptr->Next)
00289 bytes += ptr->bytesSentIfRaw;
00290 for (ptr = cl->statEncList; ptr!=NULL; ptr=ptr->Next)
00291 bytes += ptr->bytesSentIfRaw;
00292 return bytes;
00293 }
00294
00295 int rfbStatGetRcvdBytes(rfbClientPtr cl)
00296 {
00297 rfbStatList *ptr=NULL;
00298 int bytes=0;
00299 if (cl==NULL) return 0;
00300 for (ptr = cl->statMsgList; ptr!=NULL; ptr=ptr->Next)
00301 bytes += ptr->bytesRcvd;
00302 for (ptr = cl->statEncList; ptr!=NULL; ptr=ptr->Next)
00303 bytes += ptr->bytesRcvd;
00304 return bytes;
00305 }
00306
00307 int rfbStatGetRcvdBytesIfRaw(rfbClientPtr cl)
00308 {
00309 rfbStatList *ptr=NULL;
00310 int bytes=0;
00311 if (cl==NULL) return 0;
00312 for (ptr = cl->statMsgList; ptr!=NULL; ptr=ptr->Next)
00313 bytes += ptr->bytesRcvdIfRaw;
00314 for (ptr = cl->statEncList; ptr!=NULL; ptr=ptr->Next)
00315 bytes += ptr->bytesRcvdIfRaw;
00316 return bytes;
00317 }
00318
00319 int rfbStatGetMessageCountSent(rfbClientPtr cl, uint32_t type)
00320 {
00321 rfbStatList *ptr=NULL;
00322 if (cl==NULL) return 0;
00323 for (ptr = cl->statMsgList; ptr!=NULL; ptr=ptr->Next)
00324 if (ptr->type==type) return ptr->sentCount;
00325 return 0;
00326 }
00327 int rfbStatGetMessageCountRcvd(rfbClientPtr cl, uint32_t type)
00328 {
00329 rfbStatList *ptr=NULL;
00330 if (cl==NULL) return 0;
00331 for (ptr = cl->statMsgList; ptr!=NULL; ptr=ptr->Next)
00332 if (ptr->type==type) return ptr->rcvdCount;
00333 return 0;
00334 }
00335
00336 int rfbStatGetEncodingCountSent(rfbClientPtr cl, uint32_t type)
00337 {
00338 rfbStatList *ptr=NULL;
00339 if (cl==NULL) return 0;
00340 for (ptr = cl->statEncList; ptr!=NULL; ptr=ptr->Next)
00341 if (ptr->type==type) return ptr->sentCount;
00342 return 0;
00343 }
00344 int rfbStatGetEncodingCountRcvd(rfbClientPtr cl, uint32_t type)
00345 {
00346 rfbStatList *ptr=NULL;
00347 if (cl==NULL) return 0;
00348 for (ptr = cl->statEncList; ptr!=NULL; ptr=ptr->Next)
00349 if (ptr->type==type) return ptr->rcvdCount;
00350 return 0;
00351 }
00352
00353
00354
00355
00356 void rfbResetStats(rfbClientPtr cl)
00357 {
00358 rfbStatList *ptr;
00359 if (cl==NULL) return;
00360 while (cl->statEncList!=NULL)
00361 {
00362 ptr = cl->statEncList;
00363 cl->statEncList = ptr->Next;
00364 free(ptr);
00365 }
00366 while (cl->statMsgList!=NULL)
00367 {
00368 ptr = cl->statMsgList;
00369 cl->statMsgList = ptr->Next;
00370 free(ptr);
00371 }
00372 }
00373
00374
00375 void rfbPrintStats(rfbClientPtr cl)
00376 {
00377 rfbStatList *ptr=NULL;
00378 char encBuf[64];
00379 double savings=0.0;
00380 int totalRects=0;
00381 double totalBytes=0.0;
00382 double totalBytesIfRaw=0.0;
00383
00384 char *name=NULL;
00385 int bytes=0;
00386 int bytesIfRaw=0;
00387 int count=0;
00388
00389 if (cl==NULL) return;
00390
00391 rfbLog("%-21.21s %-6.6s %9.9s/%9.9s (%6.6s)\n", "Statistics", "events", "Transmit","RawEquiv","saved");
00392 for (ptr = cl->statMsgList; ptr!=NULL; ptr=ptr->Next)
00393 {
00394 name = messageNameServer2Client(ptr->type, encBuf, sizeof(encBuf));
00395 count = ptr->sentCount;
00396 bytes = ptr->bytesSent;
00397 bytesIfRaw = ptr->bytesSentIfRaw;
00398
00399 savings = 0.0;
00400 if (bytesIfRaw>0.0)
00401 savings = 100.0 - (((double)bytes / (double)bytesIfRaw) * 100.0);
00402 if ((bytes>0) || (count>0) || (bytesIfRaw>0))
00403 rfbLog(" %-20.20s: %6d | %9d/%9d (%5.1f%%)\n",
00404 name, count, bytes, bytesIfRaw, savings);
00405 totalRects += count;
00406 totalBytes += bytes;
00407 totalBytesIfRaw += bytesIfRaw;
00408 }
00409
00410 for (ptr = cl->statEncList; ptr!=NULL; ptr=ptr->Next)
00411 {
00412 name = encodingName(ptr->type, encBuf, sizeof(encBuf));
00413 count = ptr->sentCount;
00414 bytes = ptr->bytesSent;
00415 bytesIfRaw = ptr->bytesSentIfRaw;
00416 savings = 0.0;
00417
00418 if (bytesIfRaw>0.0)
00419 savings = 100.0 - (((double)bytes / (double)bytesIfRaw) * 100.0);
00420 if ((bytes>0) || (count>0) || (bytesIfRaw>0))
00421 rfbLog(" %-20.20s: %6d | %9d/%9d (%5.1f%%)\n",
00422 name, count, bytes, bytesIfRaw, savings);
00423 totalRects += count;
00424 totalBytes += bytes;
00425 totalBytesIfRaw += bytesIfRaw;
00426 }
00427 savings=0.0;
00428 if (totalBytesIfRaw>0.0)
00429 savings = 100.0 - ((totalBytes/totalBytesIfRaw)*100.0);
00430 rfbLog(" %-20.20s: %6d | %9.0f/%9.0f (%5.1f%%)\n",
00431 "TOTALS", totalRects, totalBytes,totalBytesIfRaw, savings);
00432
00433 totalRects=0.0;
00434 totalBytes=0.0;
00435 totalBytesIfRaw=0.0;
00436
00437 rfbLog("%-21.21s %-6.6s %9.9s/%9.9s (%6.6s)\n", "Statistics", "events", "Received","RawEquiv","saved");
00438 for (ptr = cl->statMsgList; ptr!=NULL; ptr=ptr->Next)
00439 {
00440 name = messageNameClient2Server(ptr->type, encBuf, sizeof(encBuf));
00441 count = ptr->rcvdCount;
00442 bytes = ptr->bytesRcvd;
00443 bytesIfRaw = ptr->bytesRcvdIfRaw;
00444 savings = 0.0;
00445
00446 if (bytesIfRaw>0.0)
00447 savings = 100.0 - (((double)bytes / (double)bytesIfRaw) * 100.0);
00448 if ((bytes>0) || (count>0) || (bytesIfRaw>0))
00449 rfbLog(" %-20.20s: %6d | %9d/%9d (%5.1f%%)\n",
00450 name, count, bytes, bytesIfRaw, savings);
00451 totalRects += count;
00452 totalBytes += bytes;
00453 totalBytesIfRaw += bytesIfRaw;
00454 }
00455 for (ptr = cl->statEncList; ptr!=NULL; ptr=ptr->Next)
00456 {
00457 name = encodingName(ptr->type, encBuf, sizeof(encBuf));
00458 count = ptr->rcvdCount;
00459 bytes = ptr->bytesRcvd;
00460 bytesIfRaw = ptr->bytesRcvdIfRaw;
00461 savings = 0.0;
00462
00463 if (bytesIfRaw>0.0)
00464 savings = 100.0 - (((double)bytes / (double)bytesIfRaw) * 100.0);
00465 if ((bytes>0) || (count>0) || (bytesIfRaw>0))
00466 rfbLog(" %-20.20s: %6d | %9d/%9d (%5.1f%%)\n",
00467 name, count, bytes, bytesIfRaw, savings);
00468 totalRects += count;
00469 totalBytes += bytes;
00470 totalBytesIfRaw += bytesIfRaw;
00471 }
00472 savings=0.0;
00473 if (totalBytesIfRaw>0.0)
00474 savings = 100.0 - ((totalBytes/totalBytesIfRaw)*100.0);
00475 rfbLog(" %-20.20s: %6d | %9.0f/%9.0f (%5.1f%%)\n",
00476 "TOTALS", totalRects, totalBytes,totalBytesIfRaw, savings);
00477
00478 }
00479