FileTransferMsg CreateFileListErrMsg(char flags) { FileTransferMsg fileListMsg; rfbFileListDataMsg* pFLD = NULL; char* data = NULL; unsigned int length = 0; memset(&fileListMsg, 0, sizeof(FileTransferMsg)); data = (char*) calloc(sizeof(rfbFileListDataMsg), sizeof(char)); if(data == NULL) { return fileListMsg; } length = sizeof(rfbFileListDataMsg) * sizeof(char); pFLD = (rfbFileListDataMsg*) data; pFLD->type = rfbFileListData; pFLD->numFiles = Swap16IfLE(0); pFLD->dataSize = Swap16IfLE(0); pFLD->compressedSize = Swap16IfLE(0); pFLD->flags = flags | 0x80; fileListMsg.data = data; fileListMsg.length = length; return fileListMsg; }
Bool rfbSendCursorPos(rfbClientPtr cl) { rfbFramebufferUpdateRectHeader rect; if (cl->ublen + sz_rfbFramebufferUpdateRectHeader > UPDATE_BUF_SIZE) { if (!rfbSendUpdateBuf(cl)) return FALSE; } cl->clientCursorLocation = currentCursorLoc(); rect.encoding = Swap32IfLE(rfbEncodingPointerPos); rect.r.x = Swap16IfLE((CARD16)cl->clientCursorLocation.x); rect.r.y = Swap16IfLE((CARD16)cl->clientCursorLocation.y); rect.r.w = 0; rect.r.h = 0; memcpy(&cl->updateBuf[cl->ublen], (char *)&rect, sz_rfbFramebufferUpdateRectHeader); cl->ublen += sz_rfbFramebufferUpdateRectHeader; cl->rfbRectanglesSent[rfbStatsCursorPosition]++; cl->rfbBytesSent[rfbStatsCursorPosition] += sz_rfbFramebufferUpdateRectHeader; if (!rfbSendUpdateBuf(cl)) return FALSE; return TRUE; }
static bool HandleRREBPP (uint32_t rx, uint32_t ry, uint32_t rw, uint32_t rh) { rfbRREHeader hdr; CARDBPP pix; rfbRectangle subrect; if (!ReadFromRFBServer((uint8_t *)&hdr, sz_rfbRREHeader)) return false; hdr.nSubrects = Swap32IfLE(hdr.nSubrects); if (!ReadFromRFBServer((uint8_t *)&pix, sizeof(pix))) return false; FillBufferRectangle(rx, ry, rw, rh, pix); for (uint32_t i = 0; i < hdr.nSubrects; i++) { if (!ReadFromRFBServer((uint8_t *)&pix, sizeof(pix))) return false; if (!ReadFromRFBServer((uint8_t *)&subrect, sz_rfbRectangle)) return false; subrect.x = Swap16IfLE(subrect.x); subrect.y = Swap16IfLE(subrect.y); subrect.w = Swap16IfLE(subrect.w); subrect.h = Swap16IfLE(subrect.h); FillBufferRectangle(rx + subrect.x, ry + subrect.y, subrect.w, subrect.h, pix); } return true; }
FileTransferMsg CreateFileDownloadBlockSizeDataMsg(unsigned short sizeFile, char *pFile) { FileTransferMsg fileDownloadBlockSizeDataMsg; int length = sz_rfbFileDownloadDataMsg + sizeFile; rfbFileDownloadDataMsg *pFDD = NULL; char *pFollow = NULL; char *pData = (char*) calloc(length, sizeof(char)); memset(&fileDownloadBlockSizeDataMsg, 0, sizeof(FileTransferMsg)); if(NULL == pData) { rfbLog("File [%s]: Method [%s]: pData is NULL\n", __FILE__, __FUNCTION__); return fileDownloadBlockSizeDataMsg; } pFDD = (rfbFileDownloadDataMsg *) pData; pFollow = &pData[sz_rfbFileDownloadDataMsg]; pFDD->type = rfbFileDownloadData; pFDD->compressLevel = 0; pFDD->compressedSize = Swap16IfLE(sizeFile); pFDD->realSize = Swap16IfLE(sizeFile); memcpy(pFollow, pFile, sizeFile); fileDownloadBlockSizeDataMsg.data = pData; fileDownloadBlockSizeDataMsg.length = length; return fileDownloadBlockSizeDataMsg; }
Bool rfbSendRectEncodingHextile(rfbClientPtr cl, int x, int y, int w, int h) { rfbFramebufferUpdateRectHeader rect; if (ublen + sz_rfbFramebufferUpdateRectHeader > UPDATE_BUF_SIZE) { if (!rfbSendUpdateBuf(cl)) return FALSE; } rect.r.x = Swap16IfLE(x); rect.r.y = Swap16IfLE(y); rect.r.w = Swap16IfLE(w); rect.r.h = Swap16IfLE(h); rect.encoding = Swap32IfLE(rfbEncodingHextile); memcpy(&updateBuf[ublen], (char *)&rect, sz_rfbFramebufferUpdateRectHeader); ublen += sz_rfbFramebufferUpdateRectHeader; cl->rfbRectanglesSent[rfbEncodingHextile]++; cl->rfbBytesSent[rfbEncodingHextile] += sz_rfbFramebufferUpdateRectHeader; switch (cl->format.bitsPerPixel) { case 8: return sendHextiles8(cl, x, y, w, h); case 16: return sendHextiles16(cl, x, y, w, h); case 32: return sendHextiles32(cl, x, y, w, h); } rfbLog("rfbSendRectEncodingHextile: bpp %d?\n", cl->format.bitsPerPixel); return FALSE; }
// Encode a rectangle inline UINT vncEncoder::EncodeRect(BYTE *source, BYTE *dest, const RECT &rect, int offsetx, int offsety) { const int rectW = rect.right - rect.left; const int rectH = rect.bottom - rect.top; // Create the header for the update in the destination area rfbFramebufferUpdateRectHeader *surh = (rfbFramebufferUpdateRectHeader *)dest; surh->r.x = (CARD16) (rect.left - offsetx); surh->r.y = (CARD16) (rect.top - offsety); surh->r.w = (CARD16) (rectW); surh->r.h = (CARD16) (rectH); surh->r.x = Swap16IfLE(surh->r.x); surh->r.y = Swap16IfLE(surh->r.y); surh->r.w = Swap16IfLE(surh->r.w); surh->r.h = Swap16IfLE(surh->r.h); surh->encoding = Swap32IfLE(rfbEncodingRaw); // Update raw encoding statistics rectangleOverhead += sz_rfbFramebufferUpdateRectHeader; dataSize += ( rectW * rectH * m_remoteformat.bitsPerPixel) / 8; encodedSize += ( rectW * rectH * m_remoteformat.bitsPerPixel) / 8; transmittedSize += sz_rfbFramebufferUpdateRectHeader + ( rectW * rectH * m_remoteformat.bitsPerPixel) / 8; // Translate the data in place in the output buffer Translate(source, dest + sz_rfbFramebufferUpdateRectHeader, rect); // Return the buffer size return sz_rfbFramebufferUpdateRectHeader + (rectW*rectH*m_remoteformat.bitsPerPixel) / 8; }
void ClientConnection::ReadCopyRect(rfbFramebufferUpdateRectHeader *pfburh) { rfbCopyRect cr; double tBlitStart; ReadExact((char *) &cr, sz_rfbCopyRect); cr.srcX = Swap16IfLE(cr.srcX); cr.srcY = Swap16IfLE(cr.srcY); // If *Cursor encoding is used, we should extend our "cursor lock area" // (previously set to destination rectangle) to the source rect as well. SoftCursorLockArea(cr.srcX, cr.srcY, pfburh->r.w, pfburh->r.h); omni_mutex_lock l(m_bitmapdcMutex); ObjectSelector b(m_hBitmapDC, m_hBitmap); PaletteSelector p(m_hBitmapDC, m_hPalette); if (m_opts.m_benchFile) tBlitStart = getTime(); if (!BitBlt(m_hBitmapDC, pfburh->r.x, pfburh->r.y, pfburh->r.w, pfburh->r.h, m_hBitmapDC, cr.srcX, cr.srcY, SRCCOPY)) vnclog.Print(0, "Error in blit in ClientConnection::CopyRect\n"); if (m_opts.m_benchFile) tBlit += getTime() - tBlitStart; }
void vncEncodeZlib::SendZlibrects(VSocket *outConn) { int NRects=m_nNbRects; const int rawDataSize = (m_Queuelen); const int maxCompSize = (m_Queuelen + (m_Queuelen/100) + 8); if (NRects==0) return; // NO update if (m_nNbRects<3 && !must_be_zipped) { outConn->SendExactQueue( (char *)m_Queuebuffer, m_Queuelen); // 1 Small update m_nNbRects=0; m_Queuelen=0; encodedSize += m_Queuelen-sz_rfbFramebufferUpdateRectHeader; rectangleOverhead += sz_rfbFramebufferUpdateRectHeader; return; } m_nNbRects=0; m_Queuelen=0; must_be_zipped=false; int nRet = compress((unsigned char*)(m_QueueCompressedbuffer), (unsigned long*)&maxCompSize, (unsigned char*)m_Queuebuffer, rawDataSize ); if (nRet != 0) { vnclog.Print(LL_INTINFO, VNCLOG("compression error")); return ; } int rawDataSize1=rawDataSize/65535; int rawDataSize2=rawDataSize%65535; rfbFramebufferUpdateRectHeader CacheRectsHeader; CacheRectsHeader.r.x = (CARD16)(NRects); CacheRectsHeader.r.y = (CARD16)(rawDataSize2); CacheRectsHeader.r.w = (CARD16)(rawDataSize1); CacheRectsHeader.r.x = Swap16IfLE(CacheRectsHeader.r.x); CacheRectsHeader.r.y = Swap16IfLE(CacheRectsHeader.r.y); CacheRectsHeader.r.w = Swap16IfLE(CacheRectsHeader.r.w); CacheRectsHeader.r.h = 0; CacheRectsHeader.encoding = Swap32IfLE(rfbEncodingSolMonoZip); // Format the ZlibHeader rfbZlibHeader CacheZipHeader; CacheZipHeader.nBytes = Swap32IfLE(maxCompSize); vnclog.Print(LL_INTINFO, VNCLOG("********QUEUEQUEUE********** %d %d %d\r\n"),maxCompSize,rawDataSize,NRects); outConn->SendExactQueue((char *)&CacheRectsHeader, sizeof(CacheRectsHeader)); outConn->SendExactQueue((char *)&CacheZipHeader, sizeof(CacheZipHeader)); outConn->SendExactQueue((char *)m_QueueCompressedbuffer, maxCompSize); // Update statistics encodedSize += sz_rfbZlibHeader + maxCompSize; rectangleOverhead += sz_rfbFramebufferUpdateRectHeader; transmittedSize += maxCompSize+sz_rfbFramebufferUpdateRectHeader+sz_rfbZlibHeader; }
void vncEncodeUltra::SendUltrarects(VSocket *outConn) { int NRects=m_nNbRects; const lzo_uint rawDataSize = (m_Queuelen); if (NRects==0) return; // NO update if (m_nNbRects<3 && !must_be_zipped) { outConn->SendExactQueue( (char *)m_Queuebuffer, m_Queuelen); // 1 Small update m_nNbRects=0; m_Queuelen=0; encodedSize += m_Queuelen-sz_rfbFramebufferUpdateRectHeader; rectangleOverhead += sz_rfbFramebufferUpdateRectHeader; return; } m_nNbRects=0; m_Queuelen=0; must_be_zipped=false; lzo1x_1_compress(m_Queuebuffer,rawDataSize,m_QueueCompressedbuffer,&out_len,wrkmem); if (out_len>rawDataSize) { outConn->SendExactQueue( (char *)m_Queuebuffer, m_Queuelen); // 1 Small update m_nNbRects=0; m_Queuelen=0; encodedSize += m_Queuelen-sz_rfbFramebufferUpdateRectHeader; rectangleOverhead += sz_rfbFramebufferUpdateRectHeader; return; } int rawDataSize1=rawDataSize/65535; int rawDataSize2=rawDataSize%65535; rfbFramebufferUpdateRectHeader CacheRectsHeader; CacheRectsHeader.r.x = (CARD16)(NRects); CacheRectsHeader.r.y = (CARD16)(rawDataSize2); CacheRectsHeader.r.w = (CARD16)(rawDataSize1); CacheRectsHeader.r.x = Swap16IfLE(CacheRectsHeader.r.x); CacheRectsHeader.r.y = Swap16IfLE(CacheRectsHeader.r.y); CacheRectsHeader.r.w = Swap16IfLE(CacheRectsHeader.r.w); CacheRectsHeader.r.h = 0; CacheRectsHeader.encoding = Swap32IfLE(rfbEncodingUltraZip); // Format the UltraHeader rfbZlibHeader CacheZipHeader; CacheZipHeader.nBytes = Swap32IfLE(out_len); vnclog.Print(LL_INTINFO, VNCLOG("********QUEUEQUEUE********** %d %d %d\r\n"),out_len,rawDataSize,NRects); outConn->SendExactQueue((char *)&CacheRectsHeader, sizeof(CacheRectsHeader)); outConn->SendExactQueue((char *)&CacheZipHeader, sizeof(CacheZipHeader)); outConn->SendExactQueue((char *)m_QueueCompressedbuffer, out_len); // Update statistics encodedSize += sz_rfbZlibHeader + out_len; rectangleOverhead += sz_rfbFramebufferUpdateRectHeader; transmittedSize += out_len+sz_rfbFramebufferUpdateRectHeader+sz_rfbZlibHeader; }
static Bool HandleRREBPP (int rx, int ry, int rw, int rh) { rfbRREHeader hdr; XGCValues gcv; int i; CARDBPP pix; rfbRectangle subrect; if (!ReadFromRFBServer((char *)&hdr, sz_rfbRREHeader)) return False; hdr.nSubrects = Swap32IfLE(hdr.nSubrects); if (!ReadFromRFBServer((char *)&pix, sizeof(pix))) return False; #if (BPP == 8) gcv.foreground = (appData.useBGR233 ? BGR233ToPixel[pix] : pix); #else gcv.foreground = pix; #endif XChangeGC(dpy, gc, GCForeground, &gcv); XFillRectangle(dpy, desktopWin, gc, rx, ry, rw, rh); #if VNC_CAPTURE myxfillrec(dpy, gc, rx, ry, rw, rh); #endif for (i = 0; i < hdr.nSubrects; i++) { if (!ReadFromRFBServer((char *)&pix, sizeof(pix))) return False; if (!ReadFromRFBServer((char *)&subrect, sz_rfbRectangle)) return False; subrect.x = Swap16IfLE(subrect.x); subrect.y = Swap16IfLE(subrect.y); subrect.w = Swap16IfLE(subrect.w); subrect.h = Swap16IfLE(subrect.h); #if (BPP == 8) gcv.foreground = (appData.useBGR233 ? BGR233ToPixel[pix] : pix); #else gcv.foreground = pix; #endif XChangeGC(dpy, gc, GCForeground, &gcv); XFillRectangle(dpy, desktopWin, gc, rx + subrect.x, ry + subrect.y, subrect.w, subrect.h); #if VNC_CAPTURE myxfillrec(dpy, gc, rx+ subrect.x, ry+ subrect.y, subrect.w, subrect.h); #endif } return True; }
Bool SetFormatAndEncodings() { printf("--- SetFormatAndEncodings\n"); rfbSetPixelFormatMsg spf; char buf[sz_rfbSetEncodingsMsg + MAX_ENCODINGS * 4]; rfbSetEncodingsMsg *se = (rfbSetEncodingsMsg *)buf; CARD32 *encs = (CARD32 *)(&buf[sz_rfbSetEncodingsMsg]); int len = 0; int i; spf.type = rfbSetPixelFormat; spf.format = myFormat; spf.format.redMax = Swap16IfLE(spf.format.redMax); spf.format.greenMax = Swap16IfLE(spf.format.greenMax); spf.format.blueMax = Swap16IfLE(spf.format.blueMax); spf.format.bigEndian = (*(char *)&endianTest ? 0 : 1); if(!WriteExact(rfbsock, (char *)&spf, sz_rfbSetPixelFormatMsg)) return False; se->type = rfbSetEncodings; se->nEncodings = 0; for(i = 0; i < nExplicitEncodings; i++) { encs[se->nEncodings++] = Swap32IfLE(explicitEncodings[i]); } if(SameMachine(rfbsock)) { encs[se->nEncodings++] = Swap32IfLE(rfbEncodingRaw); } if(addCopyRect) encs[se->nEncodings++] = Swap32IfLE(rfbEncodingCopyRect); // if(addHextile) // encs[se->nEncodings++] = Swap32IfLE(rfbEncodingHextile); // if(addCoRRE) // encs[se->nEncodings++] = Swap32IfLE(rfbEncodingCoRRE); if(addRRE) encs[se->nEncodings++] = Swap32IfLE(rfbEncodingRRE); if(addUseAlpha) { encs[se->nEncodings++] = Swap32IfLE(rfbEncSpecialUseAlpha); printf("--- Set: rfbEncSpecialUseAlpha\n"); } len = sz_rfbSetEncodingsMsg + se->nEncodings * 4; se->nEncodings = Swap16IfLE(se->nEncodings); if(!WriteExact(rfbsock, buf, len)) return False; return True; }
void ClientConnection::ReadCopyRect(rfbFramebufferUpdateRectHeader *pfburh) { rfbCopyRect cr; ReadExact((char *) &cr, sz_rfbCopyRect); cr.srcX = Swap16IfLE(cr.srcX); cr.srcY = Swap16IfLE(cr.srcY); // By sure the rect is insite the border memcopy does not like it if (!Check_Rectangle_borders(pfburh->r.x, pfburh->r.y, pfburh->r.w, pfburh->r.h)) return; if (!Check_Rectangle_borders(cr.srcX, cr.srcY, pfburh->r.w, pfburh->r.h)) return; // tight If *Cursor encoding is used, we should extend our "cursor lock area" // (previously set to destination rectangle) to the source rect as well. SoftCursorLockArea(cr.srcX, cr.srcY, pfburh->r.w, pfburh->r.h); if (m_DIBbits) { omni_mutex_lock l(m_bitmapdcMutex); int bytesPerInputRow = m_si.framebufferWidth * m_myFormat.bitsPerPixel/8; int bytesPerOutputRow = pfburh->r.w * m_myFormat.bitsPerPixel/8; int OutputHeight=pfburh->r.h; BYTE *sourcepos,*iptr,*destpos,*optr; if (cr.srcY<=pfburh->r.y) { { destpos = (BYTE*)m_DIBbits + (bytesPerInputRow * (pfburh->r.y+pfburh->r.h-1))+(pfburh->r.x * m_myFormat.bitsPerPixel/8); sourcepos = (BYTE*)m_DIBbits + (bytesPerInputRow * (cr.srcY+pfburh->r.h-1))+((cr.srcX) * m_myFormat.bitsPerPixel/8); iptr=sourcepos; optr=destpos; while (OutputHeight > 0) { memcpy(optr, iptr, bytesPerOutputRow); iptr -= bytesPerInputRow; optr -= bytesPerInputRow; OutputHeight--; } } } else if (cr.srcY>pfburh->r.y) { { destpos = (BYTE*)m_DIBbits + (bytesPerInputRow * pfburh->r.y)+(pfburh->r.x * m_myFormat.bitsPerPixel/8); sourcepos = (BYTE*)m_DIBbits + (bytesPerInputRow * (cr.srcY))+((cr.srcX) * m_myFormat.bitsPerPixel/8); iptr=sourcepos; optr=destpos; while (OutputHeight > 0) { memcpy(optr, iptr, bytesPerOutputRow); iptr += bytesPerInputRow; optr += bytesPerInputRow; OutputHeight--; } } } } }
// Send the encoder-generated palette to the client // This function only returns FALSE if the SendExact fails - any other // error is coped with internally... BOOL vncClient::SendPalette() { rfbSetColourMapEntriesMsg setcmap; RGBQUAD *rgbquad; UINT ncolours = 256; // Reserve space for the colour data rgbquad = new RGBQUAD[ncolours]; if (rgbquad == NULL) return TRUE; // Get the data if (!m_encodemgr.GetPalette(rgbquad, ncolours)) { delete [] rgbquad; return TRUE; } // Compose the message setcmap.type = rfbSetColourMapEntries; setcmap.firstColour = Swap16IfLE(0); setcmap.nColours = Swap16IfLE(ncolours); if (!m_socket->SendExact((char *) &setcmap, sz_rfbSetColourMapEntriesMsg)) { delete [] rgbquad; return FALSE; } // Now send the actual colour data... for (int i=0; i<ncolours; i++) { struct _PIXELDATA { CARD16 r, g, b; } pixeldata; pixeldata.r = Swap16IfLE(((CARD16)rgbquad[i].rgbRed) << 8); pixeldata.g = Swap16IfLE(((CARD16)rgbquad[i].rgbGreen) << 8); pixeldata.b = Swap16IfLE(((CARD16)rgbquad[i].rgbBlue) << 8); if (!m_socket->SendExact((char *) &pixeldata, sizeof(pixeldata))) { delete [] rgbquad; return FALSE; } } // Delete the rgbquad data delete [] rgbquad; return TRUE; }
void ClientConnection::ReadUltraZip(rfbFramebufferUpdateRectHeader *pfburh,HRGN *prgn) { UINT nNbCacheRects = pfburh->r.x; UINT numRawBytes = pfburh->r.y+pfburh->r.w*65535; UINT numCompBytes; lzo_uint new_len; rfbZlibHeader hdr; // Read in the rfbZlibHeader omni_mutex_lock l(m_bitmapdcMutex); ReadExact((char *)&hdr, sz_rfbZlibHeader); numCompBytes = Swap32IfLE(hdr.nBytes); // Check the net buffer CheckBufferSize(numCompBytes); // Read the compressed data ReadExact((char *)m_netbuf, numCompBytes); // Verify buffer space for cache rects list CheckZlibBufferSize(numRawBytes+500); lzo1x_decompress((BYTE*)m_netbuf,numCompBytes,(BYTE*)m_zlibbuf,&new_len,NULL); BYTE* pzipbuf = m_zlibbuf; for (UINT i = 0 ; i < nNbCacheRects; i++) { rfbFramebufferUpdateRectHeader surh; memcpy((char *) &surh,pzipbuf, sz_rfbFramebufferUpdateRectHeader); surh.r.x = Swap16IfLE(surh.r.x); surh.r.y = Swap16IfLE(surh.r.y); surh.r.w = Swap16IfLE(surh.r.w); surh.r.h = Swap16IfLE(surh.r.h); surh.encoding = Swap32IfLE(surh.encoding); pzipbuf += sz_rfbFramebufferUpdateRectHeader; RECT rect; rect.left = surh.r.x; rect.right = surh.r.x + surh.r.w; rect.top = surh.r.y; rect.bottom = surh.r.y + surh.r.h; //border check if (!Check_Rectangle_borders(rect.left,rect.top,surh.r.w,surh.r.h)) return; SoftCursorLockArea(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); if ( surh.encoding==rfbEncodingRaw) { UINT numpixels = surh.r.w * surh.r.h; if (m_DIBbits) ConvertAll(surh.r.w,surh.r.h,surh.r.x, surh.r.y,m_myFormat.bitsPerPixel/8,(BYTE *)pzipbuf,(BYTE *)m_DIBbits,m_si.framebufferWidth); pzipbuf +=numpixels*m_myFormat.bitsPerPixel/8; if (!m_opts.m_Directx)InvalidateRegion(&rect,prgn); } } }
Bool SendPointerEvent(int x, int y, int buttonMask) { rfbPointerEventMsg pe; pe.type = rfbPointerEvent; pe.buttonMask = buttonMask; if(x < 0) x = 0; if(y < 0) y = 0; pe.x = Swap16IfLE(x); pe.y = Swap16IfLE(y); return WriteExact(rfbsock, (char *)&pe, sz_rfbPointerEventMsg); }
Bool SendSetPixelFormat() { rfbSetPixelFormatMsg spf; spf.type = rfbSetPixelFormat; spf.format = myFormat; spf.format.redMax = Swap16IfLE(spf.format.redMax); spf.format.greenMax = Swap16IfLE(spf.format.greenMax); spf.format.blueMax = Swap16IfLE(spf.format.blueMax); PrintPixelFormat(&myFormat); return WriteToRFBServer((char *)&spf, sz_rfbSetPixelFormatMsg); }
void FileTransfer::SendFileUploadDataMessage(unsigned short size, char *pFile) { int msgLen = sz_rfbFileUploadDataMsg + size; char *pAllFUDMessage = new char[msgLen]; rfbFileUploadDataMsg *pFUD = (rfbFileUploadDataMsg *) pAllFUDMessage; char *pFollow = &pAllFUDMessage[sz_rfbFileUploadDataMsg]; pFUD->type = rfbFileUploadData; pFUD->compressedLevel = 0; pFUD->realSize = Swap16IfLE(size); pFUD->compressedSize = Swap16IfLE(size); memcpy(pFollow, pFile, size); m_clientconn->WriteExact(pAllFUDMessage, msgLen); delete [] pAllFUDMessage; }
static rfbBool rfbSetClientColourMapBGR233(rfbClientPtr cl) { char buf[sz_rfbSetColourMapEntriesMsg + 256 * 3 * 2]; rfbSetColourMapEntriesMsg *scme = (rfbSetColourMapEntriesMsg *)buf; uint16_t *rgb = (uint16_t *)(&buf[sz_rfbSetColourMapEntriesMsg]); int i, len; int r, g, b; if (cl->format.bitsPerPixel != 8 ) { ///rfbErr("%s: client not 8 bits per pixel\n", /// "rfbSetClientColourMapBGR233"); rfbCloseClient(cl); return FALSE; } scme->type = rfbSetColourMapEntries; scme->firstColour = Swap16IfLE(0); scme->nColours = Swap16IfLE(256); len = sz_rfbSetColourMapEntriesMsg; i = 0; for (b = 0; b < 4; b++) { for (g = 0; g < 8; g++) { for (r = 0; r < 8; r++) { rgb[i++] = Swap16IfLE(r * 65535 / 7); rgb[i++] = Swap16IfLE(g * 65535 / 7); rgb[i++] = Swap16IfLE(b * 65535 / 3); } } } len += 256 * 3 * 2; if (rfbWriteExact(cl, buf, len) < 0) { ///rfbLogPerror("rfbSetClientColourMapBGR233: write"); rfbCloseClient(cl); return FALSE; } return TRUE; }
BOOL FileTransfer:: SendFileDownloadRequest() { char path[rfbMAX_PATH + rfbMAX_PATH]; if (!m_FTServerItemInfo.IsFile(m_currentDownloadIndex)) { SetWindowText(m_hwndFTStatus, "Cannot download: not a regular file."); // Send message to start download for next selected file. PostMessage(m_hwndFileTransfer, WM_COMMAND, IDC_FTCOPY, 0); return TRUE; } ListView_GetItemText(m_hwndFTServerList, m_currentDownloadIndex, 0, m_ServerFilename, rfbMAX_PATH); strcpy(m_ClientFilename, m_ServerFilename); char buffer[rfbMAX_PATH + rfbMAX_PATH + rfbMAX_PATH]; sprintf(buffer, "Downloading: %s\\%s -> %s\\%s ...", m_ServerPath, m_ServerFilename, m_ClientPath, m_ClientFilename); SetWindowText(m_hwndFTStatus, buffer); m_sizeDownloadFile = m_FTServerItemInfo.GetIntSizeAt(m_currentDownloadIndex); rfbFileDownloadRequestMsg fdr; fdr.type = rfbFileDownloadRequest; fdr.compressedLevel = 0; fdr.position = Swap32IfLE(0); sprintf(path, "%s\\%s", m_ServerPath, m_ServerFilename); ConvertPath(path); int len = strlen(path); fdr.fNameSize = Swap16IfLE(len); m_clientconn->WriteExact((char *)&fdr, sz_rfbFileDownloadRequestMsg); m_clientconn->WriteExact(path, len); return TRUE; }
void FileTransfer::ReadDownloadFailed() { // We'll report the error only if we're actually downloading BOOL downloadActive = m_bDownloadStarted; // Stop file transfer CloseUndoneFileTransfers(); // Read the message rfbFileDownloadFailedMsg msg; m_clientconn->ReadExact((char *)&msg, sz_rfbFileDownloadFailedMsg); int len = Swap16IfLE(msg.reasonLen); char *reason = new char[len + 1]; m_clientconn->ReadExact(reason, len); reason[len] = '\0'; // Report error if (downloadActive) { char *errmsg = new char[128 + len]; sprintf(errmsg, "Download failed: %s", reason); MessageBox(m_hwndFileTransfer, errmsg, "Download Failed", MB_ICONEXCLAMATION | MB_OK); SetWindowText(m_hwndFTStatus, errmsg); vnclog.Print(1, _T("Download failed: %s\n"), reason); delete[] errmsg; } delete[] reason; // Enable dialog EnableWindow(GetDlgItem(m_hwndFileTransfer, IDC_FTCANCEL), FALSE); BlockingFileTransferDialog(TRUE); }
void FileTransfer::ReadUploadCancel() { if (m_bUploadStarted) { m_bUploadStarted = FALSE; CloseHandle(m_hFiletoRead); } // Stop file transfer CloseUndoneFileTransfers(); // Read the message rfbFileUploadCancelMsg msg; m_clientconn->ReadExact((char *)&msg, sz_rfbFileUploadCancelMsg); int len = Swap16IfLE(msg.reasonLen); char *reason = new char[len + 1]; m_clientconn->ReadExact(reason, len); reason[len] = '\0'; // Report error (only once per upload) if (m_bReportUploadCancel) { char *errmsg = new char[128 + len]; sprintf(errmsg, "Upload failed: %s", reason); MessageBox(m_hwndFileTransfer, errmsg, "Upload Failed", MB_ICONEXCLAMATION | MB_OK); SetWindowText(m_hwndFTStatus, errmsg); vnclog.Print(1, _T("Upload failed: %s\n"), reason); m_bReportUploadCancel = FALSE; delete[] errmsg; } delete[] reason; // Enable dialog EnableWindow(GetDlgItem(m_hwndFileTransfer, IDC_FTCANCEL), FALSE); BlockingFileTransferDialog(TRUE); }
FileTransferMsg CreateFileUploadErrMsg(char* reason, unsigned int reasonLen) { FileTransferMsg fileUploadErrMsg; int length = sz_rfbFileUploadCancelMsg + reasonLen; rfbFileUploadCancelMsg *pFDF = NULL; char *pFollow = NULL; char *pData = (char*) calloc(length, sizeof(char)); memset(&fileUploadErrMsg, 0, sizeof(FileTransferMsg)); if(pData == NULL) { rfbLog("File [%s]: Method [%s]: pData is NULL\n", __FILE__, __FUNCTION__); return fileUploadErrMsg; } pFDF = (rfbFileUploadCancelMsg *) pData; pFollow = &pData[sz_rfbFileUploadCancelMsg]; pFDF->type = rfbFileUploadCancel; pFDF->reasonLen = Swap16IfLE(reasonLen); memcpy(pFollow, reason, reasonLen); fileUploadErrMsg.data = pData; fileUploadErrMsg.length = length; return fileUploadErrMsg; }
void ClientConnection::ReadCopyRect(rfbFramebufferUpdateRectHeader *pfburh) { rfbCopyRect cr; ReadExact((char *) &cr, sz_rfbCopyRect); cr.srcX = Swap16IfLE(cr.srcX); cr.srcY = Swap16IfLE(cr.srcY); omni_mutex_lock l(m_bitmapdcMutex); ObjectSelector b(m_hBitmapDC, m_hBitmap); PaletteSelector p(m_hBitmapDC, m_hPalette); if (!BitBlt( m_hBitmapDC,pfburh->r.x, pfburh->r.y, pfburh->r.w, pfburh->r.h, m_hBitmapDC, cr.srcX, cr.srcY, SRCCOPY)) { log.Print(0, _T("Error in blit in ClientConnection::CopyRect\n")); } }
Bool SendFramebufferUpdateRequest(int x, int y, int w, int h, Bool incremental) { rfbFramebufferUpdateRequestMsg fur; fur.type = rfbFramebufferUpdateRequest; fur.incremental = incremental ? 1 : 0; fur.x = Swap16IfLE(x); fur.y = Swap16IfLE(y); fur.w = Swap16IfLE(w); fur.h = Swap16IfLE(h); if (!WriteToRFBServer((char *)&fur, sz_rfbFramebufferUpdateRequestMsg)) return False; return True; }
void FileTransfer::SendFileUploadDataMessage(unsigned int mTime) { rfbFileUploadDataMsg msg; msg.type = rfbFileUploadData; msg.compressedLevel = 0; msg.realSize = Swap16IfLE(0); msg.compressedSize = Swap16IfLE(0); CARD32 time32 = Swap32IfLE((CARD32)mTime); char data[sz_rfbFileUploadDataMsg + sizeof(CARD32)]; memcpy(data, &msg, sz_rfbFileUploadDataMsg); memcpy(&data[sz_rfbFileUploadDataMsg], &time32, sizeof(CARD32)); m_clientconn->WriteExact(data, sz_rfbFileUploadDataMsg + sizeof(CARD32)); }
static void rfbProcessClientInitMessage(rfbClientPtr cl) { rfbClientInitMsg ci; char buf[256]; rfbServerInitMsg *si = (rfbServerInitMsg *)buf; int len, n; if ((n = ReadExact(cl, (char *)&ci,sz_rfbClientInitMsg)) <= 0) { if (n == 0) debug_printf("rfbProcessClientInitMessage: client gone\n"); else debug_printf("rfbProcessClientInitMessage: read"); rfbCloseClient(cl); return; } si->framebufferWidth = Swap16IfLE(cl->screen->width); si->framebufferHeight = Swap16IfLE(cl->screen->height); debug_printf("width=%d hieght=%d\n",cl->screen->width,cl->screen->height); si->format = cl->screen->rfbServerFormat; si->format.redMax = Swap16IfLE(si->format.redMax); si->format.greenMax = Swap16IfLE(si->format.greenMax); si->format.blueMax = Swap16IfLE(si->format.blueMax); if (strlen(cl->screen->desktopName) > 128) /* sanity check on desktop name len */ cl->screen->desktopName[128] = 0; strcpy(buf + sz_rfbServerInitMsg, cl->screen->desktopName); len = strlen(buf + sz_rfbServerInitMsg); si->nameLength = Swap32IfLE(len); if (WriteExact(cl, buf, sz_rfbServerInitMsg + len) < 0) { debug_printf("rfbProcessClientInitMessage: write"); rfbCloseClient(cl); return; } cl->state = RFB_NORMAL; if(ci.shared) { debug_printf("The client permit share!\n"); } else { debug_printf("The client refused share!\n"); } //关于是否共享的问题,以后再谈 }
int rfbSendSetColourMapEntries(rfbClientPtr cl, int firstColour, int nColours) { char buf[sz_rfbSetColourMapEntriesMsg + 256 * 3 * 2]; char *wbuf = buf; rfbSetColourMapEntriesMsg *scme; unsigned short *rgb; int i, len; if (nColours > 256) { /* some rare hardware has, e.g., 4096 colors cells: PseudoColor:12 */ wbuf = (char *) malloc(sz_rfbSetColourMapEntriesMsg + nColours * 3 * 2); } scme = (rfbSetColourMapEntriesMsg *)wbuf; rgb = (u16 *)(&wbuf[sz_rfbSetColourMapEntriesMsg]); scme->type = rfbSetColourMapEntries; scme->firstColour = Swap16IfLE(firstColour); scme->nColours = Swap16IfLE(nColours); len = sz_rfbSetColourMapEntriesMsg; for (i = 0; i < nColours; i++) { rgb[i*3] = Swap16IfLE(i); rgb[i*3+1] = Swap16IfLE(i); rgb[i*3+2] = Swap16IfLE(i); } len += nColours * 3 * 2; if (WriteExact(cl, wbuf, len) < 0) { debug_printf("rfbSendSetColourMapEntries: write"); rfbCloseClient(cl); if (wbuf != buf) free(wbuf); return FALSE; } if (wbuf != buf) free(wbuf); return TRUE; }
static Bool ReadInteractionCaps(void) { rfbInteractionCapsMsg intr_caps; /* Read the counts of list items following */ if (!ReadFromRFBServer((char *)&intr_caps, sz_rfbInteractionCapsMsg)) return False; intr_caps.nServerMessageTypes = Swap16IfLE(intr_caps.nServerMessageTypes); intr_caps.nClientMessageTypes = Swap16IfLE(intr_caps.nClientMessageTypes); intr_caps.nEncodingTypes = Swap16IfLE(intr_caps.nEncodingTypes); /* Read the lists of server- and client-initiated messages */ return (ReadCapabilityList(serverMsgCaps, intr_caps.nServerMessageTypes) && ReadCapabilityList(clientMsgCaps, intr_caps.nClientMessageTypes) && ReadCapabilityList(encodingCaps, intr_caps.nEncodingTypes)); }
void vncEncodeTight::SendTightHeader(int x, int y, int w, int h) { rfbFramebufferUpdateRectHeader rect; rect.r.x = Swap16IfLE(x - offsetx); rect.r.y = Swap16IfLE(y - offsety); rect.r.w = Swap16IfLE(w); rect.r.h = Swap16IfLE(h); rect.encoding = Swap32IfLE(rfbEncodingTight); dataSize += w * h * (m_remoteformat.bitsPerPixel / 8); rectangleOverhead += sz_rfbFramebufferUpdateRectHeader; memcpy(m_hdrBuffer, (BYTE *)&rect, sz_rfbFramebufferUpdateRectHeader); m_hdrBufferBytes = sz_rfbFramebufferUpdateRectHeader; }
FileTransferMsg CreateFileListMsg(FileListInfo fileListInfo, char flags) { FileTransferMsg fileListMsg; rfbFileListDataMsg* pFLD = NULL; char *data = NULL, *pFileNames = NULL; unsigned int length = 0, dsSize = 0, i = 0; FileListItemSizePtr pFileListItemSize = NULL; memset(&fileListMsg, 0, sizeof(FileTransferMsg)); dsSize = fileListInfo.numEntries * 8; length = sz_rfbFileListDataMsg + dsSize + GetSumOfFileNamesLength(fileListInfo) + fileListInfo.numEntries; data = (char*) calloc(length, sizeof(char)); if(data == NULL) { return fileListMsg; } pFLD = (rfbFileListDataMsg*) data; pFileListItemSize = (FileListItemSizePtr) &data[sz_rfbFileListDataMsg]; pFileNames = &data[sz_rfbFileListDataMsg + dsSize]; pFLD->type = rfbFileListData; pFLD->flags = flags & 0xF0; pFLD->numFiles = Swap16IfLE(fileListInfo.numEntries); pFLD->dataSize = Swap16IfLE(GetSumOfFileNamesLength(fileListInfo) + fileListInfo.numEntries); pFLD->compressedSize = pFLD->dataSize; for(i =0; i <fileListInfo.numEntries; i++) { pFileListItemSize[i].size = Swap32IfLE(GetFileSizeAt(fileListInfo, i)); pFileListItemSize[i].data = Swap32IfLE(GetFileDataAt(fileListInfo, i)); strcpy(pFileNames, GetFileNameAt(fileListInfo, i)); if(i+1 < fileListInfo.numEntries) pFileNames += strlen(pFileNames) + 1; } fileListMsg.data = data; fileListMsg.length = length; return fileListMsg; }