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 #ifdef LIBVNCSERVER_HAVE_LIBZ
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #define HandleZlibBPP CONCAT2E(HandleZlib,BPP)
00033 #define CARDBPP CONCAT3E(uint,BPP,_t)
00034
00035 static rfbBool
00036 HandleZlibBPP (rfbClient* client, int rx, int ry, int rw, int rh)
00037 {
00038 rfbZlibHeader hdr;
00039 int remaining;
00040 int inflateResult;
00041 int toRead;
00042
00043
00044
00045
00046
00047
00048
00049 if ( client->raw_buffer_size < (( rw * rh ) * ( BPP / 8 ))) {
00050
00051 if ( client->raw_buffer != NULL ) {
00052
00053 free( client->raw_buffer );
00054
00055 }
00056
00057 client->raw_buffer_size = (( rw * rh ) * ( BPP / 8 ));
00058 client->raw_buffer = (char*) malloc( client->raw_buffer_size );
00059
00060 }
00061
00062 if (!ReadFromRFBServer(client, (char *)&hdr, sz_rfbZlibHeader))
00063 return FALSE;
00064
00065 remaining = rfbClientSwap32IfLE(hdr.nBytes);
00066
00067
00068 client->decompStream.next_in = ( Bytef * )client->buffer;
00069 client->decompStream.avail_in = 0;
00070 client->decompStream.next_out = ( Bytef * )client->raw_buffer;
00071 client->decompStream.avail_out = client->raw_buffer_size;
00072 client->decompStream.data_type = Z_BINARY;
00073
00074
00075 if ( client->decompStreamInited == FALSE ) {
00076
00077 inflateResult = inflateInit( &client->decompStream );
00078
00079 if ( inflateResult != Z_OK ) {
00080 rfbClientLog(
00081 "inflateInit returned error: %d, msg: %s\n",
00082 inflateResult,
00083 client->decompStream.msg);
00084 return FALSE;
00085 }
00086
00087 client->decompStreamInited = TRUE;
00088
00089 }
00090
00091 inflateResult = Z_OK;
00092
00093
00094
00095
00096 while (( remaining > 0 ) &&
00097 ( inflateResult == Z_OK )) {
00098
00099 if ( remaining > RFB_BUFFER_SIZE ) {
00100 toRead = RFB_BUFFER_SIZE;
00101 }
00102 else {
00103 toRead = remaining;
00104 }
00105
00106
00107 if (!ReadFromRFBServer(client, client->buffer,toRead))
00108 return FALSE;
00109
00110 client->decompStream.next_in = ( Bytef * )client->buffer;
00111 client->decompStream.avail_in = toRead;
00112
00113
00114 inflateResult = inflate( &client->decompStream, Z_SYNC_FLUSH );
00115
00116
00117 if ( inflateResult == Z_NEED_DICT ) {
00118 rfbClientLog("zlib inflate needs a dictionary!\n");
00119 return FALSE;
00120 }
00121 if ( inflateResult < 0 ) {
00122 rfbClientLog(
00123 "zlib inflate returned error: %d, msg: %s\n",
00124 inflateResult,
00125 client->decompStream.msg);
00126 return FALSE;
00127 }
00128
00129
00130
00131
00132 if (( client->decompStream.avail_in > 0 ) &&
00133 ( client->decompStream.avail_out <= 0 )) {
00134 rfbClientLog("zlib inflate ran out of space!\n");
00135 return FALSE;
00136 }
00137
00138 remaining -= toRead;
00139
00140 }
00141
00142 if ( inflateResult == Z_OK ) {
00143
00144
00145 CopyRectangle(client, (uint8_t *)client->raw_buffer, rx, ry, rw, rh);
00146 }
00147 else {
00148
00149 rfbClientLog(
00150 "zlib inflate returned error: %d, msg: %s\n",
00151 inflateResult,
00152 client->decompStream.msg);
00153 return FALSE;
00154
00155 }
00156
00157 return TRUE;
00158 }
00159
00160 #undef CARDBPP
00161
00162 #endif