diff -Nru oscam-1.20-10584~r10356/config.h oscam-1.20-10797~r10569/config.h --- oscam-1.20-10584~r10356/config.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/config.h 2015-02-20 11:57:49.000000000 +0000 @@ -6,7 +6,7 @@ #define WEBIF_JQUERY 1 #define TOUCH 1 //#define WITH_SSL 1 -#if defined(__linux__) +#if defined(__linux__) || defined(__CYGWIN__) #define HAVE_DVBAPI 1 #endif #define CLOCKFIX 1 diff -Nru oscam-1.20-10584~r10356/cscrypt/bn_div.c oscam-1.20-10797~r10569/cscrypt/bn_div.c --- oscam-1.20-10584~r10356/cscrypt/bn_div.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/cscrypt/bn_div.c 2015-02-20 11:57:49.000000000 +0000 @@ -144,7 +144,7 @@ * */ # define bn_div_words(n0,n1,d0) \ - ({ asm volatile ( \ + ({ __asm__ volatile ( \ "divl %4" \ : "=a"(q), "=d"(rem) \ : "a"(n1), "d"(n0), "g"(d0) \ diff -Nru oscam-1.20-10584~r10356/cscrypt/bn_lcl.h oscam-1.20-10797~r10569/cscrypt/bn_lcl.h --- oscam-1.20-10584~r10356/cscrypt/bn_lcl.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/cscrypt/bn_lcl.h 2015-02-20 11:57:49.000000000 +0000 @@ -202,7 +202,7 @@ # elif defined(__GNUC__) # define BN_UMULT_HIGH(a,b) ({ \ register BN_ULONG ret; \ - asm ("umulh %1,%2,%0" \ + __asm__ ("umulh %1,%2,%0" \ : "=r"(ret) \ : "r"(a), "r"(b)); \ ret; }) @@ -211,7 +211,7 @@ # if defined(__GNUC__) # define BN_UMULT_HIGH(a,b) ({ \ register BN_ULONG ret; \ - asm ("mulhdu %0,%1,%2" \ + __asm__ ("mulhdu %0,%1,%2" \ : "=r"(ret) \ : "r"(a), "r"(b)); \ ret; }) diff -Nru oscam-1.20-10584~r10356/csctapi/icc_async.c oscam-1.20-10797~r10569/csctapi/icc_async.c --- oscam-1.20-10584~r10356/csctapi/icc_async.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/csctapi/icc_async.c 2015-02-20 11:57:49.000000000 +0000 @@ -663,13 +663,16 @@ tempfi = FI; //set clock speed to max if internal reader - if(reader->crdr.max_clock_speed == 1) + if(reader->crdr.max_clock_speed == 1 && reader->typ == R_INTERNAL) { - if((reader->mhz == 357 || reader->mhz == 358) && reader->autospeed == 1) //no overclocking + if(reader->autospeed == 1) //no overclocking { reader->mhz = atr_fs_table[FI] / 10000; } //we are going to clock the card to this nominal frequency if(reader->cardmhz > 2000 && reader->autospeed == 1) // -1 replaced by autospeed parameter is magic number pll internal reader set cardmhz according to optimal atr speed - { reader->mhz = atr_fs_table[FI] / 10000 ; } + { + reader->mhz = atr_fs_table[FI] / 10000 ; + if((!strncmp(boxtype_get(), "vu", 2 ))||(boxtype_is("ini-8000am"))){reader->mhz = 450;} + } } if(reader->cardmhz > 2000) @@ -697,7 +700,8 @@ } if(reader->cardmhz > 2000 && reader->typ == R_INTERNAL) { F = reader->mhz; } // for PLL based internal readers else { - if ((reader->typ == R_SMART) || (!strcasecmp(reader->crdr.desc, "smargo"))) { + if (reader->typ == R_SMART || is_smargo_reader(reader)) + { if (reader->autospeed == 1) { uint32_t Fsmart = atr_fs_table[FI]; reader->mhz = Fsmart/10000; @@ -887,7 +891,7 @@ { if(reader->cardmhz > 2000) { - rdr_log(reader, "PLL Reader: ATR Fsmax is %i MHz, clocking card to %.2f Mhz (nearest possible mhz specified reader->cardmhz)", + rdr_log(reader, "PLL Reader: ATR Fsmax is %i MHz, clocking card to %.2f Mhz (nearest possible mhz specified reader->mhz)", atr_fs_table[FI] / 1000000, (float) reader->mhz / 100); } else diff -Nru oscam-1.20-10584~r10356/csctapi/ifd_sci.c oscam-1.20-10797~r10569/csctapi/ifd_sci.c --- oscam-1.20-10584~r10356/csctapi/ifd_sci.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/csctapi/ifd_sci.c 2015-02-20 11:57:49.000000000 +0000 @@ -35,9 +35,6 @@ unsigned char I; }; -static int32_t init_count; -static int32_t current_count; - static int32_t Sci_GetStatus(struct s_reader *reader, int32_t *status) { call (ioctl(reader->handle, IOCTL_GET_IS_CARD_PRESENT, status)<0); @@ -55,10 +52,15 @@ } if (in != 1) {ioctl(reader->handle, IOCTL_GET_IS_CARD_ACTIVATED, &in);} - if(in) + if(in && boxtype_is("dm8000")) { - call (ioctl(reader->handle, IOCTL_SET_DEACTIVATE)<0); + if((ioctl(reader->handle, IOCTL_SET_DEACTIVATE)<0)) + { + rdr_log(reader,"ioctl(IOCTL_SET_DEACTIVATE) not supported on %s", boxtype_get()); + return ERROR; + } } + else {return ERROR;} return OK; @@ -78,7 +80,6 @@ if (in) { -// rdr_log(reader, "Card is present in readerslot!"); cs_sleepms(50); return OK; } @@ -245,6 +246,17 @@ statusreturn = ATR_InitFromArray(atr, buf, n); // n should be same as atrlength but in case of atr read error its less so do not use atrlenght here! + if(buf[7] == 0x70 && buf[8] == 0x70 && (buf[9]&0x0F) >= 10) + { + int8_t nxtr = 0; + reader->crdr.flush = 0; + while(nxtr < 2) + { + if(IO_Serial_Read(reader, 0, 75000, 1, buf + n + nxtr)) { break; } + nxtr++; + } + } + if(statusreturn == ATR_MALFORMED) { rdr_log(reader, "WARNING: ATR is malformed, you better inspect it with a -d2 log!"); } if(statusreturn == ERROR) @@ -467,12 +479,14 @@ static int32_t Sci_Init(struct s_reader *reader) { - if(!init_count) {init_count = 0;} - if(init_count < current_count) {rdr_log(reader,"Waiting on reader_closed before restarting");} - while (init_count < current_count) // Restarting the reader while it was not closed does cause segfault. + uint8_t i = 0; + while(reader->handle_nr > 0 && i < 5) { + i++; + rdr_log(reader," Wait On closing before restart %u", i); cs_sleepms(1000); } + int flags = O_RDWR | O_NOCTTY; #if defined(__SH4__) || defined(STB04SCI) flags |= O_NONBLOCK; @@ -489,9 +503,7 @@ { return ERROR; } struct sr_data *crdr_data = reader->crdr_data; crdr_data->old_reset = 1; - init_count++; - current_count++; - + reader->handle_nr = reader->handle + 1; return OK; } @@ -512,11 +524,12 @@ static int32_t Sci_Close(struct s_reader *reader) { - --init_count; Sci_Deactivate(reader); IO_Serial_Close(reader); - cs_sleepms(300); // some stb's needs small extra time even after close procedure seems to be ok. - --current_count; + NULLFREE(reader->crdr_data); //clearing allocated module mem + NULLFREE(reader->csystem_data); //clearing allocated card system mem + cs_sleepms(150); // some stb's needs small extra time even after close procedure seems to be ok. + reader->handle_nr = 0; return OK; } diff -Nru oscam-1.20-10584~r10356/csctapi/ifd_smargo.c oscam-1.20-10797~r10569/csctapi/ifd_smargo.c --- oscam-1.20-10584~r10356/csctapi/ifd_smargo.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/csctapi/ifd_smargo.c 2015-02-20 11:57:49.000000000 +0000 @@ -50,7 +50,7 @@ smargo_set_config_mode_on(reader); - rdr_log_dbg(reader, D_DEVICE, "Smargo: sending F=%04X (%d), D=%02X (%d), Freq=%04X (%d), N=%02X (%d), T=%02X (%d), inv=%02X (%d)", + rdr_log_dbg(reader, D_DEVICE, "sending F=%04X (%d), D=%02X (%d), Freq=%04X (%d), N=%02X (%d), T=%02X (%d), inv=%02X (%d)", Fi, Fi, Di, Di, freqk, freqk, Ni, Ni, T, T, inv, inv); if(T != 14 || freq == 369) @@ -92,7 +92,6 @@ static int32_t smargo_init(struct s_reader *reader) { - rdr_log(reader, "smargo init type is %s", reader->crdr.desc); reader->handle = open(reader->device, O_RDWR); if(reader->handle < 0) @@ -175,7 +174,7 @@ static int32_t smargo_reset(struct s_reader *reader, ATR *atr) { - rdr_log_dbg(reader, D_IFD, "Smargo: Resetting card"); + rdr_log_dbg(reader, D_IFD, "Resetting card"); int32_t ret = ERROR; int32_t i; unsigned char buf[ATR_MAX_SIZE]; @@ -211,7 +210,7 @@ if(n == 0 || buf[0] == 0) { continue; } - rdr_log_dump_dbg(reader, D_IFD, buf, n, "Smargo ATR: %d bytes", n); + rdr_log_dump_dbg(reader, D_IFD, buf, n, "ATR: %d bytes", n); if((buf[0] != 0x3B && buf[0] != 0x03 && buf[0] != 0x3F) || (buf[1] == 0xFF && buf[2] == 0x00)) { continue; } // this is not a valid ATR diff -Nru oscam-1.20-10584~r10356/csctapi/ifd_smartreader.c oscam-1.20-10797~r10569/csctapi/ifd_smartreader.c --- oscam-1.20-10584~r10356/csctapi/ifd_smartreader.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/csctapi/ifd_smartreader.c 2015-02-20 11:57:49.000000000 +0000 @@ -1263,9 +1263,11 @@ static int32_t SR_Init(struct s_reader *reader) { - if(init_count < current_count) {rdr_log(reader,"Waiting on reader_closed before restarting");} - while (init_count < current_count) // Restarting the reader while it was not closed does cause segfault. + uint8_t i = 0; + while(reader->handle_nr > 0 && i < 10) // Restarting the reader while it was not closed does cause segfault. { + i++; + rdr_log(reader," Wait on close before restart second %u", i); cs_sleepms(1000); } @@ -1402,6 +1404,9 @@ --current_count; return ERROR; } + + reader->handle_nr = (long)crdr_data->usb_dev_handle + 1; + return OK; } @@ -1701,6 +1706,7 @@ } } + reader->handle_nr = 0; rdr_log(reader,"SR: smartreader closed"); return OK; diff -Nru oscam-1.20-10584~r10356/debian/changelog oscam-1.20-10797~r10569/debian/changelog --- oscam-1.20-10584~r10356/debian/changelog 2015-01-30 13:28:20.000000000 +0000 +++ oscam-1.20-10797~r10569/debian/changelog 2015-02-20 11:57:58.000000000 +0000 @@ -1,1711 +1,1916 @@ -oscam (1.20-10584~r10356-trusty) trusty; urgency=medium +oscam (1.20-10797~r10569-trusty) trusty; urgency=medium - * [r10356] - - Webif: (Tnx Ultra47 and oscam community members for their effort!) - - - Fix for http://www.streamboard.tv/oscam/ticket/4064 - - Patch r9947 enhanced - - Fix show written emms if emm logdir empty - - Optical fixes show written emms - - Show written emms on write emm tab sorted and filtred (oldest first, newest last), idea by schorsch - - - - - * [r10355] - - stat: Remove useless check. + * [r10569] - Checking for 'ea' just tricks static checkers that 'ea' can be NULL - which it can't be. + copy emm to send in emm.html + optimized loop - * [r10354] + * [r10568] - smartreader: Prevent NULL pointer derefence. + [gbx] code restructuring + - Centralize converting gbx caprovid functions in helper module + - unify add card functions + - move ecm checksum to helper + - remove caid and provid from card (use caprovid only) + - rename provid_1 to caprovid - * [r10353] - Correctly restore errno after nanosleep(). - - - * [r10352] - - [gbx] Obey reshare parameter of cccam also in gbx network. - Check for ECMs taking too many hops. + * [r10567] + boxtype info patch + http://www.streamboard.tv/wbb2/thread.php?postid=536576#post536576 - * [r10351] - fix for #4043 - * [r10350] + * [r10566] - oscam-config: Fix variable types. + Move csystem.active flag into struct s_reader. - If you have set `lb_force_fallback` in your config, because of wrong - variable type in oscam-config-reader.c initializing this variable overwrite - others after it. + This is the only thing that is modified in `struct s_cardsystem`. - This may lead to crashes and unexpected behaviour. + Moving this flag into `struct s_reader` would allow us to start + using pointer to card system ops, instead of copying the ops into + every `struct s_reader`. - * [r10349] + * [r10565] - devtools: Improve messages in check_config_tables.sh + Constify ->desc field in ops structures. + desc is always initialized with static strings, so adding const + communicates this correctly. - * [r10348] - devtools: Improve config table checking script. + * [r10564] + Remove ->active field from struct s_module. - * [r10347] + It is only set in one place but it is never used anywhere. - Prevent "too many open files" issue on OS X. - Patch by powercore posted in ticket #4008. + * [r10563] + Fix regression introduced in r10557 (try 2). - * [r10346] + This reverts r10162 and should fix fixes regression introduced + in r10557. - log: Third try to fix anticasc log. + r10562 was not the right fix. The right fix was to return the + caid when the list is empty. - This is a fix for ticket #4092. + This should fix ticket #4123 and #4142. - * [r10345] + * [r10562] - cccam: Move cacheex code into separate file. + Fix regression introduced in r10557. - This cleans up module-cccam.c (which is already very big) and - the ability to compare camd35 and cccam cacheex implementations. + This fixes regression introduced in r10557. chk_caid() func was + broken when I rewrote it and since it is pretty central to the whole + filtering the results were not pretty. - They have a lot of common. + This should fix ticket #4123. - Another nice thing is the removal of all CS_CACHEEX ifdefs in - cccam module. + * [r10561] - * [r10344] + smargo: Introduce is_smargo_reader() macro and use it where needed. - cacheex: Remove useless ifdefs. + This reduces direct manipulation of crdr.desc field. - The whole file is guarded by CS_CACHEEX ifdef, there is no - need for these extra ifdefs. + * [r10560] - * [r10343] + smargo: Remove smargo prefixes in log messages rdr_log() already adds them. - log: Fix for anticasc log. - Additional fix for ticket #4092. + * [r10559] + Do not leak caidtab when freeing accounts. - * [r10342] + Fix leak introduced in r10557. Account's caidtab was not cleared. - build: Do not warn about using openssl on OS X. + * [r10558] - * [r10341] + Replace cs_log() with rdr_log() where we have reader context. - log: Add missing new line in log lines. + This is not a complete solution, I only changed the places where + reader desc was already used in the logging message. There are + a lot of places (in modules) where we have reader context but + we're using cs_log(). If somebody wants to replace such cs_log() + calls with rdr_log(), grep for D_READER in modules-*.c - This fixes ticket #4092. + * [r10557] - * [r10340] + Convert caidtab to dynarray. - camd35: Move cacheex related code in module-camd35-cacheex.{c,h} - - Over 45% of the code in camd35 was dedicated to cacheex. So much - code deserves it's own file. This cleans camd35 a lot and makes - it ifdef free and a lot easier to follow. + Less code, smaller data structures, smaller binary size and added + tests for the functionality. + {{{ + Structures: + struct s_caidtab | -176 + struct s_reader | -168 + struct s_client | -176 + struct s_auth | -176 + struct s_config | -520 - * [r10339] + Binary: + add/remove: 3/1 grow/shrink: 10/10 up/down: 577/-1679 (-1102) + }}} - camd35: Add proper prefix to all functions that didn't have one. + caidtab is used by the following config settings: + ACCOUNT: caid + READER: caid + GLOBAL: lb_noproviderforcaid + GLOBAL: double_check_caid + GLOBAL: cwcycle_check_caid - * All camd35 funcs now have camd35_ prefix. - * All camd35 funcs that deal with cacheex now have camd35_cacheex_ prefix. + Now each of theses can hold more than 32 values which was the old + hard coded limit. - * [r10338] + * [r10556] - camd35: Mark funcs static where needed. + [gbx] Minor change regarding pointer handling in reinit proxy. - These functions are used only in this module. - * [r10337] - camd35: Prepare cacheex code for moving into separate file. + * [r10555] - This commit is just preparation for moving camd35 cacheex code - into separate file. + [gbx] Be even more pessimistic. Addition to 10554. - * [r10336] - camd35: Prepare cacheex code for moving into separate file. - This commit is just preparation for moving camd35 cacheex code - into separate file. + * [r10554] + [gbx] Protect against null pointer deref. Thx gfto. - * [r10335] - camd35: Prepare cacheex code for moving into separate file. - This commit is just preparation for moving camd35 cacheex code - into separate file. + * [r10553] - * [r10334] + Convert caidvaluetab to dynarray. - camd35: Prepare cacheex code for moving into separate file. + Less code, smaller data structures, smaller binary size and added + tests for the functionality. - This commit is just preparation for moving camd35 cacheex code - into separate file. + {{{ + Structures: + struct s_caidvaluetab | -50 + struct s_auth | -56 + Binary size: + add/remove: 3/0 grow/shrink: 4/5 up/down: 285/-872 (-587) + }}} - * [r10333] + caidvaluetab is used by the following config settings: + ACCOUNT: lb_nbest_percaid + GLOBAL: lb_nbest_percaid + GLOBAL: lb_retrylimits + GLOBAL: cacheex_mode1_delay + GLOBAL: fallbacktimeout_percaid - camd35: Prepare cacheex code for moving into separate file. + Now each of theses can hold more than 16 values which was the old + hard coded limit. - This commit is just preparation for moving camd35 cacheex code - into separate file. + * [r10552] - * [r10332] + Machine info - camd35: Prepare cacheex code for moving into separate file. + Azbox fix should now cover premium and premium+ - This commit is just preparation for moving camd35 cacheex code - into separate file. + * [r10551] - * [r10331] + Machine Info - camd35: Remove unneeded CS_CACHEEX ifdefs. + More solid for azbox - This code is already covered by ifdef CS_CACHEX, no need for - second check inside this ifdef. + * [r10550] - * [r10330] + Machine info - dvbapi experimental: auto filter limiting + Azbox premium - Some users experience "ERROR: read error on fd xx" - I guess this due to the fact too much filters (presumable emm type) are started and the box is killing random filters started before. - Even worse, soms boxes accept it all without returning to us no more filters we reached maximum. - On attempt to read the data from a certain filter the "ERROR: read error on fd xx" is returned. - Now this filter is killed and the max ammount filters is lowered by 1. - Once oscam is running for some time the max ammount filters will be settled on a value that works for your box. + * [r10549] - Feedback you can give here: http://www.streamboard.tv/wbb2/thread.php?postid=534445#post534445 + [gbx] Another small addition for r10547. - * [r10329] - WebIf: Right maxlegth for input (set Group) in user_edit.html + * [r10548] - Thx uf2k. + [gbx] Minor fix for r10547. - * [r10328] - - tryfix: moved the cs_sleepms() to a (hopefully) better place in the handler code + * [r10547] + [gbx] Move call to init_local_gbox as proposed here: + http://www.streamboard.tv/wbb2/thread.php?postid=536529#post536529 - * [r10327] - build: Fix smartreader compilation on OS X. - * [r10326] + * [r10546] - webif/pages_gen: Do not leak fds in readfile(). + webif: Change return type of tpl_{addVar,addMsg,printf} to void. - readfile() was not closing the file it opened. If your system - have lowered file open limits (like < 256) pages_gen failed - because there were too many open files. + The return value of these functions was used in only one place (and + it's usage was fishy). I'm changing the return type to void because + nothing that these functions can return is currently useful. - * [r10325] + * [r10545] - Reduce CS_CACHEEX ifdefs. + webif: Make tpl_addTmp() static and remove it from public headers. - * Structure definitions do not need to be guarded. - * Funcs that are not used would be dropped by the compiler. - * Func declarations do not need to be guarded. + This function is used only in module-webif-tpl.c. It should not be public. - No binary changes. + * [r10544] - * [r10324] + Update copyright years. - webif: Reduce WITH_LB ifdefs. + We have made changes in 2014 and 2015 (and we'll probably make even + more changes in 2015). So update the years to correctly reflect that + the code was changed. - We can use config_enabled() instead of ifdef in these cases. + * [r10543] - * [r10323] + If oscam is not running on "generic" device, show the type and name in webif. - config-reader: Reduce WITH_LB ifdefs. - Just code movement, no functional changes. + * [r10542] + Allow boxtype_is() to check for "generic" box type. - * [r10322] + Also return const declaration for box{type,name}_get() functions. const + is needed because the string returned by these functions should not be + changed. Using const makes the compiler work for us and warn if we try + to change the result of box{type,name}_get(). - config-account: Remove duplicated function. - The function already exists in oscam-config-global.c. - No need to copy/paste it. + * [r10541] + Free stb_boxname when oscam exists. - * [r10321] - camd35: Remove WITH_LB ifdefs. + * [r10540] - We can use config_enabled() instead of ifdef in this case. + webif: constify some parameters in template functions. + This makes it clear that these parameters are not going to be changed. - * [r10320] - chk: Remove WITH_LB ifdefs. + * [r10539] - Just code movement, no functional changes. + Machine Info + Webif cosmetic - * [r10319] - reader: Remove WITH_LB ifdefs. + * [r10538] - Just code movement, no functional changes. + Machine info + Display Machine type into webif status page. + If not known Machine is generic + If boxname known Machine is boxname + If boxtype known and not boxname Machine is boxtype - * [r10318] - ecm: Reduce WITH_LB ifdefs. + * [r10537] - Just code movement, no functional changes. + Patch by ultra47: + Final patch of configuriable showing of emm in emm.html?label=XXX - * [r10317] + Default set in Config part WebIf: + httpemmuclean (unique emm) => showing and filtering to a size of 256kb, over them cleaning and backup + httpemmsclean (shared) => not showing + httpemmgclean (global) => not showing - ecm: Reduce WITH_LB ifdefs. + Settings for parameter "httpemmsclean, httpemmgclean, httpemmuclean" + -1 => no showing + 0 => only show emm file + >1 => show filtered and cleaning (if the size higher as settings) emm file - Just code movement, no functional changes. + * [r10536] - * [r10316] + Machine info - ecm/dvbapi: Reduce WITH_LB ifdefs. + Extra protection for not cleared parameters - Just code movement, no functional changes. + * [r10535] - * [r10315] + Machine info - ecm: Reduce WITH_LB ifdefs. + forgot one line - Just code movement, no functional changes. + * [r10534] - * [r10314] + Machine info - ecm: Remove dead code guarded by WITH_LB ifdef. + extra fix - The removed code boils down to: - {{{ - if (!provid) { - loop { - if (some_check || some_other_check) - provid = 0; - break; - } - } - }}} + * [r10533] - which is obviously bogus since provid is already 0. + Machine Info + Correction about one name - * [r10313] - Revert "gbox: Do not use popen() to write into files." + * [r10532] - This reverts commit r10286. It turns out that gbox really wanted - to execute shell commands. See commit r9723. + Machine info + Added boxname where it's relevant (cosmetic) - * [r10312] - gbox: Add new lines at the of OSD files. + * [r10531] - Without new lines r10286 probably broke the osd functionality. + [gbx] Minor changes - * [r10311] - pcsc: Do not include PCSC/reader.h on OS X. + * [r10530] - This header do not exist on OS X's pcsc. + Machine info + Print correct info by boxtype if boxtype present. Also the final used variable will have the boxtype. - * [r10310] - build: Check USE_ flags when card reader config is being listed. + * [r10529] - This allows the build to display SMART and PCSC readers, when they - are enabled. + build: Add needed libraries when building pcsc under cygwin. + This fixes ticket #4118. The patch is inspired by patch posted by + routerunner in this ticket. - * [r10309] - build: Show what config file is being used. + * [r10528] + [gbx] small internal change for calling some card functions - * [r10308] - [gbx] One more it found. + * [r10527] + - tryfix newcamd - * [r10307] - [gbx] Small fix for r10305. + * [r10526] + Reduce camd35/cccam cacheex code differences. + No code changes just code movement. - * [r10306] - - Fix compile warning introduced in r10305 + * [r10525] + Reduce camd35/cccam cacheex code differences. + This helps reduce the diff. - * [r10305] - [gbx] Fix total cards in hello display. Fight against spaghetti code. + * [r10524] + Reduce camd35/cccam cacheex code differences. + This helps reduce the diff. - * [r10304] + * [r10523] - [gbx] Consolidate MSG_HELLO1 handling. + Reduce camd35/cccam cacheex code differences. + We already have log prefixes, so remove the artificial text difference + in logging messages. + * [r10522] - * [r10303] + Reduce camd35/cccam cacheex code differences. - [gbx] Collapse first hello handling. Do not malloc hostname on every new hello. + Reduce the differences by using simple var. + * [r10521] + Reduce camd35/cccam cacheex code differences. - * [r10302] + No code changes just code movement. - build: When getting include PATHs do not try to compile. - This speeds up include path detection nearly three times (not that - it was slow but anyway). + * [r10520] + - Fix for broken VDR support introduced in r10519 - * [r10301] - build: Allow PCSC headers to be installed in CROSS/.../local/include/PCSC - Without this oscam would try to include PCSC headers from host's - /usr/local/include/PCSC instead of the headers in the toolchain. + * [r10519] + DVBApi: - * [r10300] + - On sleepsend stop decoding the channel! + - Some rework to avoid receiver internal bufferoverflow - build: Fix cross compilation of PCSC. - We use the compiler's last include PATHs and add PCSC to it. - Basicaly it is /usr/include but in case of cross compilation it - might be something else. + * [r10518] - Since using -Iinc_path instructs the compiler to use inc_path - (without add the toolchain system root) we need to have this hack - to get the "real" last include path. Why we needs this? + move Spam to debug - Well, the PCSC headers are broken and rely on having the directory - that they are installed it to be in the include PATH. - We can't just use -I/usr/include/PCSC because it won't work in - case of cross compilation. + * [r10517] + hide another Spam from init log - * [r10299] - build: A simpler way of fixing PCSC header idiotism. + * [r10516] - Just playing with include paths is enough to work around - broken PCSC headers which are installed in include/PCSC/... - but include themselves without PCSC/ + [gbx] fix compiler warnings. Thx ni_hao. Fix #4116 - * [r10298] - README.build: Update. + * [r10515] - * [r10297] + - Fix detection of changed host ip for Cs357 connections - build: Remove TARGET_SYSROOT. - gcc option -print-sysroot is not always supported. For example - on older toolchains and for toolchains compiled without --with-sysroot. - Also this variable is not used. + * [r10514] + [gbx] small addition to r10513 - * [r10296] - build: Allow PCSC to be built with other than shipped headers in extapi. - If you do not want to use the PCSC headers shipped in extapi, - you may build oscam by specifiyng another include directory. - {{{ - make USE_PCSC=1 DEFAULT_PCSC_FLAGS=-I/usr/local/include - }}} + * [r10513] + [gbx] Unify list of cards. Move all card specific functionality into separate files. + Refer to http://www.streamboard.tv/wbb2/thread.php?threadid=43066 - * [r10295] - [gbx] more log cosmetics + * [r10512] + don't Spam on nonexistent irrelevant files - * [r10294] - README.build: Update. + * [r10511] + tests: Build tests binary by using standard build system machinery. - * [r10293] + This fixes the build under OS X and also allows the tests to cover + all oscam functionality (once the tests are written of course). - build: Clean pcsc build variables for OS X. + Note that the binary that build by `make tests` now would be called + `tests.bin` (previously it was called `tests`). You can override + that name using an undocumented TESTS_BIN `make` parameter, so + `make tests TESTS_BIN=blah` would build the tests binary called + `blah`. - * [r10292] + * [r10510] - build: Use local pcsc headers for compilation. + - Move reader emmcache usage detection in function and use it! - * [r10291] - build: Use pcsc headers in extapi. + * [r10509] + New values for parameter 'emmcache'. - * [r10290] - extapi: Add PCSC headers. + * [r10508] - PCSC headers as shipped by pcsclite project are buggy. They are - installed in /usr/{local/}include/PCSC but they use #include - and #include (Note the missing PCSC/ directory). + - Add Atemio Nemesis to fixed readerspeed of 4.5 Mhz (due to usage of TDA8024) - The result is that the compilation fails if the compiler is - not instructed to add to its include path /usr/include and/or - /usr/include/local. - Adding these paths comes with it's own set of problems for - cross compilation. - So the "cleanest" thing is to adopt pscs headers in extapi. + * [r10507] - Currently extapi/PCSC contains all headers that are needed - for PCSC compilation. The only difference between them and - the ones shipped by pcsclite is that include statements - were fixed to correctly include PCSC/... + Sci - Even if you don't have pcsc installed `make pcsc` would - compile oscam, just the final link phase would fail complaining - about missing libpcsclite. + extra fix - * [r10289] + * [r10506] - Make file PCSC + Sci - better then hack in 10288 + another small fix on autospeed - * [r10288] + * [r10505] - build: Fix PCSC cross compilation. + Sci vu+ - This hack is needed because PCSC includes instead - of . + Forgot the autospeed 1 this could still clock other speeds according to atr tables. For vu+ usseless and even could trigger bug for cards with higher max fs. The vu+ can only run at 4.5 Mhz. - It is ugly but it'll work. + * [r10504] - * [r10287] + Rewrite ftab parsing and generation functions. - Revert "build: Remove forced include path in pcsc build." + This commit affects these settings: + - account: chid, ident + - reader: chid, ident, fallback_percaid, localcards - This reverts commit r10285. + Makes the code smaller and easier to follow. bloatcheck reports + binary size savings: + {{{ + add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-1237 (-1237) + function old new delta + mk_t_ftab 426 351 -75 + ftab_fn 446 201 -245 + chk_ftab 1524 607 -917 + }}} - PCSC ships with broken headers which include when - they should include + Also add tests for the parser and generator. - It worked for me because I have copied wintypes.h into /usr/local/include. + * [r10503] - * [r10286] + tests: Small text change. - gbox: Do not use popen() to write into files. - Using popen() to write into files is highly unusual. Let's do - this properly. + * [r10502] + Move functions for dynamic array manipulations in oscam-array.{c,h} - * [r10285] - build: Remove forced include path in pcsc build. + * [r10501] - Adding /usr/include/PCSC in the include path is wrong in - case of cross compiling. We include pcsc headers using #include - which forces the compiler to use default include search path, - which in turn contains /usr/include and /usr/local/include. + tests: Check if clone functions work as expected. - So this should fix building pcsc in cross compilation - environment. + * [r10500] - * [r10284] + Rename array functions clear_XXX() to XXX_clear() - dvbapi: + This is preparation for unifying array functions. - Add support for mapped A: lines - Example: + * [r10499] - A:::10E0:0844::: 2600:000000:1FFF + Rename clone_ftab() to ftab_clone() - Receiver wants to demux srvid 10E0 on adapter 0000 camask 0001 index 0000 pmtpid 0844 - .. - .. - Added fake ecmpid 2600:000000:1fff for unencrypted stream on srvid 10E0 + This is preparation for unifying array functions. + * [r10498] + Rename clone_ttab() to tuntab_clone(). - * [r10283] + This is preparation for unifying array functions. - log: Unify logging function names under cs_log prefix. - This commit renames logging functions. Now everything that - logs can be found by searching for cs_log. + * [r10497] - Here is what is being done: + Refactor code to reduce duplication. - ` - > Existing logging: - > -> cs_log - > - > Renamed: - > cs_debug_mask -> cs_log_dbg - > rdr_debug_mask -> rdr_log_dbg - > rdr_debug_mask_sensitive -> rdr_log_dbg_sensitive - > - > Existing logging that hexdumps buffer: - > -> cs_log_dump - > -> rdr_log_dump - > - > Renamed: - > cs_ddump_mask -> cs_log_dump_dbg - > rdr_ddump_mask -> rdr_log_dump_dbg - ` + Introduce array_clone() and use it to prevent copy + paste code. - Here is the script that was used to make the changes. - {{{ - FILES=$(find -name '*.c' -o -name '*.h') + * [r10496] - perl -pi -e 's|cs_debug_mask|cs_log_dbg|g' $FILES - perl -pi -e 's|rdr_debug_mask|rdr_log_dbg|g' $FILES - perl -pi -e 's|rdr_debug_mask_sensitive|rdr_log_dbg_sensitive|g' $FILES - perl -pi -e 's|cs_ddump_mask|cs_log_dump_dbg|g' $FILES - perl -pi -e 's|rdr_ddump_mask|rdr_log_dump_dbg|g' $FILES - }}} + Refactor code to reduce duplication. - The old function names were defined as compatability but don't - use them in new code because these defines would be removed - sometimes in the future. + Introduce array_clear() and use it to prevent copy + paste code. - * [r10282] + * [r10495] - log: Unify log headers. + Refactor code to reduce duplication. - We don't really need 3 types of log headers. + Introduce array_add() and use it to prevent copy + paste code. - * [r10281] + * [r10494] - log: Add log prefix to hex dumps. + Rename ftab_add_filter() to ftab_add() + This follows the style of the other TYPE_add() functions. - * [r10280] - [gbx] Small addition to r10279 + * [r10493] + Exit early if there is nothing to be done in the cfg settings generator. + * [r10492] - * [r10279] + Rename some variables to make the code easier to understand. - [gbx] Harmonizing log messages after recent changes by gfto. Thx! + * [r10491] + - tryfix dvbapi emm freezing - * [r10278] - - Revert experimental protection against boxes that seem to close filters without being instructed to do so by dvbapi - - On hypercube su980 always return ok on io_ctl + some code cosmetics in io_ctl to make it more readable - - Some recoding on dvbapi init (boxtype+api) since cs_log() needs these parameters set before otherwise crashing + * [r10490] + vg: Clear entitlements before adding new ones. + Patch by Mandos. This fixes ticket #4115. - * [r10277] - Internal readers non-pll (cardmhz < 2000): - - Proper fix for regression introduced in r10267 + * [r10489] + Rewrite tuntab (betatunnel) conf parsing and generation functions. + Makes the code smaller and easier to follow. bloatcheck reports + binary size savings: + {{{ + add/remove: 1/0 grow/shrink: 0/2 up/down: 82/-489 (-407) + function old new delta + tuntab_add - 82 +82 + mk_t_tuntab 451 288 -163 + chk_tuntab 808 482 -326 + }}} - * [r10276] + Also add tests for 'betatunnel' parser/generator. - - Fix for segfaults due to changed logline styles (used vars must be inited before logging now!) + * [r10488] + - Small fix for dvbapi: only init emm filter values for firstrun on non-running channels - * [r10275] - - Remove unused var .Di from struct cardreadersettings + * [r10487] + - Fix for emmcache lastseen + - Some recode for emm handling without emmcache / emmstat - * [r10274] - - Somehow I managed to get oscam to use too much resources -> give it back! + * [r10486] + EMM: - * [r10273] + Reworked the emmcache and emmstats once more! - dvbapi: + usecache = 0,x,x = disable usage of emmcache and emmstats + usecache = 1,x,x = enable emmcache, emmstats and save to file if oscam is stopped + usecache = 2,x,x = enable emmcache, emmstats but dont save to file if oscam is stopped - - More rework on resorting ecmpids - - More Logcosmetics - * [r10272] + * [r10485] - More dvbapi eyecandy: log how much time sorting the ecmpids takes! + Do not increase the number of entries in the dynarray if allocation fails. + * [r10484] - * [r10271] + Rewrite ecm header whitelist code. - dvbapi: + Change the structure that tracked ecm header whitelist and rewrite + the related code. Now it is a lot simpler (68 lines less code) and + closer to ecm whitelist parser and generator. - Channelcache enhenced once more: deleting whole channelcache on oscam.dvbapi change removed. - Now exact channelcache hit is checked at end of ecmpid prio/ignore matching. - If a channelcache entry matches with highest prio -> start descrambling only that ecmpid otherwise ignore channelcache. - + Tests module was updated with support for ecm header white list. + There is a positive effect on binary size as well (-440 bytes). + {{{ + add/remove: 4/2 grow/shrink: 3/1 up/down: 1639/-2079 (-440) + function old new delta + chk_ecm_hdr_whitelist - 699 +699 + mk_t_ecm_hdr_whitelist - 555 +555 + static.ecm_ratelimit_findspace 2499 2685 +186 + ecm_hdr_whitelist_add - 113 +113 + matching_reader 1973 2008 +35 + clear_ecm_hdr_whitelist - 34 +34 + static.ecm_ratelimit_check 2728 2745 +17 + static.free_reader_ecm_headerwhitelist 66 - -66 + mk_t_ecmheaderwhitelist 669 - -669 + ecmheaderwhitelist_fn 1473 129 -1344 + }}} - * [r10270] + A negative is that after the rewrite the ecm header whitelist structure + takes a bit more memory than before. - - Same mixup D <> Di for smargo + * [r10483] + Add 'tests' to .gitignore - * [r10269] - - Correction mixup of D and Di (old code was sending D but smartreader code accepted it as Di...) + * [r10482] + - Errorhandling for emmstat, emmcache and channelcache saving: on error remove created file! - * [r10268] - csctapi: Change Fi only on sci card readers. + * [r10481] - This fixes regression introduced in r10267. + tests: Integrate test vectors into test structure. - * [r10267] + * [r10480] - csctapi: Merge three write_settings() callbacks. + Make ecm whitelist parser easier to understand. - This patch removes write_settings2 and write_settings3 callbacks - merging them into single write_settings() that receives struct - s_cardreader_settings parameter. + Rename some variables and small code cleanup. - * [r10266] + * [r10479] - serial: Don't try to be cute with logging format strings. + Improve ecm whitelist parser and generator. - The compiler will save duplicated strings only once anyway, so there - is no need for such a trick. + Invalid values (0xffff) are reset to zero and now you can have + filters that have only ident (provider_id) defined. For example + this is valid filter: `@123456:11,22,33` that will match provider + with id 123456 and ecm lengths 0x11, 0x22 and 0x33. - * [r10265] + * [r10478] - log: Rename cs_dump() and rdr_dump() to cs_log_dump() and rdr_log_dump(). + Add test module for oscam config entries parsers and generators. - Now searching for cs_log we'll get places where logging funcs are used. + We have lots of custom parsers and generators for our config file + settings. Unfortunately there are no test vectors for them or any + kind of test infrastructure which makes improving them or adding + features much harder that it needs to be. + This commit introduces stand alone `tests` module. The purpose of + this module (the code is in `tests.c`) is to collect test vectors + and to test them. - * [r10264] + The module is stand-alone and it is built as separate binary by + using `make tests`. - Use rdr_dump instead of cs_dump in card readers. + * [r10477] - * [r10263] + - fix semicolon typo - gbox: Remove duplicated log prefixes. - * [r10262] + * [r10476] - constcw: Remove duplicated log prefixes. + - Dont load/save any channelcache on dbox2 since they will crash - * [r10261] - Move logCWtoFile() func to oscam-ecm.c + * [r10475] - It is the only place where it is used also the idea of oscam-log.c - is to hold the global logging code. + - Dont load/save any emmstat or cache on dbox2 since they will crash - * [r10260] - log: Move anticasc logging code into module-anticasc.c + * [r10474] - And clean an ifdef in module-log.c + - Add dbox2 to recognized boxtypes - * [r10259] - dvbapi/azbox/mca: Clean logging messages. + * [r10473] - Now that we have module prefixes these additional prefixes are not needed. + sci + vu+ extra char was not needed - * [r10258] - dvbapi: No need to handle obvious invalid fd! + * [r10472] + Sci + fixed speed 4.50 for all vu boxes - * [r10257] - dvbapi: + * [r10471] - - Small log cosmetic I missed - - Experimental protection against boxes that seem to close filters without being instructed to do so by dvbapi + Do not initialize openssl twice when ghttp module is enabled. + * [r10470] - * [r10256] + webif/ghttp/ssl: Do not leak memory allocated by openssl. - dvbapi log cosmetics + This patch does several related things: + 1. Moves SSL initialization in one place (using it from two threads + can cause undefined behaviour). + 2. Clean openssl allocated context if ssl initialization in + webif failed for some reason (not founding certificate file for + example). + 3. Clear memory after openssl error functions are called. + * [r10469] - * [r10255] + dvbapi: Fix memset() with reversed parameters. - log: Add MODULE_LOG_PREFIX to the files that need it. + * [r10468] - * [r10254] + Rename boxtype() function to boxtype_is(). - log: Prepare anticascading log for logging prefixes. + This prevents old (and broken) compilers from warning about it. + {{{ + oscam.c: In function 'init_machine_info': + oscam.c:706:7: warning: declaration of 'boxtype' shadows a global declaration [-Wshadow] + globals.h:2042:6: warning: shadowed declaration is here [-Wshadow] + oscam.c: In function 'boxtype': + oscam.c:762:26: warning: declaration of ‘boxtype’ shadows a global declaration [-Wshadow] + oscam.c:762:6: warning: shadowed declaration is here [-Wshadow] + }}} - * [r10253] + Fixes ticket #4112. - log: Align module prefixes. + * [r10467] - * [r10252] + Do not work directly with stb_boxtype. - log: Allow each source file to declare it's own log prefix. + stb_boxtype is possible to be NULL, in which case using strcasecmp() + or similar functions would cause segfault. This patch defines two new + functions for dealing with stb_boxtype. - Adding `#define MODULE_LOG_PREFIX "mymodule"` before including - globals.h would instruct logging functions to add this prefix - in each log message. + boxtype(X) checks if stb_boxtype equals X. + boxtype_get() returns the detected box type string. - This functionality would allow a lot of cleanup in module logging - messages and it'll make it easier to sort (filter) messages by - module. + As a nice side effect (in addition to cleaner and safer code) we shave + off a bit of binary size. + bloatcheck reports: + {{{ + add/remove: 2/0 grow/shrink: 0/3 up/down: 63/-255 (-192) + function old new delta + boxtype - 43 +43 + boxtype_get - 20 +20 + dvbapi_ioctl 367 359 -8 + Sci_Deactivate 251 235 -16 + cardreader_init 1784 1553 -231 + }}} - * [r10251] - csctapi: Use rdr_debug_mask() instead of cs_debug_mask(). + * [r10466] + Sci - * [r10250] + set sci in function off boxtype by a couple of dm boxes. + Vuduo2 set to the only speed it is clocked. - smartreader: Use rdr_log() instead of cs_log(). + * [r10465] - * [r10249] + some webif fixes for commit 10403 - csctapi: Use rdr_log() in azbox and sci card readers. + * [r10464] - * [r10248] + updated doc for read_old_classes - readers: Use rdr_log() in cryptoworks and viaccess readers. + * [r10463] - * [r10247] + dvbapi: - dvbapi: Workaround for CA_SET_DESCR ioctl() on su980. + - More fix for receiver internal bufferoverflow + - Skip executing of specific emm filter handlingcode if ecm is being handled! - The kernel on su980 boxes is buggy returns error when CA_SET_DESCR is called. - For more info see: http://www.streamboard.tv/wbb2/thread.php?postid=533940 - * [r10246] + * [r10462] - Machine info + Added default value for 'read_old_classes'. - Extend boxtype info to all internall readers as harmless test. Or at least as check that it's harmless. + * [r10461] - * [r10245] + Added new parameter 'read_old_classes' to documentation. - Machine Info - cosmetic removed a not wanted space + * [r10460] + Do not rely on the compiler to clear the whole structure when using short initializer - * [r10244] + This prevents the compiler from complaining about: + {{{ + oscam-conf-chk.c: In function 'chk_ecm_whitelist': + oscam-conf-chk.c:504: warning: missing initializer + oscam-conf-chk.c:504: warning: (near initialization for 'new_ecm_whitelist.ewdata') + oscam-conf-chk.c:508: warning: missing initializer + oscam-conf-chk.c:508: warning: (near initialization for 'd.caid') + }}} - Machine info + Reported by AbrahaM. - added su980 boxtype + * [r10459] - * [r10243] + Rewrite ecm whitelist code. - oscam-log: Split cs_log_int(). + Change the structure that tracked ecm whitelist and rewrite the + related code. Now it is a lot simpler (160 lines less code). + There is a positive effect on binary size as well (-1.2k). - Split cs_log_int() into separate functions for logging single lines - and logging with buffer dumping. This is made mainly to avoid having - unused parameters in a single function. + bloatcheck report: + {{{ + add/remove: 4/2 grow/shrink: 0/5 up/down: 1059/-2357 (-1298) + function old new delta + chk_ecm_whitelist - 533 +533 + mk_t_ecm_whitelist - 425 +425 + ecm_whitelist_add - 67 +67 + clear_ecm_whitelist - 34 +34 + static.ecm_ratelimit_check 2745 2728 -17 + matching_reader 2043 1973 -70 + static.free_reader_ecm_whitelist 149 - -149 + static.ecm_ratelimit_findspace 2685 2499 -186 + update_ecmlen_from_stat 709 340 -369 + mk_t_ecmwhitelist 463 - -463 + ecmwhitelist_fn 1232 129 -1103 + }}} - As far as the users of the logging API are concerned - the API is - unchanged. + A negative is that after the rewrite the ecm whitelist structure + takes a bit more memory than before. - bloatcheck reports 12077 bytes saved from x86_64 oscam binary and - 14044 bytes saved on dm500 binary. + This fixes small memory leak in parsing shown in trac + ticket #4099 comment 11. - * [r10242] + * [r10458] - oscam-log: Prepare cs_log_int() for splitting into separate functions. + bulcrypt: Another fix for v2 EMMs. - This is just a preparation - code movement and whitespace changes. - No noticable functional changes. + Patch by chepik suggested in ticket #4110. - * [r10241] + * [r10457] - oscam-log: Remove lock parameter of cs_log_int(). + EMM: - The comment added in r10240 was wrong. liboscam_stapi.a calls cs_log() - function which is correctly emulated in module-dvbapi-stapi.c so - it is safe to remove lock parameter of cs_log_int(). + - Prevent oscam from running out of resources: remove stale emmcache + emmstats after 30 days (perhaps make this user configable?) + - Some code adoption to prevent possible null deference - According to bloatcheck this change saves 9006 bytes from the oscam - binary on x86_64. - * [r10240] + * [r10456] - oscam-log: Clarify why we keep 'lock' parameter to cs_log_int(). + minilzo: Disable internal checks because they cause build errors. + This fixes: + {{{ + LINK ../archiv/oscam-svn8403-fritz33xx-webif.debug + build/mips-linux-uclibc/minilzo/minilzo.o: In function `_lzo_config_check': + minilzo.c:(.text+0x678): undefined reference to `__clzsi2' + collect2: ld returned 1 exit status + }}} - * [r10239] + This is the same commit as r8404. - oscam-log: Remove XXX_nolock() macroses. - The `lock` parameter of cs_log_int() is even marked as unused - because it really is. There is no point in having XXX_nolock. + * [r10455] + - miniLZO update to version 2.09 (released 4 feb 2015) - * [r10238] - oscam-log: Reorder some declarations to reduce ifdefs. + * [r10454] - * [r10237] + Allocate TUNTAB dynamically - Revert "Extra dump functions." + The TUNTAB structure size is 602 bytes and also the number of + entries is limited. - This reverts commit r10016. + This structure is used to implement the beta tunnel feature via + 'betatunnel' account setting. - Gratiuous copy+paste for no reason at all. These functions were not - even used. Not worth the extra 75 lines of code that does exactly - nothing (luckily the linker knows when a code is not used so these - functions never increased the binary size and after removing them - the binary is exactly the same). + This feature is not used by everyone but everyone takes the memory hit. + This patch makes the bulk of the structure dynamically allocated. The + memory savings are as follows (x86_64 defconfig): - * [r10236] + {{{ + struct before after delta savings + s_tuntab 602 16 -586 97.4% + s_client 2440 1856 -584 24.0% + s_auth 1976 1392 -584 29.6% - failban: Restore the behaviour broken by r10232. + Binary size: + add/remove: 1/0 grow/shrink: 5/5 up/down: 335/-485 (-150) + }}} - * [r10235] + * [r10453] - - Refresh nagra entitlement only if last written emm was more than 60 minutes ago + doc: Remove CS_MAXTUNTAB mentions in the docs. + CS_MAXTUNTAB is going away when TUNTAB structure becomes dynamic. - * [r10234] + * [r10452] - - fix for pincode (now only 4 digits) - - cosmeticfix for boxkey => now double length - - fix for last channel on status.html + Clear destination FTAB before parsing the new one. - Tnx goes to Ultra47 developing the patch together with some dedicated oscam users! + * [r10451] + - Cs357 (=camd35 UDP) prevent usage of reconnecttimeout, UDP is stateless so it makes no sense! - * [r10233] - Remove ifdef from oscam-config.c + * [r10450] - * [r10232] + Small cleanup of FTAB related code. - Remove CS_ANTICASC ifdef in oscam-failban.c + * [r10449] - * [r10231] + Correctly reload ident and chid filters on client reinit. - Clean SO_REUSEPORT ifdefs. + This fixes a bug introduced in FTAB rewrite. - Most (if not all) of these calls to set socket option SO_REUSEPORT are - bogus IMHO, but cleaning this mess is left for another time. For now just - remove create a function and use it instead of sprinkling ifdefs everywhere. - I'm 97.8% sure that all of these calls can be removed... + * [r10448] - For more info about SO_REUSEPORT see: - http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=c617f398edd4db2b8567a28e899a88f8f574798d - http://stackoverflow.com/questions/3261965/so-reuseport-on-linux + - More tryfix for internal filter bufferoverlow of receiver - * [r10230] - Remove last HAVE_DVBAPI ifdef in oscam-reader.c + * [r10447] + newcamd: Fix mgclient support which was broken with ftab changes in r10426. - * [r10229] + It seems that FTAB changes in r10426 have broken mgclient support + in newcamd module. According to the reporter this patch fixes + the problem. - Move function used only in dvbapi module closer to where it is called. + Ref: http://www.streamboard.tv/wbb2/thread.php?threadid=43056 - Also cleanup the function a bit. + * [r10446] - * [r10228] + bulcrypt: Fix writing of unique EMMs in v2. - Eliminate the last two ifdefs's in oscam-work.c + Patch by chepik posted in ticket #4110. - Move the code where it belongs in module-cacheex.c and remove the - ifdefs. + * [r10445] - * [r10227] + Fix libusb linking on FreeBSD. - config: Some sed implementations do not support -i option. + This fixes ticket #4103. - Patch by kraiv @ satsupreme for improving OpenBSD support. + * [r10444] - * [r10226] + some fixes with ftab allocation - - Cosmetic fix for internal readers driving irdeto cards at wrong speed + * [r10443] + viaccess: now only reading active entitlements/classes, use + read_old_classes = 1 + in the [reader] config to read all entitlements/classes. + this should speed up card init. - * [r10225] - - Revert accidental changes to config.h + * [r10442] + - Fix for emmcache not loading if emmlogdir is set - * [r10224] - - dvbapi fix for boxtype pc using listenport (tnx Manio for reporting and testing) + * [r10441] + Revert "Add -std=c99 to compiler flags." + This reverts commit r10434. - * [r10223] + It seems that `-std=c99` really breaks oscam subtly at least + according to ticket #4106. - [gbx] Remove extra call to gbox_send_good_night + Since setting the standart is not bringing anything positive + but seems to come with it's own set of weird bugs, it is better + to revert it. + * [r10440] + __asm__ fix for c99 - * [r10222] - [gbx] Fix memleak introduced with r10140. - Supposed to fix ticket 4075. - See: http://www.streamboard.tv/wbb2/thread.php?threadid=42906 + * [r10439] + Better fix for asm usage in cscrypt. + This is better fix that the one applied in r10437. Thanks to Jens + for pointing out that this is a better way. - * [r10221] + * [r10438] - OpenBSD fixes from kraiv @ satsupreme. + - Tryfix for dvbapi internal bufferoverlow - * [r10220] - - Only allow listenport on boxtype pcnodmx + * [r10437] + cscrypt: Fix for build with -std=c99. + The optimization that is written in asm for a long time have been + performed by the compiler so having it in asm is kind of pointless. - * [r10219] + Also not using inline asm makes it possible to build oscam with + -std=c99 compiler option. - - Fix for clear channelcache sporadic crashing + This fixes ticket #4107. + * [r10436] - * [r10218] + List destruction should always set the list to NULL. - Machine Info + This removes ll_destroy_xxx_NULL() macros in favour of making all + ll_destroyXX() functions set the list parameter to NULL. We already + have three list destruction functions (too many) in addition to + that having 2 more (in the form of macros) was starting to get + unwise. - boxtype with less complicated code done by gf. + This change also removes the need for this idiom (used in couple + of places): + {{{ + ll_destroy(x); + x = NULL; + }}} - * [r10217] + The ll_destroyXXX() functions are checking if their parameter is + NULL, so there is no need for the caller to check it. - oscam-work: Reduce CS_CACHEEX ifdefs. + * [r10435] - * [r10216] + config-reader: Refactor freeing of ecm_whitelist and ecm_header_whitelist. - oscam-work: Replace ifdef with config_enabled(MODULE_CCCAM). + It is a tricky code and duplicating it can only lead to bad things. - * [r10215] + * [r10434] - Update README.build. + Add -std=c99 to compiler flags. - Somebody (probably me) forgot to run `make README.build` after - changing the help text in the Makefile. + This changes nothing in the build (we are already c99 compatible). + It just establishes the base compiler support that we are expecting. - * [r10214] + * [r10433] - dvbapi/samygo: Clean the code for future development. + pages_gen: Avoid strict-aliasing warnings. - According to the developers SAMYGO dvb code is not currently - working. This patch removes the config symbol and cleans the - code so future development can fix the code easily. - For more info: http://www.streamboard.tv/wbb2/thread.php?postid=533219 + * [r10432] - In theory if the code was working this transformation should - not break it and fixing only the samygo detection routine - should return it to the state before this patch minus all the - ifdefs. + oscam-emm-cache: Add new lines at the end of file. + Some compilers warn when files don't end with new lines. - * [r10213] - Remove more useless WITH_CARDREADER ifdef's. + * [r10431] + Additional fix for r10422 (Add card_done() callback to card readers). - * [r10212] + I've missed the fact that private data was freed also in free_reader(). + Now the leak described in r10422 should be fixed. - Remove some HAVE_DVBAPI ifdefs. + * [r10430] - * [r10211] + conf-reader: Free strings allocated by config. - emm: Remove useless ifdefs. + The memory occupied by 'description' and 'readnano' was not freed when + reader freeing function was called. - There is a static inline function defined when WITH_CARDREADER is - disabled, so the removed ifdef's were useless. + * [r10429] - * [r10210] + camd33/camd35: Allocate aes_keys per client on connect. - newcamd: Add DVBplug (0x9922) to client list. + This saves 480 bytes in `struct s_client` for every client that is not using + camd33 or camd35 protocols. - Fixes ticket #4076. + Structure changes: + {{{ + struct before after delta savings + s_client 3048 2568 -480 15.8% - * [r10209] + binary size: + add/remove: 1/0 grow/shrink: 3/0 up/down: 103/0 (103) + }}} - Machine Info : small fix. Free buffer after it's not needed anymore + * [r10428] - * [r10208] + cryptoworks/viaccess: Allocate EMM reassembly buffers on demand. - Machine Info + This patch saves 1008 bytes from `struct s_client` in the common case + where cw/via readers are enabled. Now only AU enabled clients would + allocate EMM reassembly buffer for themselves. - added dm500 or dm600pvr boxtypes + Structure changes: + {{{ + struct before after delta savings + s_client 3928 2920 -1008 25.0% + }}} - * [r10207] - Machine info : fix compile warning mac + * [r10427] + newcamd: Prevent filter copying. - * [r10206] + In addition to saving some copying, bloatcheck reports: + {{{ + add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-120 (-120) + function old new delta + newcamd_auth_client 5523 5403 -120 + }}} - Strings - previous ad of strtonchars was perfect on pc but not for stb's. - now it's ok for both + * [r10426] + Allocate FTAB dynamically - * [r10205] + The FTAB structure size is bigger than 2100 bytes and also the number + of filters is limited to 16. - - Webif fix for proper handling of 16 and 32 bit boxkeys + This structure is used to implement the account filters (via 'ident' and + 'chid' settings) and reader filters (via 'fallback_percaid', 'localcards', + 'ident' and 'chid' settings). + These settings are not used by everyone but everyone takes the memory hit. + This patch makes the bulk of the structure dynammically allocated. The + memory savings are very nice: - * [r10204] + {{{ + struct before after delta savings + s_ftab 2116 16 -2100 99.3% + s_reader 13592 5200 -8392 61.8% + s_client 8120 3928 -4192 51.7% + s_auth 6176 1976 -4200 68.1% - - Experimental attempt to avoid var size issues with time since recently comp_timeb() gives back int64_t + Binary size: + add/remove: 2/0 grow/shrink: 13/23 up/down: 1139/-434 (705) + }}} + * [r10425] - * [r10203] + cryptoworks/viaccess: Use rdr_log in EMM reassembly functions. - Strings - Added extra string function. - To read first n or last n chars of a string. + * [r10424] + ghttp: Release all memory on exit. - * [r10202] + valgrind reports: + {{{ + 192 bytes in 1 blocks are still reachable in loss record 1 of 1 + at 0x4C29ADD: malloc (vg_replace_malloc.c:296) + by 0x4B5773: cs_malloc (oscam-string.c:11) + by 0x4B1536: ll_create (oscam-llist.c:44) + by 0x44F744: module_ghttp (module-ghttp.c:758) + by 0x4048FB: main (oscam.c:1502) + }}} - [gbx] Fix warning. + and a lot of things related to SSL error strings that were not freed + when SSL is enabled. + * [r10423] + Wait before stopping GC when running under valgrind. - * [r10201] + This hack leaves some time for oscam threads to finish what they're + doing before stopping the garbage collector. It is a hack to make + valgrind happy and to produce clean report of what is possibly leaked. - [gbx] minor fixes for rebroadcast thread + * [r10422] + Add card_done() callback to card readers. + This allows card readers to free their privately allocated data and + fixes leak in videoguard2 reader. - * [r10200] + valgrind reported: - Machine Info + {{{ + 344 bytes in 2 blocks are definitely lost in loss record 436 of 733 + at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) + by 0x478FD3: cs_malloc (oscam-string.c:11) + by 0x44F2C2: memorize_cmd_table (reader-videoguard-common.c:773) + by 0x45295D: videoguard2_card_init.part.0 (reader-videoguard2.c:587) + by 0x453A77: videoguard2_card_init (reader-videoguard2.c:539) + by 0x4436A0: reader_get_cardsystem (reader-common.c:144) + by 0x443A44: cardreader_do_reset (reader-common.c:194) + by 0x47AE47: work_thread (oscam-work.c:293) + by 0x5477181: start_thread (pthread_create.c:312) + by 0x578800C: clone (clone.S:111) + }}} - forgotten fclose() + * [r10421] - * [r10199] + Remove executable bit on source files. - Machine Info - Try out. - Added dm500 and dm600pvr - to go is extra fix to differenciate dm500 and dm6000pvr + * [r10420] + EMM: - * [r10198] + Replace the simple emm ringbuffer with dynamic allocated buffering for emms and emmstats + Emmcache and emm reader stats are now loaded and saved upon oscam start and stop + For my usage the cards will only be served with fresh emms no matter how many times I start and stop oscam. - dvbapi: Simpler fix for the bug introduced in r10189 and fixed in r10196. + ToDo: + The usual fixing of broken stuff :) + Webif cosmetics: use the new additions like firstseen, lastseen, firstwrite, lastwrite, delete emmcache, delete emm reader stat.. - * [r10197] - Machine Info - cosmetic and some fixes + * [r10419] - * [r10196] + fixed aeskey list memleak - - Fix for dvbapi blocker introduced in rev 10189 - Perhaps there is a smarter fix possible but this works for me ;) + * [r10418] + fixed hashtable freeing - * [r10195] + * [r10417] - dvbapi/stapi: Leave only public functions in module-dvbapi-stapi.h + Remove dead increments. - Along with leaving only public functions in module-dvbapi-stapi.h - add static where it is needed in module-dvbapi-stapi.c + The variables that are incremented are not used after that, so the + increment can be removed. - Bloatcheck reports > 610 byte savings after this patch. + Found by clang checker. - * [r10194] + * [r10416] - dvbapi/coolapi: Leave only public functions in module-dvbapi-coolapi.h + Let the compiler decide if func needs to be inlined. - Along with leaving only public functions in module-dvbapi-coolapi.h - add static where it is needed in module-dvbapi-coolapi.c + This function is the only inlined function (that is not static) in the + whole oscam source. Surely that func is not that important but also the + compiler complains about it when c99 mode is switched on. - Bloatcheck reports > 220 byte savings after this patch. + With this patch bloatcheck reports 589 byte savings. + {{{ + add/remove: 1/0 grow/shrink: 0/1 up/down: 152/-741 (-589) + function old new delta + __xxor - 152 +152 + do_cmd 4124 3383 -741 + }}} - * [r10193] + * [r10415] - dvbapi/mca: Leave only public functions in module-dvbapi-mca.h + strings.h needs to be included for strcasecmp(). - Along with leaving only public functions in module-dvbapi-mca.h - add static where it is needed in module-dvbapi-mca.c + We got strcasecmp() indirectly because of _GNU_SOURCE, but let's be + explicit that we need that header. - Bloatcheck reports > 200 byte savings after this patch. + * [r10414] - * [r10192] + cacheex: Remove unused function and remove inline marks. - dvbapi/azbox: Leave only public functions in module-dvbapi-azbox.h - Also add static where it is needed. Bloatcheck reports minimal (12 bytes) - size saving. + * [r10413] + reader: Free emm cache. - * [r10191] + valgrind reported: + {{{ + 565,248 bytes in 46 blocks are definitely lost in loss record 483 of 487 + at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) + by 0x477F63: cs_malloc (oscam-string.c:11) + by 0x4774FF: reader_init (oscam-reader.c:1153) + by 0x47A0A1: work_thread (oscam-work.c:285) + by 0x5477181: start_thread (pthread_create.c:312) + by 0x578800C: clone (clone.S:111) + }}} - Add webif/is_defined.txt to the list ignorred files by git. + * [r10412] - * [r10190] + pages_gen: Free all memory when exiting with errors. - dvbapi: Clean powerpc ifdefs. + The bug was found with clang checker. - Now that we have ioctl() wrapper function we can fix dm500 issues - over there. + * [r10411] - * [r10189] + pages_gen: Check if we have any templates at all. - dvbapi: Create and use dvbapi_ioctl() instead of ioctl() directly. + The bug was found with clang checker. - This change would allow us to integrate SAMYGO code cleanly and also - remove some ppcold (dm500) ifdefs in the dvbapi module. + This prevents possible allocation with 0 size and weird behaviour + when there are no defined templates. - * [r10188] + * [r10410] - dvbapi/samygo: Reformat samygo's ioctl() function. + pages_gen: Simplify loading of is_defined.txt - Whitespace and comment fixes. No code changes. + We already have readfile() function, let's use it. - * [r10187] + * [r10409] - - Channelcache: Cached chid was never used -> Fixed! - - Show in log that channelcache was used to start descrambling a certain pid + webif color fix + * [r10408] - * [r10186] + Prevent possible NULL pointer deref. - - dvbapi channelcache: only allocate mem if there is valid data that needs it! + Looks impossible to me but according to clang checker it can happen. + The fix is simple enough. + * [r10407] - * [r10185] + Check the result of cs_strdup(). - [gbx] Cosmetics. + It is not a very likely situation that in this place cs_strdup() + would fail but crashing is not nice and the result of memory + allocation functions must be checked at all times. + * [r10406] + fixed memleak - * [r10184] - Machine Info : No need to allocate bigger mem buffers then required. + * [r10405] + revert camd35 pid change - * [r10183] - dvbapi/azbox+mca: Clean ifdefs. + * [r10404] - azbox and mca use their own handlers for ->s_handler and ->send_dcw. - Rework the code to make this explicit. + small fix for last commit - * [r10182] + * [r10403] - dvbapi: Clean SAMYGO ifdef. + applied patches + 10399_status_online_proxys_r4.patch + 10399_duoble_emm_online_proxies_cosmetic s_r1.patch + from: + http://www.streamboard.tv/wbb2/thread.php?postid=535337#post535337 - * [r10181] + * [r10402] - dvbapi: Clean ifdefs. + Cleanup cache allocations on oscam exit. - According to the comment, ppcold (dm500?) returns wrong error code - on ioctl(CA_SET_DESCR). + valgrind reports: - There should be no functional changes after this patch. + {{{ + 272 bytes in 1 blocks are possibly lost in loss record 3 of 5 + at 0x4C2B854: calloc (vg_replace_malloc.c:623) + by 0x40128C4: _dl_allocate_tls (in /lib64/ld-2.20.so) + by 0x4E3CFE5: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.20.so) + by 0x4B8590: start_thread (oscam.c:822) + by 0x404C2B: main (oscam.c:1562) + + 512 bytes in 1 blocks are still reachable in loss record 4 of 5 + at 0x4C29ADD: malloc (vg_replace_malloc.c:296) + by 0x4918CB: tommy_hashlin_init (tommyhashlin.c:50) + by 0x492308: init_hash_table (oscam-hashtable.c:11) + by 0x492602: init_cache (oscam-cache.c:69) + by 0x4043EA: main (oscam.c:1480) + + 512 bytes in 1 blocks are still reachable in loss record 5 of 5 + at 0x4C29ADD: malloc (vg_replace_malloc.c:296) + by 0x4918CB: tommy_hashlin_init (tommyhashlin.c:50) + by 0x492308: init_hash_table (oscam-hashtable.c:11) + by 0x41FC12: cacheex_init_hitcache (module-cacheex.c:56) + by 0x4043EF: main (oscam.c:1481) + }}} - * [r10180] + * [r10401] - Machine Info + Prevent memory loss. - added global structure for machine info. - For now only two params, In future there will be some extra. + valgrind reports: - Added a log output by pll sci readers to see if ok for effectif use. + {{{ + 66 bytes in 1 blocks are definitely lost in loss record 1 of 2 + at 0x4C29ADD: malloc (vg_replace_malloc.c:296) + by 0x4B4A83: cs_malloc (oscam-string.c:11) + by 0x4B4B6F: cs_strdup (oscam-string.c:46) + by 0x49EF2B: init_config (oscam-config-global.c:1078) + by 0x4043F4: main (oscam.c:1482) + }}} - * [r10179] + * [r10400] - Machine Info : boxtype fix + cache: Mark variables and functions static. + These are not used outside of oscam-cache.c they should be static. - * [r10178] - Machine Info : fixed error handling + * [r10399] + Sci - * [r10177] + Gives shorter init time for seca/nagra tunneled cards on Vu+ series - Machine Info : relocated and made function. + * [r10398] - * [r10176] + cache: Split cacheex code into separate function. - irdeto: Fix warning about unused parameter + * [r10397] - * [r10175] + cache: Split cycle check code into separate function. - - Fix wrong usage of memset + * [r10396] + cache: Simplify code. - * [r10174] + The `if` check is already ugly enough, let's simplify it a bit. - dvbapi: don't always reset protocol version when client closes connection - When there is more then one connection and one is closed, the protocol version - was reset, and it badly influences on the other (existing) connections. + * [r10395] - Fixed to reset only when last connection is closed. + cache: Simplify code. + Having multiple places that unlock a taken lock is an easy mistake + waiting to happen. - * [r10173] + * [r10394] - seca: Allow each reader to have it's own IDEA state. + cache: Reduce CS_CACHEEX ifdefs. + struct ecm_request_t grows by a pointer but we can always regain this + space (if needed) by just trimming the structure a bit. vid and prid + can be uint16_t, from_xxx variables can be packed into bitmask, msglog + can be slimmed down, cwc_msg_log can trimmed from 64 bytes to 32 + without any problem and there are probably more...). - * [r10172] - - Init static ideacrypt only once, this will saves cpu resources! + * [r10393] + cache: Remove CW_CYCLE_CHECK ifdefs. + Due to structure alignment (we have 3 single bytes before uint16_t) + we've already lost the single byte that is occupied by got_bad_cwc. + We can use this opportunity to simplify the code. - * [r10171] - - Tweak for channelcache: if oscam.dvbapi is changed channelcache is destroyed so new prio/ignore rules are applied! + * [r10392] + cwcycle: Move private structures out of the header file. + This structures are only used in module-cw-cycle-check. I'm leaving + only the public stuff in the header file. - * [r10170] - seca: Include IDEA library code. + * [r10391] - This fixes ticket #4066. + cacheex: Move cacheex code out of oscam-ecm.c into module-cacheex.c - * [r10169] + * [r10390] - dvbapi-chancache: Reduce allocations and clean code. + camd35 tcp: do not complain about packet size if a client closed the connection - * [r10168] + * [r10389] - dvbapi-chancache: Do not set thread name. + dvbapi: new command to stop descrambling all demuxers - This code doesn't need to set thread name! + The commit add possibility to close all demuxers related + with the connection (using network protocol). + It uses the following packet for this: + 9F 80 3f 04 83 02 00 FF - It is actually a bug because dvbapi_save_channel_cache() is called from main - thread and after set_thread_name() oscam process will be named dvbapi_save_channel_cache - which is unexpected to say the least. + If the demux index = 0xff then all related demuxers + are stopped. - * [r10167] - dvbapi: Move channel cache functions into their own file. + * [r10388] - module-dvbapi.c is already too big (5000+ lines, 160k+ size). + oscam-monitor: fixed sending corrupt packets when strlen(txt) > 255 on crypted connections - * [r10166] + * [r10387] - dvbapi: cleanup AZBOX and MCA code (openxcas support). + gbox: Remove gbox code from garbage collector. - There should be no functional changes after this patch. + gbox specific code (that is not even related to memory management) + have no place in garbage collector which is pretty central part of + oscam. + Ref: http://www.streamboard.tv/wbb2/thread.php?postid=535223 - * [r10165] - dvbapi: Prefix channel cache funcs with dvbapi_ and add static where needed. + * [r10386] - There should be no functional changes after this patch. + gbox: Remove unneeded initialization. + This field is already zero (the client is cs_malloc()'ed). - * [r10164] - cccam: Cleanup ifdefs. + * [r10385] - Use config_enabled() instead of ifdefs. This provides compile time - checking if the code is OK even if the config option is disabled. + gbox: Remove unneeded initializations in oscam-ecm. - Also make the lb checks code readable. + These fields are already zero (courtesy of cs_malloc() couple of lines up). - There should be no functional changes after this patch. + * [r10384] - * [r10163] + more fixes - dvbapi: Cleanup ifdefs. - Use config_enabled() instead of ifdefs. This provides compile time - checking if the code is OK even if the config option is disabled. + * [r10383] - There should be no functional changes after this patch. + fixed last commit - * [r10162] + * [r10382] - dvbapi: Cleanup ifdefs. + fixed memory leaks reported here: + http://www.streamboard.tv/wbb2/thread.php?postid=535176#post535176 - Try to minimize ifdefs when they are not needed. It is better to - declare static inline functions when some module is not enable than - to sprinkle ifdefs all over generic code. - There should be no functional changes after this patch. + * [r10381] + added fix for possible crash - * [r10161] - cacheex: Cleanup ifdefs. + * [r10380] - Try to minimize ifdefs when they are not needed. It is better to - declare static inline functions when some module is not enable than - to sprinkle ifdefs all over generic code. + added cccam card sid merging - There should be no functional changes after this patch. + * [r10379] - * [r10160] + final fix for warning "array subscript has type char" + we are now using the same syntax as strtolower() [oscam-string.c] + see thread: http://www.streamboard.tv/wbb2/thread.php?postid=535127 - Remove setvbuf() calls. - In my opinion there is no need to mess with stdio buffers buffers just to - read/write some small config text file. Less code == less things to go wrong, - so following that philosophy this patch removes setvbuf() calls. + * [r10378] + gbox: Disable calling external OSD scripts by default. - * [r10159] + Calling external sripts the way it is implemented is big security + hole, so this patch disables this feature by default. - bulcrypt: Fix newcamd support for Bulcrypt. + If you need it, uncomment `#define GBOX_ENABLE_UNSAFE_OSD 1` and + recompile oscam. - These changes fixed Oscam ticket 4055, credits to kraiv and chepik from - satsupreme forum. + For more info: + http://www.streamboard.tv/wbb2/thread.php?postid=534454#post534454 - * [r10158] + * [r10377] - log: Remove oscam-log-xtr.h + Fixes/cleanups related to read tiers patch committed in r10376. - I fail to see the point of having a header file which defines two variables - and it is included in only one file oscam-log.c - Even if these variables are used in other places other than oscam-log.c (and - they are not) using additional header file is again the wrong thing to do. + * [r10376] - There should be no functional changes after this patch. + vg2: Add read tiers patch. + For more info see ticket #4091. - * [r10157] + Original patch by BigGyros. Original readme follows: - - channelcache load/save: some fixes for MCA / AZBOX - - removed some stale testing code + This patch is the sum of various code: + - some found in streamboard forum (thanks to authors) + - some were reversed from a (shitty) commercial oscam mods (thanks to an + anonymous guy who sent to me) some written just by observing the logs from + a season interface + What this patch does? + 1) it fix the read of tiers for the nds cards like 09AC that stopped to support + the ins76 method + readtiers = 0 //disable + = 1 //ins70 + = 2 //ins76 + (add it in the reader section or use webif) + 2) it adds support for some ins that helps the nds card after the emm update + 3) I hope it will breaks business of assholes who gain money from the free + works of some streamboard users. + What this patch does not? + 1) this patch does not break any DRM or any countermeasure done to fight the + piracy + 2) this patch does not help anybody to share cw + 3) this patch does not help the assholes to sell receivers, lines, oscam-mod, + fake solutions, birds, woods, monkeys.. - * [r10156] + Is the patch tested? + - Yes, it works.. - - Fix for channelcache chid handling - - Fix for requestmode 0 not using exact channelcache match + * [r10375] + cacheex: Cleanup the header file a bit for easier reading. - * [r10155] - - dvbapi load and save of the channel cache to speedup decoding of channels + * [r10374] + cacheex: Move cacheex code from oscam-cache.c to module-cacheex.c + oscam-cache.c is for generic code. - * [r10154] - Machine info + * [r10373] - created extra header file. + better fix for warning "array subscript has type char" - Now info can be used in other .c modules if header is included to that file. + * [r10372] - * [r10153] + fixed warning "array subscript has type char" - Improve seca readercode + * [r10371] + disable ecm odd/even byte check for constcw requests - * [r10152] - Machine info + * [r10370] - added extra's for xp1000. - added a forgotten fclose() + Smartreader protocol + fix compile warning - * [r10151] - - more fix for ticket 4065, all vars are now protected to prevent crashing! + * [r10369] + Smartreader protocol + Modified restart protection to be dev handle base. - * [r10150] - Machine info + * [r10368] - declared some var's in c file self will have to find another way off declarations without braking some uclib compilations + Sci + IOCTL_SET_DEACTIVATE does not work on dm8000. + Free allocated mem's when closing reader. - * [r10149] - Machine info + * [r10367] - renamed models info vars + [gbx] Introduce optional parameter cccam_reshare in gbox section of oscam.server. + cccam_reshare can be used to control the number of hops of cccam cards in the gbx network. + It is independent from the global reshare settings of cccam and is similar to the parameter + cccreshare in the reader settings of cccam. + However the logic is gbx-like not cccam. + Setting it to 0 will prevent cccam cards from being shared. Settings > 0 represent the + number of hops. - * [r10148] - machine info - extra fix + * [r10366] - * [r10147] + net: Initialize local variable. - Machine info - Some small corrections. + Found by clang checker. - * [r10146] + * [r10365] - Machine info + ecm: Prevent possible NULL ptr dereference. - extra info about the router , stb or pc . - This info can become very usefull in future to automate settings like for example: sci in function of stb. + Found by clang checker. - * [r10145] + * [r10364] - - Proper fix for ticket 4065 + cccam: Prevent possible NULL ptr dereference. + Found by clang checker. - * [r10144] + * [r10363] + Correctly restore errno after nanosleep(). - [gbx:] Revert 10143 + Additional fix after r10353. + * [r10362] + oscam-log: Remove useless check. - * [r10143] + Size can't be zero, no need for check for this at all. - [gbx:] Display providing peer id in ecmfmt + * [r10361] + WebIf: + - Fix typo and set width for table in emm_running.html - * [r10142] - [gbx:] Fix warnings in some build environments. Thx AbrahaM. + * [r10360] + enabled and fixed dvbapi for cygwin. + now it is possible to run a dvbapi tcp server on windows. + for example together with dvbv-dvbapi-plugin by schwa226 + thread here: + http://www.streamboard.tv/wbb2/thread.php?threadid=42677 + * [r10359] - * [r10141] + WebIf: - [gbx:] Fix gbox_max_distance setting + 1. Fix for textarea in script.html. Show height for textarea if isn´t text output. + 2. Same width for table in emm.html as emm output in textares. + * [r10358] + Currently we are not sending the (ecm)pid over camd35, this makes constcw requests impossible. + To fix this, this change will use the "buf+18" field to store the pid. This space is ignored or set to a hard-coded value by all other camd3 implementations I checked. The orignal camd3 code either sets it to zero or fills this field with something related to the crc32 checksum and the value at buf+16. + Since up to now we just set it to '0xffff', this change should not break anything. + I have tested connecting to orignal camd3 and everything worked. - * [r10140] + * [r10357] - [gbx:] Stop flooding ecms to multiple gbx card peers - See also: http://www.streamboard.tv/wbb2/thread.php?threadid=42843 + Sci + Modified restart wait until closed protection to act really reader based. + Added a extra log output to detect incompatible commands versus stb type. Example The IOCTL_SET_DEACTIVATE function. Not supported on dm8000 but required on vuduo2. + * [r10356] - * [r10139] + Webif: (Tnx Ultra47 and oscam community members for their effort!) - - Webif cosmetic fixes for dvbapi FTA channels - - Webif page refresh fixes for side-effects introduced by commit 10134 + - Fix for http://www.streamboard.tv/oscam/ticket/4064 + - Patch r9947 enhanced + - Fix show written emms if emm logdir empty + - Optical fixes show written emms + - Show written emms on write emm tab sorted and filtred (oldest first, newest last), idea by schorsch - Tnx Hook and Ultrar47 for providing a combined patch! - -- Andrey Pavlenko Fri, 30 Jan 2015 16:28:18 +0300 + -- Andrey Pavlenko Fri, 20 Feb 2015 14:57:56 +0300 diff -Nru oscam-1.20-10584~r10356/Distribution/doc/html/oscam.server.5.html oscam-1.20-10797~r10569/Distribution/doc/html/oscam.server.5.html --- oscam-1.20-10584~r10356/Distribution/doc/html/oscam.server.5.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/Distribution/doc/html/oscam.server.5.html 2015-02-20 11:57:49.000000000 +0000 @@ -476,7 +476,13 @@
set EMM cache of local reader:

-
 usecache = 0|1: 1 = enable EMM caching, default:0 +
 usecache = 0|1||2 +

+
            0 = EMM caching disabeld (default) +
            1 = enable EMM caching and save EMMs to file after  +
                stopping OSCam +
            2 = enable EMM caching, don't save EMMs to file  +
                after stopping OSCam


 rewrite  = determines how often one and the same EMM is
            written, default:0 @@ -678,6 +684,14 @@

+ +read_old_classes = 0|1 (Viaccess SCs only) +

+0 = read only active entitlements (default) +1 = read all entitlements +
+ +

saveemm-u = 0|1

diff -Nru oscam-1.20-10584~r10356/Distribution/doc/html/oscam.user.5.html oscam-1.20-10797~r10569/Distribution/doc/html/oscam.user.5.html --- oscam-1.20-10584~r10356/Distribution/doc/html/oscam.user.5.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/Distribution/doc/html/oscam.user.5.html 2015-02-20 11:57:49.000000000 +0000 @@ -357,7 +357,7 @@ betatunnel = <CAID>.<ServiceID>:<target CAID>[,<CAID>.<ServiceID>: <target CAID>]...
-define Betacrypt tunneling (maximum see CS_MAXTUNTAB in globals.h). +Define Betacrypt tunneling. The ServiceID can also be used for wildcarded CAIDs.


 example: betatunnel = 0100.0001:0200,0300.0004:0500 diff -Nru oscam-1.20-10584~r10356/Distribution/doc/man/oscam.server.5 oscam-1.20-10797~r10569/Distribution/doc/man/oscam.server.5 --- oscam-1.20-10584~r10356/Distribution/doc/man/oscam.server.5 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/Distribution/doc/man/oscam.server.5 2015-02-20 11:57:49.000000000 +0000 @@ -367,7 +367,13 @@ .RS 3n set EMM cache of local reader: - \fBusecache\fP = \fB0\fP|\fB1\fP: 1 = enable EMM caching, default:0 + \fBusecache\fP = \fB0\fP|\fB1\fP||\fB2\fP + + \fB0\fP = EMM caching disabeld (default) + \fB1\fP = enable EMM caching and save EMMs to file after + stopping OSCam + \fB2\fP = enable EMM caching, don't save EMMs to file + after stopping OSCam \fBrewrite\fP = determines how often one and the same EMM is written, default:0 @@ -524,6 +530,12 @@ 1 = enable global EMM filter for Viaccess SCs, default:0, \fIfor camd35/cs357x protocol only\fR .RE .PP +\fBread_old_classes\fP = \fB0\fP|\fB1\fP \fI(Viaccess SCs only)\fR +.RS 3n +0 = read only active entitlements (default) +1 = read all entitlements +.RE +.PP \fBsaveemm-u\fP = \fB0\fP|\fB1\fP .RS 3n 1 = save unique EMMs to log file, default:0 diff -Nru oscam-1.20-10584~r10356/Distribution/doc/man/oscam.user.5 oscam-1.20-10797~r10569/Distribution/doc/man/oscam.user.5 --- oscam-1.20-10584~r10356/Distribution/doc/man/oscam.user.5 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/Distribution/doc/man/oscam.user.5 2015-02-20 11:57:49.000000000 +0000 @@ -266,7 +266,7 @@ \fBbetatunnel\fP = \fB.:[,.: ]...\fP .RS 3n -define Betacrypt tunneling (maximum see CS_MAXTUNTAB in \fBglobals.h\fP). +Define Betacrypt tunneling. The ServiceID can also be used for wildcarded CAIDs. example: betatunnel = 0100.0001:0200,0300.0004:0500 diff -Nru oscam-1.20-10584~r10356/Distribution/doc/txt/oscam.server.txt oscam-1.20-10797~r10569/Distribution/doc/txt/oscam.server.txt --- oscam-1.20-10584~r10356/Distribution/doc/txt/oscam.server.txt 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/Distribution/doc/txt/oscam.server.txt 2015-02-20 11:57:49.000000000 +0000 @@ -1,4 +1,4 @@ -oscam.server(5) File Formats Manual oscam.server(5) +oscam.server(5) File Formats Manual oscam.server(5) @@ -6,8 +6,8 @@ oscam.server - reader configuration file for OSCam SYNOPSIS - The server configuration file for OSCam contains reader parameters. sections in oscam.server are recurring (more than one - reader possible). At least one [reader] section is required. + The server configuration file for OSCam contains reader parameters. sections in oscam.server are recurring (more than one reader possible). At + least one [reader] section is required. DESCRIPTIONS The [reader] section @@ -105,21 +105,20 @@ status detect of card, NONE = no detection, ! = inverse, default:CD cardmhz = mhz - set standard SC frequency in units of 10 kHz, for Irdeto SC set to 600 mhz, for Dreambox DM800 / DM8000 set to 2700 - mhz, for Dreambox DM7025 set to 8300 mhz, for older PowerPC Dreambox STBs set to 3150 mhz, refer to OVERCLOCKING, - default:357 + set standard SC frequency in units of 10 kHz, for Irdeto SC set to 600 mhz, for Dreambox DM800 / DM8000 set to 2700 mhz, for Dreambox DM7025 set + to 8300 mhz, for older PowerPC Dreambox STBs set to 3150 mhz, refer to OVERCLOCKING, default:357 mhz = frequency - set reader frequency in units of 10 kHz, if mhz > cardmhz you are in overclocking mode. For Smargo readers and Dreambox - internal readers frequency will be set by ATR if autospeed is set to 1, default:357 + set reader frequency in units of 10 kHz, if mhz > cardmhz you are in overclocking mode. For Smargo readers and Dreambox internal readers frequency + will be set by ATR if autospeed is set to 1, default:357 autospeed = 0|1 - 1 = sets mhz according to ATR. Currently only used for smartreader, Smargo and Dreambox internal protocol, other read‐ - ers will be adapted to use this parameter as well. If You wan't to overclock you're card set it to 0, default:1 + 1 = sets mhz according to ATR. Currently only used for smartreader, Smargo and Dreambox internal protocol, other readers will be adapted to use + this parameter as well. If You wan't to overclock you're card set it to 0, default:1 deprecated = 0|1 - First the SC will be initialized in normal mode. If it fails, the SC will be automatically reverted to deprecated mode, - so that the SC speed will not be changed and the communication will remain on normal ATR speed of 9600 baud. + First the SC will be initialized in normal mode. If it fails, the SC will be automatically reverted to deprecated mode, so that the SC speed will + not be changed and the communication will remain on normal ATR speed of 9600 baud. 1 = use deprecated SC mode only, default:0 @@ -180,10 +179,8 @@ 12 = NDS Videoguard 1+ 2 = NDS Videoguard 2 - aeskeys = CAID #0@provid:AES key #0 CAID #0[,AES key #1 CAID #0],...[;CAID #1@provid:AES key #0 CAID #1[,AES key #1 CAID - #1],...]... - multiple 16 bytes AES keys for Viaccess SCs (the used postprocessing AES key is specified through the D2 nano of the - ECM) + aeskeys = CAID #0@provid:AES key #0 CAID #0[,AES key #1 CAID #0],...[;CAID #1@provid:AES key #0 CAID #1[,AES key #1 CAID #1],...]... + multiple 16 bytes AES keys for Viaccess SCs (the used postprocessing AES key is specified through the D2 nano of the ECM) special AES keys: @@ -192,8 +189,7 @@ example: - aeskeys = - 0500@012345:000102030405060708090a0b0c0d0e0f;0500@543210:000102030405060708090a0b0c0d0e0f,0,0f0e0d0c0b0a090807060504030201 + aeskeys = 0500@012345:000102030405060708090a0b0c0d0e0f;0500@543210:000102030405060708090a0b0c0d0e0f,0,0f0e0d0c0b0a090807060504030201 key = DES key key for newcamd remote reader encryption @@ -249,8 +245,7 @@ 1 = ignore caid and provid settings of reader due faulty clients, default:0 inactivitytimeout = seconds - inactivity timeout for all TCP based remote readers, -1 = reconnect on network failure for newcamd, even in idle, - default:0 + inactivity timeout for all TCP based remote readers, -1 = reconnect on network failure for newcamd, even in idle, default:0 reconnecttimeout = seconds reconnect if missing answers from a remote reader, default:30 @@ -268,15 +263,20 @@ 1 = define reader as fallback, standard and fallback reader must have the same group, default:0 fallback_percaid = [:[,ident]]...[;[:[,ident]]...].... - use reader as fallback for defined CAIDs only, two-digit wildcard CAIDs are possible, fallback_percaid overrules fall‐ - back, default:none + use reader as fallback for defined CAIDs only, two-digit wildcard CAIDs are possible, fallback_percaid overrules fallback, default:none example: fallback_percaid = 1234:234567;89;10:345678 emmcache = usecache,rewrite,logging set EMM cache of local reader: - usecache = 0|1: 1 = enable EMM caching, default:0 + usecache = 0|1||2 + + 0 = EMM caching disabeld (default) + 1 = enable EMM caching and save EMMs to file after + stopping OSCam + 2 = enable EMM caching, don't save EMMs to file + after stopping OSCam rewrite = determines how often one and the same EMM is written, default:0 @@ -388,6 +388,9 @@ via_emm_global = 0|1 1 = enable global EMM filter for Viaccess SCs, default:0, for camd35/cs357x protocol only + read_old_classes = 0|1 (Viaccess SCs only) + 0 = read only active entitlements (default) 1 = read all entitlements + saveemm-u = 0|1 1 = save unique EMMs to log file, default:0 @@ -407,8 +410,8 @@ savenano = all readnano = [path]filename - write file (usually a copy of a file saved by savenano) to your smartcard, if no path is specified, the specified file - is searched for in the configuration directory, only valid for physical readers, default:none + write file (usually a copy of a file saved by savenano) to your smartcard, if no path is specified, the specified file is searched for in the con‐ + figuration directory, only valid for physical readers, default:none example: readnano = write.emm readnano = /var/oscam/write.emm @@ -425,8 +428,7 @@ use this reader as local in loadbalancer's reader selection, default:none lb_whitelist_services = ,... - reader assignement to service group for channels which may never be blocked by the loadbalancer to the reader , - default=none + reader assignement to service group for channels which may never be blocked by the loadbalancer to the reader , default=none lb_weight = weight the higher the value the higher the probability for reader selection in load balacing mode, default:100 @@ -489,55 +491,51 @@ OVERCLOCKING · Dreambox and other internal readers - For Dreambox and other internal readers the highest possible clockrate will be auto detected. The mhz parameter lets - you override the values chosen by OSCam, if it differs from 357 and 358, but usually you will not set any value for - mhz. - - For certain Dreamboxes (especially PPC clones) the default mhz parameter leads to slow ECM times and/or "not found" - ECMs. By setting mhz to values like 200, 300, 400, ... 1600 you can find a value that works for your receiver and your - card. The higher the mhz value, the slower the ECM time (strange enough). + For Dreambox and other internal readers the highest possible clockrate will be auto detected. The mhz parameter lets you override the values cho‐ + sen by OSCam, if it differs from 357 and 358, but usually you will not set any value for mhz. - If you choose the value too low, your card is not recognized (no ATR or "card not supported"). If you choose the value - too high, you get slow ECM times. Our experience is that either no mhz line, or a line mhz = 1000 works best. + For certain Dreamboxes (especially PPC clones) the default mhz parameter leads to slow ECM times and/or "not found" ECMs. By setting mhz to values + like 200, 300, 400, ... 1600 you can find a value that works for your receiver and your card. The higher the mhz value, the slower the ECM time + (strange enough). + + If you choose the value too low, your card is not recognized (no ATR or "card not supported"). If you choose the value too high, you get slow ECM + times. Our experience is that either no mhz line, or a line mhz = 1000 works best. · Phoenix / Smartmouse reader - Overclocking does not work with Windows and Mac OS X. Set mhz equivalent to the frequency of the reader. OSCam can - not set the frequency of the reader. + Overclocking does not work with Windows and Mac OS X. Set mhz equivalent to the frequency of the reader. OSCam can not set the frequency of the + reader. · Smargo Smartreader+ - Use protocol = smargo for the FDDI kernel drivers (no libusb needed) or (not recommended) use protocol = smartreader - for OSCam's driver implementation based on libusb. + Use protocol = smargo for the FDDI kernel drivers (no libusb needed) or (not recommended) use protocol = smartreader for OSCam's driver implemen‐ + tation based on libusb. + + Set the reader frequency with the native Smargo Smartreader+ tool (srp_tools). If not setting mhz and cardmhz, OSCam tries to set the baudrate + automatically, according to the maximum speed indicated by ATR. Overclocking is possible. - Set the reader frequency with the native Smargo Smartreader+ tool (srp_tools). If not setting mhz and cardmhz, OSCam - tries to set the baudrate automatically, according to the maximum speed indicated by ATR. Overclocking is possible. + OSCam tries to set the baudrate automatically. A standard serial port has limited baudrate settings, so SC overclocking might not work. When using + a serial reader the best way for overclocking is connecting it to a FTDI based USB to serial port adapter. - OSCam tries to set the baudrate automatically. A standard serial port has limited baudrate settings, so SC overclocking - might not work. When using a serial reader the best way for overclocking is connecting it to a FTDI based USB to serial - port adapter. - - If overclocking does not work, verify the effective baudrate in the logfile. If it deviates too much from the requested - baudrate, the SC will not be recognized (no ATR) and the value for mhz should be adjusted again. The higher the baudrate, - the more accurate the effective baudrate can be. + If overclocking does not work, verify the effective baudrate in the logfile. If it deviates too much from the requested baudrate, the SC will not be + recognized (no ATR) and the value for mhz should be adjusted again. The higher the baudrate, the more accurate the effective baudrate can be. CACHE EXCHANGE · pull mode (on request: cache exchange from remote to local OSCam) - ECM requests will be forwarded to the remote cache exchange partner. If the CW could not be found in the cache of the - remote exchange partner, a not found will be answered. If the CW could not be found in the cache of the remote exchange - partner but a pending ECM request is open, the request will be re-initiated after the wait time defined in cacheexwait‐ - time. + ECM requests will be forwarded to the remote cache exchange partner. If the CW could not be found in the cache of the remote exchange partner, a + not found will be answered. If the CW could not be found in the cache of the remote exchange partner but a pending ECM request is open, the + request will be re-initiated after the wait time defined in cacheexwaittime. · push mode (continuous: cache exchange from remote to local OSCam) - CWs from the remote cache exchange partner will be forwarded to the local cache. Forwarding only works while the camd - camd 3.5x / 3.57x or CCcam protocol connection between the local and remote OSCam has been established. + CWs from the remote cache exchange partner will be forwarded to the local cache. Forwarding only works while the camd camd 3.5x / 3.57x or CCcam + protocol connection between the local and remote OSCam has been established. · reverse push mode (continuous: cache exchange from local to remote OSCam) - CWs from the local cache will be forwarded to the remote cache exchange partner. Forwarding only works while the camd - camd 3.5x / 3.57x or CCcam protocol connection between the remote and local OSCam has been established. + CWs from the local cache will be forwarded to the remote cache exchange partner. Forwarding only works while the camd camd 3.5x / 3.57x or CCcam + protocol connection between the remote and local OSCam has been established. EXAMPLES · serial mouse compatible reader @@ -653,10 +651,9 @@ caid = 1100 SEE ALSO - list_smargo(1), oscam(1), oscam.ac(5), oscam.cacheex(5), oscam.cert(5), oscam.conf(5), oscam.dvbapi(5), oscam.guess(5), - oscam.ird(5), oscam.provid(5), oscam.ratelimit(5), oscam.services(5), oscam.srvid(5), oscam.tiers(5), oscam.user(5), - oscam.whitelist(5) + list_smargo(1), oscam(1), oscam.ac(5), oscam.cacheex(5), oscam.cert(5), oscam.conf(5), oscam.dvbapi(5), oscam.guess(5), oscam.ird(5), + oscam.provid(5), oscam.ratelimit(5), oscam.services(5), oscam.srvid(5), oscam.tiers(5), oscam.user(5), oscam.whitelist(5) - oscam.server(5) + oscam.server(5) diff -Nru oscam-1.20-10584~r10356/Distribution/doc/txt/oscam.user.txt oscam-1.20-10797~r10569/Distribution/doc/txt/oscam.user.txt --- oscam-1.20-10584~r10356/Distribution/doc/txt/oscam.user.txt 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/Distribution/doc/txt/oscam.user.txt 2015-02-20 11:57:49.000000000 +0000 @@ -194,7 +194,7 @@ user assingment to reader groups, default:none, required betatunnel = .:[,.: ]... - define Betacrypt tunneling (maximum see CS_MAXTUNTAB in globals.h). The ServiceID can also be used for wildcarded + Define Betacrypt tunneling. The ServiceID can also be used for wildcarded CAIDs. example: betatunnel = 0100.0001:0200,0300.0004:0500 diff -Nru oscam-1.20-10584~r10356/.gitignore oscam-1.20-10797~r10569/.gitignore --- oscam-1.20-10584~r10356/.gitignore 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/.gitignore 2015-02-20 11:57:49.000000000 +0000 @@ -11,3 +11,7 @@ # Currently enabled config items webif/is_defined.txt + +# Testing program +tests.bin +tests.bin.debug diff -Nru oscam-1.20-10584~r10356/globals.h oscam-1.20-10797~r10569/globals.h --- oscam-1.20-10584~r10356/globals.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/globals.h 2015-02-20 11:57:49.000000000 +0000 @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -245,11 +246,8 @@ #endif #define CS_QLEN 128 // size of request queue #define CS_MAXCAIDTAB 32 // max. caid-defs/user -#define CS_MAXTUNTAB 100 // max. betatunnel mappings #define CS_MAXPROV 32 #define CS_MAXPORTS 32 // max server ports -#define CS_MAXFILTERS 16 -#define CS_MAX_CAIDVALUETAB 16 #define CS_CLIENT_HASHBUCKETS 32 #define CS_ECMSTORESIZE 16 // use MD5() @@ -316,6 +314,7 @@ #define is_network_reader(__X) (__X->typ & R_IS_NETWORK) #define is_cascading_reader(__X) (__X->typ & R_IS_CASCADING) +#define is_smargo_reader(__X) (strcmp(__X->crdr.desc, "smargo") == 0) //ECM rc codes: #define E_FOUND 0 @@ -538,11 +537,16 @@ #include "oscam-llist.h" +typedef struct s_caidvaluetab_data +{ + uint16_t caid; + uint16_t value; +} CAIDVALUETAB_DATA; + typedef struct s_caidvaluetab { - uint16_t n; - uint16_t caid[CS_MAX_CAIDVALUETAB]; - uint16_t value[CS_MAX_CAIDVALUETAB]; + int32_t cvnum; + CAIDVALUETAB_DATA *cvdata; } CAIDVALUETAB; typedef struct s_classtab @@ -553,19 +557,30 @@ uchar bclass[31]; } CLASSTAB; +typedef struct s_caidtab_data +{ + uint16_t caid; + uint16_t mask; + uint16_t cmap; +} CAIDTAB_DATA; + typedef struct s_caidtab { - uint16_t caid[CS_MAXCAIDTAB]; - uint16_t mask[CS_MAXCAIDTAB]; - uint16_t cmap[CS_MAXCAIDTAB]; + int32_t ctnum; + CAIDTAB_DATA *ctdata; } CAIDTAB; +typedef struct s_tuntab_data +{ + uint16_t bt_caidfrom; + uint16_t bt_caidto; + uint16_t bt_srvid; +} TUNTAB_DATA; + typedef struct s_tuntab { - uint16_t n; - uint16_t bt_caidfrom[CS_MAXTUNTAB]; - uint16_t bt_caidto[CS_MAXTUNTAB]; - uint16_t bt_srvid[CS_MAXTUNTAB]; + int32_t ttnum; + TUNTAB_DATA *ttdata; } TUNTAB; typedef struct s_sidtab @@ -590,14 +605,20 @@ typedef struct s_ftab { int32_t nfilts; - FILTER filts[CS_MAXFILTERS]; + FILTER *filts; } FTAB; +typedef struct s_ncd_ftab +{ + int32_t nfilts; + FILTER filts[16]; +} NCD_FTAB; + struct ncd_port { bool ncd_key_is_set; uint8_t ncd_key[14]; - FTAB ncd_ftab; + NCD_FTAB ncd_ftab; }; typedef struct s_port @@ -640,11 +661,23 @@ time_t time; }; -struct s_emm +struct s_emmstat { uchar emmd5[CS_EMMSTORESIZE]; uchar type; int32_t count; + struct timeb firstwritten; + struct timeb lastwritten; +}; + +struct s_emmcache +{ + uchar emmd5[CS_EMMSTORESIZE]; + uchar type; + uchar len; + uchar emm[258]; + struct timeb firstseen; + struct timeb lastseen; }; struct s_csystem_emm_filter @@ -696,11 +729,10 @@ struct s_module { - int8_t active; + const char *desc; int8_t type; int8_t large_ecm_support; int16_t listenertype; - char *desc; //int32_t s_port; IN_ADDR_T s_ip; uint16_t bufsize; @@ -751,7 +783,7 @@ struct s_cardreader { - char *desc; + const char *desc; int32_t (*reader_init)(struct s_reader *); int32_t (*get_status)(struct s_reader *, int *); int32_t (*activate)(struct s_reader *, struct s_ATR *); @@ -796,12 +828,13 @@ struct s_cardsystem { - int8_t active; - char *desc; + const char *desc; int32_t (*card_init)(struct s_reader *reader, struct s_ATR *); + void (*card_done)(struct s_reader *reader); int32_t (*card_info)(struct s_reader *); + void (*poll_status)(struct s_reader *); int32_t (*do_ecm)(struct s_reader *, const struct ecm_request_t *, struct s_ecm_answer *); - int32_t (*do_emm_reassembly)(struct s_client *, struct emm_packet_t *); // Returns 1/true if the EMM is ready to be written in the card + int32_t (*do_emm_reassembly)(struct s_reader *, struct s_client *, struct emm_packet_t *); // Returns 1/true if the EMM is ready to be written in the card int32_t (*do_emm)(struct s_reader *, struct emm_packet_t *); void (*post_process)(struct s_reader *); int32_t (*get_emm_type)(struct emm_packet_t *, struct s_reader *); @@ -868,8 +901,8 @@ void *src_data; int32_t csp_hash; // csp has its own hash -#ifdef CS_CACHEEX struct s_client *cacheex_src; // Cacheex origin +#ifdef CS_CACHEEX int8_t cacheex_pushed; // to avoid duplicate pushs uint8_t csp_answered; // =1 if er get answer by csp LLIST *csp_lastnodes; // last 10 Cacheex nodes atm cc-proto-only @@ -960,6 +993,13 @@ time_t lasttime; }; +// EMM reassemply +struct emm_rass +{ + int16_t emmlen; + uint8_t emm[512]; +}; + struct s_client { uint32_t tid; @@ -988,14 +1028,8 @@ int8_t dup; LLIST *aureader_list; int8_t autoau; -#ifdef READER_VIACCESS - int16_t via_rass_emmlen; - uint8_t via_rass_emm[512]; -#endif -#ifdef READER_CRYPTOWORKS - int16_t cw_rass_emmlen; - uint8_t cw_rass_emm[512]; -#endif + struct emm_rass *via_rass; // EMM reassembly buffer for viaccess + struct emm_rass *cw_rass; // EMM reassembly buffer for cryptoworks int8_t monlvl; CAIDTAB ctab; TUNTAB ttab; @@ -1053,7 +1087,7 @@ uchar ucrc[4]; // needed by monitor and used by camd35 uint32_t pcrc; // password crc - struct aes_keys aes_keys; + struct aes_keys *aes_keys; // used by camd33 and camd35 uint16_t ncd_msgid; uint16_t ncd_client_id; uchar ncd_skey[16]; //Also used for camd35 Cacheex to store remote node id @@ -1138,34 +1172,32 @@ struct s_client *nexthashed; }; -struct s_ecmWhitelist +typedef struct s_ecm_whitelist_data { - uint16_t caid; - struct s_ecmWhitelistIdent *idents; - struct s_ecmWhitelist *next; -}; + uint16_t len; + uint16_t caid; + uint32_t ident; +} ECM_WHITELIST_DATA; -struct s_ecmWhitelistIdent +typedef struct s_ecm_whitelist { - uint32_t ident; - struct s_ecmWhitelistLen *lengths; - struct s_ecmWhitelistIdent *next; -}; + int32_t ewnum; + ECM_WHITELIST_DATA *ewdata; +} ECM_WHITELIST; -struct s_ecmWhitelistLen +typedef struct s_ecm_hdr_whitelist_data { - int16_t len; - struct s_ecmWhitelistLen *next; -}; + uint16_t len; + uint16_t caid; + uint32_t provid; + uint8_t header[20]; +} ECM_HDR_WHITELIST_DATA; -struct s_ecmHeaderwhitelist +typedef struct s_ecm_hdr_whitelist { - uint16_t caid; - uint32_t provid; - uchar header[20]; - int16_t len; - struct s_ecmHeaderwhitelist *next; -}; + int32_t ehnum; + ECM_HDR_WHITELIST_DATA *ehdata; +} ECM_HDR_WHITELIST; //ratelimit struct ecmrl @@ -1264,6 +1296,7 @@ char device[128]; uint16_t slot; // in case of multiple slots like sc8in1; first slot = 1 int32_t handle; // device handle + int64_t handle_nr; // device handle_nr for mutiple readers same driver int32_t fdmc; // device handle for multicam int32_t detect; int32_t mhz; // actual clock rate of reader in 10khz steps @@ -1290,6 +1323,7 @@ int32_t nprov; uchar prid[CS_MAXPROV][8]; uchar sa[CS_MAXPROV][4]; // viaccess & seca + uint8_t read_old_classes; // viaccess uint16_t caid; uint16_t b_nano; uint16_t s_nano; @@ -1310,6 +1344,7 @@ void *crdr_data; // Private card reader data struct s_cardsystem csystem; void *csystem_data; // Private card system data + bool csystem_active; uint8_t ncd_key[14]; uchar ncd_skey[16]; int8_t ncd_connect_on_init; @@ -1339,11 +1374,12 @@ time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect ) time_t last_s; // send time_t last_check; // last checked + time_t last_poll; // last poll FTAB fchid; FTAB ftab; CLASSTAB cltab; - struct s_ecmWhitelist *ecmWhitelist; - struct s_ecmHeaderwhitelist *ecmHeaderwhitelist; // ECM Header Whitelist + ECM_WHITELIST ecm_whitelist; + ECM_HDR_WHITELIST ecm_hdr_whitelist; int32_t brk_pos; int32_t msg_idx; int32_t secatype; // 0=not determined, 2=seca2, 3=nagra(~seca3) this is only valid for localreaders! @@ -1388,6 +1424,7 @@ #endif unsigned char rom[15]; unsigned char irdId[4]; + unsigned char payload4C[15]; uint16_t VgCredit; uint16_t VgPin; unsigned char VgFuse; @@ -1427,16 +1464,18 @@ struct ecmrl rlecmh[MAXECMRATELIMIT]; int8_t fix_07; int8_t fix_9993; + int8_t readtiers; // method to get videoguard tiers uint8_t ins7E[0x1A + 1]; uint8_t ins7E11[0x01 + 1]; uint8_t ins2e06[0x04 + 1]; int8_t ins7e11_fast_reset; uint8_t sc8in1_dtrrts_patch; // fix for kernel commit 6a1a82df91fa0eb1cc76069a9efe5714d087eccd #ifdef MODULE_GBOX - int8_t gbox_maxdist; - int8_t gbox_maxecmsend; - int8_t gbox_reshare; - char last_gsms[128]; + uint8_t gbox_maxdist; + uint8_t gbox_maxecmsend; + uint8_t gbox_reshare; + uint8_t gbox_cccam_reshare; + char last_gsms[128]; #endif #ifdef MODULE_PANDORA @@ -1446,8 +1485,8 @@ uint8_t ghttp_use_ssl; #endif uint8_t cnxlastecm; // == 0 - las ecm has not been paired ecm, > 0 last ecm has been paired ecm - int16_t rotate; - struct s_emm *emmcache; + LLIST *emmstat; //emm stats + CS_MUTEX_LOCK emmstat_lock; struct s_reader *next; }; @@ -1682,7 +1721,7 @@ char *http_user; char *http_pwd; char *http_css; - int32_t http_prepend_embedded_css; + int8_t http_prepend_embedded_css; char *http_jscript; char *http_tpl; char *http_piconpath; @@ -1712,6 +1751,9 @@ char *http_help_lang; char *http_locale; char *http_oscam_label; + int32_t http_emmu_clean; + int32_t http_emms_clean; + int32_t http_emmg_clean; #endif int8_t http_full_cfg; int8_t http_overwrite_bak_file; @@ -2015,5 +2057,9 @@ char *get_tiername(uint16_t tierid, uint16_t caid, char *buf); char *get_provider(uint16_t caid, uint32_t provid, char *buf, uint32_t buflen); void add_provider(uint16_t caid, uint32_t provid, const char *name, const char *sat, const char *lang); +bool boxtype_is(const char *boxtype); +bool boxname_is(const char *boxname); +const char *boxtype_get(void); +const char *boxname_get(void); #endif diff -Nru oscam-1.20-10584~r10356/Makefile oscam-1.20-10797~r10569/Makefile --- oscam-1.20-10584~r10356/Makefile 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/Makefile 2015-02-20 11:57:49.000000000 +0000 @@ -2,13 +2,18 @@ .SUFFIXES: .SUFFIXES: .o .c -.PHONY: all help README.build README.config simple default debug config menuconfig allyesconfig allnoconfig defconfig clean distclean +.PHONY: all tests help README.build README.config simple default debug config menuconfig allyesconfig allnoconfig defconfig clean distclean VER := $(shell ./config.sh --oscam-version) SVN_REV := $(shell ./config.sh --oscam-revision) uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') +# This let's us use uname_S tests to detect cygwin +ifneq (,$(findstring CYGWIN,$(uname_S))) + uname_S := Cygwin +endif + LINKER_VER_OPT:=-Wl,--version # Find OSX SDK @@ -96,6 +101,11 @@ else DEFAULT_LIBUSB_LIB = -lusb-1.0 endif +# Since FreeBSD 8 (released in 2010) they are using their own +# libusb that is API compatible to libusb but with different soname +ifeq ($(uname_S),FreeBSD) +DEFAULT_LIBUSB_LIB = -lusb +endif ifeq ($(uname_S),Darwin) DEFAULT_LIBUSB_FLAGS = -I/opt/local/include DEFAULT_LIBUSB_LIB = -L/opt/local/lib -lusb-1.0 @@ -118,6 +128,10 @@ DEFAULT_PCSC_LIB = -lpcsclite endif +ifeq ($(uname_S),Cygwin) +DEFAULT_PCSC_LIB += -lwinscard +endif + # Function to initialize USE related variables # Usage: $(eval $(call prepare_use_flags,FLAG_NAME,PLUS_TARGET_TEXT)) define prepare_use_flags @@ -185,6 +199,7 @@ -include $(OBJDIR)/config.mak OSCAM_BIN := $(BINDIR)/oscam-$(VER)$(SVN_REV)-$(subst cygwin,cygwin.exe,$(TARGET)) +TESTS_BIN := tests.bin LIST_SMARGO_BIN := $(BINDIR)/list_smargo-$(VER)$(SVN_REV)-$(subst cygwin,cygwin.exe,$(TARGET)) # Build list_smargo-.... only when WITH_LIBUSB build is requested. @@ -253,6 +268,7 @@ SRC-$(CONFIG_HAVE_DVBAPI) += module-dvbapi.c SRC-$(CONFIG_MODULE_GBOX) += module-gbox-helper.c SRC-$(CONFIG_MODULE_GBOX) += module-gbox-sms.c +SRC-$(CONFIG_MODULE_GBOX) += module-gbox-cards.c SRC-$(CONFIG_MODULE_GBOX) += module-gbox.c SRC-$(CONFIG_IRDETO_GUESSING) += module-ird-guess.c SRC-$(CONFIG_LCDSUPPORT) += module-lcd.c @@ -286,6 +302,7 @@ SRC-$(CONFIG_READER_VIDEOGUARD) += reader-videoguard12.c SRC-$(CONFIG_READER_VIDEOGUARD) += reader-videoguard2.c SRC-y += oscam-aes.c +SRC-y += oscam-array.c SRC-y += oscam-hashtable.c SRC-y += oscam-cache.c SRC-y += oscam-chk.c @@ -299,6 +316,7 @@ SRC-y += oscam-config.c SRC-y += oscam-ecm.c SRC-y += oscam-emm.c +SRC-y += oscam-emm-cache.c SRC-y += oscam-failban.c SRC-y += oscam-files.c SRC-y += oscam-garbage.c @@ -315,6 +333,10 @@ SRC-y += oscam.c # config.c is automatically generated by config.sh in OBJDIR SRC-y += config.c +ifdef BUILD_TESTS +SRC-y += tests.c +override STD_DEFS += -DBUILD_TESTS=1 +endif SRC := $(SRC-y) OBJ := $(addprefix $(OBJDIR)/,$(subst .c,.o,$(SRC))) @@ -377,6 +399,14 @@ -include $(subst .o,.d,$(OBJ)) +tests: + @-$(MAKE) --no-print-directory BUILD_TESTS=1 OSCAM_BIN=$(TESTS_BIN) + @-touch oscam.c +# The above is really hideous hack :-) If we don't force oscam.c recompilation +# after we've build the tests binary, the next "normal" compilation would fail +# because there would be no run_tests() function. So the touch is there to +# ensure oscam.c would be recompiled. + config: $(SHELL) ./config.sh --gui @@ -395,7 +425,7 @@ @-$(SHELL) ./config.sh --restore clean: - @-for FILE in $(BUILD_DIR)/*; do \ + @-for FILE in $(BUILD_DIR)/* $(TESTS_BIN) $(TESTS_BIN).debug; do \ echo "RM $$FILE"; \ rm -rf $$FILE; \ done @@ -670,6 +700,9 @@ make static-libcrypto - Builds OSCam with libcrypto linked statically\n\ make static-ssl - Builds OSCam with SSL support linked statically\n\ \n\ + Developer targets:\n\ + make tests - Builds '$(TESTS_BIN)' binary\n\ +\n\ Examples:\n\ Build OSCam for SH4 (the compilers are in the path):\n\ make CROSS=sh4-linux-\n\n\ diff -Nru oscam-1.20-10584~r10356/minilzo/lzoconf.h oscam-1.20-10797~r10569/minilzo/lzoconf.h --- oscam-1.20-10584~r10356/minilzo/lzoconf.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/minilzo/lzoconf.h 2015-02-20 11:57:49.000000000 +0000 @@ -2,22 +2,7 @@ This file is part of the LZO real-time data compression library. - Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -44,10 +29,9 @@ #ifndef __LZOCONF_H_INCLUDED #define __LZOCONF_H_INCLUDED 1 -#define LZO_VERSION 0x2060 -#define LZO_VERSION_STRING "2.06" -#define LZO_VERSION_DATE "Aug 12 2011" -#define LZO_CFG_NO_CONFIG_CHECK 1 +#define LZO_VERSION 0x2090 +#define LZO_VERSION_STRING "2.09" +#define LZO_VERSION_DATE "Feb 04 2015" /* internal Autoconf configuration file - only used when building LZO */ #if defined(LZO_HAVE_CONFIG_H) @@ -56,6 +40,7 @@ #include #include +#define LZO_CFG_NO_CONFIG_CHECK 1 /*********************************************************************** // LZO requires a conforming @@ -64,7 +49,7 @@ #if !defined(CHAR_BIT) || (CHAR_BIT != 8) # error "invalid CHAR_BIT" #endif -#if !defined(UCHAR_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX) +#if !defined(UCHAR_MAX) || !defined(USHRT_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX) # error "check your compiler installation" #endif #if (USHRT_MAX < 1) || (UINT_MAX < 1) || (ULONG_MAX < 1) @@ -73,7 +58,7 @@ /* get OS and architecture defines */ #ifndef __LZODEFS_H_INCLUDED -#include "lzodefs.h" +#include #endif @@ -82,19 +67,11 @@ #endif - /*********************************************************************** - // some core defines - ************************************************************************/ - -#if !defined(LZO_UINT32_C) -# if (UINT_MAX < LZO_0xffffffffL) -# define LZO_UINT32_C(c) c ## UL -# else -# define LZO_UINT32_C(c) ((c) + 0U) -# endif -#endif +/*********************************************************************** +// some core defines +************************************************************************/ - /* memory checkers */ +/* memory checkers */ #if !defined(__LZO_CHECKER) # if defined(__BOUNDS_CHECKING_ON) # define __LZO_CHECKER 1 @@ -108,32 +85,39 @@ #endif - /*********************************************************************** - // integral and pointer types - ************************************************************************/ +/*********************************************************************** +// integral and pointer types +************************************************************************/ - /* lzo_uint should match size_t */ +/* lzo_uint must match size_t */ #if !defined(LZO_UINT_MAX) -# if defined(LZO_ABI_LLP64) /* WIN64 */ -# if defined(LZO_OS_WIN64) - typedef unsigned __int64 lzo_uint; - typedef __int64 lzo_int; +# if (LZO_ABI_LLP64) +# if (LZO_OS_WIN64) + typedef unsigned __int64 lzo_uint; + typedef __int64 lzo_int; +# define LZO_TYPEOF_LZO_INT LZO_TYPEOF___INT64 # else - typedef unsigned long long lzo_uint; - typedef long long lzo_int; + typedef lzo_ullong_t lzo_uint; + typedef lzo_llong_t lzo_int; +# define LZO_TYPEOF_LZO_INT LZO_TYPEOF_LONG_LONG # endif +# define LZO_SIZEOF_LZO_INT 8 # define LZO_UINT_MAX 0xffffffffffffffffull # define LZO_INT_MAX 9223372036854775807LL # define LZO_INT_MIN (-1LL - LZO_INT_MAX) -# elif defined(LZO_ABI_IP32L64) /* MIPS R5900 */ - typedef unsigned int lzo_uint; - typedef int lzo_int; +# elif (LZO_ABI_IP32L64) /* MIPS R5900 */ + typedef unsigned int lzo_uint; + typedef int lzo_int; +# define LZO_SIZEOF_LZO_INT LZO_SIZEOF_INT +# define LZO_TYPEOF_LZO_INT LZO_TYPEOF_INT # define LZO_UINT_MAX UINT_MAX # define LZO_INT_MAX INT_MAX # define LZO_INT_MIN INT_MIN # elif (ULONG_MAX >= LZO_0xffffffffL) - typedef unsigned long lzo_uint; - typedef long lzo_int; + typedef unsigned long lzo_uint; + typedef long lzo_int; +# define LZO_SIZEOF_LZO_INT LZO_SIZEOF_LONG +# define LZO_TYPEOF_LZO_INT LZO_TYPEOF_LONG # define LZO_UINT_MAX ULONG_MAX # define LZO_INT_MAX LONG_MAX # define LZO_INT_MIN LONG_MIN @@ -142,93 +126,84 @@ # endif #endif - /* Integral types with 32 bits or more. */ -#if !defined(LZO_UINT32_MAX) -# if (UINT_MAX >= LZO_0xffffffffL) - typedef unsigned int lzo_uint32; - typedef int lzo_int32; -# define LZO_UINT32_MAX UINT_MAX -# define LZO_INT32_MAX INT_MAX -# define LZO_INT32_MIN INT_MIN -# elif (ULONG_MAX >= LZO_0xffffffffL) - typedef unsigned long lzo_uint32; - typedef long lzo_int32; -# define LZO_UINT32_MAX ULONG_MAX -# define LZO_INT32_MAX LONG_MAX -# define LZO_INT32_MIN LONG_MIN -# else -# error "lzo_uint32" -# endif -#endif - - /* Integral types with exactly 64 bits. */ -#if !defined(LZO_UINT64_MAX) -# if (LZO_UINT_MAX >= LZO_0xffffffffL) -# if ((((LZO_UINT_MAX) >> 31) >> 31) == 3) -# define lzo_uint64 lzo_uint -# define lzo_int64 lzo_int -# define LZO_UINT64_MAX LZO_UINT_MAX -# define LZO_INT64_MAX LZO_INT_MAX -# define LZO_INT64_MIN LZO_INT_MIN -# endif -# elif (ULONG_MAX >= LZO_0xffffffffL) -# if ((((ULONG_MAX) >> 31) >> 31) == 3) - typedef unsigned long lzo_uint64; - typedef long lzo_int64; -# define LZO_UINT64_MAX ULONG_MAX -# define LZO_INT64_MAX LONG_MAX -# define LZO_INT64_MIN LONG_MIN -# endif -# endif -#endif - - /* The larger type of lzo_uint and lzo_uint32. */ -#if (LZO_UINT_MAX >= LZO_UINT32_MAX) +/* The larger type of lzo_uint and lzo_uint32_t. */ +#if (LZO_SIZEOF_LZO_INT >= 4) # define lzo_xint lzo_uint #else -# define lzo_xint lzo_uint32 +# define lzo_xint lzo_uint32_t #endif - /* Memory model that allows to access memory at offsets of lzo_uint. */ -#if !defined(__LZO_MMODEL) -# if (LZO_UINT_MAX <= UINT_MAX) -# define __LZO_MMODEL /*empty*/ -# elif defined(LZO_HAVE_MM_HUGE_PTR) -# define __LZO_MMODEL_HUGE 1 -# define __LZO_MMODEL __huge -# else -# define __LZO_MMODEL /*empty*/ -# endif +typedef int lzo_bool; + +/* sanity checks */ +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int) == LZO_SIZEOF_LZO_INT) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == LZO_SIZEOF_LZO_INT) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_xint) >= sizeof(lzo_uint)) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_xint) >= sizeof(lzo_uint32_t)) + +#ifndef __LZO_MMODEL +#define __LZO_MMODEL /*empty*/ #endif - /* no typedef here because of const-pointer issues */ +/* no typedef here because of const-pointer issues */ #define lzo_bytep unsigned char __LZO_MMODEL * #define lzo_charp char __LZO_MMODEL * #define lzo_voidp void __LZO_MMODEL * #define lzo_shortp short __LZO_MMODEL * #define lzo_ushortp unsigned short __LZO_MMODEL * -#define lzo_uint32p lzo_uint32 __LZO_MMODEL * -#define lzo_int32p lzo_int32 __LZO_MMODEL * -#if defined(LZO_UINT64_MAX) -#define lzo_uint64p lzo_uint64 __LZO_MMODEL * -#define lzo_int64p lzo_int64 __LZO_MMODEL * -#endif -#define lzo_uintp lzo_uint __LZO_MMODEL * #define lzo_intp lzo_int __LZO_MMODEL * +#define lzo_uintp lzo_uint __LZO_MMODEL * #define lzo_xintp lzo_xint __LZO_MMODEL * #define lzo_voidpp lzo_voidp __LZO_MMODEL * #define lzo_bytepp lzo_bytep __LZO_MMODEL * - /* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */ -#define lzo_byte unsigned char __LZO_MMODEL - typedef int lzo_bool; +#define lzo_int8_tp lzo_int8_t __LZO_MMODEL * +#define lzo_uint8_tp lzo_uint8_t __LZO_MMODEL * +#define lzo_int16_tp lzo_int16_t __LZO_MMODEL * +#define lzo_uint16_tp lzo_uint16_t __LZO_MMODEL * +#define lzo_int32_tp lzo_int32_t __LZO_MMODEL * +#define lzo_uint32_tp lzo_uint32_t __LZO_MMODEL * +#if defined(lzo_int64_t) +#define lzo_int64_tp lzo_int64_t __LZO_MMODEL * +#define lzo_uint64_tp lzo_uint64_t __LZO_MMODEL * +#endif + +/* Older LZO versions used to support ancient systems and memory models + * such as 16-bit MSDOS with __huge pointers or Cray PVP, but these + * obsolete configurations are not supported any longer. + */ +#if defined(__LZO_MMODEL_HUGE) +#error "__LZO_MMODEL_HUGE memory model is unsupported" +#endif +#if (LZO_MM_PVP) +#error "LZO_MM_PVP memory model is unsupported" +#endif +#if (LZO_SIZEOF_INT < 4) +#error "LZO_SIZEOF_INT < 4 is unsupported" +#endif +#if (__LZO_UINTPTR_T_IS_POINTER) +#error "__LZO_UINTPTR_T_IS_POINTER is unsupported" +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) >= 4) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) >= 4) +/* Strange configurations where sizeof(lzo_uint) != sizeof(size_t) should + * work but have not received much testing lately, so be strict here. + */ +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(size_t)) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(ptrdiff_t)) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(lzo_uintptr_t)) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(void *) == sizeof(lzo_uintptr_t)) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(char *) == sizeof(lzo_uintptr_t)) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long *) == sizeof(lzo_uintptr_t)) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(void *) == sizeof(lzo_voidp)) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(char *) == sizeof(lzo_bytep)) - /*********************************************************************** - // function types - ************************************************************************/ +/*********************************************************************** +// function types +************************************************************************/ - /* name mangling */ +/* name mangling */ #if !defined(__LZO_EXTERN_C) # ifdef __cplusplus # define __LZO_EXTERN_C extern "C" @@ -237,12 +212,12 @@ # endif #endif - /* calling convention */ +/* calling convention */ #if !defined(__LZO_CDECL) # define __LZO_CDECL __lzo_cdecl #endif - /* DLL export information */ +/* DLL export information */ #if !defined(__LZO_EXPORT1) # define __LZO_EXPORT1 /*empty*/ #endif @@ -250,89 +225,89 @@ # define __LZO_EXPORT2 /*empty*/ #endif - /* __cdecl calling convention for public C and assembly functions */ +/* __cdecl calling convention for public C and assembly functions */ #if !defined(LZO_PUBLIC) -# define LZO_PUBLIC(_rettype) __LZO_EXPORT1 _rettype __LZO_EXPORT2 __LZO_CDECL +# define LZO_PUBLIC(r) __LZO_EXPORT1 r __LZO_EXPORT2 __LZO_CDECL #endif #if !defined(LZO_EXTERN) -# define LZO_EXTERN(_rettype) __LZO_EXTERN_C LZO_PUBLIC(_rettype) +# define LZO_EXTERN(r) __LZO_EXTERN_C LZO_PUBLIC(r) #endif #if !defined(LZO_PRIVATE) -# define LZO_PRIVATE(_rettype) static _rettype __LZO_CDECL +# define LZO_PRIVATE(r) static r __LZO_CDECL #endif - /* function types */ - typedef int - (__LZO_CDECL *lzo_compress_t)(const lzo_bytep src, lzo_uint src_len, - lzo_bytep dst, lzo_uintp dst_len, - lzo_voidp wrkmem); - - typedef int - (__LZO_CDECL *lzo_decompress_t)(const lzo_bytep src, lzo_uint src_len, - lzo_bytep dst, lzo_uintp dst_len, - lzo_voidp wrkmem); - - typedef int - (__LZO_CDECL *lzo_optimize_t)(lzo_bytep src, lzo_uint src_len, - lzo_bytep dst, lzo_uintp dst_len, - lzo_voidp wrkmem); - - typedef int - (__LZO_CDECL *lzo_compress_dict_t)(const lzo_bytep src, lzo_uint src_len, - lzo_bytep dst, lzo_uintp dst_len, - lzo_voidp wrkmem, - const lzo_bytep dict, lzo_uint dict_len); - - typedef int - (__LZO_CDECL *lzo_decompress_dict_t)(const lzo_bytep src, lzo_uint src_len, - lzo_bytep dst, lzo_uintp dst_len, - lzo_voidp wrkmem, - const lzo_bytep dict, lzo_uint dict_len); +/* function types */ +typedef int +(__LZO_CDECL *lzo_compress_t) ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +typedef int +(__LZO_CDECL *lzo_decompress_t) ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +typedef int +(__LZO_CDECL *lzo_optimize_t) ( lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +typedef int +(__LZO_CDECL *lzo_compress_dict_t)(const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem, + const lzo_bytep dict, lzo_uint dict_len ); + +typedef int +(__LZO_CDECL *lzo_decompress_dict_t)(const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem, + const lzo_bytep dict, lzo_uint dict_len ); - /* Callback interface. Currently only the progress indicator ("nprogress") - * is used, but this may change in a future release. */ +/* Callback interface. Currently only the progress indicator ("nprogress") + * is used, but this may change in a future release. */ - struct lzo_callback_t; - typedef struct lzo_callback_t lzo_callback_t; +struct lzo_callback_t; +typedef struct lzo_callback_t lzo_callback_t; #define lzo_callback_p lzo_callback_t __LZO_MMODEL * - /* malloc & free function types */ - typedef lzo_voidp(__LZO_CDECL *lzo_alloc_func_t) - (lzo_callback_p self, lzo_uint items, lzo_uint size); - typedef void (__LZO_CDECL *lzo_free_func_t) - (lzo_callback_p self, lzo_voidp ptr); - - /* a progress indicator callback function */ - typedef void (__LZO_CDECL *lzo_progress_func_t) - (lzo_callback_p, lzo_uint, lzo_uint, int); - - struct lzo_callback_t - { - /* custom allocators (set to 0 to disable) */ - lzo_alloc_func_t nalloc; /* [not used right now] */ - lzo_free_func_t nfree; /* [not used right now] */ - - /* a progress indicator callback function (set to 0 to disable) */ - lzo_progress_func_t nprogress; - - /* NOTE: the first parameter "self" of the nalloc/nfree/nprogress - * callbacks points back to this struct, so you are free to store - * some extra info in the following variables. */ - lzo_voidp user1; - lzo_xint user2; - lzo_xint user3; - }; - - - /*********************************************************************** - // error codes and prototypes - ************************************************************************/ - - /* Error codes for the compression/decompression functions. Negative - * values are errors, positive values will be used for special but - * normal events. - */ +/* malloc & free function types */ +typedef lzo_voidp (__LZO_CDECL *lzo_alloc_func_t) + (lzo_callback_p self, lzo_uint items, lzo_uint size); +typedef void (__LZO_CDECL *lzo_free_func_t) + (lzo_callback_p self, lzo_voidp ptr); + +/* a progress indicator callback function */ +typedef void (__LZO_CDECL *lzo_progress_func_t) + (lzo_callback_p, lzo_uint, lzo_uint, int); + +struct lzo_callback_t +{ + /* custom allocators (set to 0 to disable) */ + lzo_alloc_func_t nalloc; /* [not used right now] */ + lzo_free_func_t nfree; /* [not used right now] */ + + /* a progress indicator callback function (set to 0 to disable) */ + lzo_progress_func_t nprogress; + + /* INFO: the first parameter "self" of the nalloc/nfree/nprogress + * callbacks points back to this struct, so you are free to store + * some extra info in the following variables. */ + lzo_voidp user1; + lzo_xint user2; + lzo_xint user3; +}; + + +/*********************************************************************** +// error codes and prototypes +************************************************************************/ + +/* Error codes for the compression/decompression functions. Negative + * values are errors, positive values will be used for special but + * normal events. + */ #define LZO_E_OK 0 #define LZO_E_ERROR (-1) #define LZO_E_OUT_OF_MEMORY (-2) /* [lzo_alloc_func_t failure] */ @@ -344,79 +319,96 @@ #define LZO_E_INPUT_NOT_CONSUMED (-8) #define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */ #define LZO_E_INVALID_ARGUMENT (-10) +#define LZO_E_INVALID_ALIGNMENT (-11) /* pointer argument is not properly aligned */ +#define LZO_E_OUTPUT_NOT_CONSUMED (-12) +#define LZO_E_INTERNAL_ERROR (-99) #ifndef lzo_sizeof_dict_t # define lzo_sizeof_dict_t ((unsigned)sizeof(lzo_bytep)) #endif - /* lzo_init() should be the first function you call. - * Check the return code ! - * - * lzo_init() is a macro to allow checking that the library and the - * compiler's view of various types are consistent. - */ +/* lzo_init() should be the first function you call. + * Check the return code ! + * + * lzo_init() is a macro to allow checking that the library and the + * compiler's view of various types are consistent. + */ #define lzo_init() __lzo_init_v2(LZO_VERSION,(int)sizeof(short),(int)sizeof(int),\ - (int)sizeof(long),(int)sizeof(lzo_uint32),(int)sizeof(lzo_uint),\ - (int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\ - (int)sizeof(lzo_callback_t)) - LZO_EXTERN(int) __lzo_init_v2(unsigned, int, int, int, int, int, int, int, int, int); - - /* version functions (useful for shared libraries) */ - LZO_EXTERN(unsigned) lzo_version(void); - LZO_EXTERN(const char *) lzo_version_string(void); - LZO_EXTERN(const char *) lzo_version_date(void); - LZO_EXTERN(const lzo_charp) _lzo_version_string(void); - LZO_EXTERN(const lzo_charp) _lzo_version_date(void); - - /* string functions */ - LZO_EXTERN(int) - lzo_memcmp(const lzo_voidp a, const lzo_voidp b, lzo_uint len); - LZO_EXTERN(lzo_voidp) - lzo_memcpy(lzo_voidp dst, const lzo_voidp src, lzo_uint len); - LZO_EXTERN(lzo_voidp) - lzo_memmove(lzo_voidp dst, const lzo_voidp src, lzo_uint len); - LZO_EXTERN(lzo_voidp) - lzo_memset(lzo_voidp buf, int c, lzo_uint len); - - /* checksum functions */ - LZO_EXTERN(lzo_uint32) - lzo_adler32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len); - LZO_EXTERN(lzo_uint32) - lzo_crc32(lzo_uint32 c, const lzo_bytep buf, lzo_uint len); - LZO_EXTERN(const lzo_uint32p) - lzo_get_crc32_table(void); - - /* misc. */ - LZO_EXTERN(int) _lzo_config_check(void); - typedef union - { - lzo_bytep p; - lzo_uint u; - } __lzo_pu_u; - typedef union - { - lzo_bytep p; - lzo_uint32 u32; - } __lzo_pu32_u; - typedef union - { - void *vp; - lzo_bytep bp; - lzo_uint u; - lzo_uint32 u32; - unsigned long l; - } lzo_align_t; + (int)sizeof(long),(int)sizeof(lzo_uint32_t),(int)sizeof(lzo_uint),\ + (int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\ + (int)sizeof(lzo_callback_t)) +LZO_EXTERN(int) __lzo_init_v2(unsigned,int,int,int,int,int,int,int,int,int); + +/* version functions (useful for shared libraries) */ +LZO_EXTERN(unsigned) lzo_version(void); +LZO_EXTERN(const char *) lzo_version_string(void); +LZO_EXTERN(const char *) lzo_version_date(void); +LZO_EXTERN(const lzo_charp) _lzo_version_string(void); +LZO_EXTERN(const lzo_charp) _lzo_version_date(void); + +/* string functions */ +LZO_EXTERN(int) + lzo_memcmp(const lzo_voidp a, const lzo_voidp b, lzo_uint len); +LZO_EXTERN(lzo_voidp) + lzo_memcpy(lzo_voidp dst, const lzo_voidp src, lzo_uint len); +LZO_EXTERN(lzo_voidp) + lzo_memmove(lzo_voidp dst, const lzo_voidp src, lzo_uint len); +LZO_EXTERN(lzo_voidp) + lzo_memset(lzo_voidp buf, int c, lzo_uint len); + +/* checksum functions */ +LZO_EXTERN(lzo_uint32_t) + lzo_adler32(lzo_uint32_t c, const lzo_bytep buf, lzo_uint len); +LZO_EXTERN(lzo_uint32_t) + lzo_crc32(lzo_uint32_t c, const lzo_bytep buf, lzo_uint len); +LZO_EXTERN(const lzo_uint32_tp) + lzo_get_crc32_table(void); + +/* misc. */ +LZO_EXTERN(int) _lzo_config_check(void); +typedef union { + lzo_voidp a00; lzo_bytep a01; lzo_uint a02; lzo_xint a03; lzo_uintptr_t a04; + void *a05; unsigned char *a06; unsigned long a07; size_t a08; ptrdiff_t a09; +#if defined(lzo_int64_t) + lzo_uint64_t a10; +#endif +} lzo_align_t; - /* align a char pointer on a boundary that is a multiple of 'size' */ - LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size); +/* align a char pointer on a boundary that is a multiple of 'size' */ +LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size); #define LZO_PTR_ALIGN_UP(p,size) \ ((p) + (lzo_uint) __lzo_align_gap((const lzo_voidp)(p),(lzo_uint)(size))) - /*********************************************************************** - // deprecated macros - only for backward compatibility with LZO v1.xx - ************************************************************************/ +/*********************************************************************** +// deprecated macros - only for backward compatibility +************************************************************************/ + +/* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */ +#define lzo_byte unsigned char +/* deprecated type names */ +#define lzo_int32 lzo_int32_t +#define lzo_uint32 lzo_uint32_t +#define lzo_int32p lzo_int32_t __LZO_MMODEL * +#define lzo_uint32p lzo_uint32_t __LZO_MMODEL * +#define LZO_INT32_MAX LZO_INT32_C(2147483647) +#define LZO_UINT32_MAX LZO_UINT32_C(4294967295) +#if defined(lzo_int64_t) +#define lzo_int64 lzo_int64_t +#define lzo_uint64 lzo_uint64_t +#define lzo_int64p lzo_int64_t __LZO_MMODEL * +#define lzo_uint64p lzo_uint64_t __LZO_MMODEL * +#define LZO_INT64_MAX LZO_INT64_C(9223372036854775807) +#define LZO_UINT64_MAX LZO_UINT64_C(18446744073709551615) +#endif +/* deprecated types */ +typedef union { lzo_bytep a; lzo_uint b; } __lzo_pu_u; +typedef union { lzo_bytep a; lzo_uint32_t b; } __lzo_pu32_u; +/* deprecated defines */ +#if !defined(LZO_SIZEOF_LZO_UINT) +# define LZO_SIZEOF_LZO_UINT LZO_SIZEOF_LZO_INT +#endif #if defined(LZO_CFG_COMPAT) @@ -459,4 +451,4 @@ #endif /* already included */ -/* vim:set ts=4 et: */ +/* vim:set ts=4 sw=4 et: */ diff -Nru oscam-1.20-10584~r10356/minilzo/lzodefs.h oscam-1.20-10797~r10569/minilzo/lzodefs.h --- oscam-1.20-10584~r10356/minilzo/lzodefs.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/minilzo/lzodefs.h 2015-02-20 11:57:49.000000000 +0000 @@ -2,22 +2,7 @@ This file is part of the LZO real-time data compression library. - Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -47,12 +32,6 @@ #if defined(__CYGWIN32__) && !defined(__CYGWIN__) # define __CYGWIN__ __CYGWIN32__ #endif -#if defined(__IBMCPP__) && !defined(__IBMC__) -# define __IBMC__ __IBMCPP__ -#endif -#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) -# define __INTEL_COMPILER __ICL -#endif #if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) # define _ALL_SOURCE 1 #endif @@ -61,19 +40,30 @@ # define __LONG_MAX__ 9223372036854775807L # endif #endif -#if defined(__INTEL_COMPILER) && defined(__linux__) +#if !defined(LZO_CFG_NO_DISABLE_WUNDEF) +#if defined(__ARMCC_VERSION) +# pragma diag_suppress 193 +#elif defined(__clang__) && defined(__clang_minor__) +# pragma clang diagnostic ignored "-Wundef" +#elif defined(__INTEL_COMPILER) # pragma warning(disable: 193) -#endif -#if defined(__KEIL__) && defined(__C166__) -# pragma warning disable = 322 -#elif 0 && defined(__C251__) +#elif defined(__KEIL__) && defined(__C166__) # pragma warning disable = 322 -#endif -#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) -# if (_MSC_VER >= 1300) +#elif defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__PATHSCALE__) +# if ((__GNUC__-0) >= 5 || ((__GNUC__-0) == 4 && (__GNUC_MINOR__-0) >= 2)) +# pragma GCC diagnostic ignored "-Wundef" +# endif +#elif defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) +# if ((_MSC_VER-0) >= 1300) # pragma warning(disable: 4668) # endif #endif +#endif +#if 0 && defined(__POCC__) && defined(_WIN32) +# if (__POCC__ >= 400) +# pragma warn(disable: 2216) +# endif +#endif #if 0 && defined(__WATCOMC__) # if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) # pragma warning 203 9 @@ -82,13 +72,29 @@ #if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) # pragma option -h #endif +#if !(LZO_CFG_NO_DISABLE_WCRTNONSTDC) +#ifndef _CRT_NONSTDC_NO_DEPRECATE +#define _CRT_NONSTDC_NO_DEPRECATE 1 +#endif +#ifndef _CRT_NONSTDC_NO_WARNINGS +#define _CRT_NONSTDC_NO_WARNINGS 1 +#endif +#ifndef _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_DEPRECATE 1 +#endif +#ifndef _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_WARNINGS 1 +#endif +#endif #if 0 -#define LZO_0xffffL 0xfffful -#define LZO_0xffffffffL 0xfffffffful +#define LZO_0xffffUL 0xfffful +#define LZO_0xffffffffUL 0xfffffffful #else -#define LZO_0xffffL 65535ul -#define LZO_0xffffffffL 4294967295ul +#define LZO_0xffffUL 65535ul +#define LZO_0xffffffffUL 4294967295ul #endif +#define LZO_0xffffL LZO_0xffffUL +#define LZO_0xffffffffL LZO_0xffffffffUL #if (LZO_0xffffL == LZO_0xffffffffL) # error "your preprocessor is broken 1" #endif @@ -103,6 +109,13 @@ # error "your preprocessor is broken 4" #endif #endif +#if defined(__COUNTER__) +# ifndef LZO_CFG_USE_COUNTER +# define LZO_CFG_USE_COUNTER 1 +# endif +#else +# undef LZO_CFG_USE_COUNTER +#endif #if (UINT_MAX == LZO_0xffffL) #if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) # if !defined(MSDOS) @@ -233,14 +246,31 @@ #endif #define LZO_PP_STRINGIZE(x) #x #define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) +#define LZO_PP_CONCAT0() /*empty*/ +#define LZO_PP_CONCAT1(a) a #define LZO_PP_CONCAT2(a,b) a ## b #define LZO_PP_CONCAT3(a,b,c) a ## b ## c #define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d #define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_PP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f +#define LZO_PP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g +#define LZO_PP_ECONCAT0() LZO_PP_CONCAT0() +#define LZO_PP_ECONCAT1(a) LZO_PP_CONCAT1(a) #define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) #define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) #define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) #define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) +#define LZO_PP_ECONCAT6(a,b,c,d,e,f) LZO_PP_CONCAT6(a,b,c,d,e,f) +#define LZO_PP_ECONCAT7(a,b,c,d,e,f,g) LZO_PP_CONCAT7(a,b,c,d,e,f,g) +#define LZO_PP_EMPTY /*empty*/ +#define LZO_PP_EMPTY0() /*empty*/ +#define LZO_PP_EMPTY1(a) /*empty*/ +#define LZO_PP_EMPTY2(a,b) /*empty*/ +#define LZO_PP_EMPTY3(a,b,c) /*empty*/ +#define LZO_PP_EMPTY4(a,b,c,d) /*empty*/ +#define LZO_PP_EMPTY5(a,b,c,d,e) /*empty*/ +#define LZO_PP_EMPTY6(a,b,c,d,e,f) /*empty*/ +#define LZO_PP_EMPTY7(a,b,c,d,e,f,g) /*empty*/ #if 1 #define LZO_CPP_STRINGIZE(x) #x #define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) @@ -248,12 +278,16 @@ #define LZO_CPP_CONCAT3(a,b,c) a ## b ## c #define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d #define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_CPP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f +#define LZO_CPP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g #define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) #define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) #define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) #define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) +#define LZO_CPP_ECONCAT6(a,b,c,d,e,f) LZO_CPP_CONCAT6(a,b,c,d,e,f) +#define LZO_CPP_ECONCAT7(a,b,c,d,e,f,g) LZO_CPP_CONCAT7(a,b,c,d,e,f,g) #endif -#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) +#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-!!(b))) - (o)) << 1) + (o)*!!(b)) #if 1 && defined(__cplusplus) # if !defined(__STDC_CONSTANT_MACROS) # define __STDC_CONSTANT_MACROS 1 @@ -263,9 +297,13 @@ # endif #endif #if defined(__cplusplus) -# define LZO_EXTERN_C extern "C" -#else -# define LZO_EXTERN_C extern +# define LZO_EXTERN_C extern "C" +# define LZO_EXTERN_C_BEGIN extern "C" { +# define LZO_EXTERN_C_END } +#else +# define LZO_EXTERN_C extern +# define LZO_EXTERN_C_BEGIN /*empty*/ +# define LZO_EXTERN_C_END /*empty*/ #endif #if !defined(__LZO_OS_OVERRIDE) #if (LZO_OS_FREESTANDING) @@ -360,18 +398,18 @@ #elif defined(__TOS__) || defined(__atarist__) # define LZO_OS_TOS 1 # define LZO_INFO_OS "tos" -#elif defined(macintosh) && !defined(__ppc__) +#elif defined(macintosh) && !defined(__arm__) && !defined(__i386__) && !defined(__ppc__) && !defined(__x64_64__) # define LZO_OS_MACCLASSIC 1 # define LZO_INFO_OS "macclassic" #elif defined(__VMS) # define LZO_OS_VMS 1 # define LZO_INFO_OS "vms" -#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +#elif (defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__) # define LZO_OS_CONSOLE 1 # define LZO_OS_CONSOLE_PS2 1 # define LZO_INFO_OS "console" # define LZO_INFO_OS_CONSOLE "ps2" -#elif (defined(__mips__) && defined(__psp__)) +#elif defined(__mips__) && defined(__psp__) # define LZO_OS_CONSOLE 1 # define LZO_OS_CONSOLE_PSP 1 # define LZO_INFO_OS "console" @@ -399,9 +437,18 @@ # elif defined(__linux__) || defined(__linux) || defined(__LINUX__) # define LZO_OS_POSIX_LINUX 1 # define LZO_INFO_OS_POSIX "linux" -# elif defined(__APPLE__) || defined(__MACOS__) -# define LZO_OS_POSIX_MACOSX 1 -# define LZO_INFO_OS_POSIX "macosx" +# elif defined(__APPLE__) && defined(__MACH__) +# if ((__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__-0) >= 20000) +# define LZO_OS_POSIX_DARWIN 1040 +# define LZO_INFO_OS_POSIX "darwin_iphone" +# elif ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0) >= 1040) +# define LZO_OS_POSIX_DARWIN __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ +# define LZO_INFO_OS_POSIX "darwin" +# else +# define LZO_OS_POSIX_DARWIN 1 +# define LZO_INFO_OS_POSIX "darwin" +# endif +# define LZO_OS_POSIX_MACOSX LZO_OS_POSIX_DARWIN # elif defined(__minix__) || defined(__minix) # define LZO_OS_POSIX_MINIX 1 # define LZO_INFO_OS_POSIX "minix" @@ -436,18 +483,18 @@ #endif #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # if (UINT_MAX != LZO_0xffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif #endif #if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) # if (UINT_MAX != LZO_0xffffffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif #endif #if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) @@ -463,59 +510,65 @@ # define LZO_INFO_CC "sdcc" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) #elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) -# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) +# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + (__PATHCC_MINOR__-0) * 0x100 + (__PATHCC_PATCHLEVEL__-0)) # define LZO_INFO_CC "Pathscale C" # define LZO_INFO_CCVER __PATHSCALE__ -#elif defined(__INTEL_COMPILER) -# define LZO_CC_INTELC 1 +# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# define LZO_CC_PATHSCALE_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# endif +#elif defined(__INTEL_COMPILER) && ((__INTEL_COMPILER-0) > 0) +# define LZO_CC_INTELC __INTEL_COMPILER # define LZO_INFO_CC "Intel C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) -# if defined(_WIN32) || defined(_WIN64) -# define LZO_CC_SYNTAX_MSC 1 -# else -# define LZO_CC_SYNTAX_GNUC 1 +# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) +# define LZO_CC_INTELC_MSC _MSC_VER +# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# define LZO_CC_INTELC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) # endif #elif defined(__POCC__) && defined(_WIN32) # define LZO_CC_PELLESC 1 # define LZO_INFO_CC "Pelles C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) -#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +#elif defined(__ARMCC_VERSION) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # if defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) # else -# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) # endif +# define LZO_CC_ARMCC __ARMCC_VERSION +# define LZO_INFO_CC "ARM C Compiler" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__clang__) && defined(__llvm__) && defined(__VERSION__) # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) -# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) +# define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) # else -# define LZO_CC_CLANG_CLANG 0x010000L +# define LZO_CC_CLANG 0x010000L +# endif +# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) +# define LZO_CC_CLANG_MSC _MSC_VER +# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) # endif -# define LZO_CC_CLANG LZO_CC_CLANG_GNUC # define LZO_INFO_CC "clang" # define LZO_INFO_CCVER __VERSION__ #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # if defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) # else -# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) # endif # define LZO_CC_LLVM LZO_CC_LLVM_GNUC # define LZO_INFO_CC "llvm-gcc" # define LZO_INFO_CCVER __VERSION__ -#elif defined(__GNUC__) && defined(__VERSION__) -# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) -# elif defined(__GNUC_MINOR__) -# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) -# else -# define LZO_CC_GNUC (__GNUC__ * 0x10000L) -# endif -# define LZO_INFO_CC "gcc" -# define LZO_INFO_CCVER __VERSION__ #elif defined(__ACK__) && defined(_ACK) # define LZO_CC_ACK 1 # define LZO_INFO_CC "Amsterdam Compiler Kit C" # define LZO_INFO_CCVER "unknown" +#elif defined(__ARMCC_VERSION) && !defined(__GNUC__) +# define LZO_CC_ARMCC __ARMCC_VERSION +# define LZO_CC_ARMCC_ARMCC __ARMCC_VERSION +# define LZO_INFO_CC "ARM C Compiler" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ARMCC_VERSION) #elif defined(__AZTEC_C__) # define LZO_CC_AZTECC 1 # define LZO_INFO_CC "Aztec C" @@ -540,10 +593,23 @@ # define LZO_CC_DECC 1 # define LZO_INFO_CC "DEC C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) +#elif (defined(__ghs) || defined(__ghs__)) && defined(__GHS_VERSION_NUMBER) && ((__GHS_VERSION_NUMBER-0) > 0) +# define LZO_CC_GHS 1 +# define LZO_INFO_CC "Green Hills C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__GHS_VERSION_NUMBER) +# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) +# define LZO_CC_GHS_MSC _MSC_VER +# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# define LZO_CC_GHS_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# endif #elif defined(__HIGHC__) # define LZO_CC_HIGHC 1 # define LZO_INFO_CC "MetaWare High C" # define LZO_INFO_CCVER "unknown" +#elif defined(__HP_aCC) && ((__HP_aCC-0) > 0) +# define LZO_CC_HPACC __HP_aCC +# define LZO_INFO_CC "HP aCC" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__HP_aCC) #elif defined(__IAR_SYSTEMS_ICC__) # define LZO_CC_IARC 1 # define LZO_INFO_CC "IAR C" @@ -552,10 +618,14 @@ # else # define LZO_INFO_CCVER "unknown" # endif -#elif defined(__IBMC__) -# define LZO_CC_IBMC 1 +#elif defined(__IBMC__) && ((__IBMC__-0) > 0) +# define LZO_CC_IBMC __IBMC__ # define LZO_INFO_CC "IBM C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) +#elif defined(__IBMCPP__) && ((__IBMCPP__-0) > 0) +# define LZO_CC_IBMC __IBMCPP__ +# define LZO_INFO_CC "IBM C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMCPP__) #elif defined(__KEIL__) && defined(__C166__) # define LZO_CC_KEILC 1 # define LZO_INFO_CC "Keil C" @@ -572,16 +642,8 @@ # else # define LZO_INFO_CCVER "unknown" # endif -#elif defined(_MSC_VER) -# define LZO_CC_MSC 1 -# define LZO_INFO_CC "Microsoft C" -# if defined(_MSC_FULL_VER) -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) -# else -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) -# endif -#elif defined(__MWERKS__) -# define LZO_CC_MWERKS 1 +#elif defined(__MWERKS__) && ((__MWERKS__-0) > 0) +# define LZO_CC_MWERKS __MWERKS__ # define LZO_INFO_CC "Metrowerks C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) #elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) @@ -592,6 +654,15 @@ # define LZO_CC_PACIFICC 1 # define LZO_INFO_CC "Pacific C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) +#elif defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) +# if defined(__PGIC_PATCHLEVEL__) +# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100 + (__PGIC_PATCHLEVEL__-0)) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) "." LZO_PP_MACRO_EXPAND(__PGIC_PATCHLEVEL__) +# else +# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) ".0" +# endif +# define LZO_INFO_CC "Portland Group PGI C" #elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) # define LZO_CC_PGI 1 # define LZO_INFO_CC "Portland Group PGI C" @@ -606,7 +677,7 @@ # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) #elif defined(__SUNPRO_C) # define LZO_INFO_CC "SunPro C" -# if ((__SUNPRO_C)+0 > 0) +# if ((__SUNPRO_C-0) > 0) # define LZO_CC_SUNPROC __SUNPRO_C # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) # else @@ -615,7 +686,7 @@ # endif #elif defined(__SUNPRO_CC) # define LZO_INFO_CC "SunPro C" -# if ((__SUNPRO_CC)+0 > 0) +# if ((__SUNPRO_CC-0) > 0) # define LZO_CC_SUNPROC __SUNPRO_CC # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) # else @@ -641,16 +712,46 @@ #elif defined(__ZTC__) # define LZO_CC_ZORTECHC 1 # define LZO_INFO_CC "Zortech C" -# if (__ZTC__ == 0x310) +# if ((__ZTC__-0) == 0x310) # define LZO_INFO_CCVER "0x310" # else # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) # endif +#elif defined(__GNUC__) && defined(__VERSION__) +# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# elif defined(__GNUC_MINOR__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) +# else +# define LZO_CC_GNUC (__GNUC__ * 0x10000L) +# endif +# define LZO_INFO_CC "gcc" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(_MSC_VER) && ((_MSC_VER-0) > 0) +# define LZO_CC_MSC _MSC_VER +# define LZO_INFO_CC "Microsoft C" +# if defined(_MSC_FULL_VER) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) +# endif #else # define LZO_CC_UNKNOWN 1 # define LZO_INFO_CC "unknown" # define LZO_INFO_CCVER "unknown" #endif +#if (LZO_CC_GNUC) && defined(__OPEN64__) +# if defined(__OPENCC__) && defined(__OPENCC_MINOR__) && defined(__OPENCC_PATCHLEVEL__) +# define LZO_CC_OPEN64 (__OPENCC__ * 0x10000L + (__OPENCC_MINOR__-0) * 0x100 + (__OPENCC_PATCHLEVEL__-0)) +# define LZO_CC_OPEN64_GNUC LZO_CC_GNUC +# endif +#endif +#if (LZO_CC_GNUC) && defined(__PCC__) +# if defined(__PCC__) && defined(__PCC_MINOR__) && defined(__PCC_MINORMINOR__) +# define LZO_CC_PCC (__PCC__ * 0x10000L + (__PCC_MINOR__-0) * 0x100 + (__PCC_MINORMINOR__-0)) +# define LZO_CC_PCC_GNUC LZO_CC_GNUC +# endif +#endif #if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) # error "LZO_CC_MSC: _MSC_FULL_VER is not defined" #endif @@ -668,8 +769,10 @@ # define LZO_INFO_ARCH "generic" #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086 1 -# define LZO_ARCH_IA16 1 # define LZO_INFO_ARCH "i086" +#elif defined(__aarch64__) +# define LZO_ARCH_ARM64 1 +# define LZO_INFO_ARCH "arm64" #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) # define LZO_ARCH_ALPHA 1 # define LZO_INFO_ARCH "alpha" @@ -679,22 +782,11 @@ #elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64) # define LZO_ARCH_AMD64 1 # define LZO_INFO_ARCH "amd64" -#elif defined(__thumb__) || (defined(_M_ARM) && defined(_M_THUMB)) +#elif defined(__arm__) || defined(_M_ARM) # define LZO_ARCH_ARM 1 -# define LZO_ARCH_ARM_THUMB 1 -# define LZO_INFO_ARCH "arm_thumb" +# define LZO_INFO_ARCH "arm" #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) # define LZO_ARCH_ARM 1 -# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) -# define LZO_ARCH_ARM_THUMB 1 -# define LZO_INFO_ARCH "arm_thumb" -# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) -# define LZO_INFO_ARCH "arm" -# else -# define LZO_INFO_ARCH "arm" -# endif -#elif defined(__arm__) || defined(_M_ARM) -# define LZO_ARCH_ARM 1 # define LZO_INFO_ARCH "arm" #elif (UINT_MAX <= LZO_0xffffL) && defined(__AVR__) # define LZO_ARCH_AVR 1 @@ -802,57 +894,167 @@ # define LZO_INFO_ARCH "unknown" #endif #endif +#if !defined(LZO_ARCH_ARM_THUMB2) +#if (LZO_ARCH_ARM) +# if defined(__ARM_ARCH_ISA_THUMB) +# if ((__ARM_ARCH_ISA_THUMB)+0 >= 2) +# define LZO_ARCH_ARM_THUMB2 1 +# endif +# elif 1 && defined(__thumb2__) +# define LZO_ARCH_ARM_THUMB2 1 +# elif 1 && defined(__TARGET_ARCH_THUMB) && ((__TARGET_ARCH_THUMB)+0 >= 4) +# define LZO_ARCH_ARM_THUMB2 1 +# endif +#endif +#endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2) # error "FIXME - missing define for CPU architecture" #endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) -# error "FIXME - missing WIN32 define for CPU architecture" +# error "FIXME - missing LZO_OS_WIN32 define for CPU architecture" #endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) -# error "FIXME - missing WIN64 define for CPU architecture" +# error "FIXME - missing LZO_OS_WIN64 define for CPU architecture" #endif #if (LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086PM 1 -# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && defined(BLX286)) # define LZO_ARCH_I086PM 1 -# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) # define LZO_ARCH_I086PM 1 -# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) # define LZO_ARCH_I086PM 1 -# define LZO_ARCH_IA16PM 1 #endif -#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) -# error "this should not happen" +#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) +# define LZO_ARCH_X64 1 +#elif (!LZO_ARCH_AMD64 && LZO_ARCH_X64) && defined(__LZO_ARCH_OVERRIDE) +# define LZO_ARCH_AMD64 1 +#endif +#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) +# define LZO_ARCH_AARCH64 1 +#elif (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) && defined(__LZO_ARCH_OVERRIDE) +# define LZO_ARCH_ARM64 1 +#endif +#if (LZO_ARCH_I386 && !LZO_ARCH_X86) +# define LZO_ARCH_X86 1 +#elif (!LZO_ARCH_I386 && LZO_ARCH_X86) && defined(__LZO_ARCH_OVERRIDE) +# define LZO_ARCH_I386 1 +#endif +#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) || (!LZO_ARCH_AMD64 && LZO_ARCH_X64) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) || (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_I386 && !LZO_ARCH_X86) || (!LZO_ARCH_I386 && LZO_ARCH_X86) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_ARM_THUMB1 && !LZO_ARCH_ARM) +# error "unexpected configuration - check your compiler defines" #endif -#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) -# error "this should not happen" +#if (LZO_ARCH_ARM_THUMB2 && !LZO_ARCH_ARM) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_ARM_THUMB1 && LZO_ARCH_ARM_THUMB2) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_I086PM && !LZO_ARCH_I086) +# error "unexpected configuration - check your compiler defines" #endif #if (LZO_ARCH_I086) # if (UINT_MAX != LZO_0xffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif #endif #if (LZO_ARCH_I386) # if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif # if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" +# endif +#endif +#if (LZO_ARCH_AMD64 || LZO_ARCH_I386) +# if !defined(LZO_TARGET_FEATURE_SSE2) +# if defined(__SSE2__) +# define LZO_TARGET_FEATURE_SSE2 1 +# elif defined(_MSC_VER) && (defined(_M_IX86_FP) && ((_M_IX86_FP)+0 >= 2)) +# define LZO_TARGET_FEATURE_SSE2 1 +# elif (LZO_CC_INTELC_MSC || LZO_CC_MSC) && defined(_M_AMD64) +# define LZO_TARGET_FEATURE_SSE2 1 +# endif +# endif +# if !defined(LZO_TARGET_FEATURE_SSSE3) +# if (LZO_TARGET_FEATURE_SSE2) +# if defined(__SSSE3__) +# define LZO_TARGET_FEATURE_SSSE3 1 +# elif defined(_MSC_VER) && defined(__AVX__) +# define LZO_TARGET_FEATURE_SSSE3 1 +# endif +# endif +# endif +# if !defined(LZO_TARGET_FEATURE_SSE4_2) +# if (LZO_TARGET_FEATURE_SSSE3) +# if defined(__SSE4_2__) +# define LZO_TARGET_FEATURE_SSE4_2 1 +# endif +# endif +# endif +# if !defined(LZO_TARGET_FEATURE_AVX) +# if (LZO_TARGET_FEATURE_SSSE3) +# if defined(__AVX__) +# define LZO_TARGET_FEATURE_AVX 1 +# endif +# endif +# endif +# if !defined(LZO_TARGET_FEATURE_AVX2) +# if (LZO_TARGET_FEATURE_AVX) +# if defined(__AVX2__) +# define LZO_TARGET_FEATURE_AVX2 1 +# endif +# endif +# endif +#endif +#if (LZO_TARGET_FEATURE_SSSE3 && !(LZO_TARGET_FEATURE_SSE2)) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_TARGET_FEATURE_SSE4_2 && !(LZO_TARGET_FEATURE_SSSE3)) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_TARGET_FEATURE_AVX && !(LZO_TARGET_FEATURE_SSSE3)) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_TARGET_FEATURE_AVX2 && !(LZO_TARGET_FEATURE_AVX)) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_ARM) +# if !defined(LZO_TARGET_FEATURE_NEON) +# if defined(__ARM_NEON) && ((__ARM_NEON)+0) +# define LZO_TARGET_FEATURE_NEON 1 +# elif 1 && defined(__ARM_NEON__) && ((__ARM_NEON__)+0) +# define LZO_TARGET_FEATURE_NEON 1 +# elif 1 && defined(__TARGET_FEATURE_NEON) && ((__TARGET_FEATURE_NEON)+0) +# define LZO_TARGET_FEATURE_NEON 1 +# endif +# endif +#elif (LZO_ARCH_ARM64) +# if !defined(LZO_TARGET_FEATURE_NEON) +# if 1 +# define LZO_TARGET_FEATURE_NEON 1 +# endif # endif #endif -#if !defined(__LZO_MM_OVERRIDE) +#if 0 +#elif !defined(__LZO_MM_OVERRIDE) #if (LZO_ARCH_I086) #if (UINT_MAX != LZO_0xffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" #endif #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) # define LZO_MM_TINY 1 @@ -879,7 +1081,7 @@ #elif (LZO_CC_ZORTECHC && defined(__VCM__)) # define LZO_MM_LARGE 1 #else -# error "unknown memory model" +# error "unknown LZO_ARCH_I086 memory model" #endif #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) #define LZO_HAVE_MM_HUGE_PTR 1 @@ -902,31 +1104,31 @@ #endif #if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) # if (LZO_OS_DOS16) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # elif (LZO_CC_ZORTECHC) # else -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif #endif #ifdef __cplusplus extern "C" { #endif #if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200)) - extern void __near __cdecl _AHSHIFT(void); + extern void __near __cdecl _AHSHIFT(void); # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) #elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) - extern void __near __cdecl _AHSHIFT(void); + extern void __near __cdecl _AHSHIFT(void); # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) #elif (LZO_CC_MSC || LZO_CC_TOPSPEEDC) - extern void __near __cdecl _AHSHIFT(void); + extern void __near __cdecl _AHSHIFT(void); # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) #elif (LZO_CC_TURBOC && (__TURBOC__ >= 0x0295)) - extern void __near __cdecl _AHSHIFT(void); + extern void __near __cdecl _AHSHIFT(void); # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) #elif ((LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_TURBOC) && LZO_OS_DOS16) # define LZO_MM_AHSHIFT 12 #elif (LZO_CC_WATCOMC) - extern unsigned char _HShift; + extern unsigned char _HShift; # define LZO_MM_AHSHIFT ((unsigned) _HShift) #else # error "FIXME - implement LZO_MM_AHSHIFT" @@ -937,7 +1139,7 @@ #endif #elif (LZO_ARCH_C166) #if !defined(__MODEL__) -# error "FIXME - C166 __MODEL__" +# error "FIXME - LZO_ARCH_C166 __MODEL__" #elif ((__MODEL__) == 0) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 1) @@ -951,11 +1153,11 @@ #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - C166 __MODEL__" +# error "FIXME - LZO_ARCH_C166 __MODEL__" #endif #elif (LZO_ARCH_MCS251) #if !defined(__MODEL__) -# error "FIXME - MCS251 __MODEL__" +# error "FIXME - LZO_ARCH_MCS251 __MODEL__" #elif ((__MODEL__) == 0) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 2) @@ -967,11 +1169,11 @@ #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - MCS251 __MODEL__" +# error "FIXME - LZO_ARCH_MCS251 __MODEL__" #endif #elif (LZO_ARCH_MCS51) #if !defined(__MODEL__) -# error "FIXME - MCS51 __MODEL__" +# error "FIXME - LZO_ARCH_MCS51 __MODEL__" #elif ((__MODEL__) == 1) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 2) @@ -983,7 +1185,7 @@ #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - MCS51 __MODEL__" +# error "FIXME - LZO_ARCH_MCS51 __MODEL__" #endif #elif (LZO_ARCH_CRAY_PVP) # define LZO_MM_PVP 1 @@ -1010,462 +1212,312 @@ # error "unknown memory model" #endif #endif -#if defined(SIZEOF_SHORT) -# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) +#if !defined(__lzo_gnuc_extension__) +#if (LZO_CC_GNUC >= 0x020800ul) +# define __lzo_gnuc_extension__ __extension__ +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_gnuc_extension__ __extension__ +#elif (LZO_CC_IBMC >= 600) +# define __lzo_gnuc_extension__ __extension__ +#else #endif -#if defined(SIZEOF_INT) -# define LZO_SIZEOF_INT (SIZEOF_INT) #endif -#if defined(SIZEOF_LONG) -# define LZO_SIZEOF_LONG (SIZEOF_LONG) +#if !defined(__lzo_gnuc_extension__) +# define __lzo_gnuc_extension__ /*empty*/ #endif -#if defined(SIZEOF_LONG_LONG) -# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) +#if !defined(lzo_has_builtin) +#if (LZO_CC_CLANG) && defined(__has_builtin) +# define lzo_has_builtin __has_builtin #endif -#if defined(SIZEOF___INT16) -# define LZO_SIZEOF___INT16 (SIZEOF___INT16) #endif -#if defined(SIZEOF___INT32) -# define LZO_SIZEOF___INT32 (SIZEOF___INT32) +#if !defined(lzo_has_builtin) +# define lzo_has_builtin(x) 0 #endif -#if defined(SIZEOF___INT64) -# define LZO_SIZEOF___INT64 (SIZEOF___INT64) +#if !defined(lzo_has_attribute) +#if (LZO_CC_CLANG) && defined(__has_attribute) +# define lzo_has_attribute __has_attribute #endif -#if defined(SIZEOF_VOID_P) -# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) #endif -#if defined(SIZEOF_SIZE_T) -# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) +#if !defined(lzo_has_attribute) +# define lzo_has_attribute(x) 0 #endif -#if defined(SIZEOF_PTRDIFF_T) -# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) +#if !defined(lzo_has_declspec_attribute) +#if (LZO_CC_CLANG) && defined(__has_declspec_attribute) +# define lzo_has_declspec_attribute __has_declspec_attribute #endif -#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) -#if !defined(LZO_SIZEOF_SHORT) -# if (LZO_ARCH_CRAY_PVP) -# define LZO_SIZEOF_SHORT 8 -# elif (USHRT_MAX == LZO_0xffffL) -# define LZO_SIZEOF_SHORT 2 -# elif (__LZO_LSR(USHRT_MAX,7) == 1) -# define LZO_SIZEOF_SHORT 1 -# elif (__LZO_LSR(USHRT_MAX,15) == 1) -# define LZO_SIZEOF_SHORT 2 -# elif (__LZO_LSR(USHRT_MAX,31) == 1) -# define LZO_SIZEOF_SHORT 4 -# elif (__LZO_LSR(USHRT_MAX,63) == 1) -# define LZO_SIZEOF_SHORT 8 -# elif (__LZO_LSR(USHRT_MAX,127) == 1) -# define LZO_SIZEOF_SHORT 16 +#endif +#if !defined(lzo_has_declspec_attribute) +# define lzo_has_declspec_attribute(x) 0 +#endif +#if !defined(lzo_has_feature) +#if (LZO_CC_CLANG) && defined(__has_feature) +# define lzo_has_feature __has_feature +#endif +#endif +#if !defined(lzo_has_feature) +# define lzo_has_feature(x) 0 +#endif +#if !defined(lzo_has_extension) +#if (LZO_CC_CLANG) && defined(__has_extension) +# define lzo_has_extension __has_extension +#elif (LZO_CC_CLANG) && defined(__has_feature) +# define lzo_has_extension __has_feature +#endif +#endif +#if !defined(lzo_has_extension) +# define lzo_has_extension 0 +#endif +#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) && defined(__cplusplus) && 0 +# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) +# define LZO_CFG_USE_NEW_STYLE_CASTS 0 +# elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1200)) +# define LZO_CFG_USE_NEW_STYLE_CASTS 0 # else -# error "LZO_SIZEOF_SHORT" +# define LZO_CFG_USE_NEW_STYLE_CASTS 1 # endif #endif -#if !defined(LZO_SIZEOF_INT) -# if (LZO_ARCH_CRAY_PVP) -# define LZO_SIZEOF_INT 8 -# elif (UINT_MAX == LZO_0xffffL) -# define LZO_SIZEOF_INT 2 -# elif (UINT_MAX == LZO_0xffffffffL) -# define LZO_SIZEOF_INT 4 -# elif (__LZO_LSR(UINT_MAX,7) == 1) -# define LZO_SIZEOF_INT 1 -# elif (__LZO_LSR(UINT_MAX,15) == 1) -# define LZO_SIZEOF_INT 2 -# elif (__LZO_LSR(UINT_MAX,31) == 1) -# define LZO_SIZEOF_INT 4 -# elif (__LZO_LSR(UINT_MAX,63) == 1) -# define LZO_SIZEOF_INT 8 -# elif (__LZO_LSR(UINT_MAX,127) == 1) -# define LZO_SIZEOF_INT 16 -# else -# error "LZO_SIZEOF_INT" +#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_CFG_USE_NEW_STYLE_CASTS 0 +#endif +#if !defined(__cplusplus) +# if defined(LZO_CFG_USE_NEW_STYLE_CASTS) +# undef LZO_CFG_USE_NEW_STYLE_CASTS # endif +# define LZO_CFG_USE_NEW_STYLE_CASTS 0 #endif -#if !defined(LZO_SIZEOF_LONG) -# if (ULONG_MAX == LZO_0xffffffffL) -# define LZO_SIZEOF_LONG 4 -# elif (__LZO_LSR(ULONG_MAX,7) == 1) -# define LZO_SIZEOF_LONG 1 -# elif (__LZO_LSR(ULONG_MAX,15) == 1) -# define LZO_SIZEOF_LONG 2 -# elif (__LZO_LSR(ULONG_MAX,31) == 1) -# define LZO_SIZEOF_LONG 4 -# elif (__LZO_LSR(ULONG_MAX,63) == 1) -# define LZO_SIZEOF_LONG 8 -# elif (__LZO_LSR(ULONG_MAX,127) == 1) -# define LZO_SIZEOF_LONG 16 -# else -# error "LZO_SIZEOF_LONG" +#if !defined(LZO_REINTERPRET_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_REINTERPRET_CAST(t,e) (reinterpret_cast (e)) # endif #endif -#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) -# if (LZO_CC_GNUC >= 0x030300ul) -# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) -# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG -# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) -# define LZO_SIZEOF_LONG_LONG 4 -# endif -# endif +#if !defined(LZO_REINTERPRET_CAST) +# define LZO_REINTERPRET_CAST(t,e) ((t) (e)) +#endif +#if !defined(LZO_STATIC_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_STATIC_CAST(t,e) (static_cast (e)) # endif #endif +#if !defined(LZO_STATIC_CAST) +# define LZO_STATIC_CAST(t,e) ((t) (e)) #endif -#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -#if (LZO_ARCH_I086 && LZO_CC_DMC) -#elif (LZO_CC_CILLY) && defined(__GNUC__) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_SIZEOF_LONG_LONG 8 -#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_OS_WIN64 || defined(_WIN64)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) -# define LZO_SIZEOF___INT64 8 -#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) -#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -# define LZO_SIZEOF_LONG_LONG 8 +#if !defined(LZO_STATIC_CAST2) +# define LZO_STATIC_CAST2(t1,t2,e) LZO_STATIC_CAST(t1, LZO_STATIC_CAST(t2, e)) #endif +#if !defined(LZO_UNCONST_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_UNCONST_CAST(t,e) (const_cast (e)) +# elif (LZO_HAVE_MM_HUGE_PTR) +# define LZO_UNCONST_CAST(t,e) ((t) (e)) +# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((const void *) (e))))) +# endif #endif +#if !defined(LZO_UNCONST_CAST) +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((const void *) (e)))) #endif -#if defined(__cplusplus) && (LZO_CC_GNUC) -# if (LZO_CC_GNUC < 0x020800ul) -# undef LZO_SIZEOF_LONG_LONG +#if !defined(LZO_UNCONST_VOLATILE_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_UNCONST_VOLATILE_CAST(t,e) (const_cast (e)) +# elif (LZO_HAVE_MM_HUGE_PTR) +# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) (e)) +# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) # endif #endif -#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) -# undef LZO_SIZEOF_LONG_LONG +#if !defined(LZO_UNCONST_VOLATILE_CAST) +# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((volatile const void *) (e)))) #endif -#if !defined(LZO_SIZEOF_VOID_P) -#if (LZO_ARCH_I086) -# define __LZO_WORDSIZE 2 -# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) -# define LZO_SIZEOF_VOID_P 2 -# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) -# define LZO_SIZEOF_VOID_P 4 -# else -# error "LZO_MM" +#if !defined(LZO_UNVOLATILE_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_UNVOLATILE_CAST(t,e) (const_cast (e)) +# elif (LZO_HAVE_MM_HUGE_PTR) +# define LZO_UNVOLATILE_CAST(t,e) ((t) (e)) +# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((volatile void *) (e))))) # endif -#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) -# define __LZO_WORDSIZE 1 -# define LZO_SIZEOF_VOID_P 2 -#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) -# define LZO_SIZEOF_VOID_P 2 -#elif (LZO_ARCH_H8300) -# if defined(__NORMAL_MODE__) -# define __LZO_WORDSIZE 4 -# define LZO_SIZEOF_VOID_P 2 -# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -# define __LZO_WORDSIZE 4 -# define LZO_SIZEOF_VOID_P 4 -# else -# define __LZO_WORDSIZE 2 -# define LZO_SIZEOF_VOID_P 2 -# endif -# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT -# endif -#elif (LZO_ARCH_M16C) -# define __LZO_WORDSIZE 2 -# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) -# define LZO_SIZEOF_VOID_P 4 -# else -# define LZO_SIZEOF_VOID_P 2 -# endif -#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -# define __LZO_WORDSIZE 8 -# define LZO_SIZEOF_VOID_P 4 -#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) -# define __LZO_WORDSIZE 8 -# define LZO_SIZEOF_VOID_P 8 -#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) -# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -#elif (LZO_OS_OS400 || defined(__OS400__)) -# define __LZO_WORDSIZE LZO_SIZEOF_LONG -# define LZO_SIZEOF_VOID_P 16 -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -# define LZO_SIZEOF_VOID_P 8 -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -#elif (LZO_ARCH_SPU) -# if 0 -# define __LZO_WORDSIZE 16 -# endif -# define LZO_SIZEOF_VOID_P 4 -#else -# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG #endif +#if !defined(LZO_UNVOLATILE_CAST) +# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((volatile void *) (e)))) #endif -#if !defined(LZO_WORDSIZE) -# if defined(__LZO_WORDSIZE) -# define LZO_WORDSIZE __LZO_WORDSIZE -# else -# define LZO_WORDSIZE LZO_SIZEOF_VOID_P +#if !defined(LZO_UNVOLATILE_CONST_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_UNVOLATILE_CONST_CAST(t,e) (const_cast (e)) +# elif (LZO_HAVE_MM_HUGE_PTR) +# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) (e)) +# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) # endif #endif -#if !defined(LZO_SIZEOF_SIZE_T) -#if (LZO_ARCH_I086 || LZO_ARCH_M16C) -# define LZO_SIZEOF_SIZE_T 2 -#else -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P -#endif +#if !defined(LZO_UNVOLATILE_CONST_CAST) +# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((volatile const void *) (e)))) #endif -#if !defined(LZO_SIZEOF_PTRDIFF_T) -#if (LZO_ARCH_I086) -# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P -# elif (LZO_MM_COMPACT || LZO_MM_LARGE) -# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) -# define LZO_SIZEOF_PTRDIFF_T 4 -# else -# define LZO_SIZEOF_PTRDIFF_T 2 -# endif -# else -# error "LZO_MM" +#if !defined(LZO_PCAST) +# if (LZO_HAVE_MM_HUGE_PTR) +# define LZO_PCAST(t,e) ((t) (e)) # endif -#else -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T #endif +#if !defined(LZO_PCAST) +# define LZO_PCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(void *, e)) #endif -#if (LZO_ABI_NEUTRAL_ENDIAN) -# undef LZO_ABI_BIG_ENDIAN -# undef LZO_ABI_LITTLE_ENDIAN -#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) -#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) -# define LZO_ABI_BIG_ENDIAN 1 -#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) -# if (__LITTLE_ENDIAN__ == 1) -# define LZO_ABI_LITTLE_ENDIAN 1 -# else -# define LZO_ABI_BIG_ENDIAN 1 +#if !defined(LZO_CCAST) +# if (LZO_HAVE_MM_HUGE_PTR) +# define LZO_CCAST(t,e) ((t) (e)) # endif -#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) -# define LZO_ABI_LITTLE_ENDIAN 1 #endif +#if !defined(LZO_CCAST) +# define LZO_CCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(const void *, e)) #endif -#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) -# error "this should not happen" +#if !defined(LZO_ICONV) +# define LZO_ICONV(t,e) LZO_STATIC_CAST(t, e) #endif -#if (LZO_ABI_BIG_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "be" -#elif (LZO_ABI_LITTLE_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "le" -#elif (LZO_ABI_NEUTRAL_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "neutral" +#if !defined(LZO_ICAST) +# define LZO_ICAST(t,e) LZO_STATIC_CAST(t, e) #endif -#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -# define LZO_ABI_I8LP16 1 -# define LZO_INFO_ABI_PM "i8lp16" -#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -# define LZO_ABI_ILP16 1 -# define LZO_INFO_ABI_PM "ilp16" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) -# define LZO_ABI_ILP32 1 -# define LZO_INFO_ABI_PM "ilp32" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) -# define LZO_ABI_LLP64 1 -# define LZO_INFO_ABI_PM "llp64" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -# define LZO_ABI_LP64 1 -# define LZO_INFO_ABI_PM "lp64" -#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -# define LZO_ABI_ILP64 1 -# define LZO_INFO_ABI_PM "ilp64" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) -# define LZO_ABI_IP32L64 1 -# define LZO_INFO_ABI_PM "ip32l64" +#if !defined(LZO_ITRUNC) +# define LZO_ITRUNC(t,e) LZO_STATIC_CAST(t, e) #endif -#if !defined(__LZO_LIBC_OVERRIDE) -#if (LZO_LIBC_NAKED) -# define LZO_INFO_LIBC "naked" -#elif (LZO_LIBC_FREESTANDING) -# define LZO_INFO_LIBC "freestanding" -#elif (LZO_LIBC_MOSTLY_FREESTANDING) -# define LZO_INFO_LIBC "mfreestanding" -#elif (LZO_LIBC_ISOC90) -# define LZO_INFO_LIBC "isoc90" -#elif (LZO_LIBC_ISOC99) -# define LZO_INFO_LIBC "isoc99" -#elif defined(__dietlibc__) -# define LZO_LIBC_DIETLIBC 1 -# define LZO_INFO_LIBC "dietlibc" -#elif defined(_NEWLIB_VERSION) -# define LZO_LIBC_NEWLIB 1 -# define LZO_INFO_LIBC "newlib" -#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) -# if defined(__UCLIBC_SUBLEVEL__) -# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) -# else -# define LZO_LIBC_UCLIBC 0x00090bL +#if !defined(__lzo_cte) +# if (LZO_CC_MSC || LZO_CC_WATCOMC) +# define __lzo_cte(e) ((void)0,(e)) +# elif 1 +# define __lzo_cte(e) ((void)0,(e)) # endif -# define LZO_INFO_LIBC "uclibc" -#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) -# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) -# define LZO_INFO_LIBC "glibc" -#elif (LZO_CC_MWERKS) && defined(__MSL__) -# define LZO_LIBC_MSL __MSL__ -# define LZO_INFO_LIBC "msl" -#elif 1 && defined(__IAR_SYSTEMS_ICC__) -# define LZO_LIBC_ISOC90 1 -# define LZO_INFO_LIBC "isoc90" -#else -# define LZO_LIBC_DEFAULT 1 -# define LZO_INFO_LIBC "default" -#endif -#endif -#if !defined(__lzo_gnuc_extension__) -#if (LZO_CC_GNUC >= 0x020800ul) -# define __lzo_gnuc_extension__ __extension__ -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_gnuc_extension__ __extension__ -#else -# define __lzo_gnuc_extension__ /*empty*/ -#endif -#endif -#if !defined(__lzo_ua_volatile) -# define __lzo_ua_volatile volatile -#endif -#if !defined(__lzo_alignof) -#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -# define __lzo_alignof(e) __alignof__(e) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) -# define __lzo_alignof(e) __alignof__(e) -#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_alignof(e) __alignof(e) -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) -# define __lzo_alignof(e) __alignof__(e) -#endif -#endif -#if defined(__lzo_alignof) -# define __lzo_HAVE_alignof 1 #endif -#if !defined(__lzo_constructor) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_constructor __attribute__((__constructor__,__used__)) -#elif (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_constructor __attribute__((__constructor__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_constructor __attribute__((__constructor__)) +#if !defined(__lzo_cte) +# define __lzo_cte(e) (e) #endif +#if !defined(LZO_BLOCK_BEGIN) +# define LZO_BLOCK_BEGIN do { +# define LZO_BLOCK_END } while __lzo_cte(0) #endif -#if defined(__lzo_constructor) -# define __lzo_HAVE_constructor 1 -#endif -#if !defined(__lzo_destructor) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_destructor __attribute__((__destructor__,__used__)) -#elif (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_destructor __attribute__((__destructor__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_destructor __attribute__((__destructor__)) +#if !defined(LZO_UNUSED) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED(var) ((void) &var) +# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030200ul)) +# define LZO_UNUSED(var) ((void) &var) +# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNUSED(var) ((void) var) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_KEILC) +# define LZO_UNUSED(var) {extern int lzo_unused__[1-2*!(sizeof(var)>0)]; (void)lzo_unused__;} +# elif (LZO_CC_PACIFICC) +# define LZO_UNUSED(var) ((void) sizeof(var)) +# elif (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED(var) ((void) var) +# else +# define LZO_UNUSED(var) ((void) &var) +# endif #endif +#if !defined(LZO_UNUSED_FUNC) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED_FUNC(func) ((void) func) +# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_CLANG || LZO_CC_LLVM) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_MSC) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_KEILC || LZO_CC_PELLESC) +# define LZO_UNUSED_FUNC(func) {extern int lzo_unused__[1-2*!(sizeof((int)func)>0)]; (void)lzo_unused__;} +# else +# define LZO_UNUSED_FUNC(func) ((void) func) +# endif #endif -#if defined(__lzo_destructor) -# define __lzo_HAVE_destructor 1 +#if !defined(LZO_UNUSED_LABEL) +# if (LZO_CC_CLANG >= 0x020800ul) +# define LZO_UNUSED_LABEL(l) (__lzo_gnuc_extension__ ((void) ((const void *) &&l))) +# elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) +# define LZO_UNUSED_LABEL(l) if __lzo_cte(0) goto l +# else +# define LZO_UNUSED_LABEL(l) switch (0) case 1:goto l +# endif #endif -#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) -# error "this should not happen" +#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) +# if 0 +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var +# elif 0 && (LZO_CC_GNUC) +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var +# else +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init +# endif #endif #if !defined(__lzo_inline) #if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) #elif defined(__cplusplus) # define __lzo_inline inline +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) +# define __lzo_inline inline #elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) # define __lzo_inline __inline -#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) # define __lzo_inline __inline__ #elif (LZO_CC_DMC) # define __lzo_inline __inline +#elif (LZO_CC_GHS) +# define __lzo_inline __inline__ +#elif (LZO_CC_IBMC >= 600) +# define __lzo_inline __inline__ #elif (LZO_CC_INTELC) # define __lzo_inline __inline #elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) # define __lzo_inline __inline #elif (LZO_CC_MSC && (_MSC_VER >= 900)) # define __lzo_inline __inline -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +#elif (LZO_CC_SUNPROC >= 0x5100) # define __lzo_inline __inline__ -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -# define __lzo_inline inline #endif #endif #if defined(__lzo_inline) +# ifndef __lzo_HAVE_inline # define __lzo_HAVE_inline 1 +# endif #else # define __lzo_inline /*empty*/ #endif #if !defined(__lzo_forceinline) #if (LZO_CC_GNUC >= 0x030200ul) # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +#elif (LZO_CC_IBMC >= 700) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) # define __lzo_forceinline __forceinline -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) #elif (LZO_CC_MSC && (_MSC_VER >= 1200)) # define __lzo_forceinline __forceinline -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +#elif (LZO_CC_PGI >= 0x0d0a00ul) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_SUNPROC >= 0x5100) # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) #endif #endif #if defined(__lzo_forceinline) +# ifndef __lzo_HAVE_forceinline # define __lzo_HAVE_forceinline 1 +# endif #else -# define __lzo_forceinline /*empty*/ +# define __lzo_forceinline __lzo_inline #endif #if !defined(__lzo_noinline) #if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) # define __lzo_noinline __attribute__((__noinline__,__used__)) #elif (LZO_CC_GNUC >= 0x030200ul) # define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) +#elif (LZO_CC_IBMC >= 700) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) # define __lzo_noinline __declspec(noinline) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) # define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_noinline __attribute__((__noinline__)) #elif (LZO_CC_MSC && (_MSC_VER >= 1300)) # define __lzo_noinline __declspec(noinline) @@ -1474,305 +1526,1121 @@ # else # define __lzo_noinline __declspec(noinline) # endif -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +#elif (LZO_CC_PGI >= 0x0d0a00ul) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_SUNPROC >= 0x5100) # define __lzo_noinline __attribute__((__noinline__)) #endif #endif #if defined(__lzo_noinline) +# ifndef __lzo_HAVE_noinline # define __lzo_HAVE_noinline 1 +# endif #else # define __lzo_noinline /*empty*/ #endif #if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" #endif -#if !defined(__lzo_noreturn) -#if (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) -# define __lzo_noreturn __declspec(noreturn) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) -# define __lzo_noreturn __declspec(noreturn) +#if !defined(__lzo_static_inline) +#if (LZO_CC_IBMC) +# define __lzo_static_inline __lzo_gnuc_extension__ static __lzo_inline #endif #endif -#if defined(__lzo_noreturn) -# define __lzo_HAVE_noreturn 1 -#else -# define __lzo_noreturn /*empty*/ +#if !defined(__lzo_static_inline) +# define __lzo_static_inline static __lzo_inline #endif -#if !defined(__lzo_nothrow) -#if (LZO_CC_GNUC >= 0x030300ul) -# define __lzo_nothrow __attribute__((__nothrow__)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) +#if !defined(__lzo_static_forceinline) +#if (LZO_CC_IBMC) +# define __lzo_static_forceinline __lzo_gnuc_extension__ static __lzo_forceinline +#endif +#endif +#if !defined(__lzo_static_forceinline) +# define __lzo_static_forceinline static __lzo_forceinline +#endif +#if !defined(__lzo_static_noinline) +#if (LZO_CC_IBMC) +# define __lzo_static_noinline __lzo_gnuc_extension__ static __lzo_noinline +#endif +#endif +#if !defined(__lzo_static_noinline) +# define __lzo_static_noinline static __lzo_noinline +#endif +#if !defined(__lzo_c99_extern_inline) +#if defined(__GNUC_GNU_INLINE__) +# define __lzo_c99_extern_inline __lzo_inline +#elif defined(__GNUC_STDC_INLINE__) +# define __lzo_c99_extern_inline extern __lzo_inline +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) +# define __lzo_c99_extern_inline extern __lzo_inline +#endif +#if !defined(__lzo_c99_extern_inline) && (__lzo_HAVE_inline) +# define __lzo_c99_extern_inline __lzo_inline +#endif +#endif +#if defined(__lzo_c99_extern_inline) +# ifndef __lzo_HAVE_c99_extern_inline +# define __lzo_HAVE_c99_extern_inline 1 +# endif +#else +# define __lzo_c99_extern_inline /*empty*/ +#endif +#if !defined(__lzo_may_alias) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_may_alias __attribute__((__may_alias__)) +#elif (LZO_CC_CLANG >= 0x020900ul) +# define __lzo_may_alias __attribute__((__may_alias__)) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1210)) && 0 +# define __lzo_may_alias __attribute__((__may_alias__)) +#elif (LZO_CC_PGI >= 0x0d0a00ul) && 0 +# define __lzo_may_alias __attribute__((__may_alias__)) +#endif +#endif +#if defined(__lzo_may_alias) +# ifndef __lzo_HAVE_may_alias +# define __lzo_HAVE_may_alias 1 +# endif +#else +# define __lzo_may_alias /*empty*/ +#endif +#if !defined(__lzo_noreturn) +#if (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_IBMC >= 700) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) +# define __lzo_noreturn __declspec(noreturn) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_noreturn __declspec(noreturn) +#elif (LZO_CC_PGI >= 0x0d0a00ul) +# define __lzo_noreturn __attribute__((__noreturn__)) +#endif +#endif +#if defined(__lzo_noreturn) +# ifndef __lzo_HAVE_noreturn +# define __lzo_HAVE_noreturn 1 +# endif +#else +# define __lzo_noreturn /*empty*/ +#endif +#if !defined(__lzo_nothrow) +#if (LZO_CC_GNUC >= 0x030300ul) +# define __lzo_nothrow __attribute__((__nothrow__)) +#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) && defined(__cplusplus) # define __lzo_nothrow __declspec(nothrow) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 900)) # define __lzo_nothrow __attribute__((__nothrow__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_nothrow __attribute__((__nothrow__)) #elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) # define __lzo_nothrow __declspec(nothrow) #endif #endif #if defined(__lzo_nothrow) +# ifndef __lzo_HAVE_nothrow # define __lzo_HAVE_nothrow 1 +# endif #else # define __lzo_nothrow /*empty*/ #endif #if !defined(__lzo_restrict) #if (LZO_CC_GNUC >= 0x030400ul) # define __lzo_restrict __restrict__ -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +#elif (LZO_CC_IBMC >= 800) && !defined(__cplusplus) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_IBMC >= 1210) # define __lzo_restrict __restrict__ -#elif (LZO_CC_CLANG || LZO_CC_LLVM) +#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM) # define __lzo_restrict __restrict__ #elif (LZO_CC_MSC && (_MSC_VER >= 1400)) # define __lzo_restrict __restrict +#elif (LZO_CC_PGI >= 0x0d0a00ul) +# define __lzo_restrict __restrict__ #endif #endif #if defined(__lzo_restrict) +# ifndef __lzo_HAVE_restrict # define __lzo_HAVE_restrict 1 +# endif #else # define __lzo_restrict /*empty*/ #endif +#if !defined(__lzo_alignof) +#if (LZO_CC_ARMCC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_GHS) && !defined(__cplusplus) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_IBMC >= 600) +# define __lzo_alignof(e) (__lzo_gnuc_extension__ __alignof__(e)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_alignof(e) __alignof(e) +#elif (LZO_CC_SUNPROC >= 0x5100) +# define __lzo_alignof(e) __alignof__(e) +#endif +#endif +#if defined(__lzo_alignof) +# ifndef __lzo_HAVE_alignof +# define __lzo_HAVE_alignof 1 +# endif +#endif +#if !defined(__lzo_struct_packed) +#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) +#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) +#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) +#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) +#elif (LZO_CC_GNUC >= 0x030400ul) && !(LZO_CC_PCC_GNUC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) +# define __lzo_struct_packed(s) struct s { +# define __lzo_struct_packed_end() } __attribute__((__gcc_struct__,__packed__)); +# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__gcc_struct__,__packed__)); +#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_struct_packed(s) struct s { +# define __lzo_struct_packed_end() } __attribute__((__packed__)); +# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); +#elif (LZO_CC_IBMC >= 700) +# define __lzo_struct_packed(s) __lzo_gnuc_extension__ struct s { +# define __lzo_struct_packed_end() } __attribute__((__packed__)); +# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); +#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_struct_packed(s) __pragma(pack(push,1)) struct s { +# define __lzo_struct_packed_end() } __pragma(pack(pop)); +#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) +# define __lzo_struct_packed(s) _Packed struct s { +# define __lzo_struct_packed_end() }; +#endif +#endif +#if defined(__lzo_struct_packed) && !defined(__lzo_struct_packed_ma) +# define __lzo_struct_packed_ma(s) __lzo_struct_packed(s) +#endif +#if defined(__lzo_struct_packed_end) && !defined(__lzo_struct_packed_ma_end) +# define __lzo_struct_packed_ma_end() __lzo_struct_packed_end() +#endif +#if !defined(__lzo_byte_struct) +#if defined(__lzo_struct_packed) +# define __lzo_byte_struct(s,n) __lzo_struct_packed(s) unsigned char a[n]; __lzo_struct_packed_end() +# define __lzo_byte_struct_ma(s,n) __lzo_struct_packed_ma(s) unsigned char a[n]; __lzo_struct_packed_ma_end() +#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_PGI || (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_byte_struct(s,n) struct s { unsigned char a[n]; } __attribute__((__packed__)); +# define __lzo_byte_struct_ma(s,n) struct s { unsigned char a[n]; } __lzo_may_alias __attribute__((__packed__)); +#endif +#endif +#if defined(__lzo_byte_struct) && !defined(__lzo_byte_struct_ma) +# define __lzo_byte_struct_ma(s,n) __lzo_byte_struct(s,n) +#endif +#if !defined(__lzo_struct_align16) && (__lzo_HAVE_alignof) +#if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x030000ul)) +#elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) +#elif (LZO_CC_CILLY || LZO_CC_PCC) +#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_struct_align16(s) struct __declspec(align(16)) s { +# define __lzo_struct_align16_end() }; +# define __lzo_struct_align32(s) struct __declspec(align(32)) s { +# define __lzo_struct_align32_end() }; +# define __lzo_struct_align64(s) struct __declspec(align(64)) s { +# define __lzo_struct_align64_end() }; +#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || (LZO_CC_IBMC >= 700) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_struct_align16(s) struct s { +# define __lzo_struct_align16_end() } __attribute__((__aligned__(16))); +# define __lzo_struct_align32(s) struct s { +# define __lzo_struct_align32_end() } __attribute__((__aligned__(32))); +# define __lzo_struct_align64(s) struct s { +# define __lzo_struct_align64_end() } __attribute__((__aligned__(64))); +#endif +#endif +#if !defined(__lzo_union_um) +#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) +#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) +#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER < 810)) +#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) +#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_union_am(s) union s { +# define __lzo_union_am_end() } __lzo_may_alias; +# define __lzo_union_um(s) union s { +# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); +#elif (LZO_CC_IBMC >= 700) +# define __lzo_union_am(s) __lzo_gnuc_extension__ union s { +# define __lzo_union_am_end() } __lzo_may_alias; +# define __lzo_union_um(s) __lzo_gnuc_extension__ union s { +# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); +#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_union_um(s) __pragma(pack(push,1)) union s { +# define __lzo_union_um_end() } __pragma(pack(pop)); +#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) +# define __lzo_union_um(s) _Packed union s { +# define __lzo_union_um_end() }; +#endif +#endif +#if !defined(__lzo_union_am) +# define __lzo_union_am(s) union s { +# define __lzo_union_am_end() }; +#endif +#if !defined(__lzo_constructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_constructor __attribute__((__constructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_constructor __attribute__((__constructor__)) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) +# define __lzo_constructor __attribute__((__constructor__,__used__)) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_constructor __attribute__((__constructor__)) +#endif +#endif +#if defined(__lzo_constructor) +# ifndef __lzo_HAVE_constructor +# define __lzo_HAVE_constructor 1 +# endif +#endif +#if !defined(__lzo_destructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_destructor __attribute__((__destructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_destructor __attribute__((__destructor__)) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) +# define __lzo_destructor __attribute__((__destructor__,__used__)) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_destructor __attribute__((__destructor__)) +#endif +#endif +#if defined(__lzo_destructor) +# ifndef __lzo_HAVE_destructor +# define __lzo_HAVE_destructor 1 +# endif +#endif +#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) +# error "unexpected configuration - check your compiler defines" +#endif #if !defined(__lzo_likely) && !defined(__lzo_unlikely) #if (LZO_CC_GNUC >= 0x030200ul) # define __lzo_likely(e) (__builtin_expect(!!(e),1)) # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_IBMC >= 1010) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) # define __lzo_likely(e) (__builtin_expect(!!(e),1)) # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_likely(e) (__builtin_expect(!!(e),1)) # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) #endif #endif #if defined(__lzo_likely) +# ifndef __lzo_HAVE_likely # define __lzo_HAVE_likely 1 +# endif #else -# define __lzo_likely(e) (e) +# define __lzo_likely(e) (e) +#endif +#if defined(__lzo_very_likely) +# ifndef __lzo_HAVE_very_likely +# define __lzo_HAVE_very_likely 1 +# endif +#else +# define __lzo_very_likely(e) __lzo_likely(e) #endif #if defined(__lzo_unlikely) +# ifndef __lzo_HAVE_unlikely # define __lzo_HAVE_unlikely 1 +# endif #else -# define __lzo_unlikely(e) (e) +# define __lzo_unlikely(e) (e) #endif -#if !defined(LZO_UNUSED) -# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) -# define LZO_UNUSED(var) ((void) &var) -# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) -# define LZO_UNUSED(var) if (&var) ; else -# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNUSED(var) ((void) var) -# elif (LZO_CC_MSC && (_MSC_VER < 900)) -# define LZO_UNUSED(var) if (&var) ; else -# elif (LZO_CC_KEILC) -# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} -# elif (LZO_CC_PACIFICC) -# define LZO_UNUSED(var) ((void) sizeof(var)) -# elif (LZO_CC_WATCOMC) && defined(__cplusplus) -# define LZO_UNUSED(var) ((void) var) -# else -# define LZO_UNUSED(var) ((void) &var) +#if defined(__lzo_very_unlikely) +# ifndef __lzo_HAVE_very_unlikely +# define __lzo_HAVE_very_unlikely 1 # endif +#else +# define __lzo_very_unlikely(e) __lzo_unlikely(e) #endif -#if !defined(LZO_UNUSED_FUNC) -# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) -# define LZO_UNUSED_FUNC(func) ((void) func) -# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) -# define LZO_UNUSED_FUNC(func) if (func) ; else -# elif (LZO_CC_CLANG || LZO_CC_LLVM) -# define LZO_UNUSED_FUNC(func) ((void) &func) -# elif (LZO_CC_MSC && (_MSC_VER < 900)) -# define LZO_UNUSED_FUNC(func) if (func) ; else -# elif (LZO_CC_MSC) -# define LZO_UNUSED_FUNC(func) ((void) &func) -# elif (LZO_CC_KEILC || LZO_CC_PELLESC) -# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} +#if !defined(__lzo_loop_forever) +# if (LZO_CC_IBMC) +# define __lzo_loop_forever() LZO_BLOCK_BEGIN for (;;) { ; } LZO_BLOCK_END # else -# define LZO_UNUSED_FUNC(func) ((void) func) +# define __lzo_loop_forever() do { ; } while __lzo_cte(1) # endif #endif -#if !defined(LZO_UNUSED_LABEL) -# if (LZO_CC_WATCOMC) && defined(__cplusplus) -# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l -# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) -# define LZO_UNUSED_LABEL(l) if (0) goto l -# else -# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l -# endif +#if !defined(__lzo_unreachable) +#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x020800ul)) && lzo_has_builtin(__builtin_unreachable) +# define __lzo_unreachable() __builtin_unreachable(); +#elif (LZO_CC_GNUC >= 0x040500ul) +# define __lzo_unreachable() __builtin_unreachable(); +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1300)) && 1 +# define __lzo_unreachable() __builtin_unreachable(); #endif -#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) +#endif +#if defined(__lzo_unreachable) +# ifndef __lzo_HAVE_unreachable +# define __lzo_HAVE_unreachable 1 +# endif +#else # if 0 -# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var -# elif 0 && (LZO_CC_GNUC) -# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var +# define __lzo_unreachable() ((void)0); # else -# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init +# define __lzo_unreachable() __lzo_loop_forever(); # endif #endif -#if !defined(LZO_UNCONST_CAST) -# if 0 && defined(__cplusplus) -# define LZO_UNCONST_CAST(t,e) (const_cast (e)) -# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) +#if !defined(lzo_unused_funcs_impl) +# if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define lzo_unused_funcs_impl(r,f) static r __attribute__((__unused__)) f +# elif 1 && (LZO_CC_BORLANDC || LZO_CC_GNUC) +# define lzo_unused_funcs_impl(r,f) static r f # else -# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) +# define lzo_unused_funcs_impl(r,f) __lzo_static_forceinline r f # endif #endif +#ifndef __LZO_CTA_NAME +#if (LZO_CFG_USE_COUNTER) +# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__COUNTER__) +#else +# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__LINE__) +#endif +#endif #if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) # if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END # elif (LZO_CC_DMC || LZO_CC_SYMANTECC) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1u-2*!(e)]; LZO_EXTERN_C_END # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END +# elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020900ul)) && defined(__cplusplus) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN int __LZO_CTA_NAME(lzo_cta_f__)(int [1-2*!(e)]); LZO_EXTERN_C_END +# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__)); LZO_EXTERN_C_END # else -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-2*!(e)]; LZO_EXTERN_C_END # endif #endif #if !defined(LZO_COMPILE_TIME_ASSERT) # if (LZO_CC_AZTECC) -# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-!(e)];} +# elif (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030000ul)) +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)] __attribute__((__unused__));} # elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) +# define LZO_COMPILE_TIME_ASSERT(e) {(void) (0/!!(e));} +# elif (LZO_CC_GNUC >= 0x040700ul) && (LZO_CFG_USE_COUNTER) && defined(__cplusplus) +# define LZO_COMPILE_TIME_ASSERT(e) {enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__));} +# elif (LZO_CC_GNUC >= 0x040700ul) +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)] __attribute__((__unused__));} # elif (LZO_CC_MSC && (_MSC_VER < 900)) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; # else -# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)];} +# endif +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(1 == 1) +#if defined(__cplusplus) +extern "C" { LZO_COMPILE_TIME_ASSERT_HEADER(2 == 2) } +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) +#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) +# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) +# define __lzo_cdecl __cdecl +# define __lzo_cdecl_atexit /*empty*/ +# define __lzo_cdecl_main __cdecl +# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +# define __lzo_cdecl_qsort __pascal +# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +# define __lzo_cdecl_qsort _stdcall +# else +# define __lzo_cdecl_qsort __cdecl +# endif +# elif (LZO_CC_WATCOMC) +# define __lzo_cdecl __cdecl +# else +# define __lzo_cdecl __cdecl +# define __lzo_cdecl_atexit __cdecl +# define __lzo_cdecl_main __cdecl +# define __lzo_cdecl_qsort __cdecl +# endif +# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) +# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) +# define __lzo_cdecl_sighandler __pascal +# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) +# define __lzo_cdecl_sighandler _stdcall +# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) +# define __lzo_cdecl_sighandler __clrcall +# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) +# if defined(_DLL) +# define __lzo_cdecl_sighandler _far _cdecl _loadds +# elif defined(_MT) +# define __lzo_cdecl_sighandler _far _cdecl +# else +# define __lzo_cdecl_sighandler _cdecl +# endif +# else +# define __lzo_cdecl_sighandler __cdecl +# endif +#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) +# define __lzo_cdecl __cdecl +#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) +# define __lzo_cdecl cdecl +#endif +#if !defined(__lzo_cdecl) +# define __lzo_cdecl /*empty*/ +#endif +#if !defined(__lzo_cdecl_atexit) +# define __lzo_cdecl_atexit /*empty*/ +#endif +#if !defined(__lzo_cdecl_main) +# define __lzo_cdecl_main /*empty*/ +#endif +#if !defined(__lzo_cdecl_qsort) +# define __lzo_cdecl_qsort /*empty*/ +#endif +#if !defined(__lzo_cdecl_sighandler) +# define __lzo_cdecl_sighandler /*empty*/ +#endif +#if !defined(__lzo_cdecl_va) +# define __lzo_cdecl_va __lzo_cdecl +#endif +#if !(LZO_CFG_NO_WINDOWS_H) +#if !defined(LZO_HAVE_WINDOWS_H) +#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) +# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) +# elif ((LZO_OS_WIN32 && defined(__PW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x030000ul))) +# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) +# else +# define LZO_HAVE_WINDOWS_H 1 +# endif +#endif +#endif +#endif +#ifndef LZO_SIZEOF_SHORT +#if defined(SIZEOF_SHORT) +# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) +#elif defined(__SIZEOF_SHORT__) +# define LZO_SIZEOF_SHORT (__SIZEOF_SHORT__) +#endif +#endif +#ifndef LZO_SIZEOF_INT +#if defined(SIZEOF_INT) +# define LZO_SIZEOF_INT (SIZEOF_INT) +#elif defined(__SIZEOF_INT__) +# define LZO_SIZEOF_INT (__SIZEOF_INT__) +#endif +#endif +#ifndef LZO_SIZEOF_LONG +#if defined(SIZEOF_LONG) +# define LZO_SIZEOF_LONG (SIZEOF_LONG) +#elif defined(__SIZEOF_LONG__) +# define LZO_SIZEOF_LONG (__SIZEOF_LONG__) +#endif +#endif +#ifndef LZO_SIZEOF_LONG_LONG +#if defined(SIZEOF_LONG_LONG) +# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) +#elif defined(__SIZEOF_LONG_LONG__) +# define LZO_SIZEOF_LONG_LONG (__SIZEOF_LONG_LONG__) +#endif +#endif +#ifndef LZO_SIZEOF___INT16 +#if defined(SIZEOF___INT16) +# define LZO_SIZEOF___INT16 (SIZEOF___INT16) +#endif +#endif +#ifndef LZO_SIZEOF___INT32 +#if defined(SIZEOF___INT32) +# define LZO_SIZEOF___INT32 (SIZEOF___INT32) +#endif +#endif +#ifndef LZO_SIZEOF___INT64 +#if defined(SIZEOF___INT64) +# define LZO_SIZEOF___INT64 (SIZEOF___INT64) +#endif +#endif +#ifndef LZO_SIZEOF_VOID_P +#if defined(SIZEOF_VOID_P) +# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) +#elif defined(__SIZEOF_POINTER__) +# define LZO_SIZEOF_VOID_P (__SIZEOF_POINTER__) +#endif +#endif +#ifndef LZO_SIZEOF_SIZE_T +#if defined(SIZEOF_SIZE_T) +# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) +#elif defined(__SIZEOF_SIZE_T__) +# define LZO_SIZEOF_SIZE_T (__SIZEOF_SIZE_T__) +#endif +#endif +#ifndef LZO_SIZEOF_PTRDIFF_T +#if defined(SIZEOF_PTRDIFF_T) +# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) +#elif defined(__SIZEOF_PTRDIFF_T__) +# define LZO_SIZEOF_PTRDIFF_T (__SIZEOF_PTRDIFF_T__) +#endif +#endif +#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) +#if !defined(LZO_SIZEOF_SHORT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_SHORT 8 +# elif (USHRT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,7) == 1) +# define LZO_SIZEOF_SHORT 1 +# elif (__LZO_LSR(USHRT_MAX,15) == 1) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,31) == 1) +# define LZO_SIZEOF_SHORT 4 +# elif (__LZO_LSR(USHRT_MAX,63) == 1) +# define LZO_SIZEOF_SHORT 8 +# elif (__LZO_LSR(USHRT_MAX,127) == 1) +# define LZO_SIZEOF_SHORT 16 +# else +# error "LZO_SIZEOF_SHORT" +# endif +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SHORT == sizeof(short)) +#if !defined(LZO_SIZEOF_INT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_INT 8 +# elif (UINT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_INT 2 +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,7) == 1) +# define LZO_SIZEOF_INT 1 +# elif (__LZO_LSR(UINT_MAX,15) == 1) +# define LZO_SIZEOF_INT 2 +# elif (__LZO_LSR(UINT_MAX,31) == 1) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,63) == 1) +# define LZO_SIZEOF_INT 8 +# elif (__LZO_LSR(UINT_MAX,127) == 1) +# define LZO_SIZEOF_INT 16 +# else +# error "LZO_SIZEOF_INT" +# endif +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_INT == sizeof(int)) +#if !defined(LZO_SIZEOF_LONG) +# if (ULONG_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,7) == 1) +# define LZO_SIZEOF_LONG 1 +# elif (__LZO_LSR(ULONG_MAX,15) == 1) +# define LZO_SIZEOF_LONG 2 +# elif (__LZO_LSR(ULONG_MAX,31) == 1) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,39) == 1) +# define LZO_SIZEOF_LONG 5 +# elif (__LZO_LSR(ULONG_MAX,63) == 1) +# define LZO_SIZEOF_LONG 8 +# elif (__LZO_LSR(ULONG_MAX,127) == 1) +# define LZO_SIZEOF_LONG 16 +# else +# error "LZO_SIZEOF_LONG" +# endif +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_LONG == sizeof(long)) +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) +# if (LZO_CC_GNUC >= 0x030300ul) +# if ((__LONG_MAX__-0) == (__LONG_LONG_MAX__-0)) +# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG +# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) +# define LZO_SIZEOF_LONG_LONG 4 +# endif +# endif +# endif +#endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +#if (LZO_ARCH_I086 && LZO_CC_DMC) +#elif (LZO_CC_CILLY) && defined(__GNUC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_SIZEOF_LONG_LONG 8 +#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_OS_WIN64 || defined(_WIN64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_CC_GHS && defined(__LLONG_BIT) && ((__LLONG_BIT-0) == 64)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && ((_INTEGRAL_MAX_BITS-0) == 64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (defined(__vms) || defined(__VMS)) && ((__INITIAL_POINTER_SIZE-0) == 64) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) +#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define LZO_SIZEOF_LONG_LONG 8 +#endif +#endif +#endif +#if defined(__cplusplus) && (LZO_CC_GNUC) +# if (LZO_CC_GNUC < 0x020800ul) +# undef LZO_SIZEOF_LONG_LONG +# endif +#endif +#if (LZO_CFG_NO_LONG_LONG) +# undef LZO_SIZEOF_LONG_LONG +#elif defined(__NO_LONG_LONG) +# undef LZO_SIZEOF_LONG_LONG +#elif defined(_NO_LONGLONG) +# undef LZO_SIZEOF_LONG_LONG +#endif +#if !defined(LZO_WORDSIZE) +#if (LZO_ARCH_ALPHA) +# define LZO_WORDSIZE 8 +#elif (LZO_ARCH_AMD64) +# define LZO_WORDSIZE 8 +#elif (LZO_ARCH_AVR) +# define LZO_WORDSIZE 1 +#elif (LZO_ARCH_H8300) +# if defined(__NORMAL_MODE__) +# define LZO_WORDSIZE 4 +# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define LZO_WORDSIZE 4 +# else +# define LZO_WORDSIZE 2 +# endif +#elif (LZO_ARCH_I086) +# define LZO_WORDSIZE 2 +#elif (LZO_ARCH_IA64) +# define LZO_WORDSIZE 8 +#elif (LZO_ARCH_M16C) +# define LZO_WORDSIZE 2 +#elif (LZO_ARCH_SPU) +# define LZO_WORDSIZE 4 +#elif (LZO_ARCH_Z80) +# define LZO_WORDSIZE 1 +#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define LZO_WORDSIZE 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) +# define LZO_WORDSIZE 8 +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_WORDSIZE 8 +#endif +#endif +#if !defined(LZO_SIZEOF_VOID_P) +#if defined(__ILP32__) || defined(__ILP32) || defined(_ILP32) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) +# define LZO_SIZEOF_VOID_P 4 +#elif defined(__ILP64__) || defined(__ILP64) || defined(_ILP64) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 8) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) +# define LZO_SIZEOF_VOID_P 8 +#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) +# define LZO_SIZEOF_VOID_P 8 +#elif defined(__LP64__) || defined(__LP64) || defined(_LP64) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) +# define LZO_SIZEOF_VOID_P 8 +#elif (LZO_ARCH_AVR) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_H8300) +# if defined(__NORMAL_MODE__) +# define LZO_SIZEOF_VOID_P 2 +# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define LZO_SIZEOF_VOID_P 4 +# else +# define LZO_SIZEOF_VOID_P 2 +# endif +# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT +# endif +#elif (LZO_ARCH_I086) +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) +# define LZO_SIZEOF_VOID_P 2 +# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) +# define LZO_SIZEOF_VOID_P 4 +# else +# error "invalid LZO_ARCH_I086 memory model" +# endif +#elif (LZO_ARCH_M16C) +# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) +# define LZO_SIZEOF_VOID_P 4 +# else +# define LZO_SIZEOF_VOID_P 2 +# endif +#elif (LZO_ARCH_SPU) +# define LZO_SIZEOF_VOID_P 4 +#elif (LZO_ARCH_Z80) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define LZO_SIZEOF_VOID_P 4 +#elif (LZO_OS_OS400 || defined(__OS400__)) +# if defined(__LLP64_IFC__) +# define LZO_SIZEOF_VOID_P 8 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +# else +# define LZO_SIZEOF_VOID_P 16 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +# endif +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_VOID_P 8 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#endif +#endif +#if !defined(LZO_SIZEOF_VOID_P) +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_VOID_P == sizeof(void *)) +#if !defined(LZO_SIZEOF_SIZE_T) +#if (LZO_ARCH_I086 || LZO_ARCH_M16C) +# define LZO_SIZEOF_SIZE_T 2 +#endif +#endif +#if !defined(LZO_SIZEOF_SIZE_T) +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P +#endif +#if defined(offsetof) +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SIZE_T == sizeof(size_t)) +#endif +#if !defined(LZO_SIZEOF_PTRDIFF_T) +#if (LZO_ARCH_I086) +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P +# elif (LZO_MM_COMPACT || LZO_MM_LARGE) +# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) +# define LZO_SIZEOF_PTRDIFF_T 4 +# else +# define LZO_SIZEOF_PTRDIFF_T 2 +# endif +# else +# error "invalid LZO_ARCH_I086 memory model" # endif #endif -#if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) -# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) -# elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) -# define __lzo_cdecl __cdecl -# define __lzo_cdecl_atexit /*empty*/ -# define __lzo_cdecl_main __cdecl -# if (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) -# define __lzo_cdecl_qsort __pascal -# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) -# define __lzo_cdecl_qsort _stdcall -# else -# define __lzo_cdecl_qsort __cdecl -# endif -# elif (LZO_CC_WATCOMC) -# define __lzo_cdecl __cdecl +#endif +#if !defined(LZO_SIZEOF_PTRDIFF_T) +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T +#endif +#if defined(offsetof) +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) +#endif +#if !defined(LZO_WORDSIZE) +# define LZO_WORDSIZE LZO_SIZEOF_VOID_P +#endif +#if (LZO_ABI_NEUTRAL_ENDIAN) +# undef LZO_ABI_BIG_ENDIAN +# undef LZO_ABI_LITTLE_ENDIAN +#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) +#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) +# define LZO_ABI_BIG_ENDIAN 1 +#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390 || LZO_ARCH_SPU) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) +# if (__LITTLE_ENDIAN__ == 1) +# define LZO_ABI_LITTLE_ENDIAN 1 # else -# define __lzo_cdecl __cdecl -# define __lzo_cdecl_atexit __cdecl -# define __lzo_cdecl_main __cdecl -# define __lzo_cdecl_qsort __cdecl +# define LZO_ABI_BIG_ENDIAN 1 # endif -# if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC || LZO_CC_WATCOMC) -# elif (LZO_OS_OS2 && (LZO_CC_DMC || LZO_CC_SYMANTECC)) -# define __lzo_cdecl_sighandler __pascal -# elif (LZO_OS_OS2 && (LZO_CC_ZORTECHC)) -# define __lzo_cdecl_sighandler _stdcall -# elif (LZO_CC_MSC && (_MSC_VER >= 1400)) && defined(_M_CEE_PURE) -# define __lzo_cdecl_sighandler __clrcall -# elif (LZO_CC_MSC && (_MSC_VER >= 600 && _MSC_VER < 700)) -# if defined(_DLL) -# define __lzo_cdecl_sighandler _far _cdecl _loadds -# elif defined(_MT) -# define __lzo_cdecl_sighandler _far _cdecl -# else -# define __lzo_cdecl_sighandler _cdecl -# endif +#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARM_BIG_ENDIAN) && ((__ARM_BIG_ENDIAN)+0) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM && LZO_CC_ARMCC_ARMCC) +# if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) +# error "unexpected configuration - check your compiler defines" +# elif defined(__BIG_ENDIAN) +# define LZO_ABI_BIG_ENDIAN 1 # else -# define __lzo_cdecl_sighandler __cdecl +# define LZO_ABI_LITTLE_ENDIAN 1 # endif -#elif (LZO_ARCH_I386) && (LZO_CC_WATCOMC) -# define __lzo_cdecl __cdecl -#elif (LZO_ARCH_M68K && LZO_OS_TOS && (LZO_CC_PUREC || LZO_CC_TURBOC)) -# define __lzo_cdecl cdecl -#endif -#if !defined(__lzo_cdecl) -# define __lzo_cdecl /*empty*/ -#endif -#if !defined(__lzo_cdecl_atexit) -# define __lzo_cdecl_atexit /*empty*/ +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM64) && defined(__ARM_BIG_ENDIAN) && ((__ARM_BIG_ENDIAN)+0) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EB__) && !defined(__AARCH64EL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EL__) && !defined(__AARCH64EB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 #endif -#if !defined(__lzo_cdecl_main) -# define __lzo_cdecl_main /*empty*/ #endif -#if !defined(__lzo_cdecl_qsort) -# define __lzo_cdecl_qsort /*empty*/ +#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) +# error "unexpected configuration - check your compiler defines" #endif -#if !defined(__lzo_cdecl_sighandler) -# define __lzo_cdecl_sighandler /*empty*/ +#if (LZO_ABI_BIG_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "be" +#elif (LZO_ABI_LITTLE_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "le" +#elif (LZO_ABI_NEUTRAL_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "neutral" #endif -#if !defined(__lzo_cdecl_va) -# define __lzo_cdecl_va __lzo_cdecl +#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_I8LP16 1 +# define LZO_INFO_ABI_PM "i8lp16" +#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_ILP16 1 +# define LZO_INFO_ABI_PM "ilp16" +#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_LP32 1 +# define LZO_INFO_ABI_PM "lp32" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_ILP32 1 +# define LZO_INFO_ABI_PM "ilp32" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) +# define LZO_ABI_LLP64 1 +# define LZO_INFO_ABI_PM "llp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_LP64 1 +# define LZO_INFO_ABI_PM "lp64" +#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_ILP64 1 +# define LZO_INFO_ABI_PM "ilp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_IP32L64 1 +# define LZO_INFO_ABI_PM "ip32l64" #endif -#if !(LZO_CFG_NO_WINDOWS_H) -#if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) -# if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) -# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) -# elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) +#if 0 +#elif !defined(__LZO_LIBC_OVERRIDE) +#if (LZO_LIBC_NAKED) +# define LZO_INFO_LIBC "naked" +#elif (LZO_LIBC_FREESTANDING) +# define LZO_INFO_LIBC "freestanding" +#elif (LZO_LIBC_MOSTLY_FREESTANDING) +# define LZO_INFO_LIBC "mfreestanding" +#elif (LZO_LIBC_ISOC90) +# define LZO_INFO_LIBC "isoc90" +#elif (LZO_LIBC_ISOC99) +# define LZO_INFO_LIBC "isoc99" +#elif (LZO_CC_ARMCC_ARMCC) && defined(__ARMCLIB_VERSION) +# define LZO_LIBC_ISOC90 1 +# define LZO_INFO_LIBC "isoc90" +#elif defined(__dietlibc__) +# define LZO_LIBC_DIETLIBC 1 +# define LZO_INFO_LIBC "dietlibc" +#elif defined(_NEWLIB_VERSION) +# define LZO_LIBC_NEWLIB 1 +# define LZO_INFO_LIBC "newlib" +#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) +# if defined(__UCLIBC_SUBLEVEL__) +# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + (__UCLIBC_MINOR__-0) * 0x100 + (__UCLIBC_SUBLEVEL__-0)) # else -# define LZO_HAVE_WINDOWS_H 1 +# define LZO_LIBC_UCLIBC 0x00090bL # endif +# define LZO_INFO_LIBC "uc" "libc" +#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) +# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + (__GLIBC_MINOR__-0) * 0x100) +# define LZO_INFO_LIBC "glibc" +#elif (LZO_CC_MWERKS) && defined(__MSL__) +# define LZO_LIBC_MSL __MSL__ +# define LZO_INFO_LIBC "msl" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_LIBC_ISOC90 1 +# define LZO_INFO_LIBC "isoc90" +#else +# define LZO_LIBC_DEFAULT 1 +# define LZO_INFO_LIBC "default" +#endif +#endif +#if (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +# define LZO_ASM_SYNTAX_MSC 1 +#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) +#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#elif (LZO_CC_GNUC) +# define LZO_ASM_SYNTAX_GNUC 1 +#endif +#if (LZO_ASM_SYNTAX_GNUC) +#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) +# define __LZO_ASM_CLOBBER "ax" +# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ +# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY /*empty*/ +# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ +#elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1000)) +# define __LZO_ASM_CLOBBER "memory" +# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ +# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "memory" +# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ +#else +# define __LZO_ASM_CLOBBER "cc", "memory" +# define __LZO_ASM_CLOBBER_LIST_CC : "cc" +# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "cc", "memory" +# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ #endif #endif #if (LZO_ARCH_ALPHA) -# define LZO_OPT_AVOID_UINT_INDEX 1 -# define LZO_OPT_AVOID_SHORT 1 -# define LZO_OPT_AVOID_USHORT 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 #elif (LZO_ARCH_AMD64) -# define LZO_OPT_AVOID_INT_INDEX 1 -# define LZO_OPT_AVOID_UINT_INDEX 1 -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 -# define LZO_OPT_UNALIGNED64 1 -#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# ifndef LZO_OPT_UNALIGNED64 +# define LZO_OPT_UNALIGNED64 1 +# endif #elif (LZO_ARCH_ARM) -# define LZO_OPT_AVOID_SHORT 1 -# define LZO_OPT_AVOID_USHORT 1 +# if defined(__ARM_FEATURE_UNALIGNED) +# if ((__ARM_FEATURE_UNALIGNED)+0) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# endif +# elif 1 && (LZO_ARCH_ARM_THUMB2) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# elif 1 && defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM)+0 >= 7) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# elif 1 && defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM)+0 >= 6) && (defined(__TARGET_PROFILE_A) || defined(__TARGET_PROFILE_R)) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# endif +#elif (LZO_ARCH_ARM64) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# ifndef LZO_OPT_UNALIGNED64 +# define LZO_OPT_UNALIGNED64 1 +# endif #elif (LZO_ARCH_CRIS) -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif #elif (LZO_ARCH_I386) -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif #elif (LZO_ARCH_IA64) -# define LZO_OPT_AVOID_INT_INDEX 1 -# define LZO_OPT_AVOID_UINT_INDEX 1 -# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_PREFER_POSTINC 1 #elif (LZO_ARCH_M68K) -# define LZO_OPT_PREFER_POSTINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 # if defined(__mc68020__) && !defined(__mcoldfire__) -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif # endif #elif (LZO_ARCH_MIPS) -# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 #elif (LZO_ARCH_POWERPC) -# define LZO_OPT_PREFER_PREINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_PREINC 1 +# define LZO_OPT_PREFER_PREDEC 1 # if (LZO_ABI_BIG_ENDIAN) -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# if (LZO_WORDSIZE == 8) +# ifndef LZO_OPT_UNALIGNED64 +# define LZO_OPT_UNALIGNED64 1 +# endif +# endif # endif #elif (LZO_ARCH_S390) -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 -# if (LZO_SIZEOF_SIZE_T == 8) -# define LZO_OPT_UNALIGNED64 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# if (LZO_WORDSIZE == 8) +# ifndef LZO_OPT_UNALIGNED64 +# define LZO_OPT_UNALIGNED64 1 +# endif # endif #elif (LZO_ARCH_SH) -# define LZO_OPT_PREFER_POSTINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 #endif #ifndef LZO_CFG_NO_INLINE_ASM -#if (LZO_CC_LLVM) +#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) # define LZO_CFG_NO_INLINE_ASM 1 +#elif (LZO_CC_LLVM) +# define LZO_CFG_NO_INLINE_ASM 1 +#endif #endif +#if (LZO_CFG_NO_INLINE_ASM) +# undef LZO_ASM_SYNTAX_MSC +# undef LZO_ASM_SYNTAX_GNUC +# undef __LZO_ASM_CLOBBER +# undef __LZO_ASM_CLOBBER_LIST_CC +# undef __LZO_ASM_CLOBBER_LIST_CC_MEMORY +# undef __LZO_ASM_CLOBBER_LIST_EMPTY #endif #ifndef LZO_CFG_NO_UNALIGNED #if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) @@ -1784,25 +2652,6 @@ # undef LZO_OPT_UNALIGNED32 # undef LZO_OPT_UNALIGNED64 #endif -#if (LZO_CFG_NO_INLINE_ASM) -#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -# define LZO_ASM_SYNTAX_MSC 1 -#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) -#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -# define LZO_ASM_SYNTAX_GNUC 1 -#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -# define LZO_ASM_SYNTAX_GNUC 1 -#endif -#if (LZO_ASM_SYNTAX_GNUC) -#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) -# define __LZO_ASM_CLOBBER "ax" -#elif (LZO_CC_INTELC) -# define __LZO_ASM_CLOBBER "memory" -#else -# define __LZO_ASM_CLOBBER "cc", "memory" -#endif -#endif #if defined(__LZO_INFOSTR_MM) #elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) # define __LZO_INFOSTR_MM "" @@ -1846,7 +2695,440 @@ #define LZO_INFO_STRING \ LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER +#if !(LZO_CFG_SKIP_LZO_TYPES) +#if (!(LZO_SIZEOF_SHORT+0 > 0 && LZO_SIZEOF_INT+0 > 0 && LZO_SIZEOF_LONG+0 > 0)) +# error "missing defines for sizes" +#endif +#if (!(LZO_SIZEOF_PTRDIFF_T+0 > 0 && LZO_SIZEOF_SIZE_T+0 > 0 && LZO_SIZEOF_VOID_P+0 > 0)) +# error "missing defines for sizes" +#endif +#define LZO_TYPEOF_CHAR 1u +#define LZO_TYPEOF_SHORT 2u +#define LZO_TYPEOF_INT 3u +#define LZO_TYPEOF_LONG 4u +#define LZO_TYPEOF_LONG_LONG 5u +#define LZO_TYPEOF___INT8 17u +#define LZO_TYPEOF___INT16 18u +#define LZO_TYPEOF___INT32 19u +#define LZO_TYPEOF___INT64 20u +#define LZO_TYPEOF___INT128 21u +#define LZO_TYPEOF___INT256 22u +#define LZO_TYPEOF___MODE_QI 33u +#define LZO_TYPEOF___MODE_HI 34u +#define LZO_TYPEOF___MODE_SI 35u +#define LZO_TYPEOF___MODE_DI 36u +#define LZO_TYPEOF___MODE_TI 37u +#define LZO_TYPEOF_CHAR_P 129u +#if !defined(lzo_llong_t) +#if (LZO_SIZEOF_LONG_LONG+0 > 0) +__lzo_gnuc_extension__ typedef long long lzo_llong_t__; +__lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; +# define lzo_llong_t lzo_llong_t__ +# define lzo_ullong_t lzo_ullong_t__ +#endif +#endif +#if !defined(lzo_int16e_t) +#if (LZO_SIZEOF_LONG == 2) +# define lzo_int16e_t long +# define lzo_uint16e_t unsigned long +# define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_LONG +#elif (LZO_SIZEOF_INT == 2) +# define lzo_int16e_t int +# define lzo_uint16e_t unsigned int +# define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_INT +#elif (LZO_SIZEOF_SHORT == 2) +# define lzo_int16e_t short int +# define lzo_uint16e_t unsigned short int +# define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_SHORT +#elif 1 && !(LZO_CFG_TYPE_NO_MODE_HI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) + typedef int lzo_int16e_hi_t__ __attribute__((__mode__(__HI__))); + typedef unsigned int lzo_uint16e_hi_t__ __attribute__((__mode__(__HI__))); +# define lzo_int16e_t lzo_int16e_hi_t__ +# define lzo_uint16e_t lzo_uint16e_hi_t__ +# define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF___MODE_HI +#elif (LZO_SIZEOF___INT16 == 2) +# define lzo_int16e_t __int16 +# define lzo_uint16e_t unsigned __int16 +# define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF___INT16 +#else +#endif +#endif +#if defined(lzo_int16e_t) +# define LZO_SIZEOF_LZO_INT16E_T 2 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == 2) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == LZO_SIZEOF_LZO_INT16E_T) +#endif +#if !defined(lzo_int32e_t) +#if (LZO_SIZEOF_LONG == 4) +# define lzo_int32e_t long int +# define lzo_uint32e_t unsigned long int +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_LONG +#elif (LZO_SIZEOF_INT == 4) +# define lzo_int32e_t int +# define lzo_uint32e_t unsigned int +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_INT +#elif (LZO_SIZEOF_SHORT == 4) +# define lzo_int32e_t short int +# define lzo_uint32e_t unsigned short int +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_SHORT +#elif (LZO_SIZEOF_LONG_LONG == 4) +# define lzo_int32e_t lzo_llong_t +# define lzo_uint32e_t lzo_ullong_t +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_LONG_LONG +#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) && (__INT_MAX__+0 > 2147483647L) + typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); + typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); +# define lzo_int32e_t lzo_int32e_si_t__ +# define lzo_uint32e_t lzo_uint32e_si_t__ +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF___MODE_SI +#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_GNUC >= 0x025f00ul) && defined(__AVR__) && (__LONG_MAX__+0 == 32767L) + typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); + typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); +# define lzo_int32e_t lzo_int32e_si_t__ +# define lzo_uint32e_t lzo_uint32e_si_t__ +# define LZO_INT32_C(c) (c##LL) +# define LZO_UINT32_C(c) (c##ULL) +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF___MODE_SI +#elif (LZO_SIZEOF___INT32 == 4) +# define lzo_int32e_t __int32 +# define lzo_uint32e_t unsigned __int32 +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF___INT32 +#else +#endif +#endif +#if defined(lzo_int32e_t) +# define LZO_SIZEOF_LZO_INT32E_T 4 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == 4) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == LZO_SIZEOF_LZO_INT32E_T) +#endif +#if !defined(lzo_int64e_t) +#if (LZO_SIZEOF___INT64 == 8) +# if (LZO_CC_BORLANDC) && !(LZO_CFG_TYPE_PREFER___INT64) +# define LZO_CFG_TYPE_PREFER___INT64 1 +# endif +#endif +#if (LZO_SIZEOF_INT == 8) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) +# define lzo_int64e_t int +# define lzo_uint64e_t unsigned int +# define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_INT +#elif (LZO_SIZEOF_LONG == 8) +# define lzo_int64e_t long int +# define lzo_uint64e_t unsigned long int +# define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_LONG +#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_TYPE_PREFER___INT64) +# define lzo_int64e_t lzo_llong_t +# define lzo_uint64e_t lzo_ullong_t +# define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_LONG_LONG +# if (LZO_CC_BORLANDC) +# define LZO_INT64_C(c) ((c) + 0ll) +# define LZO_UINT64_C(c) ((c) + 0ull) +# elif 0 +# define LZO_INT64_C(c) (__lzo_gnuc_extension__ (c##LL)) +# define LZO_UINT64_C(c) (__lzo_gnuc_extension__ (c##ULL)) +# else +# define LZO_INT64_C(c) (c##LL) +# define LZO_UINT64_C(c) (c##ULL) +# endif +#elif (LZO_SIZEOF___INT64 == 8) +# define lzo_int64e_t __int64 +# define lzo_uint64e_t unsigned __int64 +# define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF___INT64 +# if (LZO_CC_BORLANDC) +# define LZO_INT64_C(c) ((c) + 0i64) +# define LZO_UINT64_C(c) ((c) + 0ui64) +# else +# define LZO_INT64_C(c) (c##i64) +# define LZO_UINT64_C(c) (c##ui64) +# endif +#else +#endif +#endif +#if defined(lzo_int64e_t) +# define LZO_SIZEOF_LZO_INT64E_T 8 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == 8) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == LZO_SIZEOF_LZO_INT64E_T) +#endif +#if !defined(lzo_int32l_t) +#if defined(lzo_int32e_t) +# define lzo_int32l_t lzo_int32e_t +# define lzo_uint32l_t lzo_uint32e_t +# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LZO_INT32E_T +# define LZO_TYPEOF_LZO_INT32L_T LZO_TYPEOF_LZO_INT32E_T +#elif (LZO_SIZEOF_INT >= 4) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) +# define lzo_int32l_t int +# define lzo_uint32l_t unsigned int +# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_INT +# define LZO_TYPEOF_LZO_INT32L_T LZO_SIZEOF_INT +#elif (LZO_SIZEOF_LONG >= 4) +# define lzo_int32l_t long int +# define lzo_uint32l_t unsigned long int +# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LONG +# define LZO_TYPEOF_LZO_INT32L_T LZO_SIZEOF_LONG +#else +# error "lzo_int32l_t" +#endif +#endif +#if 1 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) >= 4) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) == LZO_SIZEOF_LZO_INT32L_T) +#endif +#if !defined(lzo_int64l_t) +#if defined(lzo_int64e_t) +# define lzo_int64l_t lzo_int64e_t +# define lzo_uint64l_t lzo_uint64e_t +# define LZO_SIZEOF_LZO_INT64L_T LZO_SIZEOF_LZO_INT64E_T +# define LZO_TYPEOF_LZO_INT64L_T LZO_TYPEOF_LZO_INT64E_T +#else +#endif +#endif +#if defined(lzo_int64l_t) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) >= 8) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) == LZO_SIZEOF_LZO_INT64L_T) +#endif +#if !defined(lzo_int32f_t) +#if (LZO_SIZEOF_SIZE_T >= 8) +# define lzo_int32f_t lzo_int64l_t +# define lzo_uint32f_t lzo_uint64l_t +# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT64L_T +# define LZO_TYPEOF_LZO_INT32F_T LZO_TYPEOF_LZO_INT64L_T +#else +# define lzo_int32f_t lzo_int32l_t +# define lzo_uint32f_t lzo_uint32l_t +# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT32L_T +# define LZO_TYPEOF_LZO_INT32F_T LZO_TYPEOF_LZO_INT32L_T +#endif +#endif +#if 1 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) >= 4) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) == LZO_SIZEOF_LZO_INT32F_T) +#endif +#if !defined(lzo_int64f_t) +#if defined(lzo_int64l_t) +# define lzo_int64f_t lzo_int64l_t +# define lzo_uint64f_t lzo_uint64l_t +# define LZO_SIZEOF_LZO_INT64F_T LZO_SIZEOF_LZO_INT64L_T +# define LZO_TYPEOF_LZO_INT64F_T LZO_TYPEOF_LZO_INT64L_T +#else +#endif +#endif +#if defined(lzo_int64f_t) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) >= 8) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) == LZO_SIZEOF_LZO_INT64F_T) +#endif +#if !defined(lzo_intptr_t) +#if 1 && (LZO_OS_OS400 && (LZO_SIZEOF_VOID_P == 16)) +# define __LZO_INTPTR_T_IS_POINTER 1 + typedef char * lzo_intptr_t; + typedef char * lzo_uintptr_t; +# define lzo_intptr_t lzo_intptr_t +# define lzo_uintptr_t lzo_uintptr_t +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_VOID_P +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_CHAR_P +#elif (LZO_CC_MSC && (_MSC_VER >= 1300) && (LZO_SIZEOF_VOID_P == 4) && (LZO_SIZEOF_INT == 4)) + typedef __w64 int lzo_intptr_t; + typedef __w64 unsigned int lzo_uintptr_t; +# define lzo_intptr_t lzo_intptr_t +# define lzo_uintptr_t lzo_uintptr_t +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_INT +#elif (LZO_SIZEOF_SHORT == LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT > LZO_SIZEOF_VOID_P) +# define lzo_intptr_t short +# define lzo_uintptr_t unsigned short +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_SHORT +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_SHORT +#elif (LZO_SIZEOF_INT >= LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) +# define lzo_intptr_t int +# define lzo_uintptr_t unsigned int +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_INT +#elif (LZO_SIZEOF_LONG >= LZO_SIZEOF_VOID_P) +# define lzo_intptr_t long +# define lzo_uintptr_t unsigned long +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LONG +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_LONG +#elif (LZO_SIZEOF_LZO_INT64L_T >= LZO_SIZEOF_VOID_P) +# define lzo_intptr_t lzo_int64l_t +# define lzo_uintptr_t lzo_uint64l_t +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LZO_INT64L_T +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_LZO_INT64L_T +#else +# error "lzo_intptr_t" +#endif +#endif +#if 1 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) >= sizeof(void *)) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) == sizeof(lzo_uintptr_t)) +#endif +#if !defined(lzo_word_t) +#if defined(LZO_WORDSIZE) && (LZO_WORDSIZE+0 > 0) +#if (LZO_WORDSIZE == LZO_SIZEOF_LZO_INTPTR_T) && !(__LZO_INTPTR_T_IS_POINTER) +# define lzo_word_t lzo_uintptr_t +# define lzo_sword_t lzo_intptr_t +# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INTPTR_T +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF_LZO_INTPTR_T +#elif (LZO_WORDSIZE == LZO_SIZEOF_LONG) +# define lzo_word_t unsigned long +# define lzo_sword_t long +# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LONG +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF_LONG +#elif (LZO_WORDSIZE == LZO_SIZEOF_INT) +# define lzo_word_t unsigned int +# define lzo_sword_t int +# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_INT +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF_INT +#elif (LZO_WORDSIZE == LZO_SIZEOF_SHORT) +# define lzo_word_t unsigned short +# define lzo_sword_t short +# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_SHORT +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF_SHORT +#elif (LZO_WORDSIZE == 1) +# define lzo_word_t unsigned char +# define lzo_sword_t signed char +# define LZO_SIZEOF_LZO_WORD_T 1 +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF_CHAR +#elif (LZO_WORDSIZE == LZO_SIZEOF_LZO_INT64L_T) +# define lzo_word_t lzo_uint64l_t +# define lzo_sword_t lzo_int64l_t +# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T +# define LZO_TYPEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T +#elif (LZO_ARCH_SPU) && (LZO_CC_GNUC) +#if 0 + typedef unsigned lzo_word_t __attribute__((__mode__(__V16QI__))); + typedef int lzo_sword_t __attribute__((__mode__(__V16QI__))); +# define lzo_word_t lzo_word_t +# define lzo_sword_t lzo_sword_t +# define LZO_SIZEOF_LZO_WORD_T 16 +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF___MODE_V16QI +#endif +#else +# error "lzo_word_t" +#endif +#endif +#endif +#if 1 && defined(lzo_word_t) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_word_t) == LZO_WORDSIZE) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_sword_t) == LZO_WORDSIZE) +#endif +#if 1 +#define lzo_int8_t signed char +#define lzo_uint8_t unsigned char +#define LZO_SIZEOF_LZO_INT8_T 1 +#define LZO_TYPEOF_LZO_INT8_T LZO_TYPEOF_CHAR +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == sizeof(lzo_uint8_t)) +#endif +#if defined(lzo_int16e_t) +#define lzo_int16_t lzo_int16e_t +#define lzo_uint16_t lzo_uint16e_t +#define LZO_SIZEOF_LZO_INT16_T LZO_SIZEOF_LZO_INT16E_T +#define LZO_TYPEOF_LZO_INT16_T LZO_TYPEOF_LZO_INT16E_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == sizeof(lzo_uint16_t)) +#endif +#if defined(lzo_int32e_t) +#define lzo_int32_t lzo_int32e_t +#define lzo_uint32_t lzo_uint32e_t +#define LZO_SIZEOF_LZO_INT32_T LZO_SIZEOF_LZO_INT32E_T +#define LZO_TYPEOF_LZO_INT32_T LZO_TYPEOF_LZO_INT32E_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == sizeof(lzo_uint32_t)) +#endif +#if defined(lzo_int64e_t) +#define lzo_int64_t lzo_int64e_t +#define lzo_uint64_t lzo_uint64e_t +#define LZO_SIZEOF_LZO_INT64_T LZO_SIZEOF_LZO_INT64E_T +#define LZO_TYPEOF_LZO_INT64_T LZO_TYPEOF_LZO_INT64E_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == sizeof(lzo_uint64_t)) +#endif +#if 1 +#define lzo_int_least32_t lzo_int32l_t +#define lzo_uint_least32_t lzo_uint32l_t +#define LZO_SIZEOF_LZO_INT_LEAST32_T LZO_SIZEOF_LZO_INT32L_T +#define LZO_TYPEOF_LZO_INT_LEAST32_T LZO_TYPEOF_LZO_INT32L_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) >= 4) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) == sizeof(lzo_uint_least32_t)) +#endif +#if defined(lzo_int64l_t) +#define lzo_int_least64_t lzo_int64l_t +#define lzo_uint_least64_t lzo_uint64l_t +#define LZO_SIZEOF_LZO_INT_LEAST64_T LZO_SIZEOF_LZO_INT64L_T +#define LZO_TYPEOF_LZO_INT_LEAST64_T LZO_TYPEOF_LZO_INT64L_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) >= 8) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) == sizeof(lzo_uint_least64_t)) +#endif +#if 1 +#define lzo_int_fast32_t lzo_int32f_t +#define lzo_uint_fast32_t lzo_uint32f_t +#define LZO_SIZEOF_LZO_INT_FAST32_T LZO_SIZEOF_LZO_INT32F_T +#define LZO_TYPEOF_LZO_INT_FAST32_T LZO_TYPEOF_LZO_INT32F_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) >= 4) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) == sizeof(lzo_uint_fast32_t)) +#endif +#if defined(lzo_int64f_t) +#define lzo_int_fast64_t lzo_int64f_t +#define lzo_uint_fast64_t lzo_uint64f_t +#define LZO_SIZEOF_LZO_INT_FAST64_T LZO_SIZEOF_LZO_INT64F_T +#define LZO_TYPEOF_LZO_INT_FAST64_T LZO_TYPEOF_LZO_INT64F_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) >= 8) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast64_t)) +#endif +#if !defined(LZO_INT16_C) +# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 2) +# define LZO_INT16_C(c) ((c) + 0) +# define LZO_UINT16_C(c) ((c) + 0U) +# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 2) +# define LZO_INT16_C(c) ((c) + 0L) +# define LZO_UINT16_C(c) ((c) + 0UL) +# elif (LZO_SIZEOF_INT >= 2) +# define LZO_INT16_C(c) (c) +# define LZO_UINT16_C(c) (c##U) +# elif (LZO_SIZEOF_LONG >= 2) +# define LZO_INT16_C(c) (c##L) +# define LZO_UINT16_C(c) (c##UL) +# else +# error "LZO_INT16_C" +# endif +#endif +#if !defined(LZO_INT32_C) +# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 4) +# define LZO_INT32_C(c) ((c) + 0) +# define LZO_UINT32_C(c) ((c) + 0U) +# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 4) +# define LZO_INT32_C(c) ((c) + 0L) +# define LZO_UINT32_C(c) ((c) + 0UL) +# elif (LZO_SIZEOF_INT >= 4) +# define LZO_INT32_C(c) (c) +# define LZO_UINT32_C(c) (c##U) +# elif (LZO_SIZEOF_LONG >= 4) +# define LZO_INT32_C(c) (c##L) +# define LZO_UINT32_C(c) (c##UL) +# elif (LZO_SIZEOF_LONG_LONG >= 4) +# define LZO_INT32_C(c) (c##LL) +# define LZO_UINT32_C(c) (c##ULL) +# else +# error "LZO_INT32_C" +# endif +#endif +#if !defined(LZO_INT64_C) && defined(lzo_int64l_t) +# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 8) +# define LZO_INT64_C(c) ((c) + 0) +# define LZO_UINT64_C(c) ((c) + 0U) +# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 8) +# define LZO_INT64_C(c) ((c) + 0L) +# define LZO_UINT64_C(c) ((c) + 0UL) +# elif (LZO_SIZEOF_INT >= 8) +# define LZO_INT64_C(c) (c) +# define LZO_UINT64_C(c) (c##U) +# elif (LZO_SIZEOF_LONG >= 8) +# define LZO_INT64_C(c) (c##L) +# define LZO_UINT64_C(c) (c##UL) +# else +# error "LZO_INT64_C" +# endif +#endif +#endif #endif /* already included */ -/* vim:set ts=4 et: */ +/* vim:set ts=4 sw=4 et: */ diff -Nru oscam-1.20-10584~r10356/minilzo/minilzo.c oscam-1.20-10797~r10569/minilzo/minilzo.c --- oscam-1.20-10584~r10356/minilzo/minilzo.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/minilzo/minilzo.c 2015-02-20 11:57:49.000000000 +0000 @@ -2,22 +2,7 @@ This file is part of the LZO real-time data compression library. - Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -67,12 +52,6 @@ #if defined(__CYGWIN32__) && !defined(__CYGWIN__) # define __CYGWIN__ __CYGWIN32__ #endif -#if defined(__IBMCPP__) && !defined(__IBMC__) -# define __IBMC__ __IBMCPP__ -#endif -#if defined(__ICL) && defined(_WIN32) && !defined(__INTEL_COMPILER) -# define __INTEL_COMPILER __ICL -#endif #if 1 && defined(__INTERIX) && defined(__GNUC__) && !defined(_ALL_SOURCE) # define _ALL_SOURCE 1 #endif @@ -81,19 +60,30 @@ # define __LONG_MAX__ 9223372036854775807L # endif #endif -#if defined(__INTEL_COMPILER) && defined(__linux__) +#if !defined(LZO_CFG_NO_DISABLE_WUNDEF) +#if defined(__ARMCC_VERSION) +# pragma diag_suppress 193 +#elif defined(__clang__) && defined(__clang_minor__) +# pragma clang diagnostic ignored "-Wundef" +#elif defined(__INTEL_COMPILER) # pragma warning(disable: 193) -#endif -#if defined(__KEIL__) && defined(__C166__) -# pragma warning disable = 322 -#elif 0 && defined(__C251__) +#elif defined(__KEIL__) && defined(__C166__) # pragma warning disable = 322 -#endif -#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) -# if (_MSC_VER >= 1300) +#elif defined(__GNUC__) && defined(__GNUC_MINOR__) && !defined(__PATHSCALE__) +# if ((__GNUC__-0) >= 5 || ((__GNUC__-0) == 4 && (__GNUC_MINOR__-0) >= 2)) +# pragma GCC diagnostic ignored "-Wundef" +# endif +#elif defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) +# if ((_MSC_VER-0) >= 1300) # pragma warning(disable: 4668) # endif #endif +#endif +#if 0 && defined(__POCC__) && defined(_WIN32) +# if (__POCC__ >= 400) +# pragma warn(disable: 2216) +# endif +#endif #if 0 && defined(__WATCOMC__) # if (__WATCOMC__ >= 1050) && (__WATCOMC__ < 1060) # pragma warning 203 9 @@ -102,13 +92,29 @@ #if defined(__BORLANDC__) && defined(__MSDOS__) && !defined(__FLAT__) # pragma option -h #endif +#if !(LZO_CFG_NO_DISABLE_WCRTNONSTDC) +#ifndef _CRT_NONSTDC_NO_DEPRECATE +#define _CRT_NONSTDC_NO_DEPRECATE 1 +#endif +#ifndef _CRT_NONSTDC_NO_WARNINGS +#define _CRT_NONSTDC_NO_WARNINGS 1 +#endif +#ifndef _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_DEPRECATE 1 +#endif +#ifndef _CRT_SECURE_NO_WARNINGS +#define _CRT_SECURE_NO_WARNINGS 1 +#endif +#endif #if 0 -#define LZO_0xffffL 0xfffful -#define LZO_0xffffffffL 0xfffffffful +#define LZO_0xffffUL 0xfffful +#define LZO_0xffffffffUL 0xfffffffful #else -#define LZO_0xffffL 65535ul -#define LZO_0xffffffffL 4294967295ul +#define LZO_0xffffUL 65535ul +#define LZO_0xffffffffUL 4294967295ul #endif +#define LZO_0xffffL LZO_0xffffUL +#define LZO_0xffffffffL LZO_0xffffffffUL #if (LZO_0xffffL == LZO_0xffffffffL) # error "your preprocessor is broken 1" #endif @@ -123,6 +129,13 @@ # error "your preprocessor is broken 4" #endif #endif +#if defined(__COUNTER__) +# ifndef LZO_CFG_USE_COUNTER +# define LZO_CFG_USE_COUNTER 1 +# endif +#else +# undef LZO_CFG_USE_COUNTER +#endif #if (UINT_MAX == LZO_0xffffL) #if defined(__ZTC__) && defined(__I86__) && !defined(__OS2__) # if !defined(MSDOS) @@ -253,14 +266,31 @@ #endif #define LZO_PP_STRINGIZE(x) #x #define LZO_PP_MACRO_EXPAND(x) LZO_PP_STRINGIZE(x) +#define LZO_PP_CONCAT0() /*empty*/ +#define LZO_PP_CONCAT1(a) a #define LZO_PP_CONCAT2(a,b) a ## b #define LZO_PP_CONCAT3(a,b,c) a ## b ## c #define LZO_PP_CONCAT4(a,b,c,d) a ## b ## c ## d #define LZO_PP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_PP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f +#define LZO_PP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g +#define LZO_PP_ECONCAT0() LZO_PP_CONCAT0() +#define LZO_PP_ECONCAT1(a) LZO_PP_CONCAT1(a) #define LZO_PP_ECONCAT2(a,b) LZO_PP_CONCAT2(a,b) #define LZO_PP_ECONCAT3(a,b,c) LZO_PP_CONCAT3(a,b,c) #define LZO_PP_ECONCAT4(a,b,c,d) LZO_PP_CONCAT4(a,b,c,d) #define LZO_PP_ECONCAT5(a,b,c,d,e) LZO_PP_CONCAT5(a,b,c,d,e) +#define LZO_PP_ECONCAT6(a,b,c,d,e,f) LZO_PP_CONCAT6(a,b,c,d,e,f) +#define LZO_PP_ECONCAT7(a,b,c,d,e,f,g) LZO_PP_CONCAT7(a,b,c,d,e,f,g) +#define LZO_PP_EMPTY /*empty*/ +#define LZO_PP_EMPTY0() /*empty*/ +#define LZO_PP_EMPTY1(a) /*empty*/ +#define LZO_PP_EMPTY2(a,b) /*empty*/ +#define LZO_PP_EMPTY3(a,b,c) /*empty*/ +#define LZO_PP_EMPTY4(a,b,c,d) /*empty*/ +#define LZO_PP_EMPTY5(a,b,c,d,e) /*empty*/ +#define LZO_PP_EMPTY6(a,b,c,d,e,f) /*empty*/ +#define LZO_PP_EMPTY7(a,b,c,d,e,f,g) /*empty*/ #if 1 #define LZO_CPP_STRINGIZE(x) #x #define LZO_CPP_MACRO_EXPAND(x) LZO_CPP_STRINGIZE(x) @@ -268,12 +298,16 @@ #define LZO_CPP_CONCAT3(a,b,c) a ## b ## c #define LZO_CPP_CONCAT4(a,b,c,d) a ## b ## c ## d #define LZO_CPP_CONCAT5(a,b,c,d,e) a ## b ## c ## d ## e +#define LZO_CPP_CONCAT6(a,b,c,d,e,f) a ## b ## c ## d ## e ## f +#define LZO_CPP_CONCAT7(a,b,c,d,e,f,g) a ## b ## c ## d ## e ## f ## g #define LZO_CPP_ECONCAT2(a,b) LZO_CPP_CONCAT2(a,b) #define LZO_CPP_ECONCAT3(a,b,c) LZO_CPP_CONCAT3(a,b,c) #define LZO_CPP_ECONCAT4(a,b,c,d) LZO_CPP_CONCAT4(a,b,c,d) #define LZO_CPP_ECONCAT5(a,b,c,d,e) LZO_CPP_CONCAT5(a,b,c,d,e) +#define LZO_CPP_ECONCAT6(a,b,c,d,e,f) LZO_CPP_CONCAT6(a,b,c,d,e,f) +#define LZO_CPP_ECONCAT7(a,b,c,d,e,f,g) LZO_CPP_CONCAT7(a,b,c,d,e,f,g) #endif -#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-1)) - (o)) << 1) + (o)) +#define __LZO_MASK_GEN(o,b) (((((o) << ((b)-!!(b))) - (o)) << 1) + (o)*!!(b)) #if 1 && defined(__cplusplus) # if !defined(__STDC_CONSTANT_MACROS) # define __STDC_CONSTANT_MACROS 1 @@ -283,9 +317,13 @@ # endif #endif #if defined(__cplusplus) -# define LZO_EXTERN_C extern "C" -#else -# define LZO_EXTERN_C extern +# define LZO_EXTERN_C extern "C" +# define LZO_EXTERN_C_BEGIN extern "C" { +# define LZO_EXTERN_C_END } +#else +# define LZO_EXTERN_C extern +# define LZO_EXTERN_C_BEGIN /*empty*/ +# define LZO_EXTERN_C_END /*empty*/ #endif #if !defined(__LZO_OS_OVERRIDE) #if (LZO_OS_FREESTANDING) @@ -380,18 +418,18 @@ #elif defined(__TOS__) || defined(__atarist__) # define LZO_OS_TOS 1 # define LZO_INFO_OS "tos" -#elif defined(macintosh) && !defined(__ppc__) +#elif defined(macintosh) && !defined(__arm__) && !defined(__i386__) && !defined(__ppc__) && !defined(__x64_64__) # define LZO_OS_MACCLASSIC 1 # define LZO_INFO_OS "macclassic" #elif defined(__VMS) # define LZO_OS_VMS 1 # define LZO_INFO_OS "vms" -#elif ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +#elif (defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__) # define LZO_OS_CONSOLE 1 # define LZO_OS_CONSOLE_PS2 1 # define LZO_INFO_OS "console" # define LZO_INFO_OS_CONSOLE "ps2" -#elif (defined(__mips__) && defined(__psp__)) +#elif defined(__mips__) && defined(__psp__) # define LZO_OS_CONSOLE 1 # define LZO_OS_CONSOLE_PSP 1 # define LZO_INFO_OS "console" @@ -419,9 +457,18 @@ # elif defined(__linux__) || defined(__linux) || defined(__LINUX__) # define LZO_OS_POSIX_LINUX 1 # define LZO_INFO_OS_POSIX "linux" -# elif defined(__APPLE__) || defined(__MACOS__) -# define LZO_OS_POSIX_MACOSX 1 -# define LZO_INFO_OS_POSIX "macosx" +# elif defined(__APPLE__) && defined(__MACH__) +# if ((__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__-0) >= 20000) +# define LZO_OS_POSIX_DARWIN 1040 +# define LZO_INFO_OS_POSIX "darwin_iphone" +# elif ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0) >= 1040) +# define LZO_OS_POSIX_DARWIN __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ +# define LZO_INFO_OS_POSIX "darwin" +# else +# define LZO_OS_POSIX_DARWIN 1 +# define LZO_INFO_OS_POSIX "darwin" +# endif +# define LZO_OS_POSIX_MACOSX LZO_OS_POSIX_DARWIN # elif defined(__minix__) || defined(__minix) # define LZO_OS_POSIX_MINIX 1 # define LZO_INFO_OS_POSIX "minix" @@ -456,18 +503,18 @@ #endif #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # if (UINT_MAX != LZO_0xffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif #endif #if (LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_WIN32 || LZO_OS_WIN64) # if (UINT_MAX != LZO_0xffffffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif #endif #if defined(CIL) && defined(_GNUCC) && defined(__GNUC__) @@ -483,59 +530,65 @@ # define LZO_INFO_CC "sdcc" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(SDCC) #elif defined(__PATHSCALE__) && defined(__PATHCC_PATCHLEVEL__) -# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + __PATHCC_MINOR__ * 0x100 + __PATHCC_PATCHLEVEL__) +# define LZO_CC_PATHSCALE (__PATHCC__ * 0x10000L + (__PATHCC_MINOR__-0) * 0x100 + (__PATHCC_PATCHLEVEL__-0)) # define LZO_INFO_CC "Pathscale C" # define LZO_INFO_CCVER __PATHSCALE__ -#elif defined(__INTEL_COMPILER) -# define LZO_CC_INTELC 1 +# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# define LZO_CC_PATHSCALE_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# endif +#elif defined(__INTEL_COMPILER) && ((__INTEL_COMPILER-0) > 0) +# define LZO_CC_INTELC __INTEL_COMPILER # define LZO_INFO_CC "Intel C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__INTEL_COMPILER) -# if defined(_WIN32) || defined(_WIN64) -# define LZO_CC_SYNTAX_MSC 1 -# else -# define LZO_CC_SYNTAX_GNUC 1 +# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) +# define LZO_CC_INTELC_MSC _MSC_VER +# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# define LZO_CC_INTELC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) # endif #elif defined(__POCC__) && defined(_WIN32) # define LZO_CC_PELLESC 1 # define LZO_INFO_CC "Pelles C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__POCC__) -#elif defined(__clang__) && defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +#elif defined(__ARMCC_VERSION) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # if defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) # else -# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# define LZO_CC_ARMCC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) # endif +# define LZO_CC_ARMCC __ARMCC_VERSION +# define LZO_INFO_CC "ARM C Compiler" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(__clang__) && defined(__llvm__) && defined(__VERSION__) # if defined(__clang_major__) && defined(__clang_minor__) && defined(__clang_patchlevel__) -# define LZO_CC_CLANG_CLANG (__clang_major__ * 0x10000L + __clang_minor__ * 0x100 + __clang_patchlevel__) +# define LZO_CC_CLANG (__clang_major__ * 0x10000L + (__clang_minor__-0) * 0x100 + (__clang_patchlevel__-0)) # else -# define LZO_CC_CLANG_CLANG 0x010000L +# define LZO_CC_CLANG 0x010000L +# endif +# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) +# define LZO_CC_CLANG_MSC _MSC_VER +# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# define LZO_CC_CLANG_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) # endif -# define LZO_CC_CLANG LZO_CC_CLANG_GNUC # define LZO_INFO_CC "clang" # define LZO_INFO_CCVER __VERSION__ #elif defined(__llvm__) && defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) # if defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) # else -# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) +# define LZO_CC_LLVM_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) # endif # define LZO_CC_LLVM LZO_CC_LLVM_GNUC # define LZO_INFO_CC "llvm-gcc" # define LZO_INFO_CCVER __VERSION__ -#elif defined(__GNUC__) && defined(__VERSION__) -# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) -# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100 + __GNUC_PATCHLEVEL__) -# elif defined(__GNUC_MINOR__) -# define LZO_CC_GNUC (__GNUC__ * 0x10000L + __GNUC_MINOR__ * 0x100) -# else -# define LZO_CC_GNUC (__GNUC__ * 0x10000L) -# endif -# define LZO_INFO_CC "gcc" -# define LZO_INFO_CCVER __VERSION__ #elif defined(__ACK__) && defined(_ACK) # define LZO_CC_ACK 1 # define LZO_INFO_CC "Amsterdam Compiler Kit C" # define LZO_INFO_CCVER "unknown" +#elif defined(__ARMCC_VERSION) && !defined(__GNUC__) +# define LZO_CC_ARMCC __ARMCC_VERSION +# define LZO_CC_ARMCC_ARMCC __ARMCC_VERSION +# define LZO_INFO_CC "ARM C Compiler" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ARMCC_VERSION) #elif defined(__AZTEC_C__) # define LZO_CC_AZTECC 1 # define LZO_INFO_CC "Aztec C" @@ -560,10 +613,23 @@ # define LZO_CC_DECC 1 # define LZO_INFO_CC "DEC C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__DECC) +#elif (defined(__ghs) || defined(__ghs__)) && defined(__GHS_VERSION_NUMBER) && ((__GHS_VERSION_NUMBER-0) > 0) +# define LZO_CC_GHS 1 +# define LZO_INFO_CC "Green Hills C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__GHS_VERSION_NUMBER) +# if defined(_MSC_VER) && ((_MSC_VER-0) > 0) +# define LZO_CC_GHS_MSC _MSC_VER +# elif defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__VERSION__) +# define LZO_CC_GHS_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# endif #elif defined(__HIGHC__) # define LZO_CC_HIGHC 1 # define LZO_INFO_CC "MetaWare High C" # define LZO_INFO_CCVER "unknown" +#elif defined(__HP_aCC) && ((__HP_aCC-0) > 0) +# define LZO_CC_HPACC __HP_aCC +# define LZO_INFO_CC "HP aCC" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__HP_aCC) #elif defined(__IAR_SYSTEMS_ICC__) # define LZO_CC_IARC 1 # define LZO_INFO_CC "IAR C" @@ -572,10 +638,14 @@ # else # define LZO_INFO_CCVER "unknown" # endif -#elif defined(__IBMC__) -# define LZO_CC_IBMC 1 +#elif defined(__IBMC__) && ((__IBMC__-0) > 0) +# define LZO_CC_IBMC __IBMC__ # define LZO_INFO_CC "IBM C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMC__) +#elif defined(__IBMCPP__) && ((__IBMCPP__-0) > 0) +# define LZO_CC_IBMC __IBMCPP__ +# define LZO_INFO_CC "IBM C" +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__IBMCPP__) #elif defined(__KEIL__) && defined(__C166__) # define LZO_CC_KEILC 1 # define LZO_INFO_CC "Keil C" @@ -592,16 +662,8 @@ # else # define LZO_INFO_CCVER "unknown" # endif -#elif defined(_MSC_VER) -# define LZO_CC_MSC 1 -# define LZO_INFO_CC "Microsoft C" -# if defined(_MSC_FULL_VER) -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) -# else -# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) -# endif -#elif defined(__MWERKS__) -# define LZO_CC_MWERKS 1 +#elif defined(__MWERKS__) && ((__MWERKS__-0) > 0) +# define LZO_CC_MWERKS __MWERKS__ # define LZO_INFO_CC "Metrowerks C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__MWERKS__) #elif (defined(__NDPC__) || defined(__NDPX__)) && defined(__i386) @@ -612,6 +674,15 @@ # define LZO_CC_PACIFICC 1 # define LZO_INFO_CC "Pacific C" # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PACIFIC__) +#elif defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) +# if defined(__PGIC_PATCHLEVEL__) +# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100 + (__PGIC_PATCHLEVEL__-0)) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) "." LZO_PP_MACRO_EXPAND(__PGIC_PATCHLEVEL__) +# else +# define LZO_CC_PGI (__PGIC__ * 0x10000L + (__PGIC_MINOR__-0) * 0x100) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__PGIC__) "." LZO_PP_MACRO_EXPAND(__PGIC_MINOR__) ".0" +# endif +# define LZO_INFO_CC "Portland Group PGI C" #elif defined(__PGI) && (defined(__linux__) || defined(__WIN32__)) # define LZO_CC_PGI 1 # define LZO_INFO_CC "Portland Group PGI C" @@ -626,7 +697,7 @@ # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SC__) #elif defined(__SUNPRO_C) # define LZO_INFO_CC "SunPro C" -# if ((__SUNPRO_C)+0 > 0) +# if ((__SUNPRO_C-0) > 0) # define LZO_CC_SUNPROC __SUNPRO_C # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_C) # else @@ -635,7 +706,7 @@ # endif #elif defined(__SUNPRO_CC) # define LZO_INFO_CC "SunPro C" -# if ((__SUNPRO_CC)+0 > 0) +# if ((__SUNPRO_CC-0) > 0) # define LZO_CC_SUNPROC __SUNPRO_CC # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__SUNPRO_CC) # else @@ -661,16 +732,46 @@ #elif defined(__ZTC__) # define LZO_CC_ZORTECHC 1 # define LZO_INFO_CC "Zortech C" -# if (__ZTC__ == 0x310) +# if ((__ZTC__-0) == 0x310) # define LZO_INFO_CCVER "0x310" # else # define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(__ZTC__) # endif +#elif defined(__GNUC__) && defined(__VERSION__) +# if defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100 + (__GNUC_PATCHLEVEL__-0)) +# elif defined(__GNUC_MINOR__) +# define LZO_CC_GNUC (__GNUC__ * 0x10000L + (__GNUC_MINOR__-0) * 0x100) +# else +# define LZO_CC_GNUC (__GNUC__ * 0x10000L) +# endif +# define LZO_INFO_CC "gcc" +# define LZO_INFO_CCVER __VERSION__ +#elif defined(_MSC_VER) && ((_MSC_VER-0) > 0) +# define LZO_CC_MSC _MSC_VER +# define LZO_INFO_CC "Microsoft C" +# if defined(_MSC_FULL_VER) +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) "." LZO_PP_MACRO_EXPAND(_MSC_FULL_VER) +# else +# define LZO_INFO_CCVER LZO_PP_MACRO_EXPAND(_MSC_VER) +# endif #else # define LZO_CC_UNKNOWN 1 # define LZO_INFO_CC "unknown" # define LZO_INFO_CCVER "unknown" #endif +#if (LZO_CC_GNUC) && defined(__OPEN64__) +# if defined(__OPENCC__) && defined(__OPENCC_MINOR__) && defined(__OPENCC_PATCHLEVEL__) +# define LZO_CC_OPEN64 (__OPENCC__ * 0x10000L + (__OPENCC_MINOR__-0) * 0x100 + (__OPENCC_PATCHLEVEL__-0)) +# define LZO_CC_OPEN64_GNUC LZO_CC_GNUC +# endif +#endif +#if (LZO_CC_GNUC) && defined(__PCC__) +# if defined(__PCC__) && defined(__PCC_MINOR__) && defined(__PCC_MINORMINOR__) +# define LZO_CC_PCC (__PCC__ * 0x10000L + (__PCC_MINOR__-0) * 0x100 + (__PCC_MINORMINOR__-0)) +# define LZO_CC_PCC_GNUC LZO_CC_GNUC +# endif +#endif #if 0 && (LZO_CC_MSC && (_MSC_VER >= 1200)) && !defined(_MSC_FULL_VER) # error "LZO_CC_MSC: _MSC_FULL_VER is not defined" #endif @@ -688,8 +789,10 @@ # define LZO_INFO_ARCH "generic" #elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086 1 -# define LZO_ARCH_IA16 1 # define LZO_INFO_ARCH "i086" +#elif defined(__aarch64__) +# define LZO_ARCH_ARM64 1 +# define LZO_INFO_ARCH "arm64" #elif defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA) # define LZO_ARCH_ALPHA 1 # define LZO_INFO_ARCH "alpha" @@ -699,22 +802,11 @@ #elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64) # define LZO_ARCH_AMD64 1 # define LZO_INFO_ARCH "amd64" -#elif defined(__thumb__) || (defined(_M_ARM) && defined(_M_THUMB)) +#elif defined(__arm__) || defined(_M_ARM) # define LZO_ARCH_ARM 1 -# define LZO_ARCH_ARM_THUMB 1 -# define LZO_INFO_ARCH "arm_thumb" +# define LZO_INFO_ARCH "arm" #elif defined(__IAR_SYSTEMS_ICC__) && defined(__ICCARM__) # define LZO_ARCH_ARM 1 -# if defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 1) -# define LZO_ARCH_ARM_THUMB 1 -# define LZO_INFO_ARCH "arm_thumb" -# elif defined(__CPU_MODE__) && ((__CPU_MODE__)+0 == 2) -# define LZO_INFO_ARCH "arm" -# else -# define LZO_INFO_ARCH "arm" -# endif -#elif defined(__arm__) || defined(_M_ARM) -# define LZO_ARCH_ARM 1 # define LZO_INFO_ARCH "arm" #elif (UINT_MAX <= LZO_0xffffL) && defined(__AVR__) # define LZO_ARCH_AVR 1 @@ -822,57 +914,167 @@ # define LZO_INFO_ARCH "unknown" #endif #endif +#if !defined(LZO_ARCH_ARM_THUMB2) +#if (LZO_ARCH_ARM) +# if defined(__ARM_ARCH_ISA_THUMB) +# if ((__ARM_ARCH_ISA_THUMB)+0 >= 2) +# define LZO_ARCH_ARM_THUMB2 1 +# endif +# elif 1 && defined(__thumb2__) +# define LZO_ARCH_ARM_THUMB2 1 +# elif 1 && defined(__TARGET_ARCH_THUMB) && ((__TARGET_ARCH_THUMB)+0 >= 4) +# define LZO_ARCH_ARM_THUMB2 1 +# endif +#endif +#endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_DOS32 || LZO_OS_OS2) # error "FIXME - missing define for CPU architecture" #endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN32) -# error "FIXME - missing WIN32 define for CPU architecture" +# error "FIXME - missing LZO_OS_WIN32 define for CPU architecture" #endif #if 1 && (LZO_ARCH_UNKNOWN) && (LZO_OS_WIN64) -# error "FIXME - missing WIN64 define for CPU architecture" +# error "FIXME - missing LZO_OS_WIN64 define for CPU architecture" #endif #if (LZO_OS_OS216 || LZO_OS_WIN16) # define LZO_ARCH_I086PM 1 -# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && defined(BLX286)) # define LZO_ARCH_I086PM 1 -# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && defined(DOSX286)) # define LZO_ARCH_I086PM 1 -# define LZO_ARCH_IA16PM 1 #elif 1 && (LZO_OS_DOS16 && LZO_CC_BORLANDC && defined(__DPMI16__)) # define LZO_ARCH_I086PM 1 -# define LZO_ARCH_IA16PM 1 #endif -#if (LZO_ARCH_ARM_THUMB) && !(LZO_ARCH_ARM) -# error "this should not happen" +#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) +# define LZO_ARCH_X64 1 +#elif (!LZO_ARCH_AMD64 && LZO_ARCH_X64) && defined(__LZO_ARCH_OVERRIDE) +# define LZO_ARCH_AMD64 1 +#endif +#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) +# define LZO_ARCH_AARCH64 1 +#elif (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) && defined(__LZO_ARCH_OVERRIDE) +# define LZO_ARCH_ARM64 1 +#endif +#if (LZO_ARCH_I386 && !LZO_ARCH_X86) +# define LZO_ARCH_X86 1 +#elif (!LZO_ARCH_I386 && LZO_ARCH_X86) && defined(__LZO_ARCH_OVERRIDE) +# define LZO_ARCH_I386 1 +#endif +#if (LZO_ARCH_AMD64 && !LZO_ARCH_X64) || (!LZO_ARCH_AMD64 && LZO_ARCH_X64) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_ARM64 && !LZO_ARCH_AARCH64) || (!LZO_ARCH_ARM64 && LZO_ARCH_AARCH64) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_I386 && !LZO_ARCH_X86) || (!LZO_ARCH_I386 && LZO_ARCH_X86) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_ARM_THUMB1 && !LZO_ARCH_ARM) +# error "unexpected configuration - check your compiler defines" #endif -#if (LZO_ARCH_I086PM) && !(LZO_ARCH_I086) -# error "this should not happen" +#if (LZO_ARCH_ARM_THUMB2 && !LZO_ARCH_ARM) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_ARM_THUMB1 && LZO_ARCH_ARM_THUMB2) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_I086PM && !LZO_ARCH_I086) +# error "unexpected configuration - check your compiler defines" #endif #if (LZO_ARCH_I086) # if (UINT_MAX != LZO_0xffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif #endif #if (LZO_ARCH_I386) # if (UINT_MAX != LZO_0xffffL) && defined(__i386_int16__) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif # if (UINT_MAX != LZO_0xffffffffL) && !defined(__i386_int16__) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif # if (ULONG_MAX != LZO_0xffffffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" +# endif +#endif +#if (LZO_ARCH_AMD64 || LZO_ARCH_I386) +# if !defined(LZO_TARGET_FEATURE_SSE2) +# if defined(__SSE2__) +# define LZO_TARGET_FEATURE_SSE2 1 +# elif defined(_MSC_VER) && (defined(_M_IX86_FP) && ((_M_IX86_FP)+0 >= 2)) +# define LZO_TARGET_FEATURE_SSE2 1 +# elif (LZO_CC_INTELC_MSC || LZO_CC_MSC) && defined(_M_AMD64) +# define LZO_TARGET_FEATURE_SSE2 1 +# endif +# endif +# if !defined(LZO_TARGET_FEATURE_SSSE3) +# if (LZO_TARGET_FEATURE_SSE2) +# if defined(__SSSE3__) +# define LZO_TARGET_FEATURE_SSSE3 1 +# elif defined(_MSC_VER) && defined(__AVX__) +# define LZO_TARGET_FEATURE_SSSE3 1 +# endif +# endif +# endif +# if !defined(LZO_TARGET_FEATURE_SSE4_2) +# if (LZO_TARGET_FEATURE_SSSE3) +# if defined(__SSE4_2__) +# define LZO_TARGET_FEATURE_SSE4_2 1 +# endif +# endif +# endif +# if !defined(LZO_TARGET_FEATURE_AVX) +# if (LZO_TARGET_FEATURE_SSSE3) +# if defined(__AVX__) +# define LZO_TARGET_FEATURE_AVX 1 +# endif +# endif +# endif +# if !defined(LZO_TARGET_FEATURE_AVX2) +# if (LZO_TARGET_FEATURE_AVX) +# if defined(__AVX2__) +# define LZO_TARGET_FEATURE_AVX2 1 +# endif +# endif +# endif +#endif +#if (LZO_TARGET_FEATURE_SSSE3 && !(LZO_TARGET_FEATURE_SSE2)) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_TARGET_FEATURE_SSE4_2 && !(LZO_TARGET_FEATURE_SSSE3)) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_TARGET_FEATURE_AVX && !(LZO_TARGET_FEATURE_SSSE3)) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_TARGET_FEATURE_AVX2 && !(LZO_TARGET_FEATURE_AVX)) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ARCH_ARM) +# if !defined(LZO_TARGET_FEATURE_NEON) +# if defined(__ARM_NEON) && ((__ARM_NEON)+0) +# define LZO_TARGET_FEATURE_NEON 1 +# elif 1 && defined(__ARM_NEON__) && ((__ARM_NEON__)+0) +# define LZO_TARGET_FEATURE_NEON 1 +# elif 1 && defined(__TARGET_FEATURE_NEON) && ((__TARGET_FEATURE_NEON)+0) +# define LZO_TARGET_FEATURE_NEON 1 +# endif +# endif +#elif (LZO_ARCH_ARM64) +# if !defined(LZO_TARGET_FEATURE_NEON) +# if 1 +# define LZO_TARGET_FEATURE_NEON 1 +# endif # endif #endif -#if !defined(__LZO_MM_OVERRIDE) +#if 0 +#elif !defined(__LZO_MM_OVERRIDE) #if (LZO_ARCH_I086) #if (UINT_MAX != LZO_0xffffL) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" #endif #if defined(__TINY__) || defined(M_I86TM) || defined(_M_I86TM) # define LZO_MM_TINY 1 @@ -899,7 +1101,7 @@ #elif (LZO_CC_ZORTECHC && defined(__VCM__)) # define LZO_MM_LARGE 1 #else -# error "unknown memory model" +# error "unknown LZO_ARCH_I086 memory model" #endif #if (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) #define LZO_HAVE_MM_HUGE_PTR 1 @@ -922,31 +1124,31 @@ #endif #if (LZO_ARCH_I086PM) && !(LZO_HAVE_MM_HUGE_PTR) # if (LZO_OS_DOS16) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # elif (LZO_CC_ZORTECHC) # else -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" # endif #endif #ifdef __cplusplus extern "C" { #endif #if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0200)) -extern void __near __cdecl _AHSHIFT(void); + extern void __near __cdecl _AHSHIFT(void); # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) #elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) -extern void __near __cdecl _AHSHIFT(void); + extern void __near __cdecl _AHSHIFT(void); # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) #elif (LZO_CC_MSC || LZO_CC_TOPSPEEDC) -extern void __near __cdecl _AHSHIFT(void); + extern void __near __cdecl _AHSHIFT(void); # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) #elif (LZO_CC_TURBOC && (__TURBOC__ >= 0x0295)) -extern void __near __cdecl _AHSHIFT(void); + extern void __near __cdecl _AHSHIFT(void); # define LZO_MM_AHSHIFT ((unsigned) _AHSHIFT) #elif ((LZO_CC_AZTECC || LZO_CC_PACIFICC || LZO_CC_TURBOC) && LZO_OS_DOS16) # define LZO_MM_AHSHIFT 12 #elif (LZO_CC_WATCOMC) -extern unsigned char _HShift; + extern unsigned char _HShift; # define LZO_MM_AHSHIFT ((unsigned) _HShift) #else # error "FIXME - implement LZO_MM_AHSHIFT" @@ -957,7 +1159,7 @@ #endif #elif (LZO_ARCH_C166) #if !defined(__MODEL__) -# error "FIXME - C166 __MODEL__" +# error "FIXME - LZO_ARCH_C166 __MODEL__" #elif ((__MODEL__) == 0) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 1) @@ -971,11 +1173,11 @@ #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - C166 __MODEL__" +# error "FIXME - LZO_ARCH_C166 __MODEL__" #endif #elif (LZO_ARCH_MCS251) #if !defined(__MODEL__) -# error "FIXME - MCS251 __MODEL__" +# error "FIXME - LZO_ARCH_MCS251 __MODEL__" #elif ((__MODEL__) == 0) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 2) @@ -987,11 +1189,11 @@ #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - MCS251 __MODEL__" +# error "FIXME - LZO_ARCH_MCS251 __MODEL__" #endif #elif (LZO_ARCH_MCS51) #if !defined(__MODEL__) -# error "FIXME - MCS51 __MODEL__" +# error "FIXME - LZO_ARCH_MCS51 __MODEL__" #elif ((__MODEL__) == 1) # define LZO_MM_SMALL 1 #elif ((__MODEL__) == 2) @@ -1003,7 +1205,7 @@ #elif ((__MODEL__) == 5) # define LZO_MM_XSMALL 1 #else -# error "FIXME - MCS51 __MODEL__" +# error "FIXME - LZO_ARCH_MCS51 __MODEL__" #endif #elif (LZO_ARCH_CRAY_PVP) # define LZO_MM_PVP 1 @@ -1030,462 +1232,312 @@ # error "unknown memory model" #endif #endif -#if defined(SIZEOF_SHORT) -# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) +#if !defined(__lzo_gnuc_extension__) +#if (LZO_CC_GNUC >= 0x020800ul) +# define __lzo_gnuc_extension__ __extension__ +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_gnuc_extension__ __extension__ +#elif (LZO_CC_IBMC >= 600) +# define __lzo_gnuc_extension__ __extension__ +#else #endif -#if defined(SIZEOF_INT) -# define LZO_SIZEOF_INT (SIZEOF_INT) #endif -#if defined(SIZEOF_LONG) -# define LZO_SIZEOF_LONG (SIZEOF_LONG) +#if !defined(__lzo_gnuc_extension__) +# define __lzo_gnuc_extension__ /*empty*/ #endif -#if defined(SIZEOF_LONG_LONG) -# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) +#if !defined(lzo_has_builtin) +#if (LZO_CC_CLANG) && defined(__has_builtin) +# define lzo_has_builtin __has_builtin #endif -#if defined(SIZEOF___INT16) -# define LZO_SIZEOF___INT16 (SIZEOF___INT16) #endif -#if defined(SIZEOF___INT32) -# define LZO_SIZEOF___INT32 (SIZEOF___INT32) +#if !defined(lzo_has_builtin) +# define lzo_has_builtin(x) 0 #endif -#if defined(SIZEOF___INT64) -# define LZO_SIZEOF___INT64 (SIZEOF___INT64) +#if !defined(lzo_has_attribute) +#if (LZO_CC_CLANG) && defined(__has_attribute) +# define lzo_has_attribute __has_attribute #endif -#if defined(SIZEOF_VOID_P) -# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) #endif -#if defined(SIZEOF_SIZE_T) -# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) +#if !defined(lzo_has_attribute) +# define lzo_has_attribute(x) 0 #endif -#if defined(SIZEOF_PTRDIFF_T) -# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) +#if !defined(lzo_has_declspec_attribute) +#if (LZO_CC_CLANG) && defined(__has_declspec_attribute) +# define lzo_has_declspec_attribute __has_declspec_attribute #endif -#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) -#if !defined(LZO_SIZEOF_SHORT) -# if (LZO_ARCH_CRAY_PVP) -# define LZO_SIZEOF_SHORT 8 -# elif (USHRT_MAX == LZO_0xffffL) -# define LZO_SIZEOF_SHORT 2 -# elif (__LZO_LSR(USHRT_MAX,7) == 1) -# define LZO_SIZEOF_SHORT 1 -# elif (__LZO_LSR(USHRT_MAX,15) == 1) -# define LZO_SIZEOF_SHORT 2 -# elif (__LZO_LSR(USHRT_MAX,31) == 1) -# define LZO_SIZEOF_SHORT 4 -# elif (__LZO_LSR(USHRT_MAX,63) == 1) -# define LZO_SIZEOF_SHORT 8 -# elif (__LZO_LSR(USHRT_MAX,127) == 1) -# define LZO_SIZEOF_SHORT 16 +#endif +#if !defined(lzo_has_declspec_attribute) +# define lzo_has_declspec_attribute(x) 0 +#endif +#if !defined(lzo_has_feature) +#if (LZO_CC_CLANG) && defined(__has_feature) +# define lzo_has_feature __has_feature +#endif +#endif +#if !defined(lzo_has_feature) +# define lzo_has_feature(x) 0 +#endif +#if !defined(lzo_has_extension) +#if (LZO_CC_CLANG) && defined(__has_extension) +# define lzo_has_extension __has_extension +#elif (LZO_CC_CLANG) && defined(__has_feature) +# define lzo_has_extension __has_feature +#endif +#endif +#if !defined(lzo_has_extension) +# define lzo_has_extension 0 +#endif +#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) && defined(__cplusplus) && 0 +# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) +# define LZO_CFG_USE_NEW_STYLE_CASTS 0 +# elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1200)) +# define LZO_CFG_USE_NEW_STYLE_CASTS 0 # else -# error "LZO_SIZEOF_SHORT" +# define LZO_CFG_USE_NEW_STYLE_CASTS 1 # endif #endif -#if !defined(LZO_SIZEOF_INT) -# if (LZO_ARCH_CRAY_PVP) -# define LZO_SIZEOF_INT 8 -# elif (UINT_MAX == LZO_0xffffL) -# define LZO_SIZEOF_INT 2 -# elif (UINT_MAX == LZO_0xffffffffL) -# define LZO_SIZEOF_INT 4 -# elif (__LZO_LSR(UINT_MAX,7) == 1) -# define LZO_SIZEOF_INT 1 -# elif (__LZO_LSR(UINT_MAX,15) == 1) -# define LZO_SIZEOF_INT 2 -# elif (__LZO_LSR(UINT_MAX,31) == 1) -# define LZO_SIZEOF_INT 4 -# elif (__LZO_LSR(UINT_MAX,63) == 1) -# define LZO_SIZEOF_INT 8 -# elif (__LZO_LSR(UINT_MAX,127) == 1) -# define LZO_SIZEOF_INT 16 -# else -# error "LZO_SIZEOF_INT" +#if !defined(LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_CFG_USE_NEW_STYLE_CASTS 0 +#endif +#if !defined(__cplusplus) +# if defined(LZO_CFG_USE_NEW_STYLE_CASTS) +# undef LZO_CFG_USE_NEW_STYLE_CASTS # endif +# define LZO_CFG_USE_NEW_STYLE_CASTS 0 #endif -#if !defined(LZO_SIZEOF_LONG) -# if (ULONG_MAX == LZO_0xffffffffL) -# define LZO_SIZEOF_LONG 4 -# elif (__LZO_LSR(ULONG_MAX,7) == 1) -# define LZO_SIZEOF_LONG 1 -# elif (__LZO_LSR(ULONG_MAX,15) == 1) -# define LZO_SIZEOF_LONG 2 -# elif (__LZO_LSR(ULONG_MAX,31) == 1) -# define LZO_SIZEOF_LONG 4 -# elif (__LZO_LSR(ULONG_MAX,63) == 1) -# define LZO_SIZEOF_LONG 8 -# elif (__LZO_LSR(ULONG_MAX,127) == 1) -# define LZO_SIZEOF_LONG 16 -# else -# error "LZO_SIZEOF_LONG" +#if !defined(LZO_REINTERPRET_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_REINTERPRET_CAST(t,e) (reinterpret_cast (e)) # endif #endif -#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) -# if (LZO_CC_GNUC >= 0x030300ul) -# if ((__LONG_MAX__)+0 == (__LONG_LONG_MAX__)+0) -# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG -# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) -# define LZO_SIZEOF_LONG_LONG 4 -# endif -# endif +#if !defined(LZO_REINTERPRET_CAST) +# define LZO_REINTERPRET_CAST(t,e) ((t) (e)) +#endif +#if !defined(LZO_STATIC_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_STATIC_CAST(t,e) (static_cast (e)) # endif #endif +#if !defined(LZO_STATIC_CAST) +# define LZO_STATIC_CAST(t,e) ((t) (e)) #endif -#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) -#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) -#if (LZO_ARCH_I086 && LZO_CC_DMC) -#elif (LZO_CC_CILLY) && defined(__GNUC__) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_SIZEOF_LONG_LONG 8 -#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_OS_WIN64 || defined(_WIN64)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) -# define LZO_SIZEOF___INT64 8 -#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && (_INTEGRAL_MAX_BITS == 64)) -# define LZO_SIZEOF___INT64 8 -#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -# define LZO_SIZEOF_LONG_LONG 8 -#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) -#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -# define LZO_SIZEOF_LONG_LONG 8 +#if !defined(LZO_STATIC_CAST2) +# define LZO_STATIC_CAST2(t1,t2,e) LZO_STATIC_CAST(t1, LZO_STATIC_CAST(t2, e)) #endif +#if !defined(LZO_UNCONST_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_UNCONST_CAST(t,e) (const_cast (e)) +# elif (LZO_HAVE_MM_HUGE_PTR) +# define LZO_UNCONST_CAST(t,e) ((t) (e)) +# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((const void *) (e))))) +# endif #endif +#if !defined(LZO_UNCONST_CAST) +# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((const void *) (e)))) #endif -#if defined(__cplusplus) && (LZO_CC_GNUC) -# if (LZO_CC_GNUC < 0x020800ul) -# undef LZO_SIZEOF_LONG_LONG +#if !defined(LZO_UNCONST_VOLATILE_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_UNCONST_VOLATILE_CAST(t,e) (const_cast (e)) +# elif (LZO_HAVE_MM_HUGE_PTR) +# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) (e)) +# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) # endif #endif -#if (LZO_CFG_NO_LONG_LONG) || defined(__NO_LONG_LONG) -# undef LZO_SIZEOF_LONG_LONG +#if !defined(LZO_UNCONST_VOLATILE_CAST) +# define LZO_UNCONST_VOLATILE_CAST(t,e) ((t) ((volatile void *) ((volatile const void *) (e)))) #endif -#if !defined(LZO_SIZEOF_VOID_P) -#if (LZO_ARCH_I086) -# define __LZO_WORDSIZE 2 -# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) -# define LZO_SIZEOF_VOID_P 2 -# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) -# define LZO_SIZEOF_VOID_P 4 -# else -# error "LZO_MM" +#if !defined(LZO_UNVOLATILE_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_UNVOLATILE_CAST(t,e) (const_cast (e)) +# elif (LZO_HAVE_MM_HUGE_PTR) +# define LZO_UNVOLATILE_CAST(t,e) ((t) (e)) +# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((lzo_uintptr_t) ((volatile void *) (e))))) # endif -#elif (LZO_ARCH_AVR || LZO_ARCH_Z80) -# define __LZO_WORDSIZE 1 -# define LZO_SIZEOF_VOID_P 2 -#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) -# define LZO_SIZEOF_VOID_P 2 -#elif (LZO_ARCH_H8300) -# if defined(__NORMAL_MODE__) -# define __LZO_WORDSIZE 4 -# define LZO_SIZEOF_VOID_P 2 -# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) -# define __LZO_WORDSIZE 4 -# define LZO_SIZEOF_VOID_P 4 -# else -# define __LZO_WORDSIZE 2 -# define LZO_SIZEOF_VOID_P 2 -# endif -# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT -# endif -#elif (LZO_ARCH_M16C) -# define __LZO_WORDSIZE 2 -# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) -# define LZO_SIZEOF_VOID_P 4 -# else -# define LZO_SIZEOF_VOID_P 2 -# endif -#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) -# define __LZO_WORDSIZE 8 -# define LZO_SIZEOF_VOID_P 4 -#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) -# define __LZO_WORDSIZE 8 -# define LZO_SIZEOF_VOID_P 8 -#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) -# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -#elif (LZO_OS_OS400 || defined(__OS400__)) -# define __LZO_WORDSIZE LZO_SIZEOF_LONG -# define LZO_SIZEOF_VOID_P 16 -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) -# define LZO_SIZEOF_VOID_P 8 -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG -#elif (LZO_ARCH_SPU) -# if 0 -# define __LZO_WORDSIZE 16 -# endif -# define LZO_SIZEOF_VOID_P 4 -#else -# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG #endif +#if !defined(LZO_UNVOLATILE_CAST) +# define LZO_UNVOLATILE_CAST(t,e) ((t) ((void *) ((volatile void *) (e)))) #endif -#if !defined(LZO_WORDSIZE) -# if defined(__LZO_WORDSIZE) -# define LZO_WORDSIZE __LZO_WORDSIZE -# else -# define LZO_WORDSIZE LZO_SIZEOF_VOID_P +#if !defined(LZO_UNVOLATILE_CONST_CAST) +# if (LZO_CFG_USE_NEW_STYLE_CASTS) +# define LZO_UNVOLATILE_CONST_CAST(t,e) (const_cast (e)) +# elif (LZO_HAVE_MM_HUGE_PTR) +# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) (e)) +# elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((lzo_uintptr_t) ((volatile const void *) (e))))) # endif #endif -#if !defined(LZO_SIZEOF_SIZE_T) -#if (LZO_ARCH_I086 || LZO_ARCH_M16C) -# define LZO_SIZEOF_SIZE_T 2 -#else -# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P -#endif +#if !defined(LZO_UNVOLATILE_CONST_CAST) +# define LZO_UNVOLATILE_CONST_CAST(t,e) ((t) ((const void *) ((volatile const void *) (e)))) #endif -#if !defined(LZO_SIZEOF_PTRDIFF_T) -#if (LZO_ARCH_I086) -# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P -# elif (LZO_MM_COMPACT || LZO_MM_LARGE) -# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) -# define LZO_SIZEOF_PTRDIFF_T 4 -# else -# define LZO_SIZEOF_PTRDIFF_T 2 -# endif -# else -# error "LZO_MM" +#if !defined(LZO_PCAST) +# if (LZO_HAVE_MM_HUGE_PTR) +# define LZO_PCAST(t,e) ((t) (e)) # endif -#else -# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T #endif +#if !defined(LZO_PCAST) +# define LZO_PCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(void *, e)) #endif -#if (LZO_ABI_NEUTRAL_ENDIAN) -# undef LZO_ABI_BIG_ENDIAN -# undef LZO_ABI_LITTLE_ENDIAN -#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) -#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) -# define LZO_ABI_BIG_ENDIAN 1 -#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) -# if (__LITTLE_ENDIAN__ == 1) -# define LZO_ABI_LITTLE_ENDIAN 1 -# else -# define LZO_ABI_BIG_ENDIAN 1 +#if !defined(LZO_CCAST) +# if (LZO_HAVE_MM_HUGE_PTR) +# define LZO_CCAST(t,e) ((t) (e)) # endif -#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) -# define LZO_ABI_LITTLE_ENDIAN 1 -#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) -# define LZO_ABI_BIG_ENDIAN 1 -#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) -# define LZO_ABI_LITTLE_ENDIAN 1 #endif +#if !defined(LZO_CCAST) +# define LZO_CCAST(t,e) LZO_STATIC_CAST(t, LZO_STATIC_CAST(const void *, e)) #endif -#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) -# error "this should not happen" +#if !defined(LZO_ICONV) +# define LZO_ICONV(t,e) LZO_STATIC_CAST(t, e) #endif -#if (LZO_ABI_BIG_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "be" -#elif (LZO_ABI_LITTLE_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "le" -#elif (LZO_ABI_NEUTRAL_ENDIAN) -# define LZO_INFO_ABI_ENDIAN "neutral" +#if !defined(LZO_ICAST) +# define LZO_ICAST(t,e) LZO_STATIC_CAST(t, e) #endif -#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -# define LZO_ABI_I8LP16 1 -# define LZO_INFO_ABI_PM "i8lp16" -#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) -# define LZO_ABI_ILP16 1 -# define LZO_INFO_ABI_PM "ilp16" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) -# define LZO_ABI_ILP32 1 -# define LZO_INFO_ABI_PM "ilp32" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) -# define LZO_ABI_LLP64 1 -# define LZO_INFO_ABI_PM "llp64" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -# define LZO_ABI_LP64 1 -# define LZO_INFO_ABI_PM "lp64" -#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) -# define LZO_ABI_ILP64 1 -# define LZO_INFO_ABI_PM "ilp64" -#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) -# define LZO_ABI_IP32L64 1 -# define LZO_INFO_ABI_PM "ip32l64" +#if !defined(LZO_ITRUNC) +# define LZO_ITRUNC(t,e) LZO_STATIC_CAST(t, e) #endif -#if !defined(__LZO_LIBC_OVERRIDE) -#if (LZO_LIBC_NAKED) -# define LZO_INFO_LIBC "naked" -#elif (LZO_LIBC_FREESTANDING) -# define LZO_INFO_LIBC "freestanding" -#elif (LZO_LIBC_MOSTLY_FREESTANDING) -# define LZO_INFO_LIBC "mfreestanding" -#elif (LZO_LIBC_ISOC90) -# define LZO_INFO_LIBC "isoc90" -#elif (LZO_LIBC_ISOC99) -# define LZO_INFO_LIBC "isoc99" -#elif defined(__dietlibc__) -# define LZO_LIBC_DIETLIBC 1 -# define LZO_INFO_LIBC "dietlibc" -#elif defined(_NEWLIB_VERSION) -# define LZO_LIBC_NEWLIB 1 -# define LZO_INFO_LIBC "newlib" -#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) -# if defined(__UCLIBC_SUBLEVEL__) -# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + __UCLIBC_MINOR__ * 0x100 + __UCLIBC_SUBLEVEL__) -# else -# define LZO_LIBC_UCLIBC 0x00090bL +#if !defined(__lzo_cte) +# if (LZO_CC_MSC || LZO_CC_WATCOMC) +# define __lzo_cte(e) ((void)0,(e)) +# elif 1 +# define __lzo_cte(e) ((void)0,(e)) # endif -# define LZO_INFO_LIBC "uclibc" -#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) -# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + __GLIBC_MINOR__ * 0x100) -# define LZO_INFO_LIBC "glibc" -#elif (LZO_CC_MWERKS) && defined(__MSL__) -# define LZO_LIBC_MSL __MSL__ -# define LZO_INFO_LIBC "msl" -#elif 1 && defined(__IAR_SYSTEMS_ICC__) -# define LZO_LIBC_ISOC90 1 -# define LZO_INFO_LIBC "isoc90" -#else -# define LZO_LIBC_DEFAULT 1 -# define LZO_INFO_LIBC "default" -#endif -#endif -#if !defined(__lzo_gnuc_extension__) -#if (LZO_CC_GNUC >= 0x020800ul) -# define __lzo_gnuc_extension__ __extension__ -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_gnuc_extension__ __extension__ -#else -# define __lzo_gnuc_extension__ /*empty*/ -#endif -#endif -#if !defined(__lzo_ua_volatile) -# define __lzo_ua_volatile volatile -#endif -#if !defined(__lzo_alignof) -#if (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) -# define __lzo_alignof(e) __alignof__(e) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) -# define __lzo_alignof(e) __alignof__(e) -#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) -# define __lzo_alignof(e) __alignof(e) -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) -# define __lzo_alignof(e) __alignof__(e) -#endif -#endif -#if defined(__lzo_alignof) -# define __lzo_HAVE_alignof 1 -#endif -#if !defined(__lzo_constructor) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_constructor __attribute__((__constructor__,__used__)) -#elif (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_constructor __attribute__((__constructor__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_constructor __attribute__((__constructor__)) #endif +#if !defined(__lzo_cte) +# define __lzo_cte(e) (e) #endif -#if defined(__lzo_constructor) -# define __lzo_HAVE_constructor 1 +#if !defined(LZO_BLOCK_BEGIN) +# define LZO_BLOCK_BEGIN do { +# define LZO_BLOCK_END } while __lzo_cte(0) #endif -#if !defined(__lzo_destructor) -#if (LZO_CC_GNUC >= 0x030400ul) -# define __lzo_destructor __attribute__((__destructor__,__used__)) -#elif (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_destructor __attribute__((__destructor__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_destructor __attribute__((__destructor__)) +#if !defined(LZO_UNUSED) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED(var) ((void) &var) +# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030200ul)) +# define LZO_UNUSED(var) ((void) &var) +# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_UNUSED(var) ((void) var) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED(var) if (&var) ; else +# elif (LZO_CC_KEILC) +# define LZO_UNUSED(var) {extern int lzo_unused__[1-2*!(sizeof(var)>0)]; (void)lzo_unused__;} +# elif (LZO_CC_PACIFICC) +# define LZO_UNUSED(var) ((void) sizeof(var)) +# elif (LZO_CC_WATCOMC) && defined(__cplusplus) +# define LZO_UNUSED(var) ((void) var) +# else +# define LZO_UNUSED(var) ((void) &var) +# endif #endif +#if !defined(LZO_UNUSED_FUNC) +# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) +# define LZO_UNUSED_FUNC(func) ((void) func) +# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_CLANG || LZO_CC_LLVM) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_MSC && (_MSC_VER < 900)) +# define LZO_UNUSED_FUNC(func) if (func) ; else +# elif (LZO_CC_MSC) +# define LZO_UNUSED_FUNC(func) ((void) &func) +# elif (LZO_CC_KEILC || LZO_CC_PELLESC) +# define LZO_UNUSED_FUNC(func) {extern int lzo_unused__[1-2*!(sizeof((int)func)>0)]; (void)lzo_unused__;} +# else +# define LZO_UNUSED_FUNC(func) ((void) func) +# endif #endif -#if defined(__lzo_destructor) -# define __lzo_HAVE_destructor 1 +#if !defined(LZO_UNUSED_LABEL) +# if (LZO_CC_CLANG >= 0x020800ul) +# define LZO_UNUSED_LABEL(l) (__lzo_gnuc_extension__ ((void) ((const void *) &&l))) +# elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) +# define LZO_UNUSED_LABEL(l) if __lzo_cte(0) goto l +# else +# define LZO_UNUSED_LABEL(l) switch (0) case 1:goto l +# endif #endif -#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) -# error "this should not happen" +#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) +# if 0 +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var +# elif 0 && (LZO_CC_GNUC) +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var +# else +# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init +# endif #endif #if !defined(__lzo_inline) #if (LZO_CC_TURBOC && (__TURBOC__ <= 0x0295)) #elif defined(__cplusplus) # define __lzo_inline inline +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) +# define __lzo_inline inline #elif (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0550)) # define __lzo_inline __inline -#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) # define __lzo_inline __inline__ #elif (LZO_CC_DMC) # define __lzo_inline __inline +#elif (LZO_CC_GHS) +# define __lzo_inline __inline__ +#elif (LZO_CC_IBMC >= 600) +# define __lzo_inline __inline__ #elif (LZO_CC_INTELC) # define __lzo_inline __inline #elif (LZO_CC_MWERKS && (__MWERKS__ >= 0x2405)) # define __lzo_inline __inline #elif (LZO_CC_MSC && (_MSC_VER >= 900)) # define __lzo_inline __inline -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +#elif (LZO_CC_SUNPROC >= 0x5100) # define __lzo_inline __inline__ -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -# define __lzo_inline inline #endif #endif #if defined(__lzo_inline) +# ifndef __lzo_HAVE_inline # define __lzo_HAVE_inline 1 +# endif #else # define __lzo_inline /*empty*/ #endif #if !defined(__lzo_forceinline) #if (LZO_CC_GNUC >= 0x030200ul) # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) +#elif (LZO_CC_IBMC >= 700) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) # define __lzo_forceinline __forceinline -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) #elif (LZO_CC_MSC && (_MSC_VER >= 1200)) # define __lzo_forceinline __forceinline -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +#elif (LZO_CC_PGI >= 0x0d0a00ul) +# define __lzo_forceinline __inline__ __attribute__((__always_inline__)) +#elif (LZO_CC_SUNPROC >= 0x5100) # define __lzo_forceinline __inline__ __attribute__((__always_inline__)) #endif #endif #if defined(__lzo_forceinline) +# ifndef __lzo_HAVE_forceinline # define __lzo_HAVE_forceinline 1 +# endif #else -# define __lzo_forceinline /*empty*/ +# define __lzo_forceinline __lzo_inline #endif #if !defined(__lzo_noinline) #if 1 && (LZO_ARCH_I386) && (LZO_CC_GNUC >= 0x040000ul) && (LZO_CC_GNUC < 0x040003ul) # define __lzo_noinline __attribute__((__noinline__,__used__)) #elif (LZO_CC_GNUC >= 0x030200ul) # define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_MSC) +#elif (LZO_CC_IBMC >= 700) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) # define __lzo_noinline __declspec(noinline) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800) && LZO_CC_SYNTAX_GNUC) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) # define __lzo_noinline __attribute__((__noinline__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_noinline __attribute__((__noinline__)) #elif (LZO_CC_MSC && (_MSC_VER >= 1300)) # define __lzo_noinline __declspec(noinline) @@ -1494,179 +1546,427 @@ # else # define __lzo_noinline __declspec(noinline) # endif -#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC >= 0x5100)) +#elif (LZO_CC_PGI >= 0x0d0a00ul) +# define __lzo_noinline __attribute__((__noinline__)) +#elif (LZO_CC_SUNPROC >= 0x5100) # define __lzo_noinline __attribute__((__noinline__)) #endif #endif #if defined(__lzo_noinline) +# ifndef __lzo_HAVE_noinline # define __lzo_HAVE_noinline 1 +# endif #else # define __lzo_noinline /*empty*/ #endif #if (__lzo_HAVE_forceinline || __lzo_HAVE_noinline) && !(__lzo_HAVE_inline) -# error "this should not happen" +# error "unexpected configuration - check your compiler defines" #endif -#if !defined(__lzo_noreturn) -#if (LZO_CC_GNUC >= 0x020700ul) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) -# define __lzo_noreturn __declspec(noreturn) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define __lzo_noreturn __attribute__((__noreturn__)) -#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) -# define __lzo_noreturn __declspec(noreturn) +#if !defined(__lzo_static_inline) +#if (LZO_CC_IBMC) +# define __lzo_static_inline __lzo_gnuc_extension__ static __lzo_inline #endif #endif -#if defined(__lzo_noreturn) -# define __lzo_HAVE_noreturn 1 -#else -# define __lzo_noreturn /*empty*/ +#if !defined(__lzo_static_inline) +# define __lzo_static_inline static __lzo_inline #endif -#if !defined(__lzo_nothrow) +#if !defined(__lzo_static_forceinline) +#if (LZO_CC_IBMC) +# define __lzo_static_forceinline __lzo_gnuc_extension__ static __lzo_forceinline +#endif +#endif +#if !defined(__lzo_static_forceinline) +# define __lzo_static_forceinline static __lzo_forceinline +#endif +#if !defined(__lzo_static_noinline) +#if (LZO_CC_IBMC) +# define __lzo_static_noinline __lzo_gnuc_extension__ static __lzo_noinline +#endif +#endif +#if !defined(__lzo_static_noinline) +# define __lzo_static_noinline static __lzo_noinline +#endif +#if !defined(__lzo_c99_extern_inline) +#if defined(__GNUC_GNU_INLINE__) +# define __lzo_c99_extern_inline __lzo_inline +#elif defined(__GNUC_STDC_INLINE__) +# define __lzo_c99_extern_inline extern __lzo_inline +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__-0 >= 199901L) +# define __lzo_c99_extern_inline extern __lzo_inline +#endif +#if !defined(__lzo_c99_extern_inline) && (__lzo_HAVE_inline) +# define __lzo_c99_extern_inline __lzo_inline +#endif +#endif +#if defined(__lzo_c99_extern_inline) +# ifndef __lzo_HAVE_c99_extern_inline +# define __lzo_HAVE_c99_extern_inline 1 +# endif +#else +# define __lzo_c99_extern_inline /*empty*/ +#endif +#if !defined(__lzo_may_alias) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_may_alias __attribute__((__may_alias__)) +#elif (LZO_CC_CLANG >= 0x020900ul) +# define __lzo_may_alias __attribute__((__may_alias__)) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1210)) && 0 +# define __lzo_may_alias __attribute__((__may_alias__)) +#elif (LZO_CC_PGI >= 0x0d0a00ul) && 0 +# define __lzo_may_alias __attribute__((__may_alias__)) +#endif +#endif +#if defined(__lzo_may_alias) +# ifndef __lzo_HAVE_may_alias +# define __lzo_HAVE_may_alias 1 +# endif +#else +# define __lzo_may_alias /*empty*/ +#endif +#if !defined(__lzo_noreturn) +#if (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_IBMC >= 700) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) +# define __lzo_noreturn __declspec(noreturn) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_noreturn __attribute__((__noreturn__)) +#elif (LZO_CC_MSC && (_MSC_VER >= 1200)) +# define __lzo_noreturn __declspec(noreturn) +#elif (LZO_CC_PGI >= 0x0d0a00ul) +# define __lzo_noreturn __attribute__((__noreturn__)) +#endif +#endif +#if defined(__lzo_noreturn) +# ifndef __lzo_HAVE_noreturn +# define __lzo_HAVE_noreturn 1 +# endif +#else +# define __lzo_noreturn /*empty*/ +#endif +#if !defined(__lzo_nothrow) #if (LZO_CC_GNUC >= 0x030300ul) # define __lzo_nothrow __attribute__((__nothrow__)) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 450) && LZO_CC_SYNTAX_MSC) && defined(__cplusplus) +#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 450)) && defined(__cplusplus) # define __lzo_nothrow __declspec(nothrow) -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 900) && LZO_CC_SYNTAX_GNUC) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 900)) # define __lzo_nothrow __attribute__((__nothrow__)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_nothrow __attribute__((__nothrow__)) #elif (LZO_CC_MSC && (_MSC_VER >= 1200)) && defined(__cplusplus) # define __lzo_nothrow __declspec(nothrow) #endif #endif #if defined(__lzo_nothrow) +# ifndef __lzo_HAVE_nothrow # define __lzo_HAVE_nothrow 1 +# endif #else # define __lzo_nothrow /*empty*/ #endif #if !defined(__lzo_restrict) #if (LZO_CC_GNUC >= 0x030400ul) # define __lzo_restrict __restrict__ -#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 600) && LZO_CC_SYNTAX_GNUC) +#elif (LZO_CC_IBMC >= 800) && !defined(__cplusplus) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_IBMC >= 1210) +# define __lzo_restrict __restrict__ +#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 600)) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 600)) # define __lzo_restrict __restrict__ -#elif (LZO_CC_CLANG || LZO_CC_LLVM) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM) # define __lzo_restrict __restrict__ #elif (LZO_CC_MSC && (_MSC_VER >= 1400)) # define __lzo_restrict __restrict +#elif (LZO_CC_PGI >= 0x0d0a00ul) +# define __lzo_restrict __restrict__ #endif #endif #if defined(__lzo_restrict) +# ifndef __lzo_HAVE_restrict # define __lzo_HAVE_restrict 1 +# endif #else # define __lzo_restrict /*empty*/ #endif +#if !defined(__lzo_alignof) +#if (LZO_CC_ARMCC || LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_GHS) && !defined(__cplusplus) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_IBMC >= 600) +# define __lzo_alignof(e) (__lzo_gnuc_extension__ __alignof__(e)) +#elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 700)) +# define __lzo_alignof(e) __alignof__(e) +#elif (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_alignof(e) __alignof(e) +#elif (LZO_CC_SUNPROC >= 0x5100) +# define __lzo_alignof(e) __alignof__(e) +#endif +#endif +#if defined(__lzo_alignof) +# ifndef __lzo_HAVE_alignof +# define __lzo_HAVE_alignof 1 +# endif +#endif +#if !defined(__lzo_struct_packed) +#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) +#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) +#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) +#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) +#elif (LZO_CC_GNUC >= 0x030400ul) && !(LZO_CC_PCC_GNUC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) +# define __lzo_struct_packed(s) struct s { +# define __lzo_struct_packed_end() } __attribute__((__gcc_struct__,__packed__)); +# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__gcc_struct__,__packed__)); +#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_struct_packed(s) struct s { +# define __lzo_struct_packed_end() } __attribute__((__packed__)); +# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); +#elif (LZO_CC_IBMC >= 700) +# define __lzo_struct_packed(s) __lzo_gnuc_extension__ struct s { +# define __lzo_struct_packed_end() } __attribute__((__packed__)); +# define __lzo_struct_packed_ma_end() } __lzo_may_alias __attribute__((__packed__)); +#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_struct_packed(s) __pragma(pack(push,1)) struct s { +# define __lzo_struct_packed_end() } __pragma(pack(pop)); +#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) +# define __lzo_struct_packed(s) _Packed struct s { +# define __lzo_struct_packed_end() }; +#endif +#endif +#if defined(__lzo_struct_packed) && !defined(__lzo_struct_packed_ma) +# define __lzo_struct_packed_ma(s) __lzo_struct_packed(s) +#endif +#if defined(__lzo_struct_packed_end) && !defined(__lzo_struct_packed_ma_end) +# define __lzo_struct_packed_ma_end() __lzo_struct_packed_end() +#endif +#if !defined(__lzo_byte_struct) +#if defined(__lzo_struct_packed) +# define __lzo_byte_struct(s,n) __lzo_struct_packed(s) unsigned char a[n]; __lzo_struct_packed_end() +# define __lzo_byte_struct_ma(s,n) __lzo_struct_packed_ma(s) unsigned char a[n]; __lzo_struct_packed_ma_end() +#elif (LZO_CC_CILLY || LZO_CC_CLANG || LZO_CC_PGI || (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_byte_struct(s,n) struct s { unsigned char a[n]; } __attribute__((__packed__)); +# define __lzo_byte_struct_ma(s,n) struct s { unsigned char a[n]; } __lzo_may_alias __attribute__((__packed__)); +#endif +#endif +#if defined(__lzo_byte_struct) && !defined(__lzo_byte_struct_ma) +# define __lzo_byte_struct_ma(s,n) __lzo_byte_struct(s,n) +#endif +#if !defined(__lzo_struct_align16) && (__lzo_HAVE_alignof) +#if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x030000ul)) +#elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) +#elif (LZO_CC_CILLY || LZO_CC_PCC) +#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_struct_align16(s) struct __declspec(align(16)) s { +# define __lzo_struct_align16_end() }; +# define __lzo_struct_align32(s) struct __declspec(align(32)) s { +# define __lzo_struct_align32_end() }; +# define __lzo_struct_align64(s) struct __declspec(align(64)) s { +# define __lzo_struct_align64_end() }; +#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || (LZO_CC_IBMC >= 700) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_struct_align16(s) struct s { +# define __lzo_struct_align16_end() } __attribute__((__aligned__(16))); +# define __lzo_struct_align32(s) struct s { +# define __lzo_struct_align32_end() } __attribute__((__aligned__(32))); +# define __lzo_struct_align64(s) struct s { +# define __lzo_struct_align64_end() } __attribute__((__aligned__(64))); +#endif +#endif +#if !defined(__lzo_union_um) +#if (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020800ul)) && defined(__cplusplus) +#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020700ul)) +#elif (LZO_CC_GNUC && (LZO_CC_GNUC < 0x020800ul)) && defined(__cplusplus) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER < 810)) +#elif (LZO_CC_PCC && (LZO_CC_PCC < 0x010100ul)) +#elif (LZO_CC_SUNPROC && (LZO_CC_SUNPROC < 0x5110)) && !defined(__cplusplus) +#elif (LZO_CC_ARMCC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || (LZO_CC_PGI >= 0x0d0a00ul) || (LZO_CC_SUNPROC >= 0x5100)) +# define __lzo_union_am(s) union s { +# define __lzo_union_am_end() } __lzo_may_alias; +# define __lzo_union_um(s) union s { +# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); +#elif (LZO_CC_IBMC >= 700) +# define __lzo_union_am(s) __lzo_gnuc_extension__ union s { +# define __lzo_union_am_end() } __lzo_may_alias; +# define __lzo_union_um(s) __lzo_gnuc_extension__ union s { +# define __lzo_union_um_end() } __lzo_may_alias __attribute__((__packed__)); +#elif (LZO_CC_INTELC_MSC) || (LZO_CC_MSC && (_MSC_VER >= 1300)) +# define __lzo_union_um(s) __pragma(pack(push,1)) union s { +# define __lzo_union_um_end() } __pragma(pack(pop)); +#elif (LZO_CC_WATCOMC && (__WATCOMC__ >= 900)) +# define __lzo_union_um(s) _Packed union s { +# define __lzo_union_um_end() }; +#endif +#endif +#if !defined(__lzo_union_am) +# define __lzo_union_am(s) union s { +# define __lzo_union_am_end() }; +#endif +#if !defined(__lzo_constructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_constructor __attribute__((__constructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_constructor __attribute__((__constructor__)) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) +# define __lzo_constructor __attribute__((__constructor__,__used__)) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_constructor __attribute__((__constructor__)) +#endif +#endif +#if defined(__lzo_constructor) +# ifndef __lzo_HAVE_constructor +# define __lzo_HAVE_constructor 1 +# endif +#endif +#if !defined(__lzo_destructor) +#if (LZO_CC_GNUC >= 0x030400ul) +# define __lzo_destructor __attribute__((__destructor__,__used__)) +#elif (LZO_CC_GNUC >= 0x020700ul) +# define __lzo_destructor __attribute__((__destructor__)) +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 800)) +# define __lzo_destructor __attribute__((__destructor__,__used__)) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define __lzo_destructor __attribute__((__destructor__)) +#endif +#endif +#if defined(__lzo_destructor) +# ifndef __lzo_HAVE_destructor +# define __lzo_HAVE_destructor 1 +# endif +#endif +#if (__lzo_HAVE_destructor) && !(__lzo_HAVE_constructor) +# error "unexpected configuration - check your compiler defines" +#endif #if !defined(__lzo_likely) && !defined(__lzo_unlikely) #if (LZO_CC_GNUC >= 0x030200ul) # define __lzo_likely(e) (__builtin_expect(!!(e),1)) # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) +#elif (LZO_CC_IBMC >= 1010) +# define __lzo_likely(e) (__builtin_expect(!!(e),1)) +# define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) #elif (LZO_CC_INTELC && (__INTEL_COMPILER >= 800)) # define __lzo_likely(e) (__builtin_expect(!!(e),1)) # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) -#elif (LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_LLVM || LZO_CC_PATHSCALE) # define __lzo_likely(e) (__builtin_expect(!!(e),1)) # define __lzo_unlikely(e) (__builtin_expect(!!(e),0)) #endif #endif #if defined(__lzo_likely) +# ifndef __lzo_HAVE_likely # define __lzo_HAVE_likely 1 +# endif #else -# define __lzo_likely(e) (e) +# define __lzo_likely(e) (e) +#endif +#if defined(__lzo_very_likely) +# ifndef __lzo_HAVE_very_likely +# define __lzo_HAVE_very_likely 1 +# endif +#else +# define __lzo_very_likely(e) __lzo_likely(e) #endif #if defined(__lzo_unlikely) +# ifndef __lzo_HAVE_unlikely # define __lzo_HAVE_unlikely 1 +# endif #else -# define __lzo_unlikely(e) (e) +# define __lzo_unlikely(e) (e) #endif -#if !defined(LZO_UNUSED) -# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) -# define LZO_UNUSED(var) ((void) &var) -# elif (LZO_CC_BORLANDC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PELLESC || LZO_CC_TURBOC) -# define LZO_UNUSED(var) if (&var) ; else -# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNUSED(var) ((void) var) -# elif (LZO_CC_MSC && (_MSC_VER < 900)) -# define LZO_UNUSED(var) if (&var) ; else -# elif (LZO_CC_KEILC) -# define LZO_UNUSED(var) {extern int __lzo_unused[1-2*!(sizeof(var)>0)];} -# elif (LZO_CC_PACIFICC) -# define LZO_UNUSED(var) ((void) sizeof(var)) -# elif (LZO_CC_WATCOMC) && defined(__cplusplus) -# define LZO_UNUSED(var) ((void) var) -# else -# define LZO_UNUSED(var) ((void) &var) +#if defined(__lzo_very_unlikely) +# ifndef __lzo_HAVE_very_unlikely +# define __lzo_HAVE_very_unlikely 1 # endif +#else +# define __lzo_very_unlikely(e) __lzo_unlikely(e) #endif -#if !defined(LZO_UNUSED_FUNC) -# if (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0600)) -# define LZO_UNUSED_FUNC(func) ((void) func) -# elif (LZO_CC_BORLANDC || LZO_CC_NDPC || LZO_CC_TURBOC) -# define LZO_UNUSED_FUNC(func) if (func) ; else -# elif (LZO_CC_CLANG || LZO_CC_LLVM) -# define LZO_UNUSED_FUNC(func) ((void) &func) -# elif (LZO_CC_MSC && (_MSC_VER < 900)) -# define LZO_UNUSED_FUNC(func) if (func) ; else -# elif (LZO_CC_MSC) -# define LZO_UNUSED_FUNC(func) ((void) &func) -# elif (LZO_CC_KEILC || LZO_CC_PELLESC) -# define LZO_UNUSED_FUNC(func) {extern int __lzo_unused[1-2*!(sizeof((int)func)>0)];} +#if !defined(__lzo_loop_forever) +# if (LZO_CC_IBMC) +# define __lzo_loop_forever() LZO_BLOCK_BEGIN for (;;) { ; } LZO_BLOCK_END # else -# define LZO_UNUSED_FUNC(func) ((void) func) +# define __lzo_loop_forever() do { ; } while __lzo_cte(1) # endif #endif -#if !defined(LZO_UNUSED_LABEL) -# if (LZO_CC_WATCOMC) && defined(__cplusplus) -# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l -# elif (LZO_CC_CLANG || LZO_CC_INTELC || LZO_CC_WATCOMC) -# define LZO_UNUSED_LABEL(l) if (0) goto l -# else -# define LZO_UNUSED_LABEL(l) switch(0) case 1:goto l -# endif +#if !defined(__lzo_unreachable) +#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x020800ul)) && lzo_has_builtin(__builtin_unreachable) +# define __lzo_unreachable() __builtin_unreachable(); +#elif (LZO_CC_GNUC >= 0x040500ul) +# define __lzo_unreachable() __builtin_unreachable(); +#elif (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1300)) && 1 +# define __lzo_unreachable() __builtin_unreachable(); #endif -#if !defined(LZO_DEFINE_UNINITIALIZED_VAR) +#endif +#if defined(__lzo_unreachable) +# ifndef __lzo_HAVE_unreachable +# define __lzo_HAVE_unreachable 1 +# endif +#else # if 0 -# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var -# elif 0 && (LZO_CC_GNUC) -# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = var +# define __lzo_unreachable() ((void)0); # else -# define LZO_DEFINE_UNINITIALIZED_VAR(type,var,init) type var = init +# define __lzo_unreachable() __lzo_loop_forever(); # endif #endif -#if !defined(LZO_UNCONST_CAST) -# if 0 && defined(__cplusplus) -# define LZO_UNCONST_CAST(t,e) (const_cast (e)) -# elif (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) -# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((lzo_uintptr_t) ((const void *) (e)))))) +#if !defined(lzo_unused_funcs_impl) +# if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) +# define lzo_unused_funcs_impl(r,f) static r __attribute__((__unused__)) f +# elif 1 && (LZO_CC_BORLANDC || LZO_CC_GNUC) +# define lzo_unused_funcs_impl(r,f) static r f # else -# define LZO_UNCONST_CAST(t,e) ((t) ((void *) ((char *) ((const void *) (e))))) +# define lzo_unused_funcs_impl(r,f) __lzo_static_forceinline r f # endif #endif +#ifndef __LZO_CTA_NAME +#if (LZO_CFG_USE_COUNTER) +# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__COUNTER__) +#else +# define __LZO_CTA_NAME(a) LZO_PP_ECONCAT2(a,__LINE__) +#endif +#endif #if !defined(LZO_COMPILE_TIME_ASSERT_HEADER) # if (LZO_CC_AZTECC || LZO_CC_ZORTECHC) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END # elif (LZO_CC_DMC || LZO_CC_SYMANTECC) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1u-2*!(e)]; +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1u-2*!(e)]; LZO_EXTERN_C_END # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-!(e)]; +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-!(e)]; LZO_EXTERN_C_END +# elif (LZO_CC_CLANG && (LZO_CC_CLANG < 0x020900ul)) && defined(__cplusplus) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN int __LZO_CTA_NAME(lzo_cta_f__)(int [1-2*!(e)]); LZO_EXTERN_C_END +# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__)); LZO_EXTERN_C_END # else -# define LZO_COMPILE_TIME_ASSERT_HEADER(e) extern int __lzo_cta[1-2*!(e)]; +# define LZO_COMPILE_TIME_ASSERT_HEADER(e) LZO_EXTERN_C_BEGIN extern int __LZO_CTA_NAME(lzo_cta__)[1-2*!(e)]; LZO_EXTERN_C_END # endif #endif #if !defined(LZO_COMPILE_TIME_ASSERT) # if (LZO_CC_AZTECC) -# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-!(e)];} +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-!(e)];} +# elif (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030000ul)) +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)] __attribute__((__unused__));} # elif (LZO_CC_DMC || LZO_CC_PACIFICC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; +# elif (LZO_CC_GNUC) && defined(__CHECKER__) && defined(__SPARSE_CHECKER__) +# define LZO_COMPILE_TIME_ASSERT(e) {(void) (0/!!(e));} +# elif (LZO_CC_GNUC >= 0x040700ul) && (LZO_CFG_USE_COUNTER) && defined(__cplusplus) +# define LZO_COMPILE_TIME_ASSERT(e) {enum {__LZO_CTA_NAME(lzo_cta_e__)=1/!!(e)} __attribute__((__unused__));} +# elif (LZO_CC_GNUC >= 0x040700ul) +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)] __attribute__((__unused__));} # elif (LZO_CC_MSC && (_MSC_VER < 900)) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; # elif (LZO_CC_TURBOC && (__TURBOC__ == 0x0295)) # define LZO_COMPILE_TIME_ASSERT(e) switch(0) case 1:case !(e):break; # else -# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __lzo_cta_t[1-2*!(e)];} +# define LZO_COMPILE_TIME_ASSERT(e) {typedef int __LZO_CTA_NAME(lzo_cta_t__)[1-2*!(e)];} # endif #endif +LZO_COMPILE_TIME_ASSERT_HEADER(1 == 1) +#if defined(__cplusplus) +extern "C" { LZO_COMPILE_TIME_ASSERT_HEADER(2 == 2) } +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(3 == 3) #if (LZO_ARCH_I086 || LZO_ARCH_I386) && (LZO_OS_DOS16 || LZO_OS_DOS32 || LZO_OS_OS2 || LZO_OS_OS216 || LZO_OS_WIN16 || LZO_OS_WIN32 || LZO_OS_WIN64) # if (LZO_CC_GNUC || LZO_CC_HIGHC || LZO_CC_NDPC || LZO_CC_PACIFICC) # elif (LZO_CC_DMC || LZO_CC_SYMANTECC || LZO_CC_ZORTECHC) @@ -1730,69 +2030,637 @@ # define __lzo_cdecl_va __lzo_cdecl #endif #if !(LZO_CFG_NO_WINDOWS_H) +#if !defined(LZO_HAVE_WINDOWS_H) #if (LZO_OS_CYGWIN || (LZO_OS_EMX && defined(__RSXNT__)) || LZO_OS_WIN32 || LZO_OS_WIN64) # if (LZO_CC_WATCOMC && (__WATCOMC__ < 1000)) -# elif (LZO_OS_WIN32 && LZO_CC_GNUC) && defined(__PW32__) +# elif ((LZO_OS_WIN32 && defined(__PW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x030000ul))) # elif ((LZO_OS_CYGWIN || defined(__MINGW32__)) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x025f00ul))) # else # define LZO_HAVE_WINDOWS_H 1 # endif #endif #endif -#if (LZO_ARCH_ALPHA) -# define LZO_OPT_AVOID_UINT_INDEX 1 -# define LZO_OPT_AVOID_SHORT 1 -# define LZO_OPT_AVOID_USHORT 1 -#elif (LZO_ARCH_AMD64) -# define LZO_OPT_AVOID_INT_INDEX 1 -# define LZO_OPT_AVOID_UINT_INDEX 1 -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 -# define LZO_OPT_UNALIGNED64 1 -#elif (LZO_ARCH_ARM && LZO_ARCH_ARM_THUMB) -#elif (LZO_ARCH_ARM) -# define LZO_OPT_AVOID_SHORT 1 -# define LZO_OPT_AVOID_USHORT 1 +#endif +#ifndef LZO_SIZEOF_SHORT +#if defined(SIZEOF_SHORT) +# define LZO_SIZEOF_SHORT (SIZEOF_SHORT) +#elif defined(__SIZEOF_SHORT__) +# define LZO_SIZEOF_SHORT (__SIZEOF_SHORT__) +#endif +#endif +#ifndef LZO_SIZEOF_INT +#if defined(SIZEOF_INT) +# define LZO_SIZEOF_INT (SIZEOF_INT) +#elif defined(__SIZEOF_INT__) +# define LZO_SIZEOF_INT (__SIZEOF_INT__) +#endif +#endif +#ifndef LZO_SIZEOF_LONG +#if defined(SIZEOF_LONG) +# define LZO_SIZEOF_LONG (SIZEOF_LONG) +#elif defined(__SIZEOF_LONG__) +# define LZO_SIZEOF_LONG (__SIZEOF_LONG__) +#endif +#endif +#ifndef LZO_SIZEOF_LONG_LONG +#if defined(SIZEOF_LONG_LONG) +# define LZO_SIZEOF_LONG_LONG (SIZEOF_LONG_LONG) +#elif defined(__SIZEOF_LONG_LONG__) +# define LZO_SIZEOF_LONG_LONG (__SIZEOF_LONG_LONG__) +#endif +#endif +#ifndef LZO_SIZEOF___INT16 +#if defined(SIZEOF___INT16) +# define LZO_SIZEOF___INT16 (SIZEOF___INT16) +#endif +#endif +#ifndef LZO_SIZEOF___INT32 +#if defined(SIZEOF___INT32) +# define LZO_SIZEOF___INT32 (SIZEOF___INT32) +#endif +#endif +#ifndef LZO_SIZEOF___INT64 +#if defined(SIZEOF___INT64) +# define LZO_SIZEOF___INT64 (SIZEOF___INT64) +#endif +#endif +#ifndef LZO_SIZEOF_VOID_P +#if defined(SIZEOF_VOID_P) +# define LZO_SIZEOF_VOID_P (SIZEOF_VOID_P) +#elif defined(__SIZEOF_POINTER__) +# define LZO_SIZEOF_VOID_P (__SIZEOF_POINTER__) +#endif +#endif +#ifndef LZO_SIZEOF_SIZE_T +#if defined(SIZEOF_SIZE_T) +# define LZO_SIZEOF_SIZE_T (SIZEOF_SIZE_T) +#elif defined(__SIZEOF_SIZE_T__) +# define LZO_SIZEOF_SIZE_T (__SIZEOF_SIZE_T__) +#endif +#endif +#ifndef LZO_SIZEOF_PTRDIFF_T +#if defined(SIZEOF_PTRDIFF_T) +# define LZO_SIZEOF_PTRDIFF_T (SIZEOF_PTRDIFF_T) +#elif defined(__SIZEOF_PTRDIFF_T__) +# define LZO_SIZEOF_PTRDIFF_T (__SIZEOF_PTRDIFF_T__) +#endif +#endif +#define __LZO_LSR(x,b) (((x)+0ul) >> (b)) +#if !defined(LZO_SIZEOF_SHORT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_SHORT 8 +# elif (USHRT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,7) == 1) +# define LZO_SIZEOF_SHORT 1 +# elif (__LZO_LSR(USHRT_MAX,15) == 1) +# define LZO_SIZEOF_SHORT 2 +# elif (__LZO_LSR(USHRT_MAX,31) == 1) +# define LZO_SIZEOF_SHORT 4 +# elif (__LZO_LSR(USHRT_MAX,63) == 1) +# define LZO_SIZEOF_SHORT 8 +# elif (__LZO_LSR(USHRT_MAX,127) == 1) +# define LZO_SIZEOF_SHORT 16 +# else +# error "LZO_SIZEOF_SHORT" +# endif +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SHORT == sizeof(short)) +#if !defined(LZO_SIZEOF_INT) +# if (LZO_ARCH_CRAY_PVP) +# define LZO_SIZEOF_INT 8 +# elif (UINT_MAX == LZO_0xffffL) +# define LZO_SIZEOF_INT 2 +# elif (UINT_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,7) == 1) +# define LZO_SIZEOF_INT 1 +# elif (__LZO_LSR(UINT_MAX,15) == 1) +# define LZO_SIZEOF_INT 2 +# elif (__LZO_LSR(UINT_MAX,31) == 1) +# define LZO_SIZEOF_INT 4 +# elif (__LZO_LSR(UINT_MAX,63) == 1) +# define LZO_SIZEOF_INT 8 +# elif (__LZO_LSR(UINT_MAX,127) == 1) +# define LZO_SIZEOF_INT 16 +# else +# error "LZO_SIZEOF_INT" +# endif +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_INT == sizeof(int)) +#if !defined(LZO_SIZEOF_LONG) +# if (ULONG_MAX == LZO_0xffffffffL) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,7) == 1) +# define LZO_SIZEOF_LONG 1 +# elif (__LZO_LSR(ULONG_MAX,15) == 1) +# define LZO_SIZEOF_LONG 2 +# elif (__LZO_LSR(ULONG_MAX,31) == 1) +# define LZO_SIZEOF_LONG 4 +# elif (__LZO_LSR(ULONG_MAX,39) == 1) +# define LZO_SIZEOF_LONG 5 +# elif (__LZO_LSR(ULONG_MAX,63) == 1) +# define LZO_SIZEOF_LONG 8 +# elif (__LZO_LSR(ULONG_MAX,127) == 1) +# define LZO_SIZEOF_LONG 16 +# else +# error "LZO_SIZEOF_LONG" +# endif +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_LONG == sizeof(long)) +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +# if defined(__LONG_MAX__) && defined(__LONG_LONG_MAX__) +# if (LZO_CC_GNUC >= 0x030300ul) +# if ((__LONG_MAX__-0) == (__LONG_LONG_MAX__-0)) +# define LZO_SIZEOF_LONG_LONG LZO_SIZEOF_LONG +# elif (__LZO_LSR(__LONG_LONG_MAX__,30) == 1) +# define LZO_SIZEOF_LONG_LONG 4 +# endif +# endif +# endif +#endif +#endif +#if !defined(LZO_SIZEOF_LONG_LONG) && !defined(LZO_SIZEOF___INT64) +#if (LZO_SIZEOF_LONG > 0 && LZO_SIZEOF_LONG < 8) +#if (LZO_ARCH_I086 && LZO_CC_DMC) +#elif (LZO_CC_CILLY) && defined(__GNUC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE) +# define LZO_SIZEOF_LONG_LONG 8 +#elif ((LZO_OS_WIN32 || LZO_OS_WIN64 || defined(_WIN32)) && LZO_CC_MSC && (_MSC_VER >= 1400)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_OS_WIN64 || defined(_WIN64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_DMC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_SYMANTECC && (__SC__ >= 0x700))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC && defined(__linux__))) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_MWERKS || LZO_CC_PELLESC || LZO_CC_PGI || LZO_CC_SUNPROC)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_ARCH_I386 && (LZO_CC_INTELC || LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif ((LZO_OS_WIN32 || defined(_WIN32)) && (LZO_CC_MSC)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_BORLANDC && (__BORLANDC__ >= 0x0520))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_ARCH_I386 && (LZO_CC_WATCOMC && (__WATCOMC__ >= 1100))) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_CC_GHS && defined(__LLONG_BIT) && ((__LLONG_BIT-0) == 64)) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_WATCOMC && defined(_INTEGRAL_MAX_BITS) && ((_INTEGRAL_MAX_BITS-0) == 64)) +# define LZO_SIZEOF___INT64 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) && defined(__LLP64_IFC__) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (defined(__vms) || defined(__VMS)) && ((__INITIAL_POINTER_SIZE-0) == 64) +# define LZO_SIZEOF_LONG_LONG 8 +#elif (LZO_CC_SDCC) && (LZO_SIZEOF_INT == 2) +#elif 1 && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +# define LZO_SIZEOF_LONG_LONG 8 +#endif +#endif +#endif +#if defined(__cplusplus) && (LZO_CC_GNUC) +# if (LZO_CC_GNUC < 0x020800ul) +# undef LZO_SIZEOF_LONG_LONG +# endif +#endif +#if (LZO_CFG_NO_LONG_LONG) +# undef LZO_SIZEOF_LONG_LONG +#elif defined(__NO_LONG_LONG) +# undef LZO_SIZEOF_LONG_LONG +#elif defined(_NO_LONGLONG) +# undef LZO_SIZEOF_LONG_LONG +#endif +#if !defined(LZO_WORDSIZE) +#if (LZO_ARCH_ALPHA) +# define LZO_WORDSIZE 8 +#elif (LZO_ARCH_AMD64) +# define LZO_WORDSIZE 8 +#elif (LZO_ARCH_AVR) +# define LZO_WORDSIZE 1 +#elif (LZO_ARCH_H8300) +# if defined(__NORMAL_MODE__) +# define LZO_WORDSIZE 4 +# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define LZO_WORDSIZE 4 +# else +# define LZO_WORDSIZE 2 +# endif +#elif (LZO_ARCH_I086) +# define LZO_WORDSIZE 2 +#elif (LZO_ARCH_IA64) +# define LZO_WORDSIZE 8 +#elif (LZO_ARCH_M16C) +# define LZO_WORDSIZE 2 +#elif (LZO_ARCH_SPU) +# define LZO_WORDSIZE 4 +#elif (LZO_ARCH_Z80) +# define LZO_WORDSIZE 1 +#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define LZO_WORDSIZE 8 +#elif (LZO_OS_OS400 || defined(__OS400__)) +# define LZO_WORDSIZE 8 +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_WORDSIZE 8 +#endif +#endif +#if !defined(LZO_SIZEOF_VOID_P) +#if defined(__ILP32__) || defined(__ILP32) || defined(_ILP32) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 4) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) +# define LZO_SIZEOF_VOID_P 4 +#elif defined(__ILP64__) || defined(__ILP64) || defined(_ILP64) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) == 8) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) +# define LZO_SIZEOF_VOID_P 8 +#elif defined(__LLP64__) || defined(__LLP64) || defined(_LLP64) || defined(_WIN64) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 4) +# define LZO_SIZEOF_VOID_P 8 +#elif defined(__LP64__) || defined(__LP64) || defined(_LP64) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long) == 8) +# define LZO_SIZEOF_VOID_P 8 +#elif (LZO_ARCH_AVR) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_C166 || LZO_ARCH_MCS51 || LZO_ARCH_MCS251 || LZO_ARCH_MSP430) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_ARCH_H8300) +# if defined(__NORMAL_MODE__) +# define LZO_SIZEOF_VOID_P 2 +# elif defined(__H8300H__) || defined(__H8300S__) || defined(__H8300SX__) +# define LZO_SIZEOF_VOID_P 4 +# else +# define LZO_SIZEOF_VOID_P 2 +# endif +# if (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_SIZEOF_INT == 4) +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_INT +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_INT +# endif +#elif (LZO_ARCH_I086) +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM) +# define LZO_SIZEOF_VOID_P 2 +# elif (LZO_MM_COMPACT || LZO_MM_LARGE || LZO_MM_HUGE) +# define LZO_SIZEOF_VOID_P 4 +# else +# error "invalid LZO_ARCH_I086 memory model" +# endif +#elif (LZO_ARCH_M16C) +# if defined(__m32c_cpu__) || defined(__m32cm_cpu__) +# define LZO_SIZEOF_VOID_P 4 +# else +# define LZO_SIZEOF_VOID_P 2 +# endif +#elif (LZO_ARCH_SPU) +# define LZO_SIZEOF_VOID_P 4 +#elif (LZO_ARCH_Z80) +# define LZO_SIZEOF_VOID_P 2 +#elif (LZO_SIZEOF_LONG == 8) && ((defined(__mips__) && defined(__R5900__)) || defined(__MIPS_PSX2__)) +# define LZO_SIZEOF_VOID_P 4 +#elif (LZO_OS_OS400 || defined(__OS400__)) +# if defined(__LLP64_IFC__) +# define LZO_SIZEOF_VOID_P 8 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +# else +# define LZO_SIZEOF_VOID_P 16 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +# endif +#elif (defined(__vms) || defined(__VMS)) && (__INITIAL_POINTER_SIZE+0 == 64) +# define LZO_SIZEOF_VOID_P 8 +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_LONG +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_LONG +#endif +#endif +#if !defined(LZO_SIZEOF_VOID_P) +# define LZO_SIZEOF_VOID_P LZO_SIZEOF_LONG +#endif +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_VOID_P == sizeof(void *)) +#if !defined(LZO_SIZEOF_SIZE_T) +#if (LZO_ARCH_I086 || LZO_ARCH_M16C) +# define LZO_SIZEOF_SIZE_T 2 +#endif +#endif +#if !defined(LZO_SIZEOF_SIZE_T) +# define LZO_SIZEOF_SIZE_T LZO_SIZEOF_VOID_P +#endif +#if defined(offsetof) +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_SIZE_T == sizeof(size_t)) +#endif +#if !defined(LZO_SIZEOF_PTRDIFF_T) +#if (LZO_ARCH_I086) +# if (LZO_MM_TINY || LZO_MM_SMALL || LZO_MM_MEDIUM || LZO_MM_HUGE) +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_VOID_P +# elif (LZO_MM_COMPACT || LZO_MM_LARGE) +# if (LZO_CC_BORLANDC || LZO_CC_TURBOC) +# define LZO_SIZEOF_PTRDIFF_T 4 +# else +# define LZO_SIZEOF_PTRDIFF_T 2 +# endif +# else +# error "invalid LZO_ARCH_I086 memory model" +# endif +#endif +#endif +#if !defined(LZO_SIZEOF_PTRDIFF_T) +# define LZO_SIZEOF_PTRDIFF_T LZO_SIZEOF_SIZE_T +#endif +#if defined(offsetof) +LZO_COMPILE_TIME_ASSERT_HEADER(LZO_SIZEOF_PTRDIFF_T == sizeof(ptrdiff_t)) +#endif +#if !defined(LZO_WORDSIZE) +# define LZO_WORDSIZE LZO_SIZEOF_VOID_P +#endif +#if (LZO_ABI_NEUTRAL_ENDIAN) +# undef LZO_ABI_BIG_ENDIAN +# undef LZO_ABI_LITTLE_ENDIAN +#elif !(LZO_ABI_BIG_ENDIAN) && !(LZO_ABI_LITTLE_ENDIAN) +#if (LZO_ARCH_ALPHA) && (LZO_ARCH_CRAY_MPP) +# define LZO_ABI_BIG_ENDIAN 1 +#elif (LZO_ARCH_IA64) && (LZO_OS_POSIX_LINUX || LZO_OS_WIN64) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_ALPHA || LZO_ARCH_AMD64 || LZO_ARCH_BLACKFIN || LZO_ARCH_CRIS || LZO_ARCH_I086 || LZO_ARCH_I386 || LZO_ARCH_MSP430) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif (LZO_ARCH_AVR32 || LZO_ARCH_M68K || LZO_ARCH_S390 || LZO_ARCH_SPU) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__IAR_SYSTEMS_ICC__) && defined(__LITTLE_ENDIAN__) +# if (__LITTLE_ENDIAN__ == 1) +# define LZO_ABI_LITTLE_ENDIAN 1 +# else +# define LZO_ABI_BIG_ENDIAN 1 +# endif +#elif 1 && defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARM_BIG_ENDIAN) && ((__ARM_BIG_ENDIAN)+0) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEB__) && !defined(__ARMEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM) && defined(__ARMEL__) && !defined(__ARMEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM && LZO_CC_ARMCC_ARMCC) +# if defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN) +# error "unexpected configuration - check your compiler defines" +# elif defined(__BIG_ENDIAN) +# define LZO_ABI_BIG_ENDIAN 1 +# else +# define LZO_ABI_LITTLE_ENDIAN 1 +# endif +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM64) && defined(__ARM_BIG_ENDIAN) && ((__ARM_BIG_ENDIAN)+0) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EB__) && !defined(__AARCH64EL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_ARM64) && defined(__AARCH64EL__) && !defined(__AARCH64EB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEB__) && !defined(__MIPSEL__) +# define LZO_ABI_BIG_ENDIAN 1 +#elif 1 && (LZO_ARCH_MIPS) && defined(__MIPSEL__) && !defined(__MIPSEB__) +# define LZO_ABI_LITTLE_ENDIAN 1 +#endif +#endif +#if (LZO_ABI_BIG_ENDIAN) && (LZO_ABI_LITTLE_ENDIAN) +# error "unexpected configuration - check your compiler defines" +#endif +#if (LZO_ABI_BIG_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "be" +#elif (LZO_ABI_LITTLE_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "le" +#elif (LZO_ABI_NEUTRAL_ENDIAN) +# define LZO_INFO_ABI_ENDIAN "neutral" +#endif +#if (LZO_SIZEOF_INT == 1 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_I8LP16 1 +# define LZO_INFO_ABI_PM "i8lp16" +#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 2 && LZO_SIZEOF_VOID_P == 2) +# define LZO_ABI_ILP16 1 +# define LZO_INFO_ABI_PM "ilp16" +#elif (LZO_SIZEOF_INT == 2 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_LP32 1 +# define LZO_INFO_ABI_PM "lp32" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_ILP32 1 +# define LZO_INFO_ABI_PM "ilp32" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 4 && LZO_SIZEOF_VOID_P == 8 && LZO_SIZEOF_SIZE_T == 8) +# define LZO_ABI_LLP64 1 +# define LZO_INFO_ABI_PM "llp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_LP64 1 +# define LZO_INFO_ABI_PM "lp64" +#elif (LZO_SIZEOF_INT == 8 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 8) +# define LZO_ABI_ILP64 1 +# define LZO_INFO_ABI_PM "ilp64" +#elif (LZO_SIZEOF_INT == 4 && LZO_SIZEOF_LONG == 8 && LZO_SIZEOF_VOID_P == 4) +# define LZO_ABI_IP32L64 1 +# define LZO_INFO_ABI_PM "ip32l64" +#endif +#if 0 +#elif !defined(__LZO_LIBC_OVERRIDE) +#if (LZO_LIBC_NAKED) +# define LZO_INFO_LIBC "naked" +#elif (LZO_LIBC_FREESTANDING) +# define LZO_INFO_LIBC "freestanding" +#elif (LZO_LIBC_MOSTLY_FREESTANDING) +# define LZO_INFO_LIBC "mfreestanding" +#elif (LZO_LIBC_ISOC90) +# define LZO_INFO_LIBC "isoc90" +#elif (LZO_LIBC_ISOC99) +# define LZO_INFO_LIBC "isoc99" +#elif (LZO_CC_ARMCC_ARMCC) && defined(__ARMCLIB_VERSION) +# define LZO_LIBC_ISOC90 1 +# define LZO_INFO_LIBC "isoc90" +#elif defined(__dietlibc__) +# define LZO_LIBC_DIETLIBC 1 +# define LZO_INFO_LIBC "dietlibc" +#elif defined(_NEWLIB_VERSION) +# define LZO_LIBC_NEWLIB 1 +# define LZO_INFO_LIBC "newlib" +#elif defined(__UCLIBC__) && defined(__UCLIBC_MAJOR__) && defined(__UCLIBC_MINOR__) +# if defined(__UCLIBC_SUBLEVEL__) +# define LZO_LIBC_UCLIBC (__UCLIBC_MAJOR__ * 0x10000L + (__UCLIBC_MINOR__-0) * 0x100 + (__UCLIBC_SUBLEVEL__-0)) +# else +# define LZO_LIBC_UCLIBC 0x00090bL +# endif +# define LZO_INFO_LIBC "uc" "libc" +#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) +# define LZO_LIBC_GLIBC (__GLIBC__ * 0x10000L + (__GLIBC_MINOR__-0) * 0x100) +# define LZO_INFO_LIBC "glibc" +#elif (LZO_CC_MWERKS) && defined(__MSL__) +# define LZO_LIBC_MSL __MSL__ +# define LZO_INFO_LIBC "msl" +#elif 1 && defined(__IAR_SYSTEMS_ICC__) +# define LZO_LIBC_ISOC90 1 +# define LZO_INFO_LIBC "isoc90" +#else +# define LZO_LIBC_DEFAULT 1 +# define LZO_INFO_LIBC "default" +#endif +#endif +#if (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +# define LZO_ASM_SYNTAX_MSC 1 +#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) +#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) +#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) +# define LZO_ASM_SYNTAX_GNUC 1 +#elif (LZO_CC_GNUC) +# define LZO_ASM_SYNTAX_GNUC 1 +#endif +#if (LZO_ASM_SYNTAX_GNUC) +#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) +# define __LZO_ASM_CLOBBER "ax" +# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ +# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY /*empty*/ +# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ +#elif (LZO_CC_INTELC && (__INTEL_COMPILER < 1000)) +# define __LZO_ASM_CLOBBER "memory" +# define __LZO_ASM_CLOBBER_LIST_CC /*empty*/ +# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "memory" +# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ +#else +# define __LZO_ASM_CLOBBER "cc", "memory" +# define __LZO_ASM_CLOBBER_LIST_CC : "cc" +# define __LZO_ASM_CLOBBER_LIST_CC_MEMORY : "cc", "memory" +# define __LZO_ASM_CLOBBER_LIST_EMPTY /*empty*/ +#endif +#endif +#if (LZO_ARCH_ALPHA) +# define LZO_OPT_AVOID_UINT_INDEX 1 +#elif (LZO_ARCH_AMD64) +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# ifndef LZO_OPT_UNALIGNED64 +# define LZO_OPT_UNALIGNED64 1 +# endif +#elif (LZO_ARCH_ARM) +# if defined(__ARM_FEATURE_UNALIGNED) +# if ((__ARM_FEATURE_UNALIGNED)+0) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# endif +# elif 1 && (LZO_ARCH_ARM_THUMB2) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# elif 1 && defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM)+0 >= 7) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# elif 1 && defined(__TARGET_ARCH_ARM) && ((__TARGET_ARCH_ARM)+0 >= 6) && (defined(__TARGET_PROFILE_A) || defined(__TARGET_PROFILE_R)) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# endif +#elif (LZO_ARCH_ARM64) +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# ifndef LZO_OPT_UNALIGNED64 +# define LZO_OPT_UNALIGNED64 1 +# endif #elif (LZO_ARCH_CRIS) -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif #elif (LZO_ARCH_I386) -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif #elif (LZO_ARCH_IA64) -# define LZO_OPT_AVOID_INT_INDEX 1 -# define LZO_OPT_AVOID_UINT_INDEX 1 -# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_AVOID_INT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_PREFER_POSTINC 1 #elif (LZO_ARCH_M68K) -# define LZO_OPT_PREFER_POSTINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 # if defined(__mc68020__) && !defined(__mcoldfire__) -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif # endif #elif (LZO_ARCH_MIPS) -# define LZO_OPT_AVOID_UINT_INDEX 1 +# define LZO_OPT_AVOID_UINT_INDEX 1 #elif (LZO_ARCH_POWERPC) -# define LZO_OPT_PREFER_PREINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_PREINC 1 +# define LZO_OPT_PREFER_PREDEC 1 # if (LZO_ABI_BIG_ENDIAN) -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# if (LZO_WORDSIZE == 8) +# ifndef LZO_OPT_UNALIGNED64 +# define LZO_OPT_UNALIGNED64 1 +# endif +# endif # endif #elif (LZO_ARCH_S390) -# define LZO_OPT_UNALIGNED16 1 -# define LZO_OPT_UNALIGNED32 1 -# if (LZO_SIZEOF_SIZE_T == 8) -# define LZO_OPT_UNALIGNED64 1 +# ifndef LZO_OPT_UNALIGNED16 +# define LZO_OPT_UNALIGNED16 1 +# endif +# ifndef LZO_OPT_UNALIGNED32 +# define LZO_OPT_UNALIGNED32 1 +# endif +# if (LZO_WORDSIZE == 8) +# ifndef LZO_OPT_UNALIGNED64 +# define LZO_OPT_UNALIGNED64 1 +# endif # endif #elif (LZO_ARCH_SH) -# define LZO_OPT_PREFER_POSTINC 1 -# define LZO_OPT_PREFER_PREDEC 1 +# define LZO_OPT_PREFER_POSTINC 1 +# define LZO_OPT_PREFER_PREDEC 1 #endif #ifndef LZO_CFG_NO_INLINE_ASM -#if (LZO_CC_LLVM) +#if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) # define LZO_CFG_NO_INLINE_ASM 1 +#elif (LZO_CC_LLVM) +# define LZO_CFG_NO_INLINE_ASM 1 +#endif #endif +#if (LZO_CFG_NO_INLINE_ASM) +# undef LZO_ASM_SYNTAX_MSC +# undef LZO_ASM_SYNTAX_GNUC +# undef __LZO_ASM_CLOBBER +# undef __LZO_ASM_CLOBBER_LIST_CC +# undef __LZO_ASM_CLOBBER_LIST_CC_MEMORY +# undef __LZO_ASM_CLOBBER_LIST_EMPTY #endif #ifndef LZO_CFG_NO_UNALIGNED #if (LZO_ABI_NEUTRAL_ENDIAN) || (LZO_ARCH_GENERIC) @@ -1804,25 +2672,6 @@ # undef LZO_OPT_UNALIGNED32 # undef LZO_OPT_UNALIGNED64 #endif -#if (LZO_CFG_NO_INLINE_ASM) -#elif (LZO_ARCH_I386 && (LZO_OS_DOS32 || LZO_OS_WIN32) && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -# define LZO_ASM_SYNTAX_MSC 1 -#elif (LZO_OS_WIN64 && (LZO_CC_DMC || LZO_CC_INTELC || LZO_CC_MSC || LZO_CC_PELLESC)) -#elif (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC == 0x011f00ul)) -#elif (LZO_ARCH_I386 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -# define LZO_ASM_SYNTAX_GNUC 1 -#elif (LZO_ARCH_AMD64 && (LZO_CC_CLANG || LZO_CC_GNUC || LZO_CC_INTELC || LZO_CC_PATHSCALE)) -# define LZO_ASM_SYNTAX_GNUC 1 -#endif -#if (LZO_ASM_SYNTAX_GNUC) -#if (LZO_ARCH_I386 && LZO_CC_GNUC && (LZO_CC_GNUC < 0x020000ul)) -# define __LZO_ASM_CLOBBER "ax" -#elif (LZO_CC_INTELC) -# define __LZO_ASM_CLOBBER "memory" -#else -# define __LZO_ASM_CLOBBER "cc", "memory" -#endif -#endif #if defined(__LZO_INFOSTR_MM) #elif (LZO_MM_FLAT) && (defined(__LZO_INFOSTR_PM) || defined(LZO_INFO_ABI_PM)) # define __LZO_INFOSTR_MM "" @@ -1866,6 +2715,439 @@ #define LZO_INFO_STRING \ LZO_INFO_ARCH __LZO_INFOSTR_MM __LZO_INFOSTR_PM __LZO_INFOSTR_ENDIAN \ " " __LZO_INFOSTR_OSNAME __LZO_INFOSTR_LIBC " " LZO_INFO_CC __LZO_INFOSTR_CCVER +#if !(LZO_CFG_SKIP_LZO_TYPES) +#if (!(LZO_SIZEOF_SHORT+0 > 0 && LZO_SIZEOF_INT+0 > 0 && LZO_SIZEOF_LONG+0 > 0)) +# error "missing defines for sizes" +#endif +#if (!(LZO_SIZEOF_PTRDIFF_T+0 > 0 && LZO_SIZEOF_SIZE_T+0 > 0 && LZO_SIZEOF_VOID_P+0 > 0)) +# error "missing defines for sizes" +#endif +#define LZO_TYPEOF_CHAR 1u +#define LZO_TYPEOF_SHORT 2u +#define LZO_TYPEOF_INT 3u +#define LZO_TYPEOF_LONG 4u +#define LZO_TYPEOF_LONG_LONG 5u +#define LZO_TYPEOF___INT8 17u +#define LZO_TYPEOF___INT16 18u +#define LZO_TYPEOF___INT32 19u +#define LZO_TYPEOF___INT64 20u +#define LZO_TYPEOF___INT128 21u +#define LZO_TYPEOF___INT256 22u +#define LZO_TYPEOF___MODE_QI 33u +#define LZO_TYPEOF___MODE_HI 34u +#define LZO_TYPEOF___MODE_SI 35u +#define LZO_TYPEOF___MODE_DI 36u +#define LZO_TYPEOF___MODE_TI 37u +#define LZO_TYPEOF_CHAR_P 129u +#if !defined(lzo_llong_t) +#if (LZO_SIZEOF_LONG_LONG+0 > 0) +__lzo_gnuc_extension__ typedef long long lzo_llong_t__; +__lzo_gnuc_extension__ typedef unsigned long long lzo_ullong_t__; +# define lzo_llong_t lzo_llong_t__ +# define lzo_ullong_t lzo_ullong_t__ +#endif +#endif +#if !defined(lzo_int16e_t) +#if (LZO_SIZEOF_LONG == 2) +# define lzo_int16e_t long +# define lzo_uint16e_t unsigned long +# define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_LONG +#elif (LZO_SIZEOF_INT == 2) +# define lzo_int16e_t int +# define lzo_uint16e_t unsigned int +# define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_INT +#elif (LZO_SIZEOF_SHORT == 2) +# define lzo_int16e_t short int +# define lzo_uint16e_t unsigned short int +# define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF_SHORT +#elif 1 && !(LZO_CFG_TYPE_NO_MODE_HI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) + typedef int lzo_int16e_hi_t__ __attribute__((__mode__(__HI__))); + typedef unsigned int lzo_uint16e_hi_t__ __attribute__((__mode__(__HI__))); +# define lzo_int16e_t lzo_int16e_hi_t__ +# define lzo_uint16e_t lzo_uint16e_hi_t__ +# define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF___MODE_HI +#elif (LZO_SIZEOF___INT16 == 2) +# define lzo_int16e_t __int16 +# define lzo_uint16e_t unsigned __int16 +# define LZO_TYPEOF_LZO_INT16E_T LZO_TYPEOF___INT16 +#else +#endif +#endif +#if defined(lzo_int16e_t) +# define LZO_SIZEOF_LZO_INT16E_T 2 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == 2) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16e_t) == LZO_SIZEOF_LZO_INT16E_T) +#endif +#if !defined(lzo_int32e_t) +#if (LZO_SIZEOF_LONG == 4) +# define lzo_int32e_t long int +# define lzo_uint32e_t unsigned long int +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_LONG +#elif (LZO_SIZEOF_INT == 4) +# define lzo_int32e_t int +# define lzo_uint32e_t unsigned int +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_INT +#elif (LZO_SIZEOF_SHORT == 4) +# define lzo_int32e_t short int +# define lzo_uint32e_t unsigned short int +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_SHORT +#elif (LZO_SIZEOF_LONG_LONG == 4) +# define lzo_int32e_t lzo_llong_t +# define lzo_uint32e_t lzo_ullong_t +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF_LONG_LONG +#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x025f00ul) || LZO_CC_LLVM) && (__INT_MAX__+0 > 2147483647L) + typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); + typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); +# define lzo_int32e_t lzo_int32e_si_t__ +# define lzo_uint32e_t lzo_uint32e_si_t__ +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF___MODE_SI +#elif 1 && !(LZO_CFG_TYPE_NO_MODE_SI) && (LZO_CC_GNUC >= 0x025f00ul) && defined(__AVR__) && (__LONG_MAX__+0 == 32767L) + typedef int lzo_int32e_si_t__ __attribute__((__mode__(__SI__))); + typedef unsigned int lzo_uint32e_si_t__ __attribute__((__mode__(__SI__))); +# define lzo_int32e_t lzo_int32e_si_t__ +# define lzo_uint32e_t lzo_uint32e_si_t__ +# define LZO_INT32_C(c) (c##LL) +# define LZO_UINT32_C(c) (c##ULL) +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF___MODE_SI +#elif (LZO_SIZEOF___INT32 == 4) +# define lzo_int32e_t __int32 +# define lzo_uint32e_t unsigned __int32 +# define LZO_TYPEOF_LZO_INT32E_T LZO_TYPEOF___INT32 +#else +#endif +#endif +#if defined(lzo_int32e_t) +# define LZO_SIZEOF_LZO_INT32E_T 4 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == 4) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32e_t) == LZO_SIZEOF_LZO_INT32E_T) +#endif +#if !defined(lzo_int64e_t) +#if (LZO_SIZEOF___INT64 == 8) +# if (LZO_CC_BORLANDC) && !(LZO_CFG_TYPE_PREFER___INT64) +# define LZO_CFG_TYPE_PREFER___INT64 1 +# endif +#endif +#if (LZO_SIZEOF_INT == 8) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) +# define lzo_int64e_t int +# define lzo_uint64e_t unsigned int +# define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_INT +#elif (LZO_SIZEOF_LONG == 8) +# define lzo_int64e_t long int +# define lzo_uint64e_t unsigned long int +# define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_LONG +#elif (LZO_SIZEOF_LONG_LONG == 8) && !(LZO_CFG_TYPE_PREFER___INT64) +# define lzo_int64e_t lzo_llong_t +# define lzo_uint64e_t lzo_ullong_t +# define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF_LONG_LONG +# if (LZO_CC_BORLANDC) +# define LZO_INT64_C(c) ((c) + 0ll) +# define LZO_UINT64_C(c) ((c) + 0ull) +# elif 0 +# define LZO_INT64_C(c) (__lzo_gnuc_extension__ (c##LL)) +# define LZO_UINT64_C(c) (__lzo_gnuc_extension__ (c##ULL)) +# else +# define LZO_INT64_C(c) (c##LL) +# define LZO_UINT64_C(c) (c##ULL) +# endif +#elif (LZO_SIZEOF___INT64 == 8) +# define lzo_int64e_t __int64 +# define lzo_uint64e_t unsigned __int64 +# define LZO_TYPEOF_LZO_INT64E_T LZO_TYPEOF___INT64 +# if (LZO_CC_BORLANDC) +# define LZO_INT64_C(c) ((c) + 0i64) +# define LZO_UINT64_C(c) ((c) + 0ui64) +# else +# define LZO_INT64_C(c) (c##i64) +# define LZO_UINT64_C(c) (c##ui64) +# endif +#else +#endif +#endif +#if defined(lzo_int64e_t) +# define LZO_SIZEOF_LZO_INT64E_T 8 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == 8) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64e_t) == LZO_SIZEOF_LZO_INT64E_T) +#endif +#if !defined(lzo_int32l_t) +#if defined(lzo_int32e_t) +# define lzo_int32l_t lzo_int32e_t +# define lzo_uint32l_t lzo_uint32e_t +# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LZO_INT32E_T +# define LZO_TYPEOF_LZO_INT32L_T LZO_TYPEOF_LZO_INT32E_T +#elif (LZO_SIZEOF_INT >= 4) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) +# define lzo_int32l_t int +# define lzo_uint32l_t unsigned int +# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_INT +# define LZO_TYPEOF_LZO_INT32L_T LZO_SIZEOF_INT +#elif (LZO_SIZEOF_LONG >= 4) +# define lzo_int32l_t long int +# define lzo_uint32l_t unsigned long int +# define LZO_SIZEOF_LZO_INT32L_T LZO_SIZEOF_LONG +# define LZO_TYPEOF_LZO_INT32L_T LZO_SIZEOF_LONG +#else +# error "lzo_int32l_t" +#endif +#endif +#if 1 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) >= 4) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32l_t) == LZO_SIZEOF_LZO_INT32L_T) +#endif +#if !defined(lzo_int64l_t) +#if defined(lzo_int64e_t) +# define lzo_int64l_t lzo_int64e_t +# define lzo_uint64l_t lzo_uint64e_t +# define LZO_SIZEOF_LZO_INT64L_T LZO_SIZEOF_LZO_INT64E_T +# define LZO_TYPEOF_LZO_INT64L_T LZO_TYPEOF_LZO_INT64E_T +#else +#endif +#endif +#if defined(lzo_int64l_t) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) >= 8) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64l_t) == LZO_SIZEOF_LZO_INT64L_T) +#endif +#if !defined(lzo_int32f_t) +#if (LZO_SIZEOF_SIZE_T >= 8) +# define lzo_int32f_t lzo_int64l_t +# define lzo_uint32f_t lzo_uint64l_t +# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT64L_T +# define LZO_TYPEOF_LZO_INT32F_T LZO_TYPEOF_LZO_INT64L_T +#else +# define lzo_int32f_t lzo_int32l_t +# define lzo_uint32f_t lzo_uint32l_t +# define LZO_SIZEOF_LZO_INT32F_T LZO_SIZEOF_LZO_INT32L_T +# define LZO_TYPEOF_LZO_INT32F_T LZO_TYPEOF_LZO_INT32L_T +#endif +#endif +#if 1 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) >= 4) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32f_t) == LZO_SIZEOF_LZO_INT32F_T) +#endif +#if !defined(lzo_int64f_t) +#if defined(lzo_int64l_t) +# define lzo_int64f_t lzo_int64l_t +# define lzo_uint64f_t lzo_uint64l_t +# define LZO_SIZEOF_LZO_INT64F_T LZO_SIZEOF_LZO_INT64L_T +# define LZO_TYPEOF_LZO_INT64F_T LZO_TYPEOF_LZO_INT64L_T +#else +#endif +#endif +#if defined(lzo_int64f_t) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) >= 8) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64f_t) == LZO_SIZEOF_LZO_INT64F_T) +#endif +#if !defined(lzo_intptr_t) +#if 1 && (LZO_OS_OS400 && (LZO_SIZEOF_VOID_P == 16)) +# define __LZO_INTPTR_T_IS_POINTER 1 + typedef char * lzo_intptr_t; + typedef char * lzo_uintptr_t; +# define lzo_intptr_t lzo_intptr_t +# define lzo_uintptr_t lzo_uintptr_t +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_VOID_P +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_CHAR_P +#elif (LZO_CC_MSC && (_MSC_VER >= 1300) && (LZO_SIZEOF_VOID_P == 4) && (LZO_SIZEOF_INT == 4)) + typedef __w64 int lzo_intptr_t; + typedef __w64 unsigned int lzo_uintptr_t; +# define lzo_intptr_t lzo_intptr_t +# define lzo_uintptr_t lzo_uintptr_t +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_INT +#elif (LZO_SIZEOF_SHORT == LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT > LZO_SIZEOF_VOID_P) +# define lzo_intptr_t short +# define lzo_uintptr_t unsigned short +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_SHORT +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_SHORT +#elif (LZO_SIZEOF_INT >= LZO_SIZEOF_VOID_P) && (LZO_SIZEOF_INT < LZO_SIZEOF_LONG) +# define lzo_intptr_t int +# define lzo_uintptr_t unsigned int +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_INT +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_INT +#elif (LZO_SIZEOF_LONG >= LZO_SIZEOF_VOID_P) +# define lzo_intptr_t long +# define lzo_uintptr_t unsigned long +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LONG +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_LONG +#elif (LZO_SIZEOF_LZO_INT64L_T >= LZO_SIZEOF_VOID_P) +# define lzo_intptr_t lzo_int64l_t +# define lzo_uintptr_t lzo_uint64l_t +# define LZO_SIZEOF_LZO_INTPTR_T LZO_SIZEOF_LZO_INT64L_T +# define LZO_TYPEOF_LZO_INTPTR_T LZO_TYPEOF_LZO_INT64L_T +#else +# error "lzo_intptr_t" +#endif +#endif +#if 1 + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) >= sizeof(void *)) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_intptr_t) == sizeof(lzo_uintptr_t)) +#endif +#if !defined(lzo_word_t) +#if defined(LZO_WORDSIZE) && (LZO_WORDSIZE+0 > 0) +#if (LZO_WORDSIZE == LZO_SIZEOF_LZO_INTPTR_T) && !(__LZO_INTPTR_T_IS_POINTER) +# define lzo_word_t lzo_uintptr_t +# define lzo_sword_t lzo_intptr_t +# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INTPTR_T +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF_LZO_INTPTR_T +#elif (LZO_WORDSIZE == LZO_SIZEOF_LONG) +# define lzo_word_t unsigned long +# define lzo_sword_t long +# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LONG +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF_LONG +#elif (LZO_WORDSIZE == LZO_SIZEOF_INT) +# define lzo_word_t unsigned int +# define lzo_sword_t int +# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_INT +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF_INT +#elif (LZO_WORDSIZE == LZO_SIZEOF_SHORT) +# define lzo_word_t unsigned short +# define lzo_sword_t short +# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_SHORT +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF_SHORT +#elif (LZO_WORDSIZE == 1) +# define lzo_word_t unsigned char +# define lzo_sword_t signed char +# define LZO_SIZEOF_LZO_WORD_T 1 +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF_CHAR +#elif (LZO_WORDSIZE == LZO_SIZEOF_LZO_INT64L_T) +# define lzo_word_t lzo_uint64l_t +# define lzo_sword_t lzo_int64l_t +# define LZO_SIZEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T +# define LZO_TYPEOF_LZO_WORD_T LZO_SIZEOF_LZO_INT64L_T +#elif (LZO_ARCH_SPU) && (LZO_CC_GNUC) +#if 0 + typedef unsigned lzo_word_t __attribute__((__mode__(__V16QI__))); + typedef int lzo_sword_t __attribute__((__mode__(__V16QI__))); +# define lzo_word_t lzo_word_t +# define lzo_sword_t lzo_sword_t +# define LZO_SIZEOF_LZO_WORD_T 16 +# define LZO_TYPEOF_LZO_WORD_T LZO_TYPEOF___MODE_V16QI +#endif +#else +# error "lzo_word_t" +#endif +#endif +#endif +#if 1 && defined(lzo_word_t) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_word_t) == LZO_WORDSIZE) + LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_sword_t) == LZO_WORDSIZE) +#endif +#if 1 +#define lzo_int8_t signed char +#define lzo_uint8_t unsigned char +#define LZO_SIZEOF_LZO_INT8_T 1 +#define LZO_TYPEOF_LZO_INT8_T LZO_TYPEOF_CHAR +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == sizeof(lzo_uint8_t)) +#endif +#if defined(lzo_int16e_t) +#define lzo_int16_t lzo_int16e_t +#define lzo_uint16_t lzo_uint16e_t +#define LZO_SIZEOF_LZO_INT16_T LZO_SIZEOF_LZO_INT16E_T +#define LZO_TYPEOF_LZO_INT16_T LZO_TYPEOF_LZO_INT16E_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == sizeof(lzo_uint16_t)) +#endif +#if defined(lzo_int32e_t) +#define lzo_int32_t lzo_int32e_t +#define lzo_uint32_t lzo_uint32e_t +#define LZO_SIZEOF_LZO_INT32_T LZO_SIZEOF_LZO_INT32E_T +#define LZO_TYPEOF_LZO_INT32_T LZO_TYPEOF_LZO_INT32E_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == sizeof(lzo_uint32_t)) +#endif +#if defined(lzo_int64e_t) +#define lzo_int64_t lzo_int64e_t +#define lzo_uint64_t lzo_uint64e_t +#define LZO_SIZEOF_LZO_INT64_T LZO_SIZEOF_LZO_INT64E_T +#define LZO_TYPEOF_LZO_INT64_T LZO_TYPEOF_LZO_INT64E_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == sizeof(lzo_uint64_t)) +#endif +#if 1 +#define lzo_int_least32_t lzo_int32l_t +#define lzo_uint_least32_t lzo_uint32l_t +#define LZO_SIZEOF_LZO_INT_LEAST32_T LZO_SIZEOF_LZO_INT32L_T +#define LZO_TYPEOF_LZO_INT_LEAST32_T LZO_TYPEOF_LZO_INT32L_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) >= 4) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least32_t) == sizeof(lzo_uint_least32_t)) +#endif +#if defined(lzo_int64l_t) +#define lzo_int_least64_t lzo_int64l_t +#define lzo_uint_least64_t lzo_uint64l_t +#define LZO_SIZEOF_LZO_INT_LEAST64_T LZO_SIZEOF_LZO_INT64L_T +#define LZO_TYPEOF_LZO_INT_LEAST64_T LZO_TYPEOF_LZO_INT64L_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) >= 8) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_least64_t) == sizeof(lzo_uint_least64_t)) +#endif +#if 1 +#define lzo_int_fast32_t lzo_int32f_t +#define lzo_uint_fast32_t lzo_uint32f_t +#define LZO_SIZEOF_LZO_INT_FAST32_T LZO_SIZEOF_LZO_INT32F_T +#define LZO_TYPEOF_LZO_INT_FAST32_T LZO_TYPEOF_LZO_INT32F_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) >= 4) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast32_t) == sizeof(lzo_uint_fast32_t)) +#endif +#if defined(lzo_int64f_t) +#define lzo_int_fast64_t lzo_int64f_t +#define lzo_uint_fast64_t lzo_uint64f_t +#define LZO_SIZEOF_LZO_INT_FAST64_T LZO_SIZEOF_LZO_INT64F_T +#define LZO_TYPEOF_LZO_INT_FAST64_T LZO_TYPEOF_LZO_INT64F_T +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) >= 8) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int_fast64_t) == sizeof(lzo_uint_fast64_t)) +#endif +#if !defined(LZO_INT16_C) +# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 2) +# define LZO_INT16_C(c) ((c) + 0) +# define LZO_UINT16_C(c) ((c) + 0U) +# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 2) +# define LZO_INT16_C(c) ((c) + 0L) +# define LZO_UINT16_C(c) ((c) + 0UL) +# elif (LZO_SIZEOF_INT >= 2) +# define LZO_INT16_C(c) (c) +# define LZO_UINT16_C(c) (c##U) +# elif (LZO_SIZEOF_LONG >= 2) +# define LZO_INT16_C(c) (c##L) +# define LZO_UINT16_C(c) (c##UL) +# else +# error "LZO_INT16_C" +# endif +#endif +#if !defined(LZO_INT32_C) +# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 4) +# define LZO_INT32_C(c) ((c) + 0) +# define LZO_UINT32_C(c) ((c) + 0U) +# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 4) +# define LZO_INT32_C(c) ((c) + 0L) +# define LZO_UINT32_C(c) ((c) + 0UL) +# elif (LZO_SIZEOF_INT >= 4) +# define LZO_INT32_C(c) (c) +# define LZO_UINT32_C(c) (c##U) +# elif (LZO_SIZEOF_LONG >= 4) +# define LZO_INT32_C(c) (c##L) +# define LZO_UINT32_C(c) (c##UL) +# elif (LZO_SIZEOF_LONG_LONG >= 4) +# define LZO_INT32_C(c) (c##LL) +# define LZO_UINT32_C(c) (c##ULL) +# else +# error "LZO_INT32_C" +# endif +#endif +#if !defined(LZO_INT64_C) && defined(lzo_int64l_t) +# if (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_INT >= 8) +# define LZO_INT64_C(c) ((c) + 0) +# define LZO_UINT64_C(c) ((c) + 0U) +# elif (LZO_BROKEN_INTEGRAL_CONSTANTS) && (LZO_SIZEOF_LONG >= 8) +# define LZO_INT64_C(c) ((c) + 0L) +# define LZO_UINT64_C(c) ((c) + 0UL) +# elif (LZO_SIZEOF_INT >= 8) +# define LZO_INT64_C(c) (c) +# define LZO_UINT64_C(c) (c##U) +# elif (LZO_SIZEOF_LONG >= 8) +# define LZO_INT64_C(c) (c##L) +# define LZO_UINT64_C(c) (c##UL) +# else +# error "LZO_INT64_C" +# endif +#endif +#endif #endif @@ -1874,7 +3156,7 @@ #undef LZO_HAVE_CONFIG_H #include "minilzo.h" -#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2060) +#if !defined(MINILZO_VERSION) || (MINILZO_VERSION != 0x2090) # error "version mismatch in miniLZO source files" #endif @@ -1886,23 +3168,9 @@ #define __LZO_CONF_H 1 #if !defined(__LZO_IN_MINILZO) -#if (LZO_CFG_FREESTANDING) +#if defined(LZO_CFG_FREESTANDING) && (LZO_CFG_FREESTANDING) # define LZO_LIBC_FREESTANDING 1 # define LZO_OS_FREESTANDING 1 -# define ACC_LIBC_FREESTANDING 1 -# define ACC_OS_FREESTANDING 1 -#endif -#if (LZO_CFG_NO_UNALIGNED) -# define ACC_CFG_NO_UNALIGNED 1 -#endif -#if (LZO_ARCH_GENERIC) -# define ACC_ARCH_GENERIC 1 -#endif -#if (LZO_ABI_NEUTRAL_ENDIAN) -# define ACC_ABI_NEUTRAL_ENDIAN 1 -#endif -#if (LZO_HAVE_CONFIG_H) -# define ACC_CONFIG_NO_HEADER 1 #endif #if defined(LZO_CFG_EXTRA_CONFIG_HEADER) # include LZO_CFG_EXTRA_CONFIG_HEADER @@ -1910,23 +3178,41 @@ #if defined(__LZOCONF_H) || defined(__LZOCONF_H_INCLUDED) # error "include this file first" #endif -#include "lzo/lzoconf.h" +#if defined(LZO_CFG_BUILD_DLL) && (LZO_CFG_BUILD_DLL+0) && !defined(__LZO_EXPORT1) && !defined(__LZO_EXPORT2) && 0 +#ifndef __LZODEFS_H_INCLUDED +#if defined(LZO_HAVE_CONFIG_H) +# include +#endif +#include +#include +#include +#endif +#endif +#include +#if defined(LZO_CFG_EXTRA_CONFIG_HEADER2) +# include LZO_CFG_EXTRA_CONFIG_HEADER2 +#endif #endif -#if (LZO_VERSION < 0x02000) || !defined(__LZOCONF_H_INCLUDED) +#if !defined(__LZOCONF_H_INCLUDED) || (LZO_VERSION+0 != 0x2090) # error "version mismatch" #endif -#if (LZO_CC_BORLANDC && LZO_ARCH_I086) -# pragma option -h +#if (LZO_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1100)) +# pragma warning(disable: 4702) #endif - #if (LZO_CC_MSC && (_MSC_VER >= 1000)) # pragma warning(disable: 4127 4701) +# pragma warning(disable: 4514 4710 4711) #endif #if (LZO_CC_MSC && (_MSC_VER >= 1300)) # pragma warning(disable: 4820) -# pragma warning(disable: 4514 4710 4711) +#endif +#if (LZO_CC_MSC && (_MSC_VER >= 1800)) +# pragma warning(disable: 4746) +#endif +#if (LZO_CC_INTELC && (__INTEL_COMPILER >= 900)) +# pragma warning(disable: 1684) #endif #if (LZO_CC_SUNPROC) @@ -1937,46 +3223,40 @@ #endif #endif -#if (__LZO_MMODEL_HUGE) && !(LZO_HAVE_MM_HUGE_PTR) -# error "this should not happen - check defines for __huge" +#if !defined(__LZO_NOEXPORT1) +# define __LZO_NOEXPORT1 /*empty*/ +#endif +#if !defined(__LZO_NOEXPORT2) +# define __LZO_NOEXPORT2 /*empty*/ #endif -#if defined(__LZO_IN_MINILZO) || defined(LZO_CFG_FREESTANDING) -#elif (LZO_OS_DOS16 || LZO_OS_OS216 || LZO_OS_WIN16) -# define ACC_WANT_ACC_INCD_H 1 -# define ACC_WANT_ACC_INCE_H 1 -# define ACC_WANT_ACC_INCI_H 1 +#if 1 +# define LZO_PUBLIC_DECL(r) LZO_EXTERN(r) +#endif +#if 1 +# define LZO_PUBLIC_IMPL(r) LZO_PUBLIC(r) +#endif +#if !defined(LZO_LOCAL_DECL) +# define LZO_LOCAL_DECL(r) __LZO_EXTERN_C LZO_LOCAL_IMPL(r) +#endif +#if !defined(LZO_LOCAL_IMPL) +# define LZO_LOCAL_IMPL(r) __LZO_NOEXPORT1 r __LZO_NOEXPORT2 __LZO_CDECL +#endif +#if 1 +# define LZO_STATIC_DECL(r) LZO_PRIVATE(r) +#endif +#if 1 +# define LZO_STATIC_IMPL(r) LZO_PRIVATE(r) +#endif + +#if defined(__LZO_IN_MINILZO) || (LZO_CFG_FREESTANDING) #elif 1 # include #else -# define ACC_WANT_ACC_INCD_H 1 +# define LZO_WANT_ACC_INCD_H 1 #endif - -#if (LZO_ARCH_I086) -# define ACC_MM_AHSHIFT LZO_MM_AHSHIFT -# define ACC_PTR_FP_OFF(x) (((const unsigned __far*)&(x))[0]) -# define ACC_PTR_FP_SEG(x) (((const unsigned __far*)&(x))[1]) -# define ACC_PTR_MK_FP(s,o) ((void __far*)(((unsigned long)(s)<<16)+(unsigned)(o))) -#endif - -#if !defined(lzo_uintptr_t) -# if defined(__LZO_MMODEL_HUGE) -# define lzo_uintptr_t unsigned long -# elif 1 && defined(LZO_OS_OS400) && (LZO_SIZEOF_VOID_P == 16) -# define __LZO_UINTPTR_T_IS_POINTER 1 -typedef char *lzo_uintptr_t; -# define lzo_uintptr_t lzo_uintptr_t -# elif (LZO_SIZEOF_SIZE_T == LZO_SIZEOF_VOID_P) -# define lzo_uintptr_t size_t -# elif (LZO_SIZEOF_LONG == LZO_SIZEOF_VOID_P) -# define lzo_uintptr_t unsigned long -# elif (LZO_SIZEOF_INT == LZO_SIZEOF_VOID_P) -# define lzo_uintptr_t unsigned int -# elif (LZO_SIZEOF_LONG_LONG == LZO_SIZEOF_VOID_P) -# define lzo_uintptr_t unsigned long long -# else -# define lzo_uintptr_t size_t -# endif +#if defined(LZO_HAVE_CONFIG_H) +# define LZO_CFG_NO_CONFIG_HEADER 1 #endif #if 1 && !defined(LZO_CFG_FREESTANDING) @@ -2001,6 +3281,23 @@ #include #endif +#if 1 || defined(lzo_int8_t) || defined(lzo_uint8_t) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int8_t) == 1) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint8_t) == 1) +#endif +#if 1 || defined(lzo_int16_t) || defined(lzo_uint16_t) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int16_t) == 2) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint16_t) == 2) +#endif +#if 1 || defined(lzo_int32_t) || defined(lzo_uint32_t) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int32_t) == 4) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint32_t) == 4) +#endif +#if defined(lzo_int64_t) || defined(lzo_uint64_t) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int64_t) == 8) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint64_t) == 8) +#endif + #if (LZO_CFG_FREESTANDING) # undef HAVE_MEMCMP # undef HAVE_MEMCPY @@ -2011,28 +3308,28 @@ #if !(HAVE_MEMCMP) # undef memcmp # define memcmp(a,b,c) lzo_memcmp(a,b,c) -#elif !(__LZO_MMODEL_HUGE) +#else # undef lzo_memcmp # define lzo_memcmp(a,b,c) memcmp(a,b,c) #endif #if !(HAVE_MEMCPY) # undef memcpy # define memcpy(a,b,c) lzo_memcpy(a,b,c) -#elif !(__LZO_MMODEL_HUGE) +#else # undef lzo_memcpy # define lzo_memcpy(a,b,c) memcpy(a,b,c) #endif #if !(HAVE_MEMMOVE) # undef memmove # define memmove(a,b,c) lzo_memmove(a,b,c) -#elif !(__LZO_MMODEL_HUGE) +#else # undef lzo_memmove # define lzo_memmove(a,b,c) memmove(a,b,c) #endif #if !(HAVE_MEMSET) # undef memset # define memset(a,b,c) lzo_memset(a,b,c) -#elif !(__LZO_MMODEL_HUGE) +#else # undef lzo_memset # define lzo_memset(a,b,c) memset(a,b,c) #endif @@ -2057,27 +3354,29 @@ # define BOUNDS_CHECKING_OFF_IN_EXPR(expr) (expr) #endif -#if !defined(__lzo_inline) -# define __lzo_inline /*empty*/ -#endif -#if !defined(__lzo_forceinline) -# define __lzo_forceinline /*empty*/ -#endif -#if !defined(__lzo_noinline) -# define __lzo_noinline /*empty*/ -#endif - #if (LZO_CFG_PGO) -# undef __acc_likely -# undef __acc_unlikely # undef __lzo_likely # undef __lzo_unlikely -# define __acc_likely(e) (e) -# define __acc_unlikely(e) (e) # define __lzo_likely(e) (e) # define __lzo_unlikely(e) (e) #endif +#undef _ +#undef __ +#undef ___ +#undef ____ +#undef _p0 +#undef _p1 +#undef _p2 +#undef _p3 +#undef _p4 +#undef _s0 +#undef _s1 +#undef _s2 +#undef _s3 +#undef _s4 +#undef _ww + #if 1 # define LZO_BYTE(x) ((unsigned char) (x)) #else @@ -2096,81 +3395,544 @@ #define LZO_SIZE(bits) (1u << (bits)) #define LZO_MASK(bits) (LZO_SIZE(bits) - 1) -#define LZO_LSIZE(bits) (1ul << (bits)) -#define LZO_LMASK(bits) (LZO_LSIZE(bits) - 1) - #define LZO_USIZE(bits) ((lzo_uint) 1 << (bits)) #define LZO_UMASK(bits) (LZO_USIZE(bits) - 1) #if !defined(DMUL) #if 0 -# define DMUL(a,b) ((lzo_xint) ((lzo_uint32)(a) * (lzo_uint32)(b))) +# define DMUL(a,b) ((lzo_xint) ((lzo_uint32_t)(a) * (lzo_uint32_t)(b))) #else # define DMUL(a,b) ((lzo_xint) ((a) * (b))) #endif #endif -#if 1 && (LZO_ARCH_AMD64 || LZO_ARCH_I386 || LZO_ARCH_POWERPC) -# if (LZO_SIZEOF_SHORT == 2) -# define LZO_UNALIGNED_OK_2 1 -# endif -# if (LZO_SIZEOF_INT == 4) -# define LZO_UNALIGNED_OK_4 1 -# endif +#ifndef __LZO_FUNC_H +#define __LZO_FUNC_H 1 + +#if !defined(LZO_BITOPS_USE_ASM_BITSCAN) && !defined(LZO_BITOPS_USE_GNUC_BITSCAN) && !defined(LZO_BITOPS_USE_MSC_BITSCAN) +#if 1 && (LZO_ARCH_AMD64) && (LZO_CC_GNUC && (LZO_CC_GNUC < 0x040000ul)) && (LZO_ASM_SYNTAX_GNUC) +#define LZO_BITOPS_USE_ASM_BITSCAN 1 +#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC_GNUC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_LLVM && (!defined(__llvm_tools_version__) || (__llvm_tools_version__+0 >= 0x010500ul)))) +#define LZO_BITOPS_USE_GNUC_BITSCAN 1 +#elif (LZO_OS_WIN32 || LZO_OS_WIN64) && ((LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 1010)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) +#define LZO_BITOPS_USE_MSC_BITSCAN 1 +#if (LZO_CC_MSC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) +#include #endif -#if 1 && (LZO_ARCH_AMD64) -# if defined(LZO_UINT64_MAX) -# define LZO_UNALIGNED_OK_8 1 -# endif +#if (LZO_CC_MSC) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) +#pragma intrinsic(_BitScanReverse) +#pragma intrinsic(_BitScanForward) #endif -#if (LZO_CFG_NO_UNALIGNED) -# undef LZO_UNALIGNED_OK_2 -# undef LZO_UNALIGNED_OK_4 -# undef LZO_UNALIGNED_OK_8 -#endif - -#undef UA_GET16 -#undef UA_SET16 -#undef UA_COPY16 -#undef UA_GET32 -#undef UA_SET32 -#undef UA_COPY32 -#undef UA_GET64 -#undef UA_SET64 -#undef UA_COPY64 -#if defined(LZO_UNALIGNED_OK_2) -# if 1 && defined(ACC_UA_COPY16) -# define UA_GET16 ACC_UA_GET16 -# define UA_SET16 ACC_UA_SET16 -# define UA_COPY16 ACC_UA_COPY16 -# else -# define UA_GET16(p) (* (__lzo_ua_volatile const lzo_ushortp) (__lzo_ua_volatile const lzo_voidp) (p)) -# define UA_SET16(p,v) ((* (__lzo_ua_volatile lzo_ushortp) (__lzo_ua_volatile lzo_voidp) (p)) = (unsigned short) (v)) -# define UA_COPY16(d,s) UA_SET16(d, UA_GET16(s)) -# endif -#endif -#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) -# if 1 && defined(ACC_UA_COPY32) -# define UA_GET32 ACC_UA_GET32 -# define UA_SET32 ACC_UA_SET32 -# define UA_COPY32 ACC_UA_COPY32 -# else -# define UA_GET32(p) (* (__lzo_ua_volatile const lzo_uint32p) (__lzo_ua_volatile const lzo_voidp) (p)) -# define UA_SET32(p,v) ((* (__lzo_ua_volatile lzo_uint32p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint32) (v)) -# define UA_COPY32(d,s) UA_SET32(d, UA_GET32(s)) -# endif -#endif -#if defined(LZO_UNALIGNED_OK_8) -# if 1 && defined(ACC_UA_COPY64) -# define UA_GET64 ACC_UA_GET64 -# define UA_SET64 ACC_UA_SET64 -# define UA_COPY64 ACC_UA_COPY64 -# else -# define UA_GET64(p) (* (__lzo_ua_volatile const lzo_uint64p) (__lzo_ua_volatile const lzo_voidp) (p)) -# define UA_SET64(p,v) ((* (__lzo_ua_volatile lzo_uint64p) (__lzo_ua_volatile lzo_voidp) (p)) = (lzo_uint64) (v)) -# define UA_COPY64(d,s) UA_SET64(d, UA_GET64(s)) -# endif +#if (LZO_CC_MSC) && (LZO_ARCH_AMD64) +#pragma intrinsic(_BitScanReverse64) +#pragma intrinsic(_BitScanForward64) +#endif +#endif +#endif + +__lzo_static_forceinline unsigned lzo_bitops_ctlz32_func(lzo_uint32_t v) +{ +#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) + unsigned long r; (void) _BitScanReverse(&r, v); return (unsigned) r ^ 31; +#define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v) +#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC) + lzo_uint32_t r; + __asm__("bsr %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); + return (unsigned) r ^ 31; +#define lzo_bitops_ctlz32(v) lzo_bitops_ctlz32_func(v) +#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT == 4) + unsigned r; r = (unsigned) __builtin_clz(v); return r; +#define lzo_bitops_ctlz32(v) ((unsigned) __builtin_clz(v)) +#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG == 8) && (LZO_WORDSIZE >= 8) + unsigned r; r = (unsigned) __builtin_clzl(v); return r ^ 32; +#define lzo_bitops_ctlz32(v) (((unsigned) __builtin_clzl(v)) ^ 32) +#else + LZO_UNUSED(v); return 0; +#endif +} + +#if defined(lzo_uint64_t) +__lzo_static_forceinline unsigned lzo_bitops_ctlz64_func(lzo_uint64_t v) +{ +#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64) + unsigned long r; (void) _BitScanReverse64(&r, v); return (unsigned) r ^ 63; +#define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v) +#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC) + lzo_uint64_t r; + __asm__("bsr %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); + return (unsigned) r ^ 63; +#define lzo_bitops_ctlz64(v) lzo_bitops_ctlz64_func(v) +#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG == 8) && (LZO_WORDSIZE >= 8) + unsigned r; r = (unsigned) __builtin_clzl(v); return r; +#define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzl(v)) +#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG == 8) && (LZO_WORDSIZE >= 8) + unsigned r; r = (unsigned) __builtin_clzll(v); return r; +#define lzo_bitops_ctlz64(v) ((unsigned) __builtin_clzll(v)) +#else + LZO_UNUSED(v); return 0; +#endif +} +#endif + +__lzo_static_forceinline unsigned lzo_bitops_cttz32_func(lzo_uint32_t v) +{ +#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) + unsigned long r; (void) _BitScanForward(&r, v); return (unsigned) r; +#define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v) +#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64 || LZO_ARCH_I386) && (LZO_ASM_SYNTAX_GNUC) + lzo_uint32_t r; + __asm__("bsf %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); + return (unsigned) r; +#define lzo_bitops_cttz32(v) lzo_bitops_cttz32_func(v) +#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_INT >= 4) + unsigned r; r = (unsigned) __builtin_ctz(v); return r; +#define lzo_bitops_cttz32(v) ((unsigned) __builtin_ctz(v)) +#else + LZO_UNUSED(v); return 0; +#endif +} + +#if defined(lzo_uint64_t) +__lzo_static_forceinline unsigned lzo_bitops_cttz64_func(lzo_uint64_t v) +{ +#if (LZO_BITOPS_USE_MSC_BITSCAN) && (LZO_ARCH_AMD64) + unsigned long r; (void) _BitScanForward64(&r, v); return (unsigned) r; +#define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v) +#elif (LZO_BITOPS_USE_ASM_BITSCAN) && (LZO_ARCH_AMD64) && (LZO_ASM_SYNTAX_GNUC) + lzo_uint64_t r; + __asm__("bsf %1,%0" : "=r" (r) : "rm" (v) __LZO_ASM_CLOBBER_LIST_CC); + return (unsigned) r; +#define lzo_bitops_cttz64(v) lzo_bitops_cttz64_func(v) +#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG >= 8) && (LZO_WORDSIZE >= 8) + unsigned r; r = (unsigned) __builtin_ctzl(v); return r; +#define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzl(v)) +#elif (LZO_BITOPS_USE_GNUC_BITSCAN) && (LZO_SIZEOF_LONG_LONG >= 8) && (LZO_WORDSIZE >= 8) + unsigned r; r = (unsigned) __builtin_ctzll(v); return r; +#define lzo_bitops_cttz64(v) ((unsigned) __builtin_ctzll(v)) +#else + LZO_UNUSED(v); return 0; +#endif +} +#endif + +lzo_unused_funcs_impl(void, lzo_bitops_unused_funcs)(void) +{ + LZO_UNUSED_FUNC(lzo_bitops_unused_funcs); + LZO_UNUSED_FUNC(lzo_bitops_ctlz32_func); + LZO_UNUSED_FUNC(lzo_bitops_cttz32_func); +#if defined(lzo_uint64_t) + LZO_UNUSED_FUNC(lzo_bitops_ctlz64_func); + LZO_UNUSED_FUNC(lzo_bitops_cttz64_func); +#endif +} + +#if defined(__lzo_alignof) && !(LZO_CFG_NO_UNALIGNED) +#if !defined(lzo_memops_tcheck__) && 0 +#define lzo_memops_tcheck__(t,a,b) ((void)0, sizeof(t) == (a) && __lzo_alignof(t) == (b)) +#endif +#endif +#ifndef lzo_memops_TU0p +#define lzo_memops_TU0p void __LZO_MMODEL * +#endif +#ifndef lzo_memops_TU1p +#define lzo_memops_TU1p unsigned char __LZO_MMODEL * +#endif +#ifndef lzo_memops_TU2p +#if (LZO_OPT_UNALIGNED16) +typedef lzo_uint16_t __lzo_may_alias lzo_memops_TU2; +#define lzo_memops_TU2p volatile lzo_memops_TU2 * +#elif defined(__lzo_byte_struct) +__lzo_byte_struct(lzo_memops_TU2_struct,2) +typedef struct lzo_memops_TU2_struct lzo_memops_TU2; +#else +struct lzo_memops_TU2_struct { unsigned char a[2]; } __lzo_may_alias; +typedef struct lzo_memops_TU2_struct lzo_memops_TU2; +#endif +#ifndef lzo_memops_TU2p +#define lzo_memops_TU2p lzo_memops_TU2 * +#endif +#endif +#ifndef lzo_memops_TU4p +#if (LZO_OPT_UNALIGNED32) +typedef lzo_uint32_t __lzo_may_alias lzo_memops_TU4; +#define lzo_memops_TU4p volatile lzo_memops_TU4 __LZO_MMODEL * +#elif defined(__lzo_byte_struct) +__lzo_byte_struct(lzo_memops_TU4_struct,4) +typedef struct lzo_memops_TU4_struct lzo_memops_TU4; +#else +struct lzo_memops_TU4_struct { unsigned char a[4]; } __lzo_may_alias; +typedef struct lzo_memops_TU4_struct lzo_memops_TU4; +#endif +#ifndef lzo_memops_TU4p +#define lzo_memops_TU4p lzo_memops_TU4 __LZO_MMODEL * +#endif +#endif +#ifndef lzo_memops_TU8p +#if (LZO_OPT_UNALIGNED64) +typedef lzo_uint64_t __lzo_may_alias lzo_memops_TU8; +#define lzo_memops_TU8p volatile lzo_memops_TU8 __LZO_MMODEL * +#elif defined(__lzo_byte_struct) +__lzo_byte_struct(lzo_memops_TU8_struct,8) +typedef struct lzo_memops_TU8_struct lzo_memops_TU8; +#else +struct lzo_memops_TU8_struct { unsigned char a[8]; } __lzo_may_alias; +typedef struct lzo_memops_TU8_struct lzo_memops_TU8; +#endif +#ifndef lzo_memops_TU8p +#define lzo_memops_TU8p lzo_memops_TU8 __LZO_MMODEL * +#endif +#endif +#ifndef lzo_memops_set_TU1p +#define lzo_memops_set_TU1p volatile lzo_memops_TU1p +#endif +#ifndef lzo_memops_move_TU1p +#define lzo_memops_move_TU1p lzo_memops_TU1p +#endif +#define LZO_MEMOPS_SET1(dd,cc) \ + LZO_BLOCK_BEGIN \ + lzo_memops_set_TU1p d__1 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ + d__1[0] = LZO_BYTE(cc); \ + LZO_BLOCK_END +#define LZO_MEMOPS_SET2(dd,cc) \ + LZO_BLOCK_BEGIN \ + lzo_memops_set_TU1p d__2 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ + d__2[0] = LZO_BYTE(cc); d__2[1] = LZO_BYTE(cc); \ + LZO_BLOCK_END +#define LZO_MEMOPS_SET3(dd,cc) \ + LZO_BLOCK_BEGIN \ + lzo_memops_set_TU1p d__3 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ + d__3[0] = LZO_BYTE(cc); d__3[1] = LZO_BYTE(cc); d__3[2] = LZO_BYTE(cc); \ + LZO_BLOCK_END +#define LZO_MEMOPS_SET4(dd,cc) \ + LZO_BLOCK_BEGIN \ + lzo_memops_set_TU1p d__4 = (lzo_memops_set_TU1p) (lzo_memops_TU0p) (dd); \ + d__4[0] = LZO_BYTE(cc); d__4[1] = LZO_BYTE(cc); d__4[2] = LZO_BYTE(cc); d__4[3] = LZO_BYTE(cc); \ + LZO_BLOCK_END +#define LZO_MEMOPS_MOVE1(dd,ss) \ + LZO_BLOCK_BEGIN \ + lzo_memops_move_TU1p d__1 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ + const lzo_memops_move_TU1p s__1 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ + d__1[0] = s__1[0]; \ + LZO_BLOCK_END +#define LZO_MEMOPS_MOVE2(dd,ss) \ + LZO_BLOCK_BEGIN \ + lzo_memops_move_TU1p d__2 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ + const lzo_memops_move_TU1p s__2 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ + d__2[0] = s__2[0]; d__2[1] = s__2[1]; \ + LZO_BLOCK_END +#define LZO_MEMOPS_MOVE3(dd,ss) \ + LZO_BLOCK_BEGIN \ + lzo_memops_move_TU1p d__3 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ + const lzo_memops_move_TU1p s__3 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ + d__3[0] = s__3[0]; d__3[1] = s__3[1]; d__3[2] = s__3[2]; \ + LZO_BLOCK_END +#define LZO_MEMOPS_MOVE4(dd,ss) \ + LZO_BLOCK_BEGIN \ + lzo_memops_move_TU1p d__4 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ + const lzo_memops_move_TU1p s__4 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ + d__4[0] = s__4[0]; d__4[1] = s__4[1]; d__4[2] = s__4[2]; d__4[3] = s__4[3]; \ + LZO_BLOCK_END +#define LZO_MEMOPS_MOVE8(dd,ss) \ + LZO_BLOCK_BEGIN \ + lzo_memops_move_TU1p d__8 = (lzo_memops_move_TU1p) (lzo_memops_TU0p) (dd); \ + const lzo_memops_move_TU1p s__8 = (const lzo_memops_move_TU1p) (const lzo_memops_TU0p) (ss); \ + d__8[0] = s__8[0]; d__8[1] = s__8[1]; d__8[2] = s__8[2]; d__8[3] = s__8[3]; \ + d__8[4] = s__8[4]; d__8[5] = s__8[5]; d__8[6] = s__8[6]; d__8[7] = s__8[7]; \ + LZO_BLOCK_END +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU1p)0)==1) +#define LZO_MEMOPS_COPY1(dd,ss) LZO_MEMOPS_MOVE1(dd,ss) +#if (LZO_OPT_UNALIGNED16) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU2p)0)==2) +#define LZO_MEMOPS_COPY2(dd,ss) \ + * (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss) +#elif defined(lzo_memops_tcheck__) +#define LZO_MEMOPS_COPY2(dd,ss) \ + LZO_BLOCK_BEGIN if (lzo_memops_tcheck__(lzo_memops_TU2,2,1)) { \ + * (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss); \ + } else { LZO_MEMOPS_MOVE2(dd,ss); } LZO_BLOCK_END +#else +#define LZO_MEMOPS_COPY2(dd,ss) LZO_MEMOPS_MOVE2(dd,ss) +#endif +#if (LZO_OPT_UNALIGNED32) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU4p)0)==4) +#define LZO_MEMOPS_COPY4(dd,ss) \ + * (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss) +#elif defined(lzo_memops_tcheck__) +#define LZO_MEMOPS_COPY4(dd,ss) \ + LZO_BLOCK_BEGIN if (lzo_memops_tcheck__(lzo_memops_TU4,4,1)) { \ + * (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss); \ + } else { LZO_MEMOPS_MOVE4(dd,ss); } LZO_BLOCK_END +#else +#define LZO_MEMOPS_COPY4(dd,ss) LZO_MEMOPS_MOVE4(dd,ss) +#endif +#if (LZO_WORDSIZE != 8) +#define LZO_MEMOPS_COPY8(dd,ss) \ + LZO_BLOCK_BEGIN LZO_MEMOPS_COPY4(dd,ss); LZO_MEMOPS_COPY4((lzo_memops_TU1p)(lzo_memops_TU0p)(dd)+4,(const lzo_memops_TU1p)(const lzo_memops_TU0p)(ss)+4); LZO_BLOCK_END +#else +#if (LZO_OPT_UNALIGNED64) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU8p)0)==8) +#define LZO_MEMOPS_COPY8(dd,ss) \ + * (lzo_memops_TU8p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss) +#elif (LZO_OPT_UNALIGNED32) +#define LZO_MEMOPS_COPY8(dd,ss) \ + LZO_BLOCK_BEGIN LZO_MEMOPS_COPY4(dd,ss); LZO_MEMOPS_COPY4((lzo_memops_TU1p)(lzo_memops_TU0p)(dd)+4,(const lzo_memops_TU1p)(const lzo_memops_TU0p)(ss)+4); LZO_BLOCK_END +#elif defined(lzo_memops_tcheck__) +#define LZO_MEMOPS_COPY8(dd,ss) \ + LZO_BLOCK_BEGIN if (lzo_memops_tcheck__(lzo_memops_TU8,8,1)) { \ + * (lzo_memops_TU8p) (lzo_memops_TU0p) (dd) = * (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss); \ + } else { LZO_MEMOPS_MOVE8(dd,ss); } LZO_BLOCK_END +#else +#define LZO_MEMOPS_COPY8(dd,ss) LZO_MEMOPS_MOVE8(dd,ss) +#endif +#endif +#define LZO_MEMOPS_COPYN(dd,ss,nn) \ + LZO_BLOCK_BEGIN \ + lzo_memops_TU1p d__n = (lzo_memops_TU1p) (lzo_memops_TU0p) (dd); \ + const lzo_memops_TU1p s__n = (const lzo_memops_TU1p) (const lzo_memops_TU0p) (ss); \ + lzo_uint n__n = (nn); \ + while ((void)0, n__n >= 8) { LZO_MEMOPS_COPY8(d__n, s__n); d__n += 8; s__n += 8; n__n -= 8; } \ + if ((void)0, n__n >= 4) { LZO_MEMOPS_COPY4(d__n, s__n); d__n += 4; s__n += 4; n__n -= 4; } \ + if ((void)0, n__n > 0) do { *d__n++ = *s__n++; } while (--n__n > 0); \ + LZO_BLOCK_END + +__lzo_static_forceinline lzo_uint16_t lzo_memops_get_le16(const lzo_voidp ss) +{ + lzo_uint16_t v; +#if (LZO_ABI_LITTLE_ENDIAN) + LZO_MEMOPS_COPY2(&v, ss); +#elif (LZO_OPT_UNALIGNED16 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) + const lzo_memops_TU2p s = (const lzo_memops_TU2p) ss; + unsigned long vv; + __asm__("lhbrx %0,0,%1" : "=r" (vv) : "r" (s), "m" (*s)); + v = (lzo_uint16_t) vv; +#else + const lzo_memops_TU1p s = (const lzo_memops_TU1p) ss; + v = (lzo_uint16_t) (((lzo_uint16_t)s[0]) | ((lzo_uint16_t)s[1] << 8)); +#endif + return v; +} +#if (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) +#define LZO_MEMOPS_GET_LE16(ss) (* (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss)) +#else +#define LZO_MEMOPS_GET_LE16(ss) lzo_memops_get_le16(ss) +#endif + +__lzo_static_forceinline lzo_uint32_t lzo_memops_get_le32(const lzo_voidp ss) +{ + lzo_uint32_t v; +#if (LZO_ABI_LITTLE_ENDIAN) + LZO_MEMOPS_COPY4(&v, ss); +#elif (LZO_OPT_UNALIGNED32 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) + const lzo_memops_TU4p s = (const lzo_memops_TU4p) ss; + unsigned long vv; + __asm__("lwbrx %0,0,%1" : "=r" (vv) : "r" (s), "m" (*s)); + v = (lzo_uint32_t) vv; +#else + const lzo_memops_TU1p s = (const lzo_memops_TU1p) ss; + v = (lzo_uint32_t) (((lzo_uint32_t)s[0]) | ((lzo_uint32_t)s[1] << 8) | ((lzo_uint32_t)s[2] << 16) | ((lzo_uint32_t)s[3] << 24)); +#endif + return v; +} +#if (LZO_OPT_UNALIGNED32) && (LZO_ABI_LITTLE_ENDIAN) +#define LZO_MEMOPS_GET_LE32(ss) (* (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss)) +#else +#define LZO_MEMOPS_GET_LE32(ss) lzo_memops_get_le32(ss) +#endif + +#if (LZO_OPT_UNALIGNED64) && (LZO_ABI_LITTLE_ENDIAN) +#define LZO_MEMOPS_GET_LE64(ss) (* (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss)) +#endif + +__lzo_static_forceinline lzo_uint16_t lzo_memops_get_ne16(const lzo_voidp ss) +{ + lzo_uint16_t v; + LZO_MEMOPS_COPY2(&v, ss); + return v; +} +#if (LZO_OPT_UNALIGNED16) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU2p)0)==2) +#define LZO_MEMOPS_GET_NE16(ss) (* (const lzo_memops_TU2p) (const lzo_memops_TU0p) (ss)) +#else +#define LZO_MEMOPS_GET_NE16(ss) lzo_memops_get_ne16(ss) +#endif + +__lzo_static_forceinline lzo_uint32_t lzo_memops_get_ne32(const lzo_voidp ss) +{ + lzo_uint32_t v; + LZO_MEMOPS_COPY4(&v, ss); + return v; +} +#if (LZO_OPT_UNALIGNED32) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU4p)0)==4) +#define LZO_MEMOPS_GET_NE32(ss) (* (const lzo_memops_TU4p) (const lzo_memops_TU0p) (ss)) +#else +#define LZO_MEMOPS_GET_NE32(ss) lzo_memops_get_ne32(ss) +#endif + +#if (LZO_OPT_UNALIGNED64) +LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(*(lzo_memops_TU8p)0)==8) +#define LZO_MEMOPS_GET_NE64(ss) (* (const lzo_memops_TU8p) (const lzo_memops_TU0p) (ss)) +#endif + +__lzo_static_forceinline void lzo_memops_put_le16(lzo_voidp dd, lzo_uint16_t vv) +{ +#if (LZO_ABI_LITTLE_ENDIAN) + LZO_MEMOPS_COPY2(dd, &vv); +#elif (LZO_OPT_UNALIGNED16 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) + lzo_memops_TU2p d = (lzo_memops_TU2p) dd; + unsigned long v = vv; + __asm__("sthbrx %2,0,%1" : "=m" (*d) : "r" (d), "r" (v)); +#else + lzo_memops_TU1p d = (lzo_memops_TU1p) dd; + d[0] = LZO_BYTE((vv ) & 0xff); + d[1] = LZO_BYTE((vv >> 8) & 0xff); +#endif +} +#if (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) +#define LZO_MEMOPS_PUT_LE16(dd,vv) (* (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = (vv)) +#else +#define LZO_MEMOPS_PUT_LE16(dd,vv) lzo_memops_put_le16(dd,vv) +#endif + +__lzo_static_forceinline void lzo_memops_put_le32(lzo_voidp dd, lzo_uint32_t vv) +{ +#if (LZO_ABI_LITTLE_ENDIAN) + LZO_MEMOPS_COPY4(dd, &vv); +#elif (LZO_OPT_UNALIGNED32 && LZO_ARCH_POWERPC && LZO_ABI_BIG_ENDIAN) && (LZO_ASM_SYNTAX_GNUC) + lzo_memops_TU4p d = (lzo_memops_TU4p) dd; + unsigned long v = vv; + __asm__("stwbrx %2,0,%1" : "=m" (*d) : "r" (d), "r" (v)); +#else + lzo_memops_TU1p d = (lzo_memops_TU1p) dd; + d[0] = LZO_BYTE((vv ) & 0xff); + d[1] = LZO_BYTE((vv >> 8) & 0xff); + d[2] = LZO_BYTE((vv >> 16) & 0xff); + d[3] = LZO_BYTE((vv >> 24) & 0xff); +#endif +} +#if (LZO_OPT_UNALIGNED32) && (LZO_ABI_LITTLE_ENDIAN) +#define LZO_MEMOPS_PUT_LE32(dd,vv) (* (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = (vv)) +#else +#define LZO_MEMOPS_PUT_LE32(dd,vv) lzo_memops_put_le32(dd,vv) +#endif + +__lzo_static_forceinline void lzo_memops_put_ne16(lzo_voidp dd, lzo_uint16_t vv) +{ + LZO_MEMOPS_COPY2(dd, &vv); +} +#if (LZO_OPT_UNALIGNED16) +#define LZO_MEMOPS_PUT_NE16(dd,vv) (* (lzo_memops_TU2p) (lzo_memops_TU0p) (dd) = (vv)) +#else +#define LZO_MEMOPS_PUT_NE16(dd,vv) lzo_memops_put_ne16(dd,vv) +#endif + +__lzo_static_forceinline void lzo_memops_put_ne32(lzo_voidp dd, lzo_uint32_t vv) +{ + LZO_MEMOPS_COPY4(dd, &vv); +} +#if (LZO_OPT_UNALIGNED32) +#define LZO_MEMOPS_PUT_NE32(dd,vv) (* (lzo_memops_TU4p) (lzo_memops_TU0p) (dd) = (vv)) +#else +#define LZO_MEMOPS_PUT_NE32(dd,vv) lzo_memops_put_ne32(dd,vv) +#endif + +lzo_unused_funcs_impl(void, lzo_memops_unused_funcs)(void) +{ + LZO_UNUSED_FUNC(lzo_memops_unused_funcs); + LZO_UNUSED_FUNC(lzo_memops_get_le16); + LZO_UNUSED_FUNC(lzo_memops_get_le32); + LZO_UNUSED_FUNC(lzo_memops_get_ne16); + LZO_UNUSED_FUNC(lzo_memops_get_ne32); + LZO_UNUSED_FUNC(lzo_memops_put_le16); + LZO_UNUSED_FUNC(lzo_memops_put_le32); + LZO_UNUSED_FUNC(lzo_memops_put_ne16); + LZO_UNUSED_FUNC(lzo_memops_put_ne32); +} + +#endif + +#ifndef UA_SET1 +#define UA_SET1 LZO_MEMOPS_SET1 +#endif +#ifndef UA_SET2 +#define UA_SET2 LZO_MEMOPS_SET2 +#endif +#ifndef UA_SET3 +#define UA_SET3 LZO_MEMOPS_SET3 +#endif +#ifndef UA_SET4 +#define UA_SET4 LZO_MEMOPS_SET4 +#endif +#ifndef UA_MOVE1 +#define UA_MOVE1 LZO_MEMOPS_MOVE1 +#endif +#ifndef UA_MOVE2 +#define UA_MOVE2 LZO_MEMOPS_MOVE2 +#endif +#ifndef UA_MOVE3 +#define UA_MOVE3 LZO_MEMOPS_MOVE3 +#endif +#ifndef UA_MOVE4 +#define UA_MOVE4 LZO_MEMOPS_MOVE4 +#endif +#ifndef UA_MOVE8 +#define UA_MOVE8 LZO_MEMOPS_MOVE8 +#endif +#ifndef UA_COPY1 +#define UA_COPY1 LZO_MEMOPS_COPY1 +#endif +#ifndef UA_COPY2 +#define UA_COPY2 LZO_MEMOPS_COPY2 +#endif +#ifndef UA_COPY3 +#define UA_COPY3 LZO_MEMOPS_COPY3 +#endif +#ifndef UA_COPY4 +#define UA_COPY4 LZO_MEMOPS_COPY4 +#endif +#ifndef UA_COPY8 +#define UA_COPY8 LZO_MEMOPS_COPY8 +#endif +#ifndef UA_COPYN +#define UA_COPYN LZO_MEMOPS_COPYN +#endif +#ifndef UA_COPYN_X +#define UA_COPYN_X LZO_MEMOPS_COPYN +#endif +#ifndef UA_GET_LE16 +#define UA_GET_LE16 LZO_MEMOPS_GET_LE16 +#endif +#ifndef UA_GET_LE32 +#define UA_GET_LE32 LZO_MEMOPS_GET_LE32 +#endif +#ifdef LZO_MEMOPS_GET_LE64 +#ifndef UA_GET_LE64 +#define UA_GET_LE64 LZO_MEMOPS_GET_LE64 +#endif +#endif +#ifndef UA_GET_NE16 +#define UA_GET_NE16 LZO_MEMOPS_GET_NE16 +#endif +#ifndef UA_GET_NE32 +#define UA_GET_NE32 LZO_MEMOPS_GET_NE32 +#endif +#ifdef LZO_MEMOPS_GET_NE64 +#ifndef UA_GET_NE64 +#define UA_GET_NE64 LZO_MEMOPS_GET_NE64 +#endif +#endif +#ifndef UA_PUT_LE16 +#define UA_PUT_LE16 LZO_MEMOPS_PUT_LE16 +#endif +#ifndef UA_PUT_LE32 +#define UA_PUT_LE32 LZO_MEMOPS_PUT_LE32 +#endif +#ifndef UA_PUT_NE16 +#define UA_PUT_NE16 LZO_MEMOPS_PUT_NE16 +#endif +#ifndef UA_PUT_NE32 +#define UA_PUT_NE32 LZO_MEMOPS_PUT_NE32 #endif #define MEMCPY8_DS(dest,src,len) \ @@ -2187,29 +3949,14 @@ #ifndef __LZO_PTR_H #define __LZO_PTR_H 1 -#ifdef __cplusplus -extern "C" { -#endif - -#if !defined(lzo_uintptr_t) -# if (__LZO_MMODEL_HUGE) -# define lzo_uintptr_t unsigned long -# else -# define lzo_uintptr_t acc_uintptr_t -# ifdef __ACC_INTPTR_T_IS_POINTER -# define __LZO_UINTPTR_T_IS_POINTER 1 -# endif -# endif +#ifdef __cplusplus +extern "C" { #endif #if (LZO_ARCH_I086) -#define PTR(a) ((lzo_bytep) (a)) -#define PTR_ALIGNED_4(a) ((ACC_PTR_FP_OFF(a) & 3) == 0) -#define PTR_ALIGNED2_4(a,b) (((ACC_PTR_FP_OFF(a) | ACC_PTR_FP_OFF(b)) & 3) == 0) +#error "LZO_ARCH_I086 is unsupported" #elif (LZO_MM_PVP) -#define PTR(a) ((lzo_bytep) (a)) -#define PTR_ALIGNED_8(a) ((((lzo_uintptr_t)(a)) >> 61) == 0) -#define PTR_ALIGNED2_8(a,b) ((((lzo_uintptr_t)(a)|(lzo_uintptr_t)(b)) >> 61) == 0) +#error "LZO_MM_PVP is unsupported" #else #define PTR(a) ((lzo_uintptr_t) (a)) #define PTR_LINEAR(a) PTR(a) @@ -2239,24 +3986,28 @@ unsigned long a_ulong; lzo_int a_lzo_int; lzo_uint a_lzo_uint; - lzo_int32 a_lzo_int32; - lzo_uint32 a_lzo_uint32; -#if defined(LZO_UINT64_MAX) - lzo_int64 a_lzo_int64; - lzo_uint64 a_lzo_uint64; + lzo_xint a_lzo_xint; + lzo_int16_t a_lzo_int16_t; + lzo_uint16_t a_lzo_uint16_t; + lzo_int32_t a_lzo_int32_t; + lzo_uint32_t a_lzo_uint32_t; +#if defined(lzo_uint64_t) + lzo_int64_t a_lzo_int64_t; + lzo_uint64_t a_lzo_uint64_t; #endif + size_t a_size_t; ptrdiff_t a_ptrdiff_t; lzo_uintptr_t a_lzo_uintptr_t; + void * a_void_p; + char * a_char_p; + unsigned char * a_uchar_p; + const void * a_c_void_p; + const char * a_c_char_p; + const unsigned char * a_c_uchar_p; lzo_voidp a_lzo_voidp; - void *a_void_p; lzo_bytep a_lzo_bytep; - lzo_bytepp a_lzo_bytepp; - lzo_uintp a_lzo_uintp; - lzo_uint *a_lzo_uint_p; - lzo_uint32p a_lzo_uint32p; - lzo_uint32 *a_lzo_uint32_p; - unsigned char *a_uchar_p; - char *a_char_p; + const lzo_voidp a_c_lzo_voidp; + const lzo_bytep a_c_lzo_bytep; } lzo_full_align_t; @@ -2272,18 +4023,14 @@ #ifndef LZO_DICT_USE_PTR #define LZO_DICT_USE_PTR 1 -#if 0 && (LZO_ARCH_I086) -# undef LZO_DICT_USE_PTR -# define LZO_DICT_USE_PTR 0 -#endif #endif #if (LZO_DICT_USE_PTR) # define lzo_dict_t const lzo_bytep -# define lzo_dict_p lzo_dict_t __LZO_MMODEL * +# define lzo_dict_p lzo_dict_t * #else # define lzo_dict_t lzo_uint -# define lzo_dict_p lzo_dict_t __LZO_MMODEL * +# define lzo_dict_p lzo_dict_t * #endif #endif @@ -2296,10 +4043,9 @@ lzo_uintptr_t p; #if (LZO_ARCH_I086) - p = (((lzo_uintptr_t)(ACC_PTR_FP_SEG(ptr))) << (16 - ACC_MM_AHSHIFT)) + (ACC_PTR_FP_OFF(ptr)); +#error "LZO_ARCH_I086 is unsupported" #elif (LZO_MM_PVP) - p = (lzo_uintptr_t) (ptr); - p = (p << 3) | (p >> 61); +#error "LZO_MM_PVP is unsupported" #else p = (lzo_uintptr_t) PTR_LINEAR(ptr); #endif @@ -2310,16 +4056,20 @@ LZO_PUBLIC(unsigned) __lzo_align_gap(const lzo_voidp ptr, lzo_uint size) { -#if defined(__LZO_UINTPTR_T_IS_POINTER) - size_t n = (size_t) ptr; - n = (((n + size - 1) / size) * size) - n; +#if (__LZO_UINTPTR_T_IS_POINTER) +#error "__LZO_UINTPTR_T_IS_POINTER is unsupported" #else lzo_uintptr_t p, n; + if (size < 2) return 0; p = __lzo_ptr_linear(ptr); +#if 0 n = (((p + size - 1) / size) * size) - p; +#else + if ((size & (size - 1)) != 0) + return 0; + n = size; n = ((p + n - 1) & ~(n - 1)) - p; +#endif #endif - - assert(size > 0); assert((long)n >= 0); assert(n <= size); return (unsigned)n; @@ -2332,27 +4082,25 @@ * keep this copyright string in the executable of your product. */ -static const char __lzo_copyright[] = +static const char lzo_copyright_[] = #if !defined(__LZO_IN_MINLZO) LZO_VERSION_STRING; #else "\r\n\n" "LZO data compression library.\n" - "$Copyright: LZO Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\n" + "$Copyright: LZO Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer\n" "\n" "http://www.oberhumer.com $\n\n" "$Id: LZO version: v" LZO_VERSION_STRING ", " LZO_VERSION_DATE " $\n" "$Info: " LZO_INFO_STRING " $\n"; #endif +static const char lzo_version_string_[] = LZO_VERSION_STRING; +static const char lzo_version_date_[] = LZO_VERSION_DATE; LZO_PUBLIC(const lzo_bytep) lzo_copyright(void) { -#if (LZO_OS_DOS16 && LZO_CC_TURBOC) - return (lzo_voidp) __lzo_copyright; -#else - return (const lzo_bytep) __lzo_copyright; -#endif + return (const lzo_bytep) lzo_copyright_; } LZO_PUBLIC(unsigned) @@ -2364,41 +4112,41 @@ LZO_PUBLIC(const char *) lzo_version_string(void) { - return LZO_VERSION_STRING; + return lzo_version_string_; } LZO_PUBLIC(const char *) lzo_version_date(void) { - return LZO_VERSION_DATE; + return lzo_version_date_; } LZO_PUBLIC(const lzo_charp) _lzo_version_string(void) { - return LZO_VERSION_STRING; + return lzo_version_string_; } LZO_PUBLIC(const lzo_charp) _lzo_version_date(void) { - return LZO_VERSION_DATE; + return lzo_version_date_; } #define LZO_BASE 65521u #define LZO_NMAX 5552 #define LZO_DO1(buf,i) s1 += buf[i]; s2 += s1 -#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1); -#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2); -#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4); -#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8); +#define LZO_DO2(buf,i) LZO_DO1(buf,i); LZO_DO1(buf,i+1) +#define LZO_DO4(buf,i) LZO_DO2(buf,i); LZO_DO2(buf,i+2) +#define LZO_DO8(buf,i) LZO_DO4(buf,i); LZO_DO4(buf,i+4) +#define LZO_DO16(buf,i) LZO_DO8(buf,i); LZO_DO8(buf,i+8) -LZO_PUBLIC(lzo_uint32) -lzo_adler32(lzo_uint32 adler, const lzo_bytep buf, lzo_uint len) +LZO_PUBLIC(lzo_uint32_t) +lzo_adler32(lzo_uint32_t adler, const lzo_bytep buf, lzo_uint len) { - lzo_uint32 s1 = adler & 0xffff; - lzo_uint32 s2 = (adler >> 16) & 0xffff; + lzo_uint32_t s1 = adler & 0xffff; + lzo_uint32_t s2 = (adler >> 16) & 0xffff; unsigned k; if (buf == NULL) @@ -2409,18 +4157,16 @@ k = len < LZO_NMAX ? (unsigned) len : LZO_NMAX; len -= k; if (k >= 16) do - { - LZO_DO16(buf, 0); - buf += 16; - k -= 16; - } - while (k >= 16); + { + LZO_DO16(buf,0); + buf += 16; + k -= 16; + } while (k >= 16); if (k != 0) do - { - s1 += *buf++; - s2 += s1; - } - while (--k > 0); + { + s1 += *buf++; + s2 += s1; + } while (--k > 0); s1 %= LZO_BASE; s2 %= LZO_BASE; } @@ -2457,16 +4203,15 @@ LZOLIB_PUBLIC(int, lzo_hmemcmp) (const lzo_hvoid_p s1, const lzo_hvoid_p s2, lzo_hsize_t len) { #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCMP) - const lzo_hbyte_p p1 = (const lzo_hbyte_p) s1; - const lzo_hbyte_p p2 = (const lzo_hbyte_p) s2; + const lzo_hbyte_p p1 = LZO_STATIC_CAST(const lzo_hbyte_p, s1); + const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, s2); if __lzo_likely(len > 0) do - { - int d = *p1 - *p2; - if (d != 0) - return d; - p1++; p2++; - } - while __lzo_likely(--len > 0); + { + int d = *p1 - *p2; + if (d != 0) + return d; + p1++; p2++; + } while __lzo_likely(--len > 0); return 0; #else return memcmp(s1, s2, len); @@ -2475,8 +4220,8 @@ LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemcpy) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) { #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMCPY) - lzo_hbyte_p p1 = (lzo_hbyte_p) dest; - const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; + lzo_hbyte_p p1 = LZO_STATIC_CAST(lzo_hbyte_p, dest); + const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, src); if (!(len > 0) || p1 == p2) return dest; do @@ -2490,8 +4235,8 @@ LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemmove) (lzo_hvoid_p dest, const lzo_hvoid_p src, lzo_hsize_t len) { #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMMOVE) - lzo_hbyte_p p1 = (lzo_hbyte_p) dest; - const lzo_hbyte_p p2 = (const lzo_hbyte_p) src; + lzo_hbyte_p p1 = LZO_STATIC_CAST(lzo_hbyte_p, dest); + const lzo_hbyte_p p2 = LZO_STATIC_CAST(const lzo_hbyte_p, src); if (!(len > 0) || p1 == p2) return dest; if (p1 < p2) @@ -2513,16 +4258,17 @@ return memmove(dest, src, len); #endif } -LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int c, lzo_hsize_t len) +LZOLIB_PUBLIC(lzo_hvoid_p, lzo_hmemset) (lzo_hvoid_p s, int cc, lzo_hsize_t len) { #if (LZO_HAVE_MM_HUGE_PTR) || !(HAVE_MEMSET) - lzo_hbyte_p p = (lzo_hbyte_p) s; + lzo_hbyte_p p = LZO_STATIC_CAST(lzo_hbyte_p, s); + unsigned char c = LZO_ITRUNC(unsigned char, cc); if __lzo_likely(len > 0) do - *p++ = (unsigned char) c; - while __lzo_likely(--len > 0); + *p++ = c; + while __lzo_likely(--len > 0); return s; #else - return memset(s, c, len); + return memset(s, cc, len); #endif } #undef LZOLIB_PUBLIC @@ -2531,103 +4277,28 @@ #if !defined(__LZO_IN_MINILZO) -#define ACC_WANT_ACC_CHK_CH 1 -#undef ACCCHK_ASSERT - -ACCCHK_ASSERT_IS_SIGNED_T(lzo_int) -ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) - -ACCCHK_ASSERT_IS_SIGNED_T(lzo_int32) -ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint32) -ACCCHK_ASSERT((LZO_UINT32_C(1) << (int)(8 * sizeof(LZO_UINT32_C(1)) - 1)) > 0) -ACCCHK_ASSERT(sizeof(lzo_uint32) >= 4) -#if defined(LZO_UINT64_MAX) -ACCCHK_ASSERT(sizeof(lzo_uint64) == 8) -ACCCHK_ASSERT_IS_SIGNED_T(lzo_int64) -ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uint64) -#endif - -#if !defined(__LZO_UINTPTR_T_IS_POINTER) -ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) -#endif -ACCCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) - -ACCCHK_ASSERT_IS_UNSIGNED_T(lzo_xint) -ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint32)) -ACCCHK_ASSERT(sizeof(lzo_xint) >= sizeof(lzo_uint)) -ACCCHK_ASSERT(sizeof(lzo_xint) == sizeof(lzo_uint32) || sizeof(lzo_xint) == sizeof(lzo_uint)) +#define LZO_WANT_ACC_CHK_CH 1 +#undef LZOCHK_ASSERT + LZOCHK_ASSERT((LZO_UINT32_C(1) << (int)(8*sizeof(LZO_UINT32_C(1))-1)) > 0) + LZOCHK_ASSERT_IS_SIGNED_T(lzo_int) + LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_uint) +#if !(__LZO_UINTPTR_T_IS_POINTER) + LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_uintptr_t) #endif -#undef ACCCHK_ASSERT - -#define WANT_lzo_bitops_clz32 1 -#define WANT_lzo_bitops_clz64 1 -#define WANT_lzo_bitops_ctz32 1 -#define WANT_lzo_bitops_ctz64 1 + LZOCHK_ASSERT(sizeof(lzo_uintptr_t) >= sizeof(lzo_voidp)) + LZOCHK_ASSERT_IS_UNSIGNED_T(lzo_xint) -#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) -#include -#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 -#pragma intrinsic(_BitScanReverse) -static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) -{ - unsigned long r; - (void) _BitScanReverse(&r, v); - return (unsigned) r; -} -#define lzo_bitops_clz32 lzo_bitops_clz32 -#endif -#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 -#pragma intrinsic(_BitScanReverse64) -static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) -{ - unsigned long r; - (void) _BitScanReverse64(&r, v); - return (unsigned) r; -} -#define lzo_bitops_clz64 lzo_bitops_clz64 -#endif -#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) -#pragma intrinsic(_BitScanForward) -static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) -{ - unsigned long r; - (void) _BitScanForward(&r, v); - return (unsigned) r; -} -#define lzo_bitops_ctz32 lzo_bitops_ctz32 -#endif -#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) -#pragma intrinsic(_BitScanForward64) -static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) -{ - unsigned long r; - (void) _BitScanForward64(&r, v); - return (unsigned) r; -} -#define lzo_bitops_ctz64 lzo_bitops_ctz64 #endif +#undef LZOCHK_ASSERT -#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_LLVM && (!defined(__llvm_tools_version__) || (__llvm_tools_version__+0 >= 0x010500ul)))) -#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) -#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) -#endif -#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) -#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) -#endif -#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) -#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) -#endif -#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) -#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) -#endif -#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) -#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) -#endif -#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) -#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) -#endif +union lzo_config_check_union { + lzo_uint a[2]; + unsigned char b[2*LZO_MAX(8,sizeof(lzo_uint))]; +#if defined(lzo_uint64_t) + lzo_uint64_t c[2]; #endif +}; #if 0 #define u2p(ptr,off) ((lzo_voidp) (((lzo_bytep)(lzo_voidp)(ptr)) + (off))) @@ -2641,96 +4312,119 @@ LZO_PUBLIC(int) _lzo_config_check(void) { - lzo_bool r = 1; - union - { - lzo_xint a[2]; unsigned char b[2 * LZO_MAX(8, sizeof(lzo_xint))]; -#if defined(LZO_UNALIGNED_OK_8) - lzo_uint64 c[2]; +#if (LZO_CC_CLANG && (LZO_CC_CLANG >= 0x030100ul && LZO_CC_CLANG < 0x030300ul)) +# if 0 + volatile +# endif #endif - unsigned short x[2]; lzo_uint32 y[2]; lzo_uint z[2]; - } u; + union lzo_config_check_union u; lzo_voidp p; + unsigned r = 1; u.a[0] = u.a[1] = 0; p = u2p(&u, 0); r &= ((* (lzo_bytep) p) == 0); -#if !defined(LZO_CFG_NO_CONFIG_CHECK) -#if defined(LZO_ABI_BIG_ENDIAN) +#if !(LZO_CFG_NO_CONFIG_CHECK) +#if (LZO_ABI_BIG_ENDIAN) u.a[0] = u.a[1] = 0; u.b[sizeof(lzo_uint) - 1] = 128; p = u2p(&u, 0); r &= ((* (lzo_uintp) p) == 128); #endif -#if defined(LZO_ABI_LITTLE_ENDIAN) +#if (LZO_ABI_LITTLE_ENDIAN) u.a[0] = u.a[1] = 0; u.b[0] = 128; p = u2p(&u, 0); r &= ((* (lzo_uintp) p) == 128); #endif -#if defined(LZO_UNALIGNED_OK_2) u.a[0] = u.a[1] = 0; - u.b[0] = 1; u.b[sizeof(unsigned short) + 1] = 2; + u.b[0] = 1; u.b[3] = 2; p = u2p(&u, 1); - r &= ((* (lzo_ushortp) p) == 0); + r &= UA_GET_NE16(p) == 0; + r &= UA_GET_LE16(p) == 0; + u.b[1] = 128; + r &= UA_GET_LE16(p) == 128; + u.b[2] = 129; + r &= UA_GET_LE16(p) == LZO_UINT16_C(0x8180); +#if (LZO_ABI_BIG_ENDIAN) + r &= UA_GET_NE16(p) == LZO_UINT16_C(0x8081); +#endif +#if (LZO_ABI_LITTLE_ENDIAN) + r &= UA_GET_NE16(p) == LZO_UINT16_C(0x8180); #endif -#if defined(LZO_UNALIGNED_OK_4) u.a[0] = u.a[1] = 0; - u.b[0] = 3; u.b[sizeof(lzo_uint32) + 1] = 4; + u.b[0] = 3; u.b[5] = 4; p = u2p(&u, 1); - r &= ((* (lzo_uint32p) p) == 0); + r &= UA_GET_NE32(p) == 0; + r &= UA_GET_LE32(p) == 0; + u.b[1] = 128; + r &= UA_GET_LE32(p) == 128; + u.b[2] = 129; u.b[3] = 130; u.b[4] = 131; + r &= UA_GET_LE32(p) == LZO_UINT32_C(0x83828180); +#if (LZO_ABI_BIG_ENDIAN) + r &= UA_GET_NE32(p) == LZO_UINT32_C(0x80818283); +#endif +#if (LZO_ABI_LITTLE_ENDIAN) + r &= UA_GET_NE32(p) == LZO_UINT32_C(0x83828180); #endif -#if defined(LZO_UNALIGNED_OK_8) +#if defined(UA_GET_NE64) u.c[0] = u.c[1] = 0; - u.b[0] = 5; u.b[sizeof(lzo_uint64) + 1] = 6; + u.b[0] = 5; u.b[9] = 6; p = u2p(&u, 1); - r &= ((* (lzo_uint64p) p) == 0); -#endif -#if defined(lzo_bitops_clz32) - { - unsigned i; lzo_uint32 v = 1; - for (i = 0; i < 32; i++, v <<= 1) - r &= lzo_bitops_clz32(v) == 31 - i; - } -#endif -#if defined(lzo_bitops_clz64) - { - unsigned i; lzo_uint64 v = 1; - for (i = 0; i < 64; i++, v <<= 1) - r &= lzo_bitops_clz64(v) == 63 - i; - } -#endif -#if defined(lzo_bitops_ctz32) - { - unsigned i; lzo_uint32 v = 1; - for (i = 0; i < 32; i++, v <<= 1) - r &= lzo_bitops_ctz32(v) == i; - } -#endif -#if defined(lzo_bitops_ctz64) - { - unsigned i; lzo_uint64 v = 1; - for (i = 0; i < 64; i++, v <<= 1) - r &= lzo_bitops_ctz64(v) == i; - } + u.c[0] = u.c[1] = 0; + r &= UA_GET_NE64(p) == 0; +#if defined(UA_GET_LE64) + r &= UA_GET_LE64(p) == 0; + u.b[1] = 128; + r &= UA_GET_LE64(p) == 128; +#endif +#endif +#if defined(lzo_bitops_ctlz32) + { unsigned i = 0; lzo_uint32_t v; + for (v = 1; v != 0 && r == 1; v <<= 1, i++) { + r &= lzo_bitops_ctlz32(v) == 31 - i; + r &= lzo_bitops_ctlz32_func(v) == 31 - i; + }} +#endif +#if defined(lzo_bitops_ctlz64) + { unsigned i = 0; lzo_uint64_t v; + for (v = 1; v != 0 && r == 1; v <<= 1, i++) { + r &= lzo_bitops_ctlz64(v) == 63 - i; + r &= lzo_bitops_ctlz64_func(v) == 63 - i; + }} +#endif +#if defined(lzo_bitops_cttz32) + { unsigned i = 0; lzo_uint32_t v; + for (v = 1; v != 0 && r == 1; v <<= 1, i++) { + r &= lzo_bitops_cttz32(v) == i; + r &= lzo_bitops_cttz32_func(v) == i; + }} +#endif +#if defined(lzo_bitops_cttz64) + { unsigned i = 0; lzo_uint64_t v; + for (v = 1; v != 0 && r == 1; v <<= 1, i++) { + r &= lzo_bitops_cttz64(v) == i; + r &= lzo_bitops_cttz64_func(v) == i; + }} #endif #endif + LZO_UNUSED_FUNC(lzo_bitops_unused_funcs); return r == 1 ? LZO_E_OK : LZO_E_ERROR; } LZO_PUBLIC(int) __lzo_init_v2(unsigned v, int s1, int s2, int s3, int s4, int s5, - int s6, int s7, int s8, int s9) + int s6, int s7, int s8, int s9) { int r; #if defined(__LZO_IN_MINILZO) #elif (LZO_CC_MSC && ((_MSC_VER) < 700)) #else -#define ACC_WANT_ACC_CHK_CH 1 -#undef ACCCHK_ASSERT -#define ACCCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) +#define LZO_WANT_ACC_CHK_CH 1 +#undef LZOCHK_ASSERT +#define LZOCHK_ASSERT(expr) LZO_COMPILE_TIME_ASSERT(expr) #endif -#undef ACCCHK_ASSERT +#undef LZOCHK_ASSERT if (v == 0) return LZO_E_ERROR; @@ -2738,7 +4432,7 @@ r = (s1 == -1 || s1 == (int) sizeof(short)) && (s2 == -1 || s2 == (int) sizeof(int)) && (s3 == -1 || s3 == (int) sizeof(long)) && - (s4 == -1 || s4 == (int) sizeof(lzo_uint32)) && + (s4 == -1 || s4 == (int) sizeof(lzo_uint32_t)) && (s5 == -1 || s5 == (int) sizeof(lzo_uint)) && (s6 == -1 || s6 == (int) lzo_sizeof_dict_t) && (s7 == -1 || s7 == (int) sizeof(char *)) && @@ -2781,11 +4475,11 @@ #if !defined(MINILZO_CFG_SKIP_LZO1X_1_COMPRESS) -#if 1 && defined(UA_GET32) +#if 1 && defined(UA_GET_LE32) #undef LZO_DICT_USE_PTR #define LZO_DICT_USE_PTR 0 #undef lzo_dict_t -#define lzo_dict_t unsigned short +#define lzo_dict_t lzo_uint16_t #endif #define LZO_NEED_DICT_H 1 @@ -2808,7 +4502,7 @@ #endif #if !defined(__LZO_IN_MINILZO) -#include "lzo/lzo1x.h" +#include #endif #ifndef LZO_EOF_CODE @@ -2925,27 +4619,27 @@ #if (DL_MIN_LEN == 3) # define _DV2_A(p,shift1,shift2) \ - (((( (lzo_xint)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2]) + (((( (lzo_xint)((p)[0]) << shift1) ^ (p)[1]) << shift2) ^ (p)[2]) # define _DV2_B(p,shift1,shift2) \ - (((( (lzo_xint)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0]) + (((( (lzo_xint)((p)[2]) << shift1) ^ (p)[1]) << shift2) ^ (p)[0]) # define _DV3_B(p,shift1,shift2,shift3) \ - ((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0]) + ((_DV2_B((p)+1,shift1,shift2) << (shift3)) ^ (p)[0]) #elif (DL_MIN_LEN == 2) # define _DV2_A(p,shift1,shift2) \ - (( (lzo_xint)(p[0]) << shift1) ^ p[1]) + (( (lzo_xint)(p[0]) << shift1) ^ p[1]) # define _DV2_B(p,shift1,shift2) \ - (( (lzo_xint)(p[1]) << shift1) ^ p[2]) + (( (lzo_xint)(p[1]) << shift1) ^ p[2]) #else # error "invalid DL_MIN_LEN" #endif #define _DV_A(p,shift) _DV2_A(p,shift,shift) #define _DV_B(p,shift) _DV2_B(p,shift,shift) #define DA2(p,s1,s2) \ - (((((lzo_xint)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0]) + (((((lzo_xint)((p)[2]) << (s2)) + (p)[1]) << (s1)) + (p)[0]) #define DS2(p,s1,s2) \ - (((((lzo_xint)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0]) + (((((lzo_xint)((p)[2]) << (s2)) - (p)[1]) << (s1)) - (p)[0]) #define DX2(p,s1,s2) \ - (((((lzo_xint)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0]) + (((((lzo_xint)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0]) #define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0]) #define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0]) #define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0]) @@ -2966,7 +4660,7 @@ # define __LZO_HASH_INCREMENTAL 1 # define DVAL_FIRST(dv,p) dv = _DV_A((p),5) # define DVAL_NEXT(dv,p) \ - dv ^= (lzo_xint)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2]) + dv ^= (lzo_xint)(p[-1]) << (2*5); dv = (((dv) << 5) ^ p[2]) # define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5) # define DVAL_LOOKAHEAD DL_MIN_LEN @@ -2974,7 +4668,7 @@ # define __LZO_HASH_INCREMENTAL 1 # define DVAL_FIRST(dv,p) dv = _DV_B((p),5) # define DVAL_NEXT(dv,p) \ - dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_xint)(p[2]) << (2*5))) + dv ^= p[-1]; dv = (((dv) >> 5) ^ ((lzo_xint)(p[2]) << (2*5))) # define _DINDEX(dv,p) ((DMUL(0x9f5f,dv)) >> 5) # define DVAL_LOOKAHEAD DL_MIN_LEN @@ -3000,7 +4694,7 @@ #if !defined(DVAL_ASSERT) #if defined(__LZO_HASH_INCREMENTAL) && !defined(NDEBUG) -#if (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_LLVM) +#if 1 && (LZO_CC_ARMCC_GNUC || LZO_CC_CLANG || (LZO_CC_GNUC >= 0x020700ul) || LZO_CC_INTELC_GNUC || LZO_CC_LLVM || LZO_CC_PATHSCALE || LZO_CC_PGI) static void __attribute__((__unused__)) #else static void @@ -3008,8 +4702,8 @@ DVAL_ASSERT(lzo_xint dv, const lzo_bytep p) { lzo_xint df; - DVAL_FIRST(df, (p)); - assert(DINDEX(dv, p) == DINDEX(df, p)); + DVAL_FIRST(df,(p)); + assert(DINDEX(dv,p) == DINDEX(df,p)); } #else # define DVAL_ASSERT(dv,p) ((void) 0) @@ -3033,37 +4727,37 @@ #else # define UPDATE_D(dict,drun,dv,p,in) \ - dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK + dict[ DINDEX(dv,p) + drun++ ] = DENTRY(p,in); drun &= DD_MASK # define UPDATE_I(dict,drun,index,p,in) \ - dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK + dict[ (index) + drun++ ] = DENTRY(p,in); drun &= DD_MASK # define UPDATE_P(ptr,drun,p,in) \ - (ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK + (ptr) [ drun++ ] = DENTRY(p,in); drun &= DD_MASK #endif #if (LZO_DICT_USE_PTR) #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ - (m_pos == NULL || (m_off = pd(ip, m_pos)) > max_offset) + (m_pos == NULL || (m_off = pd(ip, m_pos)) > max_offset) #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ (BOUNDS_CHECKING_OFF_IN_EXPR(( \ - m_pos = ip - (lzo_uint) PTR_DIFF(ip,m_pos), \ - PTR_LT(m_pos,in) || \ - (m_off = (lzo_uint) PTR_DIFF(ip,m_pos)) == 0 || \ - m_off > max_offset ))) + m_pos = ip - (lzo_uint) PTR_DIFF(ip,m_pos), \ + PTR_LT(m_pos,in) || \ + (m_off = (lzo_uint) PTR_DIFF(ip,m_pos)) == 0 || \ + m_off > max_offset ))) #else #define LZO_CHECK_MPOS_DET(m_pos,m_off,in,ip,max_offset) \ - (m_off == 0 || \ - ((m_off = pd(ip, in) - m_off) > max_offset) || \ - (m_pos = (ip) - (m_off), 0) ) + (m_off == 0 || \ + ((m_off = pd(ip, in) - m_off) > max_offset) || \ + (m_pos = (ip) - (m_off), 0) ) #define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \ - (pd(ip, in) <= m_off || \ - ((m_off = pd(ip, in) - m_off) > max_offset) || \ - (m_pos = (ip) - (m_off), 0) ) + (pd(ip, in) <= m_off || \ + ((m_off = pd(ip, in) - m_off) > max_offset) || \ + (m_pos = (ip) - (m_off), 0) ) #endif @@ -3090,89 +4784,15 @@ #endif #if 1 && defined(DO_COMPRESS) && !defined(do_compress) -# define do_compress LZO_CPP_ECONCAT2(DO_COMPRESS,_core) -#endif - -#if defined(UA_GET64) && (LZO_ABI_BIG_ENDIAN) -# define WANT_lzo_bitops_clz64 1 -#elif defined(UA_GET64) && (LZO_ABI_LITTLE_ENDIAN) -# define WANT_lzo_bitops_ctz64 1 -#elif defined(UA_GET32) && (LZO_ABI_BIG_ENDIAN) -# define WANT_lzo_bitops_clz32 1 -#elif defined(UA_GET32) && (LZO_ABI_LITTLE_ENDIAN) -# define WANT_lzo_bitops_ctz32 1 -#endif - -#if (defined(_WIN32) || defined(_WIN64)) && ((LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_MSC && (_MSC_VER >= 1400))) -#include -#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) && 0 -#pragma intrinsic(_BitScanReverse) -static __lzo_inline unsigned lzo_bitops_clz32(lzo_uint32 v) -{ - unsigned long r; - (void) _BitScanReverse(&r, v); - return (unsigned) r; -} -#define lzo_bitops_clz32 lzo_bitops_clz32 -#endif -#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) && 0 -#pragma intrinsic(_BitScanReverse64) -static __lzo_inline unsigned lzo_bitops_clz64(lzo_uint64 v) -{ - unsigned long r; - (void) _BitScanReverse64(&r, v); - return (unsigned) r; -} -#define lzo_bitops_clz64 lzo_bitops_clz64 -#endif -#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) -#pragma intrinsic(_BitScanForward) -static __lzo_inline unsigned lzo_bitops_ctz32(lzo_uint32 v) -{ - unsigned long r; - (void) _BitScanForward(&r, v); - return (unsigned) r; -} -#define lzo_bitops_ctz32 lzo_bitops_ctz32 -#endif -#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) -#pragma intrinsic(_BitScanForward64) -static __lzo_inline unsigned lzo_bitops_ctz64(lzo_uint64 v) -{ - unsigned long r; - (void) _BitScanForward64(&r, v); - return (unsigned) r; -} -#define lzo_bitops_ctz64 lzo_bitops_ctz64 -#endif - -#elif (LZO_CC_CLANG || (LZO_CC_GNUC >= 0x030400ul) || (LZO_CC_INTELC && (__INTEL_COMPILER >= 1000)) || (LZO_CC_LLVM && (!defined(__llvm_tools_version__) || (__llvm_tools_version__+0 >= 0x010500ul)))) -#if !defined(lzo_bitops_clz32) && defined(WANT_lzo_bitops_clz32) -#define lzo_bitops_clz32(v) ((unsigned) __builtin_clz(v)) -#endif -#if !defined(lzo_bitops_clz64) && defined(WANT_lzo_bitops_clz64) && defined(LZO_UINT64_MAX) -#define lzo_bitops_clz64(v) ((unsigned) __builtin_clzll(v)) -#endif -#if !defined(lzo_bitops_ctz32) && defined(WANT_lzo_bitops_ctz32) -#define lzo_bitops_ctz32(v) ((unsigned) __builtin_ctz(v)) -#endif -#if !defined(lzo_bitops_ctz64) && defined(WANT_lzo_bitops_ctz64) && defined(LZO_UINT64_MAX) -#define lzo_bitops_ctz64(v) ((unsigned) __builtin_ctzll(v)) -#endif -#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount32) -#define lzo_bitops_popcount32(v) ((unsigned) __builtin_popcount(v)) -#endif -#if !defined(lzo_bitops_popcount32) && defined(WANT_lzo_bitops_popcount64) && defined(LZO_UINT64_MAX) -#define lzo_bitops_popcount64(v) ((unsigned) __builtin_popcountll(v)) -#endif +# define do_compress LZO_PP_ECONCAT2(DO_COMPRESS,_core) #endif static __lzo_noinline lzo_uint do_compress ( const lzo_bytep in , lzo_uint in_len, - lzo_bytep out, lzo_uintp out_len, - lzo_uint ti, lzo_voidp wrkmem) + lzo_bytep out, lzo_uintp out_len, + lzo_uint ti, lzo_voidp wrkmem) { - register const lzo_bytep ip; + const lzo_bytep ip; lzo_bytep op; const lzo_bytep const in_end = in + in_len; const lzo_bytep const ip_end = in + in_len - 20; @@ -3194,227 +4814,206 @@ next: if __lzo_unlikely(ip >= ip_end) break; - DINDEX1(dindex, ip); - GINDEX(m_pos, m_off, dict, dindex, in); - if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M4_MAX_OFFSET)) + DINDEX1(dindex,ip); + GINDEX(m_pos,m_off,dict,dindex,in); + if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) goto literal; #if 1 if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) goto try_match; - DINDEX2(dindex, ip); + DINDEX2(dindex,ip); #endif - GINDEX(m_pos, m_off, dict, dindex, in); - if (LZO_CHECK_MPOS_NON_DET(m_pos, m_off, in, ip, M4_MAX_OFFSET)) + GINDEX(m_pos,m_off,dict,dindex,in); + if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET)) goto literal; if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3]) goto try_match; goto literal; try_match: -#if defined(UA_GET32) - if (UA_GET32(m_pos) != UA_GET32(ip)) +#if (LZO_OPT_UNALIGNED32) + if (UA_GET_NE32(m_pos) != UA_GET_NE32(ip)) #else if (m_pos[0] != ip[0] || m_pos[1] != ip[1] || m_pos[2] != ip[2] || m_pos[3] != ip[3]) #endif { literal: - UPDATE_I(dict, 0, dindex, ip, in); + UPDATE_I(dict,0,dindex,ip,in); ip += 1 + ((ip - ii) >> 5); continue; } - UPDATE_I(dict, 0, dindex, ip, in); + UPDATE_I(dict,0,dindex,ip,in); #else lzo_uint m_off; lzo_uint m_len; { - lzo_uint32 dv; - lzo_uint dindex; + lzo_uint32_t dv; + lzo_uint dindex; literal: - ip += 1 + ((ip - ii) >> 5); + ip += 1 + ((ip - ii) >> 5); next: - if __lzo_unlikely(ip >= ip_end) - break; - dv = UA_GET32(ip); - dindex = DINDEX(dv, ip); - GINDEX(m_off, m_pos, in + dict, dindex, in); - UPDATE_I(dict, 0, dindex, ip, in); - if __lzo_unlikely(dv != UA_GET32(m_pos)) - goto literal; + if __lzo_unlikely(ip >= ip_end) + break; + dv = UA_GET_LE32(ip); + dindex = DINDEX(dv,ip); + GINDEX(m_off,m_pos,in+dict,dindex,in); + UPDATE_I(dict,0,dindex,ip,in); + if __lzo_unlikely(dv != UA_GET_LE32(m_pos)) + goto literal; } #endif ii -= ti; ti = 0; { - register lzo_uint t = pd(ip, ii); - if (t != 0) + lzo_uint t = pd(ip,ii); + if (t != 0) + { + if (t <= 3) { - if (t <= 3) - { - op[-2] |= LZO_BYTE(t); -#if defined(UA_COPY32) - UA_COPY32(op, ii); - op += t; + op[-2] = LZO_BYTE(op[-2] | t); +#if (LZO_OPT_UNALIGNED32) + UA_COPY4(op, ii); + op += t; #else - { - do *op++ = *ii++; - while (--t > 0); - } -#endif - } -#if defined(UA_COPY32) || defined(UA_COPY64) - else if (t <= 16) - { - *op++ = LZO_BYTE(t - 3); -#if defined(UA_COPY64) - UA_COPY64(op, ii); - UA_COPY64(op + 8, ii + 8); -#else - UA_COPY32(op, ii); - UA_COPY32(op + 4, ii + 4); - UA_COPY32(op + 8, ii + 8); - UA_COPY32(op + 12, ii + 12); + { do *op++ = *ii++; while (--t > 0); } #endif - op += t; - } + } +#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64) + else if (t <= 16) + { + *op++ = LZO_BYTE(t - 3); + UA_COPY8(op, ii); + UA_COPY8(op+8, ii+8); + op += t; + } #endif + else + { + if (t <= 18) + *op++ = LZO_BYTE(t - 3); else { - if (t <= 18) - *op++ = LZO_BYTE(t - 3); - else - { - register lzo_uint tt = t - 18; - *op++ = 0; - while __lzo_unlikely(tt > 255) - { - tt -= 255; -#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) - * (volatile unsigned char *) op++ = 0; -#else - *op++ = 0; -#endif - } - assert(tt > 0); - *op++ = LZO_BYTE(tt); - } -#if defined(UA_COPY32) || defined(UA_COPY64) - do - { -#if defined(UA_COPY64) - UA_COPY64(op, ii); - UA_COPY64(op + 8, ii + 8); -#else - UA_COPY32(op, ii); - UA_COPY32(op + 4, ii + 4); - UA_COPY32(op + 8, ii + 8); - UA_COPY32(op + 12, ii + 12); -#endif - op += 16; ii += 16; t -= 16; - } - while (t >= 16); if (t > 0) -#endif + lzo_uint tt = t - 18; + *op++ = 0; + while __lzo_unlikely(tt > 255) { - do *op++ = *ii++; - while (--t > 0); + tt -= 255; + UA_SET1(op, 0); + op++; } + assert(tt > 0); + *op++ = LZO_BYTE(tt); } +#if (LZO_OPT_UNALIGNED32) || (LZO_OPT_UNALIGNED64) + do { + UA_COPY8(op, ii); + UA_COPY8(op+8, ii+8); + op += 16; ii += 16; t -= 16; + } while (t >= 16); if (t > 0) +#endif + { do *op++ = *ii++; while (--t > 0); } } } + } m_len = 4; { -#if defined(UA_GET64) - lzo_uint64 v; - v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); - if __lzo_unlikely(v == 0) - { - do - { - m_len += 8; - v = UA_GET64(ip + m_len) ^ UA_GET64(m_pos + m_len); - if __lzo_unlikely(ip + m_len >= ip_end) - goto m_len_done; - } - while (v == 0); - } -#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_clz64) - m_len += lzo_bitops_clz64(v) / CHAR_BIT; +#if (LZO_OPT_UNALIGNED64) + lzo_uint64_t v; + v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len); + if __lzo_unlikely(v == 0) { + do { + m_len += 8; + v = UA_GET_NE64(ip + m_len) ^ UA_GET_NE64(m_pos + m_len); + if __lzo_unlikely(ip + m_len >= ip_end) + goto m_len_done; + } while (v == 0); + } +#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz64) + m_len += lzo_bitops_ctlz64(v) / CHAR_BIT; #elif (LZO_ABI_BIG_ENDIAN) - if ((v >> (64 - CHAR_BIT)) == 0) do - { - v <<= CHAR_BIT; - m_len += 1; - } - while ((v >> (64 - CHAR_BIT)) == 0); -#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz64) - m_len += lzo_bitops_ctz64(v) / CHAR_BIT; + if ((v >> (64 - CHAR_BIT)) == 0) do { + v <<= CHAR_BIT; + m_len += 1; + } while ((v >> (64 - CHAR_BIT)) == 0); +#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz64) + m_len += lzo_bitops_cttz64(v) / CHAR_BIT; #elif (LZO_ABI_LITTLE_ENDIAN) - if ((v & UCHAR_MAX) == 0) do - { - v >>= CHAR_BIT; - m_len += 1; - } - while ((v & UCHAR_MAX) == 0); -#else - if (ip[m_len] == m_pos[m_len]) do - { - m_len += 1; - } - while (ip[m_len] == m_pos[m_len]); -#endif -#elif defined(UA_GET32) - lzo_uint32 v; - v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); - if __lzo_unlikely(v == 0) - { - do - { - m_len += 4; - v = UA_GET32(ip + m_len) ^ UA_GET32(m_pos + m_len); - if __lzo_unlikely(ip + m_len >= ip_end) - goto m_len_done; - } - while (v == 0); - } -#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_clz32) - m_len += lzo_bitops_clz32(v) / CHAR_BIT; + if ((v & UCHAR_MAX) == 0) do { + v >>= CHAR_BIT; + m_len += 1; + } while ((v & UCHAR_MAX) == 0); +#else + if (ip[m_len] == m_pos[m_len]) do { + m_len += 1; + } while (ip[m_len] == m_pos[m_len]); +#endif +#elif (LZO_OPT_UNALIGNED32) + lzo_uint32_t v; + v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); + if __lzo_unlikely(v == 0) { + do { + m_len += 4; + v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); + if (v != 0) + break; + m_len += 4; + v = UA_GET_NE32(ip + m_len) ^ UA_GET_NE32(m_pos + m_len); + if __lzo_unlikely(ip + m_len >= ip_end) + goto m_len_done; + } while (v == 0); + } +#if (LZO_ABI_BIG_ENDIAN) && defined(lzo_bitops_ctlz32) + m_len += lzo_bitops_ctlz32(v) / CHAR_BIT; #elif (LZO_ABI_BIG_ENDIAN) - if ((v >> (32 - CHAR_BIT)) == 0) do - { - v <<= CHAR_BIT; - m_len += 1; - } - while ((v >> (32 - CHAR_BIT)) == 0); -#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_ctz32) - m_len += lzo_bitops_ctz32(v) / CHAR_BIT; + if ((v >> (32 - CHAR_BIT)) == 0) do { + v <<= CHAR_BIT; + m_len += 1; + } while ((v >> (32 - CHAR_BIT)) == 0); +#elif (LZO_ABI_LITTLE_ENDIAN) && defined(lzo_bitops_cttz32) + m_len += lzo_bitops_cttz32(v) / CHAR_BIT; #elif (LZO_ABI_LITTLE_ENDIAN) - if ((v & UCHAR_MAX) == 0) do - { - v >>= CHAR_BIT; - m_len += 1; - } - while ((v & UCHAR_MAX) == 0); -#else - if (ip[m_len] == m_pos[m_len]) do - { - m_len += 1; - } - while (ip[m_len] == m_pos[m_len]); -#endif -#else - if __lzo_unlikely(ip[m_len] == m_pos[m_len]) - { - do - { - m_len += 1; - if __lzo_unlikely(ip + m_len >= ip_end) - goto m_len_done; - } - while (ip[m_len] == m_pos[m_len]); - } + if ((v & UCHAR_MAX) == 0) do { + v >>= CHAR_BIT; + m_len += 1; + } while ((v & UCHAR_MAX) == 0); +#else + if (ip[m_len] == m_pos[m_len]) do { + m_len += 1; + } while (ip[m_len] == m_pos[m_len]); +#endif +#else + if __lzo_unlikely(ip[m_len] == m_pos[m_len]) { + do { + m_len += 1; + if (ip[m_len] != m_pos[m_len]) + break; + m_len += 1; + if (ip[m_len] != m_pos[m_len]) + break; + m_len += 1; + if (ip[m_len] != m_pos[m_len]) + break; + m_len += 1; + if (ip[m_len] != m_pos[m_len]) + break; + m_len += 1; + if (ip[m_len] != m_pos[m_len]) + break; + m_len += 1; + if (ip[m_len] != m_pos[m_len]) + break; + m_len += 1; + if (ip[m_len] != m_pos[m_len]) + break; + m_len += 1; + if __lzo_unlikely(ip + m_len >= ip_end) + goto m_len_done; + } while (ip[m_len] == m_pos[m_len]); + } #endif } m_len_done: - m_off = pd(ip, m_pos); + m_off = pd(ip,m_pos); ip += m_len; ii = ip; if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET) @@ -3440,11 +5039,8 @@ while __lzo_unlikely(m_len > 255) { m_len -= 255; -#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) - * (volatile unsigned char *) op++ = 0; -#else - *op++ = 0; -#endif + UA_SET1(op, 0); + op++; } *op++ = LZO_BYTE(m_len); } @@ -3463,11 +5059,8 @@ while __lzo_unlikely(m_len > 255) { m_len -= 255; -#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) - * (volatile unsigned char *) op++ = 0; -#else - *op++ = 0; -#endif + UA_SET1(op, 0); + op++; } *op++ = LZO_BYTE(m_len); } @@ -3478,13 +5071,13 @@ } *out_len = pd(op, out); - return pd(in_end, ii - ti); + return pd(in_end,ii-ti); } LZO_PUBLIC(int) DO_COMPRESS ( const lzo_bytep in , lzo_uint in_len, - lzo_bytep out, lzo_uintp out_len, - lzo_voidp wrkmem ) + lzo_bytep out, lzo_uintp out_len, + lzo_voidp wrkmem ) { const lzo_bytep ip = in; lzo_bytep op = out; @@ -3504,7 +5097,7 @@ #if (LZO_DETERMINISTIC) lzo_memset(wrkmem, 0, ((lzo_uint)1 << D_BITS) * sizeof(lzo_dict_t)); #endif - t = do_compress(ip, ll, op, out_len, t, wrkmem); + t = do_compress(ip,ll,op,out_len,t,wrkmem); ip += ll; op += *out_len; l -= ll; @@ -3518,7 +5111,7 @@ if (op == out && t <= 238) *op++ = LZO_BYTE(17 + t); else if (t <= 3) - op[-2] |= LZO_BYTE(t); + op[-2] = LZO_BYTE(op[-2] | t); else if (t <= 18) *op++ = LZO_BYTE(t - 3); else @@ -3529,17 +5122,14 @@ while (tt > 255) { tt -= 255; -#if 1 && (LZO_CC_MSC && (_MSC_VER >= 1400)) - - * (volatile unsigned char *) op++ = 0; -#else - *op++ = 0; -#endif + UA_SET1(op, 0); + op++; } assert(tt > 0); *op++ = LZO_BYTE(tt); } - do *op++ = *ii++; while (--t > 0); + UA_COPYN(op, ii, t); + op += t; } *op++ = M4_MARKER | 1; @@ -3576,10 +5166,13 @@ #undef TEST_IP #undef TEST_OP +#undef TEST_IP_AND_TEST_OP #undef TEST_LB #undef TEST_LBO #undef NEED_IP #undef NEED_OP +#undef TEST_IV +#undef TEST_OV #undef HAVE_TEST_IP #undef HAVE_TEST_OP #undef HAVE_NEED_IP @@ -3593,7 +5186,8 @@ # endif # if (LZO_TEST_OVERRUN_INPUT >= 2) # define NEED_IP(x) \ - if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun + if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun +# define TEST_IV(x) if ((x) > (lzo_uint)0 - (511)) goto input_overrun # endif #endif @@ -3604,13 +5198,14 @@ # if (LZO_TEST_OVERRUN_OUTPUT >= 2) # undef TEST_OP # define NEED_OP(x) \ - if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun + if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun +# define TEST_OV(x) if ((x) > (lzo_uint)0 - (511)) goto output_overrun # endif #endif #if defined(LZO_TEST_OVERRUN_LOOKBEHIND) -# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun -# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun +# define TEST_LB(m_pos) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op)) goto lookbehind_overrun +# define TEST_LBO(m_pos,o) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op-(o))) goto lookbehind_overrun #else # define TEST_LB(m_pos) ((void) 0) # define TEST_LBO(m_pos,o) ((void) 0) @@ -3631,15 +5226,27 @@ # define TEST_OP 1 #endif +#if defined(HAVE_TEST_IP) && defined(HAVE_TEST_OP) +# define TEST_IP_AND_TEST_OP (TEST_IP && TEST_OP) +#elif defined(HAVE_TEST_IP) +# define TEST_IP_AND_TEST_OP TEST_IP +#elif defined(HAVE_TEST_OP) +# define TEST_IP_AND_TEST_OP TEST_OP +#else +# define TEST_IP_AND_TEST_OP 1 +#endif + #if defined(NEED_IP) # define HAVE_NEED_IP 1 #else # define NEED_IP(x) ((void) 0) +# define TEST_IV(x) ((void) 0) #endif #if defined(NEED_OP) # define HAVE_NEED_OP 1 #else # define NEED_OP(x) ((void) 0) +# define TEST_OV(x) ((void) 0) #endif #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) @@ -3652,18 +5259,18 @@ #if defined(DO_DECOMPRESS) LZO_PUBLIC(int) DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, - lzo_bytep out, lzo_uintp out_len, - lzo_voidp wrkmem ) + lzo_bytep out, lzo_uintp out_len, + lzo_voidp wrkmem ) #endif { - register lzo_bytep op; - register const lzo_bytep ip; - register lzo_uint t; + lzo_bytep op; + const lzo_bytep ip; + lzo_uint t; #if defined(COPY_DICT) lzo_uint m_off; const lzo_bytep dict_end; #else - register const lzo_bytep m_pos; + const lzo_bytep m_pos; #endif const lzo_bytep const ip_end = in + in_len; @@ -3698,86 +5305,78 @@ op = out; ip = in; + NEED_IP(1); if (*ip > 17) { t = *ip++ - 17; if (t < 4) goto match_next; - assert(t > 0); NEED_OP(t); NEED_IP(t + 1); + assert(t > 0); NEED_OP(t); NEED_IP(t+3); do *op++ = *ip++; while (--t > 0); goto first_literal_run; } - while (TEST_IP && TEST_OP) + for (;;) { + NEED_IP(3); t = *ip++; if (t >= 16) goto match; if (t == 0) { - NEED_IP(1); while (*ip == 0) { t += 255; ip++; + TEST_IV(t); NEED_IP(1); } t += 15 + *ip++; } - assert(t > 0); NEED_OP(t + 3); NEED_IP(t + 4); -#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) + assert(t > 0); NEED_OP(t+3); NEED_IP(t+6); +#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) t += 3; if (t >= 8) do - { - UA_COPY64(op, ip); - op += 8; ip += 8; t -= 8; - } - while (t >= 8); + { + UA_COPY8(op,ip); + op += 8; ip += 8; t -= 8; + } while (t >= 8); if (t >= 4) { - UA_COPY32(op, ip); + UA_COPY4(op,ip); op += 4; ip += 4; t -= 4; } if (t > 0) { *op++ = *ip++; - if (t > 1) - { - *op++ = *ip++; - if (t > 2) - { - *op++ = *ip++; - } - } + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } } -#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) -#if !defined(LZO_UNALIGNED_OK_4) - if (PTR_ALIGNED2_4(op, ip)) +#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) +#if !(LZO_OPT_UNALIGNED32) + if (PTR_ALIGNED2_4(op,ip)) { #endif - UA_COPY32(op, ip); - op += 4; ip += 4; - if (--t > 0) + UA_COPY4(op,ip); + op += 4; ip += 4; + if (--t > 0) + { + if (t >= 4) { - if (t >= 4) - { - do - { - UA_COPY32(op, ip); - op += 4; ip += 4; t -= 4; - } - while (t >= 4); - if (t > 0) do *op++ = *ip++; while (--t > 0); - } - else - do *op++ = *ip++; while (--t > 0); + do { + UA_COPY4(op,ip); + op += 4; ip += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *ip++; while (--t > 0); } -#if !defined(LZO_UNALIGNED_OK_4) + else + do *op++ = *ip++; while (--t > 0); + } +#if !(LZO_OPT_UNALIGNED32) } else #endif #endif -#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) +#if !(LZO_OPT_UNALIGNED32) { *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; do *op++ = *ip++; while (--t > 0); @@ -3797,7 +5396,7 @@ m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2); #endif NEED_OP(3); - t = 3; COPY_DICT(t, m_off) + t = 3; COPY_DICT(t,m_off) #else #if defined(LZO1Z) t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); @@ -3813,8 +5412,7 @@ #endif goto match_done; - do - { + for (;;) { match: if (t >= 64) { @@ -3865,7 +5463,7 @@ } t = (t >> 5) - 1; #endif - TEST_LB(m_pos); assert(t > 0); NEED_OP(t + 3 - 1); + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); goto copy_match; #endif } @@ -3874,14 +5472,15 @@ t &= 31; if (t == 0) { - NEED_IP(1); while (*ip == 0) { t += 255; ip++; + TEST_OV(t); NEED_IP(1); } t += 31 + *ip++; + NEED_IP(2); } #if defined(COPY_DICT) #if defined(LZO1Z) @@ -3897,9 +5496,9 @@ m_pos = op - off; last_m_off = off; } -#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) +#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) m_pos = op - 1; - m_pos -= UA_GET16(ip) >> 2; + m_pos -= UA_GET_LE16(ip) >> 2; #else m_pos = op - 1; m_pos -= (ip[0] >> 2) + (ip[1] << 6); @@ -3918,14 +5517,15 @@ t &= 7; if (t == 0) { - NEED_IP(1); while (*ip == 0) { t += 255; ip++; + TEST_OV(t); NEED_IP(1); } t += 7 + *ip++; + NEED_IP(2); } #if defined(COPY_DICT) #if defined(LZO1Z) @@ -3943,8 +5543,8 @@ #else #if defined(LZO1Z) m_pos -= (ip[0] << 6) + (ip[1] >> 2); -#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) - m_pos -= UA_GET16(ip) >> 2; +#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) + m_pos -= UA_GET_LE16(ip) >> 2; #else m_pos -= (ip[0] >> 2) + (ip[1] << 6); #endif @@ -3967,7 +5567,7 @@ m_off = 1 + (t >> 2) + (*ip++ << 2); #endif NEED_OP(2); - t = 2; COPY_DICT(t, m_off) + t = 2; COPY_DICT(t,m_off) #else #if defined(LZO1Z) t = 1 + (t << 6) + (*ip++ >> 2); @@ -3986,59 +5586,49 @@ #if defined(COPY_DICT) - NEED_OP(t + 3 - 1); - t += 3 - 1; COPY_DICT(t, m_off) + NEED_OP(t+3-1); + t += 3-1; COPY_DICT(t,m_off) #else - TEST_LB(m_pos); assert(t > 0); NEED_OP(t + 3 - 1); -#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); +#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) if (op - m_pos >= 8) { t += (3 - 1); if (t >= 8) do - { - UA_COPY64(op, m_pos); - op += 8; m_pos += 8; t -= 8; - } - while (t >= 8); + { + UA_COPY8(op,m_pos); + op += 8; m_pos += 8; t -= 8; + } while (t >= 8); if (t >= 4) { - UA_COPY32(op, m_pos); + UA_COPY4(op,m_pos); op += 4; m_pos += 4; t -= 4; } if (t > 0) { *op++ = m_pos[0]; - if (t > 1) - { - *op++ = m_pos[1]; - if (t > 2) - { - *op++ = m_pos[2]; - } - } + if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } } } } else -#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) -#if !defined(LZO_UNALIGNED_OK_4) - if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op, m_pos)) +#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) +#if !(LZO_OPT_UNALIGNED32) + if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) { assert((op - m_pos) >= 4); #else if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) { #endif - UA_COPY32(op, m_pos); + UA_COPY4(op,m_pos); op += 4; m_pos += 4; t -= 4 - (3 - 1); - do - { - UA_COPY32(op, m_pos); + do { + UA_COPY4(op,m_pos); op += 4; m_pos += 4; t -= 4; - } - while (t >= 4); - if (t > 0) do *op++ = *m_pos++; while (--t > 0); + } while (t >= 4); + if (t > 0) do *op++ = *m_pos++; while (--t > 0); } else #endif @@ -4060,34 +5650,21 @@ break; match_next: - assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t + 1); + assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+3); #if 0 do *op++ = *ip++; while (--t > 0); #else *op++ = *ip++; - if (t > 1) - { - *op++ = *ip++; - if (t > 2) - { - *op++ = *ip++; - } - } + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } #endif t = *ip++; - } while (TEST_IP && TEST_OP); + } } -#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) - *out_len = pd(op, out); - return LZO_E_EOF_NOT_FOUND; -#endif - eof_found: - assert(t == 1); *out_len = pd(op, out); return (ip == ip_end ? LZO_E_OK : - (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); #if defined(HAVE_NEED_IP) input_overrun: @@ -4130,10 +5707,13 @@ #undef TEST_IP #undef TEST_OP +#undef TEST_IP_AND_TEST_OP #undef TEST_LB #undef TEST_LBO #undef NEED_IP #undef NEED_OP +#undef TEST_IV +#undef TEST_OV #undef HAVE_TEST_IP #undef HAVE_TEST_OP #undef HAVE_NEED_IP @@ -4147,7 +5727,8 @@ # endif # if (LZO_TEST_OVERRUN_INPUT >= 2) # define NEED_IP(x) \ - if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun + if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun +# define TEST_IV(x) if ((x) > (lzo_uint)0 - (511)) goto input_overrun # endif #endif @@ -4158,13 +5739,14 @@ # if (LZO_TEST_OVERRUN_OUTPUT >= 2) # undef TEST_OP # define NEED_OP(x) \ - if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun + if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun +# define TEST_OV(x) if ((x) > (lzo_uint)0 - (511)) goto output_overrun # endif #endif #if defined(LZO_TEST_OVERRUN_LOOKBEHIND) -# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun -# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun +# define TEST_LB(m_pos) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op)) goto lookbehind_overrun +# define TEST_LBO(m_pos,o) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op-(o))) goto lookbehind_overrun #else # define TEST_LB(m_pos) ((void) 0) # define TEST_LBO(m_pos,o) ((void) 0) @@ -4185,15 +5767,27 @@ # define TEST_OP 1 #endif +#if defined(HAVE_TEST_IP) && defined(HAVE_TEST_OP) +# define TEST_IP_AND_TEST_OP (TEST_IP && TEST_OP) +#elif defined(HAVE_TEST_IP) +# define TEST_IP_AND_TEST_OP TEST_IP +#elif defined(HAVE_TEST_OP) +# define TEST_IP_AND_TEST_OP TEST_OP +#else +# define TEST_IP_AND_TEST_OP 1 +#endif + #if defined(NEED_IP) # define HAVE_NEED_IP 1 #else # define NEED_IP(x) ((void) 0) +# define TEST_IV(x) ((void) 0) #endif #if defined(NEED_OP) # define HAVE_NEED_OP 1 #else # define NEED_OP(x) ((void) 0) +# define TEST_OV(x) ((void) 0) #endif #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP) @@ -4206,18 +5800,18 @@ #if defined(DO_DECOMPRESS) LZO_PUBLIC(int) DO_DECOMPRESS ( const lzo_bytep in , lzo_uint in_len, - lzo_bytep out, lzo_uintp out_len, - lzo_voidp wrkmem ) + lzo_bytep out, lzo_uintp out_len, + lzo_voidp wrkmem ) #endif { - register lzo_bytep op; - register const lzo_bytep ip; - register lzo_uint t; + lzo_bytep op; + const lzo_bytep ip; + lzo_uint t; #if defined(COPY_DICT) lzo_uint m_off; const lzo_bytep dict_end; #else - register const lzo_bytep m_pos; + const lzo_bytep m_pos; #endif const lzo_bytep const ip_end = in + in_len; @@ -4252,86 +5846,78 @@ op = out; ip = in; + NEED_IP(1); if (*ip > 17) { t = *ip++ - 17; if (t < 4) goto match_next; - assert(t > 0); NEED_OP(t); NEED_IP(t + 1); + assert(t > 0); NEED_OP(t); NEED_IP(t+3); do *op++ = *ip++; while (--t > 0); goto first_literal_run; } - while (TEST_IP && TEST_OP) + for (;;) { + NEED_IP(3); t = *ip++; if (t >= 16) goto match; if (t == 0) { - NEED_IP(1); while (*ip == 0) { t += 255; ip++; + TEST_IV(t); NEED_IP(1); } t += 15 + *ip++; } - assert(t > 0); NEED_OP(t + 3); NEED_IP(t + 4); -#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) + assert(t > 0); NEED_OP(t+3); NEED_IP(t+6); +#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) t += 3; if (t >= 8) do - { - UA_COPY64(op, ip); - op += 8; ip += 8; t -= 8; - } - while (t >= 8); + { + UA_COPY8(op,ip); + op += 8; ip += 8; t -= 8; + } while (t >= 8); if (t >= 4) { - UA_COPY32(op, ip); + UA_COPY4(op,ip); op += 4; ip += 4; t -= 4; } if (t > 0) { *op++ = *ip++; - if (t > 1) - { - *op++ = *ip++; - if (t > 2) - { - *op++ = *ip++; - } - } + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } } -#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) -#if !defined(LZO_UNALIGNED_OK_4) - if (PTR_ALIGNED2_4(op, ip)) +#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) +#if !(LZO_OPT_UNALIGNED32) + if (PTR_ALIGNED2_4(op,ip)) { #endif - UA_COPY32(op, ip); - op += 4; ip += 4; - if (--t > 0) + UA_COPY4(op,ip); + op += 4; ip += 4; + if (--t > 0) + { + if (t >= 4) { - if (t >= 4) - { - do - { - UA_COPY32(op, ip); - op += 4; ip += 4; t -= 4; - } - while (t >= 4); - if (t > 0) do *op++ = *ip++; while (--t > 0); - } - else - do *op++ = *ip++; while (--t > 0); + do { + UA_COPY4(op,ip); + op += 4; ip += 4; t -= 4; + } while (t >= 4); + if (t > 0) do *op++ = *ip++; while (--t > 0); } -#if !defined(LZO_UNALIGNED_OK_4) + else + do *op++ = *ip++; while (--t > 0); + } +#if !(LZO_OPT_UNALIGNED32) } else #endif #endif -#if !defined(LZO_UNALIGNED_OK_4) && !defined(LZO_UNALIGNED_OK_8) +#if !(LZO_OPT_UNALIGNED32) { *op++ = *ip++; *op++ = *ip++; *op++ = *ip++; do *op++ = *ip++; while (--t > 0); @@ -4351,7 +5937,7 @@ m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2); #endif NEED_OP(3); - t = 3; COPY_DICT(t, m_off) + t = 3; COPY_DICT(t,m_off) #else #if defined(LZO1Z) t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2); @@ -4367,8 +5953,7 @@ #endif goto match_done; - do - { + for (;;) { match: if (t >= 64) { @@ -4419,7 +6004,7 @@ } t = (t >> 5) - 1; #endif - TEST_LB(m_pos); assert(t > 0); NEED_OP(t + 3 - 1); + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); goto copy_match; #endif } @@ -4428,14 +6013,15 @@ t &= 31; if (t == 0) { - NEED_IP(1); while (*ip == 0) { t += 255; ip++; + TEST_OV(t); NEED_IP(1); } t += 31 + *ip++; + NEED_IP(2); } #if defined(COPY_DICT) #if defined(LZO1Z) @@ -4451,9 +6037,9 @@ m_pos = op - off; last_m_off = off; } -#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) +#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) m_pos = op - 1; - m_pos -= UA_GET16(ip) >> 2; + m_pos -= UA_GET_LE16(ip) >> 2; #else m_pos = op - 1; m_pos -= (ip[0] >> 2) + (ip[1] << 6); @@ -4472,14 +6058,15 @@ t &= 7; if (t == 0) { - NEED_IP(1); while (*ip == 0) { t += 255; ip++; + TEST_OV(t); NEED_IP(1); } t += 7 + *ip++; + NEED_IP(2); } #if defined(COPY_DICT) #if defined(LZO1Z) @@ -4497,8 +6084,8 @@ #else #if defined(LZO1Z) m_pos -= (ip[0] << 6) + (ip[1] >> 2); -#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN) - m_pos -= UA_GET16(ip) >> 2; +#elif (LZO_OPT_UNALIGNED16) && (LZO_ABI_LITTLE_ENDIAN) + m_pos -= UA_GET_LE16(ip) >> 2; #else m_pos -= (ip[0] >> 2) + (ip[1] << 6); #endif @@ -4521,7 +6108,7 @@ m_off = 1 + (t >> 2) + (*ip++ << 2); #endif NEED_OP(2); - t = 2; COPY_DICT(t, m_off) + t = 2; COPY_DICT(t,m_off) #else #if defined(LZO1Z) t = 1 + (t << 6) + (*ip++ >> 2); @@ -4540,59 +6127,49 @@ #if defined(COPY_DICT) - NEED_OP(t + 3 - 1); - t += 3 - 1; COPY_DICT(t, m_off) + NEED_OP(t+3-1); + t += 3-1; COPY_DICT(t,m_off) #else - TEST_LB(m_pos); assert(t > 0); NEED_OP(t + 3 - 1); -#if defined(LZO_UNALIGNED_OK_8) && defined(LZO_UNALIGNED_OK_4) + TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1); +#if (LZO_OPT_UNALIGNED64) && (LZO_OPT_UNALIGNED32) if (op - m_pos >= 8) { t += (3 - 1); if (t >= 8) do - { - UA_COPY64(op, m_pos); - op += 8; m_pos += 8; t -= 8; - } - while (t >= 8); + { + UA_COPY8(op,m_pos); + op += 8; m_pos += 8; t -= 8; + } while (t >= 8); if (t >= 4) { - UA_COPY32(op, m_pos); + UA_COPY4(op,m_pos); op += 4; m_pos += 4; t -= 4; } if (t > 0) { *op++ = m_pos[0]; - if (t > 1) - { - *op++ = m_pos[1]; - if (t > 2) - { - *op++ = m_pos[2]; - } - } + if (t > 1) { *op++ = m_pos[1]; if (t > 2) { *op++ = m_pos[2]; } } } } else -#elif defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4) -#if !defined(LZO_UNALIGNED_OK_4) - if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op, m_pos)) +#elif (LZO_OPT_UNALIGNED32) || (LZO_ALIGNED_OK_4) +#if !(LZO_OPT_UNALIGNED32) + if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) { assert((op - m_pos) >= 4); #else if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) { #endif - UA_COPY32(op, m_pos); + UA_COPY4(op,m_pos); op += 4; m_pos += 4; t -= 4 - (3 - 1); - do - { - UA_COPY32(op, m_pos); + do { + UA_COPY4(op,m_pos); op += 4; m_pos += 4; t -= 4; - } - while (t >= 4); - if (t > 0) do *op++ = *m_pos++; while (--t > 0); + } while (t >= 4); + if (t > 0) do *op++ = *m_pos++; while (--t > 0); } else #endif @@ -4614,34 +6191,21 @@ break; match_next: - assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t + 1); + assert(t > 0); assert(t < 4); NEED_OP(t); NEED_IP(t+3); #if 0 do *op++ = *ip++; while (--t > 0); #else *op++ = *ip++; - if (t > 1) - { - *op++ = *ip++; - if (t > 2) - { - *op++ = *ip++; - } - } + if (t > 1) { *op++ = *ip++; if (t > 2) { *op++ = *ip++; } } #endif t = *ip++; - } while (TEST_IP && TEST_OP); + } } -#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP) - *out_len = pd(op, out); - return LZO_E_EOF_NOT_FOUND; -#endif - eof_found: - assert(t == 1); *out_len = pd(op, out); return (ip == ip_end ? LZO_E_OK : - (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); + (ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN)); #if defined(HAVE_NEED_IP) input_overrun: @@ -4665,4 +6229,3 @@ #endif /***** End of minilzo.c *****/ - diff -Nru oscam-1.20-10584~r10356/minilzo/minilzo.h oscam-1.20-10797~r10569/minilzo/minilzo.h --- oscam-1.20-10584~r10356/minilzo/minilzo.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/minilzo/minilzo.h 2015-02-20 11:57:49.000000000 +0000 @@ -2,22 +2,7 @@ This file is part of the LZO real-time data compression library. - Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer - Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer All Rights Reserved. The LZO library is free software; you can redistribute it and/or @@ -47,15 +32,25 @@ */ -#ifndef __MINILZO_H -#define __MINILZO_H 1 +#ifndef __MINILZO_H_INCLUDED +#define __MINILZO_H_INCLUDED 1 -#define MINILZO_VERSION 0x2060 +#define MINILZO_VERSION 0x2090 -#ifdef __LZOCONF_H +#if defined(__LZOCONF_H_INCLUDED) # error "you cannot use both LZO and miniLZO" #endif +/* internal Autoconf configuration file - only used when building miniLZO */ +#ifdef MINILZO_HAVE_CONFIG_H +# include +#endif +#include +#include + +#ifndef __LZODEFS_H_INCLUDED +#include "lzodefs.h" +#endif #undef LZO_HAVE_CONFIG_H #include "lzoconf.h" @@ -69,36 +64,36 @@ #endif - /*********************************************************************** - // - ************************************************************************/ - - /* Memory required for the wrkmem parameter. - * When the required size is 0, you can also pass a NULL pointer. - */ +/*********************************************************************** +// +************************************************************************/ + +/* Memory required for the wrkmem parameter. + * When the required size is 0, you can also pass a NULL pointer. + */ #define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS -#define LZO1X_1_MEM_COMPRESS ((lzo_uint32) (16384L * lzo_sizeof_dict_t)) +#define LZO1X_1_MEM_COMPRESS ((lzo_uint32_t) (16384L * lzo_sizeof_dict_t)) #define LZO1X_MEM_DECOMPRESS (0) - /* compression */ - LZO_EXTERN(int) - lzo1x_1_compress(const lzo_bytep src, lzo_uint src_len, - lzo_bytep dst, lzo_uintp dst_len, - lzo_voidp wrkmem); - - /* decompression */ - LZO_EXTERN(int) - lzo1x_decompress(const lzo_bytep src, lzo_uint src_len, - lzo_bytep dst, lzo_uintp dst_len, - lzo_voidp wrkmem /* NOT USED */); - - /* safe decompression with overrun testing */ - LZO_EXTERN(int) - lzo1x_decompress_safe(const lzo_bytep src, lzo_uint src_len, - lzo_bytep dst, lzo_uintp dst_len, - lzo_voidp wrkmem /* NOT USED */); +/* compression */ +LZO_EXTERN(int) +lzo1x_1_compress ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem ); + +/* decompression */ +LZO_EXTERN(int) +lzo1x_decompress ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem /* NOT USED */ ); + +/* safe decompression with overrun testing */ +LZO_EXTERN(int) +lzo1x_decompress_safe ( const lzo_bytep src, lzo_uint src_len, + lzo_bytep dst, lzo_uintp dst_len, + lzo_voidp wrkmem /* NOT USED */ ); #ifdef __cplusplus @@ -107,3 +102,5 @@ #endif /* already included */ + +/* vim:set ts=4 sw=4 et: */ diff -Nru oscam-1.20-10584~r10356/minilzo/README.LZO oscam-1.20-10797~r10569/minilzo/README.LZO --- oscam-1.20-10584~r10356/minilzo/README.LZO 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/minilzo/README.LZO 2015-02-20 11:57:49.000000000 +0000 @@ -6,8 +6,8 @@ Author : Markus Franz Xaver Johannes Oberhumer http://www.oberhumer.com/opensource/lzo/ - Version : 2.06 - Date : 12 Aug 2011 + Version : 2.09 + Date : 04 Feb 2015 I've created miniLZO for projects where it is inconvenient to include (or require) the full LZO source code just because you @@ -110,9 +110,8 @@ Appendix D: Copyright --------------------- - LZO and miniLZO are Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 - Markus Franz Xaver Oberhumer . + LZO and miniLZO are Copyright (C) 1996-2015 Markus Franz Xaver Oberhumer + All Rights Reserved. LZO and miniLZO are distributed under the terms of the GNU General Public License (GPL). See the file COPYING. diff -Nru oscam-1.20-10584~r10356/module-cacheex.c oscam-1.20-10797~r10569/module-cacheex.c --- oscam-1.20-10584~r10356/module-cacheex.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-cacheex.c 2015-02-20 11:57:49.000000000 +0000 @@ -12,6 +12,7 @@ #include "oscam-client.h" #include "oscam-conf.h" #include "oscam-ecm.h" +#include "oscam-hashtable.h" #include "oscam-lock.h" #include "oscam-net.h" #include "oscam-string.h" @@ -30,6 +31,208 @@ extern CS_MUTEX_LOCK ecmcache_lock; extern struct ecm_request_t *ecmcwcache; +// HIT CACHE functions ************************************************************** + +typedef struct hit_key_t { + uint16_t caid; + uint32_t prid; + uint16_t srvid; +} HIT_KEY; + +typedef struct cache_hit_t { + HIT_KEY key; + struct timeb time; + uint64_t grp; + node ht_node; + node ll_node; +} CACHE_HIT; + +static pthread_rwlock_t hitcache_lock; +static hash_table ht_hitcache; +static list ll_hitcache; +static bool cacheex_running; + +void cacheex_init_hitcache(void) +{ + init_hash_table(&ht_hitcache, &ll_hitcache); + if (pthread_rwlock_init(&hitcache_lock,NULL) != 0) + cs_log("Error creating lock hitcache_lock!"); + cacheex_running = true; +} + +void cacheex_free_hitcache(void) +{ + cacheex_running = false; + cacheex_cleanup_hitcache(true); + deinitialize_hash_table(&ht_hitcache); + pthread_rwlock_destroy(&hitcache_lock); +} + +static int cacheex_compare_hitkey(const void *arg, const void *obj) +{ + if(((const HIT_KEY*)arg)->caid==((const CACHE_HIT*)obj)->key.caid + && ((const HIT_KEY*)arg)->prid==((const CACHE_HIT*)obj)->key.prid + && ((const HIT_KEY*)arg)->srvid==((const CACHE_HIT*)obj)->key.srvid) + { + return 0; + } + return 1; +} + +static int32_t cacheex_check_hitcache(ECM_REQUEST *er, struct s_client *cl) +{ + CACHE_HIT *result; + HIT_KEY search; + memset(&search, 0, sizeof(HIT_KEY)); + search.caid = er->caid; + search.prid = er->prid; + search.srvid = er->srvid; + pthread_rwlock_rdlock(&hitcache_lock); + result = find_hash_table(&ht_hitcache, &search, sizeof(HIT_KEY), &cacheex_compare_hitkey); + if(result){ + struct timeb now; + cs_ftime(&now); + int64_t gone = comp_timeb(&now, &result->time); + uint64_t grp = cl?cl->grp:0; + if( + gone <= (cfg.max_hitcache_time*1000) + && + (!grp || !result->grp || (grp & result->grp)) + ) + { + pthread_rwlock_unlock(&hitcache_lock); + return 1; + } + } + pthread_rwlock_unlock(&hitcache_lock); + return 0; +} + +static void cacheex_add_hitcache(struct s_client *cl, ECM_REQUEST *er) +{ + if (!cfg.max_hitcache_time) //we don't want check/save hitcache + return; + if (!cfg.cacheex_wait_timetab.n) + return; + uint32_t cacheex_wait_time = get_cacheex_wait_time(er,NULL); + if (!cacheex_wait_time) + return; + + CACHE_HIT *result; + HIT_KEY search; + + memset(&search, 0, sizeof(HIT_KEY)); + search.caid = er->caid; + search.prid = er->prid; + search.srvid = er->srvid; + + pthread_rwlock_wrlock(&hitcache_lock); + + result = find_hash_table(&ht_hitcache, &search, sizeof(HIT_KEY), &cacheex_compare_hitkey); + if(!result) { //not found, add it! + if(cs_malloc(&result, sizeof(CACHE_HIT))) + { + memset(result, 0, sizeof(CACHE_HIT)); + result->key.caid = er->caid; + result->key.prid = er->prid; + result->key.srvid = er->srvid; + add_hash_table(&ht_hitcache, &result->ht_node, &ll_hitcache, &result->ll_node, result, &result->key, sizeof(HIT_KEY)); + } + } + + if(result) + { + if(cl) result->grp |= cl->grp; + cs_ftime(&result->time); //always update time; + } + + pthread_rwlock_unlock(&hitcache_lock); +} + +static void cacheex_del_hitcache(ECM_REQUEST *er) +{ + HIT_KEY search; + + memset(&search, 0, sizeof(HIT_KEY)); + search.caid = er->caid; + search.prid = er->prid; + search.srvid = er->srvid; + + pthread_rwlock_wrlock(&hitcache_lock); + search_remove_elem_hash_table(&ht_hitcache, &search, sizeof(HIT_KEY), &cacheex_compare_hitkey); + pthread_rwlock_unlock(&hitcache_lock); +} + +void cacheex_cleanup_hitcache(bool force) +{ + CACHE_HIT *cachehit; + node *i,*i_next; + struct timeb now; + int64_t gone; + int32_t timeout = (cfg.max_hitcache_time + (cfg.max_hitcache_time / 2))*1000; //1,5 + pthread_rwlock_wrlock(&hitcache_lock); + i = get_first_node_list(&ll_hitcache); + while (i) + { + i_next = i->next; + cachehit = get_data_from_node(i); + + if(!cachehit) + { + i = i_next; + continue; + } + + cs_ftime(&now); + gone = comp_timeb(&now, &cachehit->time); + if(force || gone>timeout) + { + remove_elem_list(&ll_hitcache, &cachehit->ll_node); + remove_elem_hash_table(&ht_hitcache, &cachehit->ht_node); + NULLFREE(cachehit); + } + i = i_next; + } + pthread_rwlock_unlock(&hitcache_lock); +} + +static int32_t cacheex_ecm_hash_calc(uchar *buf, int32_t n) +{ + int32_t i, h = 0; + for(i = 0; i < n; i++) + { + h = 31 * h + buf[i]; + } + return h; +} + +void cacheex_update_hash(ECM_REQUEST *er) +{ + er->csp_hash = cacheex_ecm_hash_calc(er->ecm + 3, er->ecmlen - 3); +} + +void cacheex_free_csp_lastnodes(ECM_REQUEST *er) +{ + ll_destroy_free_data(&er->csp_lastnodes); +} + +void cacheex_set_csp_lastnode(ECM_REQUEST *er) +{ + er->csp_lastnodes = NULL; +} + +void cacheex_set_cacheex_src(ECM_REQUEST *ecm, struct s_client *cl) +{ + if(ecm->cacheex_src == cl) + ecm->cacheex_src = NULL; +} + +void cacheex_init_cacheex_src(ECM_REQUEST *ecm, ECM_REQUEST *er) +{ + if(!ecm->cacheex_src) + ecm->cacheex_src = er->cacheex_src; +} + static void *chkcache_process(void) { set_thread_name(__func__); @@ -43,7 +246,7 @@ struct s_client *cex_src=NULL; struct s_write_from_cache *wfc=NULL; - while(1) + while(cacheex_running) { cs_readlock(&ecmcache_lock); for(er = ecmcwcache; er; er = er->next) @@ -86,7 +289,7 @@ } if(add_hitcache_er) - { add_hitcache(cex_src, er); } //USE cacheex client (to get correct group) and ecm from requesting client (to get correct caid|prid|srvid)!!! + { cacheex_add_hitcache(cex_src, er); } //USE cacheex client (to get correct group) and ecm from requesting client (to get correct caid|prid|srvid)!!! } } @@ -95,7 +298,7 @@ { //add_hitcache already called, but we have to remove it because cacheex not coming before wait_time if(ecm->prid==er->prid && ecm->srvid==er->srvid) - { del_hitcache(ecm); } + { cacheex_del_hitcache(ecm); } } } //END check for add_hitcache @@ -221,6 +424,17 @@ } /** + * Check for NULL ecmd5 + **/ +static uint8_t checkECMD5(ECM_REQUEST *er) +{ + int8_t i; + for(i = 0; i < CS_ECMSTORESIZE; i++) + if(er->ecmd5[i]) { return 1; } + return 0; +} + +/** * cacheex modes: * * cacheex=1 CACHE PULL: @@ -337,7 +551,7 @@ -static inline struct s_cacheex_matcher *is_cacheex_matcher_matching(ECM_REQUEST *from_er, ECM_REQUEST *to_er) +static struct s_cacheex_matcher *is_cacheex_matcher_matching(ECM_REQUEST *from_er, ECM_REQUEST *to_er) { struct s_cacheex_matcher *entry = cfg.cacheex_matcher; int8_t v_ok = (from_er && to_er) ? 2 : 1; @@ -377,33 +591,17 @@ return check_client(cl) && cl->account && cl->account->cacheex.mode == 1 && is_cacheex_matcher_matching(NULL, er); } -inline int8_t cacheex_match_alias(struct s_client *cl, ECM_REQUEST *er, ECM_REQUEST *ecm) +static void log_cacheex_cw(ECM_REQUEST *er, char *reason) { - if(check_client(cl) && cl->account && cl->account->cacheex.mode == 1) - { - struct s_cacheex_matcher *entry = is_cacheex_matcher_matching(ecm, er); - if(entry) - { - int64_t diff = comp_timeb(&er->tps, &ecm->tps); - if(diff > entry->valid_from && diff < entry->valid_to) - { -#ifdef WITH_DEBUG - if(D_CACHEEX & cs_dblevel) - { - char result[CXM_FMT_LEN] = { 0 }; - int32_t s, size = CXM_FMT_LEN; - s = ecmfmt(entry->caid, 0, entry->provid, entry->chid, entry->pid, entry->srvid, entry->ecmlen, 0, 0, 0, result, size, 0, 0); - s += snprintf(result + s, size - s, " = "); - s += ecmfmt(entry->to_caid, 0, entry->to_provid, entry->to_chid, entry->to_pid, entry->to_srvid, entry->to_ecmlen, 0, 0, 0, result + s, size - s, 0, 0); - s += snprintf(result + s, size - s, " valid %d/%d", entry->valid_from, entry->valid_to); - cs_log_dbg(D_CACHEEX, "cacheex-matching for: %s", result); - } -#endif - return 1; - } - } - } - return 0; + uint8_t *data; + uchar remotenodeid[16]; + data = ll_last_element(er->csp_lastnodes); + if(data) + memcpy(remotenodeid, data, 8); + char buf_ecm[109]; + format_ecm(er, buf_ecm, 109); + cs_log_dbg(D_CACHEEX,"got pushed ecm [%s]: %s - odd/even 0x%x - CSP cw: %s - pushed from %s, at hop %d, origin node-id %" PRIu64 "X", + reason, buf_ecm, er->ecm[0], (checkECMD5(er)?"NO":"YES"), er->from_csp ? "csp" : username((er->cacheex_src?er->cacheex_src:er->client)), ll_count(er->csp_lastnodes), er->csp_lastnodes ? cacheex_node_id(remotenodeid): 0); } static int32_t cacheex_add_to_cache_int(struct s_client *cl, ECM_REQUEST *er, int8_t csp) @@ -487,7 +685,7 @@ first_client->cwcacheexgot++; } - add_hitcache(cl, er); //we have to call it before add_cache, because in chk_process we could remove it! + cacheex_add_hitcache(cl, er); //we have to call it before add_cache, because in chk_process we could remove it! add_cache(er); cacheex_add_stats(cl, er->caid, er->srvid, er->prid, 1); @@ -514,21 +712,6 @@ } -void log_cacheex_cw(ECM_REQUEST *er, char *reason){ - uint8_t *data; - uchar remotenodeid[16]; - data = ll_last_element(er->csp_lastnodes); - if(data) - { - memcpy(remotenodeid, data, 8); - } - - char buf_ecm[109]; - format_ecm(er, buf_ecm, 109); - cs_log_dbg(D_CACHEEX,"got pushed ecm [%s]: %s - odd/even 0x%x - CSP cw: %s - pushed from %s, at hop %d, origin node-id %" PRIu64 "X", - reason, buf_ecm, er->ecm[0], (checkECMD5(er)?"NO":"YES"), er->from_csp ? "csp" : username((er->cacheex_src?er->cacheex_src:er->client)), ll_count(er->csp_lastnodes), er->csp_lastnodes ? cacheex_node_id(remotenodeid): 0); -} - //Format: //caid:prov:srvid:pid:chid:ecmlen=caid:prov:srvid:pid:chid:ecmlen[,validfrom,validto] //validfrom: default=-2000 @@ -693,27 +876,7 @@ uint16_t get_cacheex_mode1_delay(ECM_REQUEST *er) { - uint16_t delay = 0; - - int32_t i; - for(i = 0; i < cfg.cacheex_mode1_delay_tab.n; i++) - { - - if(i == 0 && cfg.cacheex_mode1_delay_tab.caid[i] <= 0) - { - delay = cfg.cacheex_mode1_delay_tab.value[i]; - continue; - } - - - if(cfg.cacheex_mode1_delay_tab.caid[i] == er->caid || cfg.cacheex_mode1_delay_tab.caid[i] == er->caid >> 8) - { - delay = cfg.cacheex_mode1_delay_tab.value[i]; - break; - } - } - - return delay; + return caidvaluetab_get_value(&cfg.cacheex_mode1_delay_tab, er->caid, 0); } @@ -759,7 +922,7 @@ if(awtime > 0 || dwtime > 0) { //if found last in cache return dynwaittime else alwayswaittime - if(check_hitcache(er,cl)) + if(cacheex_check_hitcache(er,cl)) { return dwtime >= awtime ? dwtime : awtime; } else { return awtime > 0 ? awtime : 0; } @@ -843,4 +1006,69 @@ return 1; } +void cacheex_mode1_delay(ECM_REQUEST *er) +{ + if(!er->cacheex_wait_time_expired + && er->cacheex_mode1_delay + && er->cacheex_reader_count > 0 + && !er->stage + && er->rc >= E_UNHANDLED) + { + cs_log_dbg(D_LB, "{client %s, caid %04X, prid %06X, srvid %04X} cacheex_mode1_delay timeout! ", (check_client(er->client) ? er->client->account->usr : "-"), er->caid, er->prid, er->srvid); + request_cw_from_readers(er, 1); // setting stop_stage=1, we request only cacheex mode 1 readers. Others are requested at cacheex timeout! + } +} + +void cacheex_timeout(ECM_REQUEST *er) +{ + if(er->cacheex_wait_time_expired) + return; + er->cacheex_wait_time_expired = 1; + if(er->rc >= E_UNHANDLED) + { + cs_log_dbg(D_LB, "{client %s, caid %04X, prid %06X, srvid %04X} cacheex timeout! ", (check_client(er->client) ? er->client->account->usr : "-"), er->caid, er->prid, er->srvid); + //if check_cw mode=0, first try to get cw from cache without check counter! + CWCHECK check_cw = get_cwcheck(er); + if(!check_cw.mode) + { + struct ecm_request_t *ecm=NULL; + ecm = check_cache(er, er->client); + if(ecm) //found in cache + { + struct s_write_from_cache *wfc=NULL; + if(!cs_malloc(&wfc, sizeof(struct s_write_from_cache))) + { + NULLFREE(ecm); + return; + } + wfc->er_new=er; + wfc->er_cache=ecm; + if(!add_job(er->client, ACTION_ECM_ANSWER_CACHE, wfc, sizeof(struct s_write_from_cache))) //write_ecm_answer_fromcache + { NULLFREE(ecm); } + return; + } + } + //check if "normal" readers selected, if not send NOT FOUND! + //cacheex1-client (having always no "normal" reader), or not-cacheex-1 client with no normal readers available (or filtered by LB) + if( (er->reader_count + er->fallback_reader_count - er->cacheex_reader_count) <= 0 ) + { + if(!cfg.wait_until_ctimeout){ + er->rc = E_NOTFOUND; + er->selected_reader = NULL; + er->rcEx = 0; + cs_log_dbg(D_LB, "{client %s, caid %04X, prid %06X, srvid %04X} cacheex timeout: NO \"normal\" readers... not_found! ", (check_client(er->client) ? er->client->account->usr : "-"), er->caid, er->prid, er->srvid); + send_dcw(er->client, er); + return; + } + } + else + { + if(er->stage < 2){ + debug_ecm(D_TRACE, "request for %s %s", username(er->client), buf); + request_cw_from_readers(er, 0); + } + } + } +} + #endif diff -Nru oscam-1.20-10584~r10356/module-cacheex.h oscam-1.20-10797~r10569/module-cacheex.h --- oscam-1.20-10584~r10356/module-cacheex.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-cacheex.h 2015-02-20 11:57:49.000000000 +0000 @@ -7,87 +7,59 @@ return *x; } -extern uint8_t cacheex_peer_id[8]; - -extern int32_t cacheex_add_stats(struct s_client *cl, uint16_t caid, uint16_t srvid, uint32_t prid, uint8_t direction); -extern int8_t cacheex_maxhop(struct s_client *cl); +uint32_t get_cacheex_wait_time(ECM_REQUEST *er, struct s_client *cl); +CWCHECK get_cwcheck(ECM_REQUEST *er); +uint16_t get_cacheex_mode1_delay(ECM_REQUEST *er); +int32_t chk_csp_ctab(ECM_REQUEST *er, CECSPVALUETAB *tab); +uint8_t check_cacheex_filter(struct s_client *cl, ECM_REQUEST *er); +void cacheex_add_to_cache(struct s_client *cl, ECM_REQUEST *er); +void cacheex_add_to_cache_from_csp(struct s_client *cl, ECM_REQUEST *er); void cacheex_cache_push(ECM_REQUEST *er); -extern inline int8_t cacheex_match_alias(struct s_client *cl, ECM_REQUEST *er, ECM_REQUEST *ecm); -extern void cacheex_add_to_cache(struct s_client *cl, ECM_REQUEST *er); -extern void cacheex_add_to_cache_from_csp(struct s_client *cl, ECM_REQUEST *er); +int32_t cacheex_add_stats(struct s_client *cl, uint16_t caid, uint16_t srvid, uint32_t prid, uint8_t direction); +int8_t cacheex_maxhop(struct s_client *cl); + #ifdef CS_CACHEEX -void log_cacheex_cw(ECM_REQUEST *er, char *s); extern void cacheex_init(void); extern void cacheex_clear_account_stats(struct s_auth *account); extern void cacheex_clear_client_stats(struct s_client *client); extern void cacheex_load_config_file(void); -static inline bool cacheex_reader(struct s_reader *rdr) -{ - return rdr->cacheex.mode == 1; -}; +static inline bool cacheex_reader(struct s_reader *rdr) { return rdr->cacheex.mode == 1; } extern bool cacheex_is_match_alias(struct s_client *cl, ECM_REQUEST *er); -static inline void cacheex_set_csp_lastnode(ECM_REQUEST *er) -{ - er->csp_lastnodes = NULL; -} -static inline void cacheex_free_csp_lastnodes(ECM_REQUEST *er) -{ - LLIST *l = er->csp_lastnodes; - er->csp_lastnodes = NULL; - ll_destroy_free_data(l); -} -static inline void cacheex_set_cacheex_src(ECM_REQUEST *ecm, struct s_client *cl) -{ - if(ecm->cacheex_src == cl) - { ecm->cacheex_src = NULL; } -} -static inline void cacheex_init_cacheex_src(ECM_REQUEST *ecm, ECM_REQUEST *er) -{ - if(!ecm->cacheex_src) - { ecm->cacheex_src = er->cacheex_src; } -} -/** - * Check for NULL ecmd5 - **/ -static inline uint8_t checkECMD5(ECM_REQUEST *er) -{ - int8_t i; - for(i = 0; i < CS_ECMSTORESIZE; i++) - if(er->ecmd5[i]) { return 1; } - return 0; -} -uint32_t get_cacheex_wait_time(ECM_REQUEST *er, struct s_client *cl); -int32_t chk_csp_ctab(ECM_REQUEST *er, CECSPVALUETAB *tab); -uint8_t check_cacheex_filter(struct s_client *cl, ECM_REQUEST *er); +void cacheex_set_csp_lastnode(ECM_REQUEST *er); +void cacheex_set_cacheex_src(ECM_REQUEST *ecm, struct s_client *cl); +void cacheex_init_cacheex_src(ECM_REQUEST *ecm, ECM_REQUEST *er); +void cacheex_free_csp_lastnodes(ECM_REQUEST *er); void checkcache_process_thread_start(void); -CWCHECK get_cwcheck(ECM_REQUEST *er); -uint16_t get_cacheex_mode1_delay(ECM_REQUEST *er); void cacheex_push_out(struct s_client *cl, ECM_REQUEST *er); bool cacheex_check_queue_length(struct s_client *cl); static inline int8_t cacheex_get_rdr_mode(struct s_reader *reader) { return reader->cacheex.mode; } - +void cacheex_init_hitcache(void); +void cacheex_free_hitcache(void); +void cacheex_cleanup_hitcache(bool force); +void cacheex_update_hash(ECM_REQUEST *er); +void cacheex_mode1_delay(ECM_REQUEST *er); +void cacheex_timeout(ECM_REQUEST *er); #else -static inline void cacheex_init(void) { }; -static inline void cacheex_clear_account_stats(struct s_auth *UNUSED(account)) { }; -static inline void cacheex_clear_client_stats(struct s_client *UNUSED(client)) { }; -static inline void cacheex_load_config_file(void) { }; -static inline bool cacheex_reader(struct s_reader *UNUSED(rdr)) -{ - return false; -}; -static inline bool cacheex_is_match_alias(struct s_client *UNUSED(cl), ECM_REQUEST *UNUSED(er)) -{ - return false; -} +static inline void cacheex_init(void) { } +static inline void cacheex_clear_account_stats(struct s_auth *UNUSED(account)) { } +static inline void cacheex_clear_client_stats(struct s_client *UNUSED(client)) { } +static inline void cacheex_load_config_file(void) { } +static inline bool cacheex_reader(struct s_reader *UNUSED(rdr)) { return false; } +static inline bool cacheex_is_match_alias(struct s_client *UNUSED(cl), ECM_REQUEST *UNUSED(er)) { return false; } static inline void cacheex_set_csp_lastnode(ECM_REQUEST *UNUSED(er)) { } static inline void cacheex_free_csp_lastnodes(ECM_REQUEST *UNUSED(er)) { } static inline void cacheex_set_cacheex_src(ECM_REQUEST *UNUSED(ecm), struct s_client *UNUSED(cl)) { } static inline void cacheex_init_cacheex_src(ECM_REQUEST *UNUSED(ecm), ECM_REQUEST *UNUSED(er)) { } -static inline void cleanup_hitcache(void) { } static inline void checkcache_process_thread_start(void) { } static inline void cacheex_push_out(struct s_client *UNUSED(cl), ECM_REQUEST *UNUSED(er)) { } static inline bool cacheex_check_queue_length(struct s_client *UNUSED(cl)) { return 0; } static inline int8_t cacheex_get_rdr_mode(struct s_reader *UNUSED(reader)) { return 0; } +static inline void cacheex_init_hitcache(void) { } +static inline void cacheex_free_hitcache(void) { } +static inline void cacheex_cleanup_hitcache(bool UNUSED(force)) { } +static inline void cacheex_update_hash(ECM_REQUEST *UNUSED(er)) { } +static inline void cacheex_mode1_delay(ECM_REQUEST *UNUSED(er)) { } +static inline void cacheex_timeout(ECM_REQUEST *UNUSED(er)) { } #endif #endif diff -Nru oscam-1.20-10584~r10356/module-camd33.c oscam-1.20-10797~r10569/module-camd33.c --- oscam-1.20-10584~r10356/module-camd33.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-camd33.c 2015-02-20 11:57:49.000000000 +0000 @@ -19,7 +19,7 @@ memset(buf + ml, 0, l - ml); cs_log_dump_dbg(D_CLIENT, buf, l, "send %d bytes to client", l); if(cur_client()->crypted) - { aes_encrypt_idx(&cur_client()->aes_keys, buf, l); } + { aes_encrypt_idx(cur_client()->aes_keys, buf, l); } return (send(cur_client()->pfd, buf, l, 0)); } @@ -31,7 +31,7 @@ { client->last = time((time_t *) 0); if(client->crypted) - { aes_encrypt_idx(&cur_client()->aes_keys, buf, n); } + { aes_encrypt_idx(cur_client()->aes_keys, buf, n); } } cs_log_dump_dbg(D_CLIENT, buf, n, "received %d bytes from client", n); return (n); @@ -81,7 +81,13 @@ { cl->crypted = !check_ip(cfg.c33_plain, cl->ip); } if(cl->crypted) - { aes_set_key(&cl->aes_keys, (char *)cfg.c33_key); } + { + if (!aes_set_key_alloc(&cl->aes_keys, (char *)cfg.c33_key)) + { + cs_disconnect_client(cl); + return; + } + } mbuf[0] = 0; camd33_send(mbuf, 1); // send login-request diff -Nru oscam-1.20-10584~r10356/module-camd35.c oscam-1.20-10797~r10569/module-camd35.c --- oscam-1.20-10584~r10356/module-camd35.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-camd35.c 2015-02-20 11:57:49.000000000 +0000 @@ -56,7 +56,7 @@ i2b_buf(4, crc32(0L, sbuf + 20, buflen), sbuf + 4); l = boundary(4, l); cs_log_dump_dbg(cl->typ == 'c' ? D_CLIENT : D_READER, sbuf, l, "send %d bytes to %s", l, username(cl)); - aes_encrypt_idx(&cl->aes_keys, sbuf, l); + aes_encrypt_idx(cl->aes_keys, sbuf, l); int32_t status; if(cl->is_udp) @@ -124,7 +124,10 @@ { memcpy(cl->ucrc, ucrc, 4); cs_strncpy((char *)cl->upwd, account->pwd, sizeof(cl->upwd)); - aes_set_key(&cl->aes_keys, (char *) MD5(cl->upwd, strlen((char *)cl->upwd), md5tmp)); + if (!aes_set_key_alloc(&cl->aes_keys, (char *) MD5(cl->upwd, strlen((char *)cl->upwd), md5tmp))) + { + return 1; + } return 0; } } @@ -172,6 +175,7 @@ break; } if (readed == 0){ // nothing to read left! + rc = -5; break; } if (readed > 0){ // received something, add it! @@ -184,8 +188,9 @@ } if(rs < 36) - { - rc = -1; + { + if(rc != -5) + { rc = -1; } goto out; } break; @@ -204,7 +209,7 @@ memmove(buf, buf + 4, rs -= 4); break; case 2: - aes_decrypt(&client->aes_keys, buf, rs); + aes_decrypt(client->aes_keys, buf, rs); if(rs != boundary(4, rs)) cs_log_dbg(client->typ == 'c' ? D_CLIENT : D_READER, "WARNING: packet size has wrong decryption boundary"); @@ -248,7 +253,7 @@ if(len > 0) { rs += len; - aes_decrypt(&client->aes_keys, buf + 32, len); + aes_decrypt(client->aes_keys, buf + 32, len); } if(len < 0) { @@ -295,6 +300,9 @@ case -4: cs_log("checksum error (wrong password ?)"); break; + case -5: + cs_log_dbg(client->typ == 'c' ? D_CLIENT : D_READER, "connection closed"); + break; //default: cs_log_dbg(D_TRACE, "camd35_recv returns rc=%d", rc); break; } @@ -422,7 +430,7 @@ if(!buf) { - cs_log("%s: src_data missing.",client->reader->ph.desc); + rdr_log(client->reader, "ERROR: src_data missing"); return; } @@ -535,13 +543,32 @@ cl->pfd = cl->udp_fd = handle; } if(!cl->udp_fd) { return (0); } // Check if client has no handle -> error - // check if client reached timeout, if reached and reader is not udp type disconnect reader + + // check if client reached timeout if(cl->reader->tcp_rto && (cl->reader->last_s - cl->reader->last_g > cl->reader->tcp_rto)) { - network_tcp_connection_close(cl->reader, "rto"); - return 0; + if(!cl->is_udp) //tcp on timeout disconnect reader + { + network_tcp_connection_close(cl->reader, "rto"); + return 0; + } + else //udp check to discover ip change on dynamic ip servers + { + IN_ADDR_T last_ip; + IP_ASSIGN(last_ip, cl->ip); + if(!hostResolve(cl->reader)) + { + network_tcp_connection_close(cl->reader, "no ip"); + return 0; + } + if(!IP_EQUAL(last_ip, cl->ip)) + { + network_tcp_connection_close(cl->reader, "ip change"); + return 0; + } + } } - + return (1); // all ok } @@ -591,10 +618,13 @@ unsigned char md5tmp[MD5_DIGEST_LENGTH]; cs_strncpy((char *)cl->upwd, cl->reader->r_pwd, sizeof(cl->upwd)); i2b_buf(4, crc32(0L, MD5((unsigned char *)cl->reader->r_usr, strlen(cl->reader->r_usr), md5tmp), 16), cl->ucrc); - aes_set_key(&cl->aes_keys, (char *)MD5(cl->upwd, strlen((char *)cl->upwd), md5tmp)); + if (!aes_set_key_alloc(&cl->aes_keys, (char *)MD5(cl->upwd, strlen((char *)cl->upwd), md5tmp))) + { + return 1; + } cl->crypted=1; - cs_log("%s proxy %s:%d", cl->reader->ph.desc, cl->reader->device, cl->reader->r_port); + rdr_log(cl->reader, "proxy %s:%d", cl->reader->device, cl->reader->r_port); if(cl->reader->keepalive) camd35_send_keepalive(cl); @@ -628,7 +658,7 @@ { if(check_client(cl) && cl->reader->tcp_connected && cl->reader->ph.type==MOD_CONN_TCP) { - cs_log_dbg(D_READER, "%s inactive_timeout, close connection (fd=%d)", cl->reader->ph.desc, cl->pfd); + rdr_log_dbg(cl->reader, D_READER, "inactive_timeout, close connection (fd=%d)", cl->pfd); network_tcp_connection_close(cl->reader, "inactivity"); } else @@ -649,7 +679,7 @@ { client->reader->last_s = time(NULL); // fixup: last send is now (if client is only sending emms connection would be dropped!) } - cs_log("%s_SERVER last = %d, last_s = %d, last_g = %d", client->reader->ph.desc, (int) client->last, (int) client->reader->last_s, (int) client->reader->last_g); + rdr_log(client->reader, "SERVER last = %d, last_s = %d, last_g = %d", (int) client->last, (int) client->reader->last_s, (int) client->reader->last_g); } client->last = time(NULL); // last client action is now diff -Nru oscam-1.20-10584~r10356/module-camd35-cacheex.c oscam-1.20-10797~r10569/module-camd35-cacheex.c --- oscam-1.20-10584~r10356/module-camd35-cacheex.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-camd35-cacheex.c 2015-02-20 11:57:49.000000000 +0000 @@ -16,38 +16,6 @@ uint8_t camd35_node_id[8]; /** - * send own id - */ -void camd35_cacheex_push_send_own_id(struct s_client *cl, uint8_t *mbuf) -{ - uint8_t rbuf[32]; //minimal size - if(!cl->crypted) { return; } - cs_log_dbg(D_CACHEEX, "cacheex: received id request from node %" PRIu64 "X %s", cacheex_node_id(mbuf + 20), username(cl)); - memset(rbuf, 0, sizeof(rbuf)); - rbuf[0] = 0x3e; - rbuf[1] = 12; - rbuf[2] = 0; - memcpy(rbuf + 20, camd35_node_id, 8); - cs_log_dbg(D_CACHEEX, "cacheex: sending own id %" PRIu64 "X request %s", cacheex_node_id(camd35_node_id), username(cl)); - camd35_send(cl, rbuf, 12); //send adds +20 -} - -/** - * request remote id - */ -void camd35_cacheex_push_request_remote_id(struct s_client *cl) -{ - uint8_t rbuf[32];//minimal size - memset(rbuf, 0, sizeof(rbuf)); - rbuf[0] = 0x3d; - rbuf[1] = 12; - rbuf[2] = 0; - memcpy(rbuf + 20, camd35_node_id, 8); - cs_log_dbg(D_CACHEEX, "cacheex: sending id request to %s", username(cl)); - camd35_send(cl, rbuf, 12); //send adds +20 -} - -/** * send push filter */ void camd35_cacheex_send_push_filter(struct s_client *cl, uint8_t mode) @@ -78,7 +46,8 @@ i2b_buf(2, filter->n, buf + i); i += 2; - for(j=0; j<15; j++) + int32_t max_filters = 15; + for(j=0; jn = CS_MAXCAIDTAB; } - for(j=0; j<15; j++) + int32_t max_filters = 15; + for(j=0; jinit_done) - { - cl->cacheex_needfilter = 1; - } -} - -/** - * store received remote id - */ -static void camd35_cacheex_push_receive_remote_id(struct s_client *cl, uint8_t *buf) -{ - - memcpy(cl->ncd_skey, buf + 20, 8); - cl->ncd_skey[8] = 1; - cs_log_dbg(D_CACHEEX, "cacheex: received id answer from %s: %" PRIu64 "X", username(cl), cacheex_node_id(cl->ncd_skey)); -} - static int32_t camd35_cacheex_push_chk(struct s_client *cl, ECM_REQUEST *er) { if(ll_count(er->csp_lastnodes) >= cacheex_maxhop(cl)) //check max 10 nodes to push: @@ -310,7 +258,7 @@ else if((cl->typ == 'p' || cl->typ == 'r') && (cl->reader && cl->reader->cacheex.mode)) { cl->cwc_info++; } - cs_log_dbg(D_CWC, "CWC (CE) push to %s (camd3) cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(cl), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); + cs_log_dbg(D_CWC, "CWC (CE) push to %s cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(cl), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); } buf[19] = er->ecm[0] != 0x80 && er->ecm[0] != 0x81 ? 0 : er->ecm[0]; @@ -352,57 +300,6 @@ return res; } -void camd35_cacheex_recv_ce1_cwc_info(struct s_client *cl, uchar *buf, int32_t idx) -{ - if(!(buf[0] == 0x01 && buf[18] < 0xFF && buf[18] > 0x00)) // cwc info ; normal camd3 ecms send 0xFF but we need no cycletime of 255 ;) - return; - - ECM_REQUEST *er = NULL; - int32_t i; - - for(i = 0; i < cfg.max_pending; i++) - { - if (cl->ecmtask[i].idx == idx) - { - er = &cl->ecmtask[i]; - break; - } - } - - if(!er) - { return; } - - int8_t rc = buf[3]; - if(rc != E_FOUND) - { return; } - - if(buf[18]) - { - if(buf[18] & (0x01 << 7)) - { - er->cwc_cycletime = (buf[18] & 0x7F); // remove bit 8 to get cycletime - er->parent->cwc_cycletime = er->cwc_cycletime; - er->cwc_next_cw_cycle = 1; - er->parent->cwc_next_cw_cycle = er->cwc_next_cw_cycle; - } - else - { - er->cwc_cycletime = buf[18]; - er->parent->cwc_cycletime = er->cwc_cycletime; - er->cwc_next_cw_cycle = 0; - er->parent->cwc_next_cw_cycle = er->cwc_next_cw_cycle; - } - } - - if(cl->typ == 'c' && cl->account && cl->account->cacheex.mode) - { cl->account->cwc_info++; } - else if((cl->typ == 'p' || cl->typ == 'r') && (cl->reader && cl->reader->cacheex.mode)) - { cl->cwc_info++; } - - cs_log_dbg(D_CWC, "CWC (CE1) received from %s (camd3) cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(cl), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); - -} - static void camd35_cacheex_push_in(struct s_client *cl, uchar *buf) { int8_t rc = buf[3]; @@ -449,7 +346,7 @@ { cl->account->cwc_info++; } else if((cl->typ == 'p' || cl->typ == 'r') && (cl->reader && cl->reader->cacheex.mode)) { cl->cwc_info++; } - cs_log_dbg(D_CWC, "CWC (CE) received from %s (camd3) cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(cl), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); + cs_log_dbg(D_CWC, "CWC (CE) received from %s cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(cl), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); } uint8_t *ofs = buf + 20; @@ -525,19 +422,84 @@ cs_log_dbg(D_CACHEEX, "cacheex: added missing remote node id %" PRIu64 "X", cacheex_node_id(data)); } - // if (!ll_count(er->csp_lastnodes)) { - // if (!cs_malloc(&data, 8)) - // break; - // memcpy(data, &cl->ip, 4); - // memcpy(data+4, &cl->port, 2); - // memcpy(data+6, &cl->is_udp, 1); - // ll_append(er->csp_lastnodes, data); - // cs_log_dbg(D_CACHEEX, "cacheex: added compat remote node id %" PRIu64 "X", cacheex_node_id(data)); - // } - cacheex_add_to_cache(cl, er); } +void camd35_cacheex_recv_ce1_cwc_info(struct s_client *cl, uchar *buf, int32_t idx) +{ + if(!(buf[0] == 0x01 && buf[18] < 0xFF && buf[18] > 0x00)) // cwc info ; normal camd3 ecms send 0xFF but we need no cycletime of 255 ;) + return; + + ECM_REQUEST *er = NULL; + int32_t i; + + for(i = 0; i < cfg.max_pending; i++) + { + if (cl->ecmtask[i].idx == idx) + { + er = &cl->ecmtask[i]; + break; + } + } + + if(!er) + { return; } + + int8_t rc = buf[3]; + if(rc != E_FOUND) + { return; } + + if(buf[18]) + { + if(buf[18] & (0x01 << 7)) + { + er->cwc_cycletime = (buf[18] & 0x7F); // remove bit 8 to get cycletime + er->parent->cwc_cycletime = er->cwc_cycletime; + er->cwc_next_cw_cycle = 1; + er->parent->cwc_next_cw_cycle = er->cwc_next_cw_cycle; + } + else + { + er->cwc_cycletime = buf[18]; + er->parent->cwc_cycletime = er->cwc_cycletime; + er->cwc_next_cw_cycle = 0; + er->parent->cwc_next_cw_cycle = er->cwc_next_cw_cycle; + } + } + + if(cl->typ == 'c' && cl->account && cl->account->cacheex.mode) + { cl->account->cwc_info++; } + else if((cl->typ == 'p' || cl->typ == 'r') && (cl->reader && cl->reader->cacheex.mode)) + { cl->cwc_info++; } + + cs_log_dbg(D_CWC, "CWC (CE1) received from %s cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(cl), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); + +} + + +/** + * when a server client connects + */ +static void camd35_server_client_init(struct s_client *cl) +{ + if(!cl->init_done) + { + cl->cacheex_needfilter = 1; + } +} + +/** + * store received remote id + */ +static void camd35_cacheex_push_receive_remote_id(struct s_client *cl, uint8_t *buf) +{ + + memcpy(cl->ncd_skey, buf + 20, 8); + cl->ncd_skey[8] = 1; + cs_log_dbg(D_CACHEEX, "cacheex: received id answer from %s: %" PRIu64 "X", username(cl), cacheex_node_id(cl->ncd_skey)); +} + + void camd35_cacheex_init_dcw(struct s_client *client, ECM_REQUEST *er) { uint8_t *buf = er->src_data; // get orig request @@ -553,11 +515,28 @@ { client->account->cwc_info++; } else if((client->typ == 'p' || client->typ == 'r') && (client->reader && client->reader->cacheex.mode)) { client->cwc_info++; } - cs_log_dbg(D_CWC, "CWC (CE1) push to %s (camd3) cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(client), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); + cs_log_dbg(D_CWC, "CWC (CE1) push to %s cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(client), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); buf[19] = er->ecm[0]; } } +/** + * send own id + */ +void camd35_cacheex_push_send_own_id(struct s_client *cl, uint8_t *mbuf) +{ + uint8_t rbuf[32]; //minimal size + if(!cl->crypted) { return; } + cs_log_dbg(D_CACHEEX, "cacheex: received id request from node %" PRIu64 "X %s", cacheex_node_id(mbuf + 20), username(cl)); + memset(rbuf, 0, sizeof(rbuf)); + rbuf[0] = 0x3e; + rbuf[1] = 12; + rbuf[2] = 0; + memcpy(rbuf + 20, camd35_node_id, 8); + cs_log_dbg(D_CACHEEX, "cacheex: sending own id %" PRIu64 "X request %s", cacheex_node_id(camd35_node_id), username(cl)); + camd35_send(cl, rbuf, 12); //send adds +20 +} + bool camd35_cacheex_server(struct s_client *client, uint8_t *mbuf) { switch(mbuf[0]) @@ -613,6 +592,21 @@ return 1; // Processed by cacheex } +/** + * request remote id + */ +void camd35_cacheex_push_request_remote_id(struct s_client *cl) +{ + uint8_t rbuf[32];//minimal size + memset(rbuf, 0, sizeof(rbuf)); + rbuf[0] = 0x3d; + rbuf[1] = 12; + rbuf[2] = 0; + memcpy(rbuf + 20, camd35_node_id, 8); + cs_log_dbg(D_CACHEEX, "cacheex: sending id request to %s", username(cl)); + camd35_send(cl, rbuf, 12); //send adds +20 +} + void camd35_cacheex_module_init(struct s_module *ph) { ph->c_cache_push = camd35_cacheex_push_out; diff -Nru oscam-1.20-10584~r10356/module-cccam.c oscam-1.20-10797~r10569/module-cccam.c --- oscam-1.20-10584~r10356/module-cccam.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-cccam.c 2015-02-20 11:57:49.000000000 +0000 @@ -339,7 +339,7 @@ return srvid != NULL; } -struct cc_srvid *is_good_sid(struct cc_card *card, struct cc_srvid *srvid_good) +struct cc_srvid *is_good_sid(struct cc_card *card, struct cc_srvid *srvid_good) { LL_ITER it = ll_iter_create(card->goodsids); struct cc_srvid *srvid; @@ -355,8 +355,7 @@ #define BLOCKING_SECONDS 60 -void add_sid_block(struct s_client *cl __attribute__((unused)), struct cc_card *card, - struct cc_srvid *srvid_blocked) +void add_sid_block(struct cc_card *card, struct cc_srvid *srvid_blocked, bool temporary) { if(is_sid_blocked(card, srvid_blocked)) { return; } @@ -365,11 +364,13 @@ if(!cs_malloc(&srvid, sizeof(struct cc_srvid_block))) { return; } memcpy(srvid, srvid_blocked, sizeof(struct cc_srvid)); - srvid->blocked_till = time(NULL) + BLOCKING_SECONDS; + + if(temporary) + { srvid->blocked_till = time(NULL) + BLOCKING_SECONDS; } + ll_append(card->badsids, srvid); - cs_log_dbg(D_READER, "%s added sid block %04X(CHID %04X, length %d) for card %08x", - getprefix(), srvid_blocked->sid, srvid_blocked->chid, srvid_blocked->ecmlen, - card->id); + cs_log_dbg(D_READER, "added sid block %04X(CHID %04X, length %d) for card %08x", + srvid_blocked->sid, srvid_blocked->chid, srvid_blocked->ecmlen, card->id); } void remove_sid_block(struct cc_card *card, struct cc_srvid *srvid_blocked) @@ -379,19 +380,12 @@ while((srvid = ll_iter_next(&it))) if(sid_eq_nb(srvid_blocked, srvid)) { ll_iter_remove_data(&it); } + + cs_log_dbg(D_READER, "removed sid block %04X(CHID %04X, length %d) for card %08x", + srvid_blocked->sid, srvid_blocked->chid, srvid_blocked->ecmlen, card->id); } -void remove_good_sid(struct cc_card *card, struct cc_srvid *srvid_good) -{ - LL_ITER it = ll_iter_create(card->goodsids); - struct cc_srvid *srvid; - while((srvid = ll_iter_next(&it))) - if(sid_eq(srvid, srvid_good)) - { ll_iter_remove_data(&it); } -} - -void add_good_sid(struct s_client *cl __attribute__((unused)), struct cc_card *card, - struct cc_srvid *srvid_good) +void add_good_sid(struct cc_card *card, struct cc_srvid *srvid_good) { if(is_good_sid(card, srvid_good)) { return; } @@ -402,8 +396,18 @@ { return; } memcpy(srvid, srvid_good, sizeof(struct cc_srvid)); ll_append(card->goodsids, srvid); - cs_log_dbg(D_READER, "%s added good sid %04X(%d) for card %08x", - getprefix(), srvid_good->sid, srvid_good->ecmlen, card->id); + cs_log_dbg(D_READER, "added good sid %04X(%d) for card %08x", srvid_good->sid, srvid_good->ecmlen, card->id); +} + +void remove_good_sid(struct cc_card *card, struct cc_srvid *srvid_good) +{ + LL_ITER it = ll_iter_create(card->goodsids); + struct cc_srvid *srvid; + while((srvid = ll_iter_next(&it))) + if(sid_eq(srvid, srvid_good)) + { ll_iter_remove_data(&it); } + + cs_log_dbg(D_READER, "removed good sid %04X(%d) for card %08x", srvid_good->sid, srvid_good->ecmlen, card->id); } /** @@ -1267,7 +1271,7 @@ { struct cc_data *cc = cl->cc; struct s_reader *rdr = cl->reader; - if(cl->kill || !rdr) + if(cl->kill || !rdr || !cc) { return NULL; } struct cc_srvid cur_srvid; @@ -1723,6 +1727,8 @@ int32_t cc_send_pending_emms(struct s_client *cl) { struct cc_data *cc = cl->cc; + if (!cc) + return 0; LL_ITER it = ll_iter_create(cc->pending_emms); uint8_t *emmbuf; @@ -1867,10 +1873,10 @@ if(!card) { return; } - ll_destroy_data_NULL(card->providers); - ll_destroy_data_NULL(card->badsids); - ll_destroy_data_NULL(card->goodsids); - ll_destroy_data_NULL(card->remote_nodes); + ll_destroy_data(&card->providers); + ll_destroy_data(&card->badsids); + ll_destroy_data(&card->goodsids); + ll_destroy_data(&card->remote_nodes); add_garbage(card); } @@ -1902,7 +1908,7 @@ cc_free_card(card); } if(destroy_list) - { ll_destroy_NULL(card_list); } + ll_destroy(&card_list); } } @@ -1920,9 +1926,9 @@ cs_log_dbg(D_TRACE, "exit cccam1/3"); cc_free_cardlist(cc->cards, 1); - ll_destroy_data_NULL(cc->pending_emms); + ll_destroy_data(&cc->pending_emms); free_extended_ecm_idx(cc); - ll_destroy_data_NULL(cc->extended_ecm_idx); + ll_destroy_data(&cc->extended_ecm_idx); cs_writeunlock(&cc->lockcmd); @@ -2038,7 +2044,7 @@ //check inactivity timeout: if((abs(rdr->last_s - now) > rdr->tcp_ito) && (abs(rdr->last_g - now) > rdr->tcp_ito)) // inactivity timeout is entered in seconds in webif! { - cs_log_dbg(D_READER, "%s inactive_timeout, close connection (fd=%d)", rdr->ph.desc, rdr->client->pfd); + rdr_log_dbg(rdr, D_READER, "inactive_timeout, close connection (fd=%d)", rdr->client->pfd); network_tcp_connection_close(rdr, "inactivity"); return; } @@ -2048,7 +2054,7 @@ //cs_log("last_g - now = %d, rto=%d", rto, rdr->tcp_rto); if(rto > (rdr->tcp_rto)) // this is also entered in seconds, actually its an receive timeout! { - cs_log_dbg(D_READER, "%s read timeout, close connection (fd=%d)", rdr->ph.desc, rdr->client->pfd); + rdr_log_dbg(rdr, D_READER, "read timeout, close connection (fd=%d)", rdr->client->pfd); network_tcp_connection_close(rdr, "rto"); return; } @@ -2653,7 +2659,7 @@ { move_card_to_end(cl, card); if(cwlastresptime < 5000) - { add_sid_block(cl, card, &srvid); } + { add_sid_block(card, &srvid, true); } else { card->rating--; } } @@ -2663,14 +2669,14 @@ { move_card_to_end(cl, card); if(cwlastresptime < 5000) - { add_sid_block(cl, card, &srvid); } + { add_sid_block(card, &srvid, true); } else { card->rating--; } } else { move_card_to_end(cl, card); - add_sid_block(cl, card, &srvid); + add_sid_block(card, &srvid, true); } if(card->rating < MIN_RATING) @@ -2885,7 +2891,7 @@ cs_log_dbg(D_READER, "%s null dcw received! sid=%04X(%d)", getprefix(), srvid.sid, srvid.ecmlen); move_card_to_end(cl, card); - add_sid_block(cl, card, &srvid); + add_sid_block(card, &srvid, true); //ecm retry: cc_reset_pending(cl, ecm_idx); buf[1] = MSG_CW_NOK2; //So it's really handled like a nok! @@ -3852,14 +3858,17 @@ return -3; } - rdr->caid = rdr->ftab.filts[0].caid; - rdr->nprov = rdr->ftab.filts[0].nprids; - for(n = 0; n < rdr->nprov; n++) - { - rdr->prid[n][0] = rdr->ftab.filts[0].prids[n] >> 24; - rdr->prid[n][1] = rdr->ftab.filts[0].prids[n] >> 16; - rdr->prid[n][2] = rdr->ftab.filts[0].prids[n] >> 8; - rdr->prid[n][3] = rdr->ftab.filts[0].prids[n] & 0xff; + if (rdr->ftab.filts) + { + rdr->caid = rdr->ftab.filts[0].caid; + rdr->nprov = rdr->ftab.filts[0].nprids; + for(n = 0; n < rdr->nprov; n++) + { + rdr->prid[n][0] = rdr->ftab.filts[0].prids[n] >> 24; + rdr->prid[n][1] = rdr->ftab.filts[0].prids[n] >> 16; + rdr->prid[n][2] = rdr->ftab.filts[0].prids[n] >> 8; + rdr->prid[n][3] = rdr->ftab.filts[0].prids[n] & 0xff; + } } rdr->card_status = CARD_NEED_INIT; diff -Nru oscam-1.20-10584~r10356/module-cccam-cacheex.c oscam-1.20-10797~r10569/module-cccam-cacheex.c --- oscam-1.20-10584~r10356/module-cccam-cacheex.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-cccam-cacheex.c 2015-02-20 11:57:49.000000000 +0000 @@ -44,7 +44,8 @@ i2b_buf(2, filter->n, buf + i); i += 2; - for(j=0; j<30; j++) + int32_t max_filters = 30; + for(j=0; jn = b2i(2, buf + i); i += 2; - for(j=0; j<30; j++) + int32_t max_filters = 30; + for(j=0; jpeer_node_id; + //search existing peer nodes: LL_LOCKITER *li = ll_li_create(er->csp_lastnodes, 0); uint8_t *node; while((node = ll_li_next(li))) { - cs_log_dbg(D_CACHEEX, "cacheex: check node %" PRIu64 "X == %" PRIu64 "X ?", cacheex_node_id(node), cacheex_node_id(cc->peer_node_id)); - if(memcmp(node, cc->peer_node_id, 8) == 0) + cs_log_dbg(D_CACHEEX, "cacheex: check node %" PRIu64 "X == %" PRIu64 "X ?", cacheex_node_id(node), cacheex_node_id(remote_node)); + if(memcmp(node, remote_node, 8) == 0) { break; } @@ -222,11 +226,11 @@ return (-1); } - uint32_t size = 20 + sizeof(er->ecmd5) + sizeof(er->csp_hash) + sizeof(er->cw) + sizeof(uint8_t) + + uint32_t size = sizeof(er->ecmd5) + sizeof(er->csp_hash) + sizeof(er->cw) + sizeof(uint8_t) + (ll_count(er->csp_lastnodes) + 1) * 8; unsigned char *buf; - if(!cs_malloc(&buf, size)) + if(!cs_malloc(&buf, size + 20)) //camd35_send() adds +20 { return -1; } // build ecm message @@ -258,7 +262,7 @@ { cl->account->cwc_info++; } else if((cl->typ == 'p' || cl->typ == 'r') && (cl->reader && cl->reader->cacheex.mode)) { cl->cwc_info++; } - cs_log_dbg(D_CWC, "CWC (CE) push to %s (cccam) cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(cl), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); + cs_log_dbg(D_CWC, "CWC (CE) push to %s cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(cl), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); } buf[19] = er->ecm[0] != 0x80 && er->ecm[0] != 0x81 ? 0 : er->ecm[0]; @@ -295,7 +299,7 @@ } ll_li_destroy(li); - int32_t res = cc_cmd_send(cl, buf, size, MSG_CACHE_PUSH); + int32_t res = cc_cmd_send(cl, buf, size + 20, MSG_CACHE_PUSH); if(res > 0) // cache-ex is pushing out, so no receive but last_g should be updated otherwise disconnect! { if(cl->reader) @@ -322,7 +326,7 @@ uint16_t size = buf[12] | (buf[13] << 8); if(size != sizeof(er->ecmd5) + sizeof(er->csp_hash) + sizeof(er->cw)) { - cs_log_dbg(D_CACHEEX, "%s received wrong cache-push format! data ignored!", username(cl)); + cs_log_dbg(D_CACHEEX, "cacheex: %s received old cash-push format! data ignored!", username(cl)); return; } if(!(er = get_ecmtask())) @@ -334,6 +338,8 @@ er->ecm[0] = buf[19]!=0x80 && buf[19]!=0x81 ? 0 : buf[19]; //odd/even byte, usefull to send it over CSP and to check cw for swapping er->rc = rc; + er->ecmlen = 0; + if(buf[18]) { if(buf[18] & (0x01 << 7)) @@ -354,11 +360,9 @@ { cl->account->cwc_info++; } else if((cl->typ == 'p' || cl->typ == 'r') && (cl->reader && cl->reader->cacheex.mode)) { cl->cwc_info++; } - cs_log_dbg(D_CWC, "CWC (CE) received from %s (cccam) cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(cl), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); + cs_log_dbg(D_CWC, "CWC (CE) received from %s cycletime: %isek - nextcwcycle: CW%i for %04X:%06X:%04X", username(cl), er->cwc_cycletime, er->cwc_next_cw_cycle, er->caid, er->prid, er->srvid); } - er->ecmlen = 0; - uint8_t *ofs = buf + 20; //Read ecmd5 diff -Nru oscam-1.20-10584~r10356/module-cccshare.c oscam-1.20-10797~r10569/module-cccshare.c --- oscam-1.20-10584~r10356/module-cccshare.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-cccshare.c 2015-02-20 11:57:49.000000000 +0000 @@ -467,7 +467,7 @@ if(reported_carddatas) { i = cc_clear_reported_carddata(reported_carddatas, except, send_removed); - ll_destroy_NULL(reported_carddatas); + ll_destroy(&reported_carddatas); } return i; } @@ -825,6 +825,56 @@ return 0; } +void merge_sids(struct cc_card *carddst, struct cc_card *cardsrc) +{ + LL_ITER it; + struct cc_srvid *srvid; + struct cc_srvid_block *srvidb; + + int32_t goodSidCountSrc = ll_count(cardsrc->goodsids); + int32_t goodSidCountDst = ll_count(carddst->goodsids); + + if(goodSidCountDst == 0) + { + // remove sid blocks good+notbad from src + it = ll_iter_create(cardsrc->goodsids); + while((srvid = ll_iter_next(&it))) + { + if(!is_sid_blocked(cardsrc, srvid)) + { remove_sid_block(carddst, srvid); } + } + } + else + { + if(goodSidCountSrc == 0) + { + // del goods from dst + ll_clear(carddst->goodsids); + + // del bads from dst + ll_clear(carddst->badsids); + + // add bads from src + it = ll_iter_create(cardsrc->badsids); + while((srvidb = ll_iter_next(&it))) + { + { add_sid_block(carddst, (struct cc_srvid*)srvidb, false); } + } + } + else + { + // add good sid good+notbad from src + it = ll_iter_create(cardsrc->goodsids); + while((srvid = ll_iter_next(&it))) + { + if(!is_sid_blocked(cardsrc, srvid)) + { add_good_sid(carddst, srvid); } + } + } + } + +} + /** * Adds a new card to a cardlist. */ @@ -899,9 +949,8 @@ card_dup_count++; card2->grp |= card->grp; //add group to the card add_card_providers(card2, card, 0); //merge all providers - ll_clear_data(card2->remote_nodes); //clear remote nodes - if(!card2->sidtab) - { ll_clear_data(card2->badsids); } + ll_clear_data(card2->remote_nodes); //clear remote nodes + merge_sids(card2, card); } } @@ -947,8 +996,7 @@ card_dup_count++; card2->grp |= card->grp; //add group to the card add_card_providers(card2, card, 0); - if(!card2->sidtab) - { ll_clear_data(card2->badsids); } + merge_sids(card2, card); } } @@ -1192,7 +1240,7 @@ //Filts by Hardware readers: if((rdr->typ != R_CCCAM) && rdr->ftab.filts && !flt) { - for(j = 0; j < CS_MAXFILTERS; j++) + for(j = 0; j < rdr->ftab.nfilts; j++) { uint16_t caid = rdr->ftab.filts[j].caid; if(caid) @@ -1236,13 +1284,14 @@ if((rdr->typ != R_CCCAM) && !rdr->caid && !flt) { - for(j = 0; j < CS_MAXCAIDTAB; j++) + for(j = 0; j < rdr->ctab.ctnum; j++) { - //cs_log("CAID map CCcam card report caid: %04X cmap: %04X", rdr->ctab.caid[j], rdr->ctab.cmap[j]); - uint16_t lcaid = rdr->ctab.caid[j]; + CAIDTAB_DATA *d = &rdr->ctab.ctdata[j]; + //cs_log("CAID map CCcam card report caid: %04X cmap: %04X", d->caid, d->cmap); + uint16_t lcaid = d->caid; if(!lcaid || (lcaid == 0xFFFF)) - { lcaid = rdr->ctab.cmap[j]; } + { lcaid = d->cmap; } if(lcaid && (lcaid != 0xFFFF)) { @@ -1260,15 +1309,16 @@ } } - if((rdr->typ != R_CCCAM) && rdr->ctab.caid[0] && !flt) + if((rdr->typ != R_CCCAM) && rdr->ctab.ctnum && !flt) { //cs_log("tcp_connected: %d card_status: %d ", rdr->tcp_connected, rdr->card_status); int32_t c; if(rdr->tcp_connected || rdr->card_status == CARD_INSERTED) { - for(c = 0; c < CS_MAXCAIDTAB; c++) + for(c = 0; c < rdr->ctab.ctnum; c++) { - uint16_t caid = rdr->ctab.caid[c]; + CAIDTAB_DATA *d = &rdr->ctab.ctdata[c]; + uint16_t caid = d->caid; if(!caid) { break; } card = create_card2(rdr, c, caid, reshare); @@ -1424,7 +1474,7 @@ { send_card_to_all_clients(card); } - ll_destroy_NULL(new_cards); + ll_destroy(&new_cards); cs_writeunlock(&cc_shares_lock); diff -Nru oscam-1.20-10584~r10356/module-cccshare.h oscam-1.20-10797~r10569/module-cccshare.h --- oscam-1.20-10584~r10356/module-cccshare.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-cccshare.h 2015-02-20 11:57:49.000000000 +0000 @@ -25,4 +25,14 @@ void cc_SA_oscam2cccam(uint8_t *in, uint8_t *out); void set_card_timeout(struct cc_card *card); +struct cc_srvid *is_good_sid(struct cc_card *card, struct cc_srvid *srvid_good); +struct cc_srvid_block *is_sid_blocked(struct cc_card *card, struct cc_srvid *srvid_blocked); + +void add_good_sid(struct cc_card *card, struct cc_srvid *srvid_good); +void remove_good_sid(struct cc_card *card, struct cc_srvid *srvid_good); +void add_sid_block(struct cc_card *card, struct cc_srvid *srvid_blocked, bool temporary); +void remove_sid_block(struct cc_card *card, struct cc_srvid *srvid_blocked); + +void merge_sids(struct cc_card *carddst, struct cc_card *cardsrc); + #endif diff -Nru oscam-1.20-10584~r10356/module-cw-cycle-check.c oscam-1.20-10797~r10569/module-cw-cycle-check.c --- oscam-1.20-10584~r10356/module-cw-cycle-check.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-cw-cycle-check.c 2015-02-20 11:57:49.000000000 +0000 @@ -11,6 +11,35 @@ #include "oscam-string.h" #include "oscam-cache.h" +struct s_cwc_md5 +{ + uchar md5[CS_ECMSTORESIZE]; + int32_t csp_hash; + uchar cw[16]; +}; + +struct s_cw_cycle_check +{ + uchar cw[16]; + time_t time; + time_t locktime; // lock in learning + uint16_t caid; + uint16_t sid; + uint16_t chid; + uint32_t provid; + int16_t ecmlen; + int8_t stage; + int32_t cycletime; + int32_t dyncycletime; + int8_t nextcyclecw; + struct s_cwc_md5 ecm_md5[15]; // max 15 old ecm md5 /csp-hashs + int8_t cwc_hist_entry; + uint8_t old; + int8_t stage4_repeat; + struct s_cw_cycle_check *prev; + struct s_cw_cycle_check *next; +}; + extern CS_MUTEX_LOCK cwcycle_lock; static struct s_cw_cycle_check *cw_cc_list; diff -Nru oscam-1.20-10584~r10356/module-cw-cycle-check.h oscam-1.20-10797~r10569/module-cw-cycle-check.h --- oscam-1.20-10584~r10356/module-cw-cycle-check.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-cw-cycle-check.h 2015-02-20 11:57:49.000000000 +0000 @@ -1,41 +1,12 @@ #ifndef MODULE_CW_CYCLE_CHECK_H_ #define MODULE_CW_CYCLE_CHECK_H_ -#ifdef CW_CYCLE_CHECK - -struct s_cwc_md5 -{ - uchar md5[CS_ECMSTORESIZE]; - int32_t csp_hash; - uchar cw[16]; -}; - -struct s_cw_cycle_check -{ - uchar cw[16]; - time_t time; - time_t locktime; // lock in learning - uint16_t caid; - uint16_t sid; - uint16_t chid; - uint32_t provid; - int16_t ecmlen; - int8_t stage; - int32_t cycletime; - int32_t dyncycletime; - int8_t nextcyclecw; - struct s_cwc_md5 ecm_md5[15]; // max 15 old ecm md5 /csp-hashs - int8_t cwc_hist_entry; - uint8_t old; - int8_t stage4_repeat; - struct s_cw_cycle_check *prev; - struct s_cw_cycle_check *next; -}; +uint8_t checkcwcycle(struct s_client *client, ECM_REQUEST *er, struct s_reader *reader, uchar *cw, int8_t rc, uint8_t cycletime_fr, uint8_t next_cw_cycle_fr); +#ifdef CW_CYCLE_CHECK void cleanupcwcycle(void); -uint8_t checkcwcycle(struct s_client *client, ECM_REQUEST *er, struct s_reader *reader, uchar *cw, int8_t rc, uint8_t cycletime_fr, uint8_t next_cw_cycle_fr); #else -static inline void cleanupcwcycle(void) { }; +static inline void cleanupcwcycle(void) { } #endif #endif diff -Nru oscam-1.20-10584~r10356/module-dvbapi.c oscam-1.20-10797~r10569/module-dvbapi.c --- oscam-1.20-10584~r10356/module-dvbapi.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-dvbapi.c 2015-02-20 11:57:49.000000000 +0000 @@ -25,8 +25,16 @@ #include "oscam-work.h" #include "reader-irdeto.h" +#if defined (__CYGWIN__) +#define F_NOTIFY 0 +#define F_SETSIG 0 +#define DN_MODIFY 0 +#define DN_CREATE 0 +#define DN_DELETE 0 +#define DN_MULTISHOT 0 +#endif + static int is_samygo; -extern char *stb_boxtype; static int dvbapi_ioctl(int fd, uint32_t request, ...) { @@ -90,10 +98,8 @@ #endif // FIXME: Workaround for su980 bug // See: http://www.streamboard.tv/wbb2/thread.php?postid=533940 - if(streq(stb_boxtype, "su980")) - { + if(boxtype_is("su980")) ret = 1; - } va_end(args); return ret; } @@ -670,9 +676,19 @@ } len = read(dmx_fd, buf, length); - + if(len < 1) - { cs_log("ERROR: Read error on fd %d (errno=%d %s)", dmx_fd, errno, strerror(errno)); } + { + if(errno == EOVERFLOW) + { + cs_log("fd %d no valid data present since receiver reported an internal bufferoverflow!", dmx_fd); + return 0; + } + else + { + cs_log("ERROR: Read error on fd %d (errno=%d %s)", dmx_fd, errno, strerror(errno)); + } + } else { cs_log_dump_dbg(D_TRACE, buf, len, "Readed:"); } return len; } @@ -738,25 +754,27 @@ { int32_t i; struct s_client *cl = cur_client(); - TUNTAB *ttab; - ttab = &cl->ttab; + TUNTAB *ttab = &cl->ttab; + + if (!ttab->ttnum) + return caid; if(direct) { - for(i = 0; i < ttab->n; i++) + for(i = 0; i < ttab->ttnum; i++) { - if(caid == ttab->bt_caidto[i] - && (srvid == ttab->bt_srvid[i] || ttab->bt_srvid[i] == 0xFFFF || !ttab->bt_srvid[i])) - { return ttab->bt_caidfrom[i]; } + if(caid == ttab->ttdata[i].bt_caidto + && (srvid == ttab->ttdata[i].bt_srvid || ttab->ttdata[i].bt_srvid == 0xFFFF || !ttab->ttdata[i].bt_srvid)) + { return ttab->ttdata[i].bt_caidfrom; } } } else { - for(i = 0; i < ttab->n; i++) + for(i = 0; i < ttab->ttnum; i++) { - if(caid == ttab->bt_caidfrom[i] - && (srvid == ttab->bt_srvid[i] || ttab->bt_srvid[i] == 0xFFFF || !ttab->bt_srvid[i])) - { return ttab->bt_caidto[i]; } + if(caid == ttab->ttdata[i].bt_caidfrom + && (srvid == ttab->ttdata[i].bt_srvid || ttab->ttdata[i].bt_srvid == 0xFFFF || !ttab->ttdata[i].bt_srvid)) + { return ttab->ttdata[i].bt_caidto; } } } return caid; @@ -766,7 +784,7 @@ { int32_t g, ret = -1; - for(g = 0; g < maxfilter; g++) + for(g = 0; g < MAX_FILTER; g++) // just stop them all, we dont want to risk leaving any stale filters running due to lowering of maxfilters { if(demux[demux_index].demux_fd[g].type == type) { @@ -1645,7 +1663,7 @@ #else ret = sscanf(trim(token), "%c: %63s %63s", &type, str1, str1 + 64); #endif - type = tolower(type); + type = tolower((uchar)type); if(ret < 1 || (type != 'p' && type != 'i' && type != 'm' && type != 'd' && type != 's' && type != 'l' && type != 'j' && type != 'a' && type != 'x')) @@ -2672,14 +2690,17 @@ } } - demux[demux_id].emm_filter = -1; // to register first run emmfilter start - if(cfg.dvbapi_au > 0 && demux[demux_id].emmstart.time == 1) // irdeto fetch emm cat direct! + if(running == 0) // only do emm setup on non-running channels! { - cs_ftime(&demux[demux_id].emmstart); // trick to let emm fetching start after 30 seconds to speed up zapping - dvbapi_start_filter(demux_id, demux[demux_id].pidindex, 0x001, 0x001, 0x01, 0x01, 0xFF, 0, TYPE_EMM); //CAT + demux[demux_id].emm_filter = -1; // to register first run emmfilter start + if(cfg.dvbapi_au > 0 && demux[demux_id].emmstart.time == 1) // irdeto fetch emm cat direct! + { + cs_ftime(&demux[demux_id].emmstart); // trick to let emm fetching start after 30 seconds to speed up zapping + dvbapi_start_filter(demux_id, demux[demux_id].pidindex, 0x001, 0x001, 0x01, 0x01, 0xFF, 0, TYPE_EMM); //CAT + } + else { cs_ftime(&demux[demux_id].emmstart); } // for all other caids delayed start! } - else { cs_ftime(&demux[demux_id].emmstart); } // for all other caids delayed start! - + openxcas_set_sid(program_number); if(demux[demux_id].ECMpidcount == 0) { // for FTA it ends here, but do logging and part of ecmhandler since there will be no ecms asked! @@ -2745,7 +2766,13 @@ int32_t demux_index = buffer[7 + k]; for(i = 0; i < MAX_DEMUX; i++) { - if(demux[i].demux_index == demux_index) + // 0xff demux_index is a wildcard => close all related demuxers + if (demux_index == 0xff) + { + if (demux[i].socket_fd == connfd) + dvbapi_stop_descrambling(i); + } + else if (demux[i].demux_index == demux_index) { dvbapi_stop_descrambling(i); break; @@ -2979,7 +3006,7 @@ } cs_log_dbg(D_DVBAPI, "found pmt file %s", dest); - //cs_sleepms(100); why wait? + cs_sleepms(100); uint32_t len = read(pmt_fd, mbuf, sizeof(mbuf)); int32_t ret = close(pmt_fd); @@ -3084,34 +3111,36 @@ if(demux[demux_id].demux_fd[filter_num].type == TYPE_ECM) { - cs_log_dbg(D_DVBAPI, "Demuxer #%d Filter #%d fetched ECM data (ecmlength = %03X)", demux_id, filter_num + 1, ecmlen); - if((uint) len < ecmlen) // invalid CAT length + if(len != 0) // len = 0 receiver encountered an internal bufferoverflow! { - cs_log_dbg(D_DVBAPI, "Received data with total length %03X but ECM length is %03X -> invalid CAT length!", len, ecmlen); - return; - } + cs_log_dbg(D_DVBAPI, "Demuxer #%d Filter #%d fetched ECM data (ecmlength = %03X)", demux_id, filter_num + 1, ecmlen); + if((uint) len < ecmlen) // invalid CAT length + { + cs_log_dbg(D_DVBAPI, "Received data with total length %03X but ECM length is %03X -> invalid CAT length!", len, ecmlen); + return; + } - if(!(buffer[0] == 0x80 || buffer[0] == 0x81)) - { - cs_log_dbg(D_DVBAPI, "Received an ECM with invalid ecmtable ID %02X -> ignoring!", buffer[0]); - return; - } + if(!(buffer[0] == 0x80 || buffer[0] == 0x81)) + { + cs_log_dbg(D_DVBAPI, "Received an ECM with invalid ecmtable ID %02X -> ignoring!", buffer[0]); + return; + } - if(curpid->table == buffer[0] && curpid->CAID >> 8 != 0x06) // wait for odd / even ecm change (only not for irdeto!) - { return; } + if(curpid->table == buffer[0] && curpid->CAID >> 8 != 0x06) // wait for odd / even ecm change (only not for irdeto!) + { return; } - if(curpid->CAID >> 8 == 0x06) //irdeto cas - { - // 80 70 39 53 04 05 00 88 - // 81 70 41 41 01 06 00 13 00 06 80 38 1F 52 93 D2 - //if (buffer[5]>20) return; - if(curpid->irdeto_maxindex != buffer[5]) //6, register max irdeto index + if(curpid->CAID >> 8 == 0x06) //irdeto cas { - cs_log_dbg(D_DVBAPI, "Found %d IRDETO ECM CHIDs", buffer[5] + 1); - curpid->irdeto_maxindex = buffer[5]; // numchids = 7 (0..6) + // 80 70 39 53 04 05 00 88 + // 81 70 41 41 01 06 00 13 00 06 80 38 1F 52 93 D2 + //if (buffer[5]>20) return; + if(curpid->irdeto_maxindex != buffer[5]) //6, register max irdeto index + { + cs_log_dbg(D_DVBAPI, "Found %d IRDETO ECM CHIDs", buffer[5] + 1); + curpid->irdeto_maxindex = buffer[5]; // numchids = 7 (0..6) + } } } - ECM_REQUEST *er; if(!(er = get_ecmtask())) { return; } @@ -3131,6 +3160,14 @@ chid = get_subid(er); // fetch chid or fake chid er->chid = chid; + + if(len == 0) // only used on receiver internal bufferoverflow to get quickly fresh ecm filterdata otherwise freezing! + { + curpid->table = 0; + dvbapi_set_section_filter(demux_id, er); + NULLFREE(er); + return; + } if(curpid->CAID >> 8 == 0x06) //irdeto cas { @@ -3293,6 +3330,7 @@ curpid->table = er->ecm[0]; } request_cw(dvbapi_client, er, demux_id, 1); // register this ecm for delayed ecm response check + return; // end of ecm filterhandling! } if(demux[demux_id].demux_fd[filter_num].type == TYPE_EMM) @@ -3535,7 +3573,7 @@ pfdcount = (listenfd > -1) ? 1 : 0; for(i = 0; i < MAX_DEMUX; i++) - { + { // add client fd's which are not yet associated with the demux but needs to be polled for data if (unassoc_fd[i]) { pfd2[pfdcount].fd = unassoc_fd[i]; @@ -3544,7 +3582,7 @@ } if(demux[i].program_number == 0) { continue; } // only evalutate demuxers that have channels assigned - + uint32_t ecmcounter = 0, emmcounter = 0; for(g = 0; g < maxfilter; g++) { @@ -3602,7 +3640,7 @@ dvbapi_start_emm_filter(i); // start emmfiltering delayed if filters already were running } } - if(emmstarted != demux[i].emm_filter && !emmcounter) { continue; } // proceed with next demuxer if no emms where running before + //if(emmstarted != demux[i].emm_filter && !emmcounter) { continue; } // proceed with next demuxer if no emms where running before } if(ecmcounter == 0 && demux[i].ECMpidcount > 0) // Restart decoding all caids we have ecmpids but no ecm filters! @@ -3727,7 +3765,6 @@ for(i = 0; i < pfdcount && rc > 0; i++) { - cs_sleepms(1); // give time to other processes! if(pfd2[i].revents == 0) { continue; } // skip sockets with no changes rc--; //event handled! cs_log_dbg(D_TRACE, "Now handling fd %d that reported event %d", pfd2[i].fd, pfd2[i].revents); @@ -3778,7 +3815,7 @@ connfd = accept(listenfd, (struct sockaddr *)&servaddr, (socklen_t *)&clilen); cs_log_dbg(D_DVBAPI, "new socket connection fd: %d", connfd); if (cfg.dvbapi_listenport) - {; + { //update webif data client->ip = SIN_GET_ADDR(servaddr); client->port = ntohs(SIN_GET_PORT(servaddr)); @@ -3993,14 +4030,21 @@ { int32_t demux_index = ids[i]; int32_t n = fdn[i]; - - if((int)demux[demux_index].demux_fd[n].fd != pfd2[i].fd) { continue; } // filter already killed, no need to process this data! - if((len = dvbapi_read_device(pfd2[i].fd, mbuf, sizeof(mbuf))) <= 0) + if((len = dvbapi_read_device(pfd2[i].fd, mbuf, sizeof(mbuf))) <= 0) // always read to empty receiver databuffer { - dvbapi_stop_filternum(demux_index, n); // stop filter since its giving errors and wont return anything good. - maxfilter--; // lower maxfilters to avoid this with new filter setups! - continue; + if((int)demux[demux_index].demux_fd[n].fd != pfd2[i].fd) { continue; } // but if filter already killed no need to process the data! + + if(len < 0) // serious filterdata read error + { + dvbapi_stop_filternum(demux_index, n); // stop filter since its giving errors and wont return anything good. + maxfilter--; // lower maxfilters to avoid this with new filter setups! + continue; + } + if(!len) // receiver internal filterbuffer overflow + { + memset(mbuf, 0, sizeof(mbuf)); + } } dvbapi_process_input(demux_index, n, mbuf, len); @@ -4242,6 +4286,12 @@ if(er->rc >= E_NOTFOUND) // not found on requestmode 0 + 1 { + if(er->rc == E_SLEEPING) + { + dvbapi_stop_descrambling(i); + return; + } + struct s_dvbapi_priority *forceentry = dvbapi_check_prio_match(i, j, 'p'); if(forceentry && forceentry->force) // forced pid? keep trying the forced ecmpid! diff -Nru oscam-1.20-10584~r10356/module-dvbapi-chancache.c oscam-1.20-10797~r10569/module-dvbapi-chancache.c --- oscam-1.20-10584~r10356/module-dvbapi-chancache.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-dvbapi-chancache.c 2015-02-20 11:57:49.000000000 +0000 @@ -16,7 +16,10 @@ void dvbapi_save_channel_cache(void) { + if(boxtype_is("dbox2")) return; // dont save channelcache on these boxes, they lack resources and will crash! + char fname[256]; + int32_t result = 0; get_config_filename(fname, sizeof(fname), "oscam.ccache"); FILE *file = fopen(fname, "w"); @@ -30,7 +33,21 @@ struct s_channel_cache *c; while((c = ll_iter_next(&it))) { - fprintf(file, "%04X,%06X,%04X,%04X,%06X\n", c->caid, c->prid, c->srvid, c->pid, c->chid); + result = fprintf(file, "%04X,%06X,%04X,%04X,%06X\n", c->caid, c->prid, c->srvid, c->pid, c->chid); + if(result < 0) + { + fclose(file); + result = remove(fname); + if(!result) + { + cs_log("error writing cache -> cache file removed!"); + } + else + { + cs_log("error writing cache -> cache file could not be removed either!"); + } + return; + } } fclose(file); @@ -39,6 +56,8 @@ void dvbapi_load_channel_cache(void) { + if(boxtype_is("dbox2")) return; // dont load channelcache on these boxes, they lack resources and will crash! + if (USE_OPENXCAS) // Why? return; @@ -51,10 +70,10 @@ file = fopen(fname, "r"); if(!file) { - cs_log("dvbapi channelcache can't read from file %s", fname); + cs_log_dbg(D_TRACE, "dvbapi channelcache can't read from file %s", fname); return; } - + int32_t i = 1; int32_t valid = 0; char *ptr, *saveptr1 = NULL; diff -Nru oscam-1.20-10584~r10356/module-gbox.c oscam-1.20-10797~r10569/module-gbox.c --- oscam-1.20-10584~r10356/module-gbox.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-gbox.c 2015-02-20 11:57:49.000000000 +0000 @@ -6,6 +6,7 @@ #include "module-gbox.h" #include "module-gbox-helper.h" #include "module-gbox-sms.h" +#include "module-gbox-cards.h" #include "module-cccam.h" #include "module-cccam-data.h" #include "oscam-failban.h" @@ -20,21 +21,6 @@ #include "oscam-garbage.h" #include "oscam-files.h" - -#define FILE_GBOX_VERSION "gbox.ver" -#define FILE_SHARED_CARDS_INFO "share.info" -#define FILE_ATTACK_INFO "attack.txt" -#define FILE_GBOX_PEER_ONL "share.onl" -#define FILE_STATS "stats.info" -#define FILE_GOODNIGHT_OSD "goodnight.osd" -#define FILE_Local_CARDS_INFO "sc.info" - -#define GBOX_STAT_HELLOL 0 -#define GBOX_STAT_HELLOS 1 -#define GBOX_STAT_HELLOR 2 -#define GBOX_STAT_HELLO3 3 -#define GBOX_STAT_HELLO4 4 - #define RECEIVE_BUFFER_SIZE 1024 #define MIN_GBOX_MESSAGE_LENGTH 10 //CMD + pw + pw. TODO: Check if is really min #define MIN_ECM_LENGTH 8 @@ -44,11 +30,9 @@ #define LOCAL_GBOX_MAJOR_VERSION 0x02 static struct gbox_data local_gbox; +static uint8_t local_gbox_initialized = 0; static time_t last_stats_written; -//static void gbox_send_boxinfo(struct s_client *cli); -static void gbox_send_hello(struct s_client *cli); -static void gbox_send_hello_packet(struct s_client *cli, int8_t number, uchar *outbuf, uchar *ptr, int32_t nbcards); static void gbox_send_checkcode(struct s_client *cli); static void gbox_local_cards(struct s_client *cli); static void gbox_init_ecm_request_ext(struct gbox_ecm_request_ext *ere); @@ -60,8 +44,6 @@ static int32_t gbox_checkcode_recv(struct s_client *cli, uchar *checkcode); static uint16_t gbox_convert_password_to_id(uint32_t password); static int32_t gbox_send_ecm(struct s_client *cli, ECM_REQUEST *er, uchar *UNUSED(buf)); -uint32_t gbox_get_ecmchecksum(uchar *ecm, uint16_t ecmlen); -static void init_local_gbox(void); char *get_gbox_tmp_fname(char *fext) { @@ -185,138 +167,16 @@ void gbox_write_version(void) { - char *fext= FILE_GBOX_VERSION; - char *fname = get_gbox_tmp_fname(fext); - - FILE *fhandle = fopen(fname, "w"); + FILE *fhandle = fopen(get_gbox_tmp_fname(FILE_GBOX_VERSION), "w"); if(!fhandle) { - cs_log("Couldn't open %s: %s", fname, strerror(errno)); + cs_log("Couldn't open %s: %s", get_gbox_tmp_fname(FILE_GBOX_VERSION), strerror(errno)); return; } fprintf(fhandle, "%02X.%02X\n", LOCAL_GBOX_MAJOR_VERSION, gbox_get_my_vers()); fclose(fhandle); } -void gbox_write_local_cards_info(void) -{ - int32_t card_count = 0; - char *fext= FILE_Local_CARDS_INFO; - char *fname = get_gbox_tmp_fname(fext); - FILE *fhandle; - fhandle = fopen(fname, "w"); - if(!fhandle) - { - cs_log("Couldn't open %s: %s", fname, strerror(errno)); - return; - } - LL_ITER it; - struct gbox_card *card; - it = ll_iter_create(local_gbox.cards); - char *crdtype = NULL; - while((card = ll_iter_next(&it))) - { - if(card->type == 1) - {crdtype = "Local_Card";} - if(card->type == 2) - {crdtype = "Betun_Card";} - if(card->type == 3) - {crdtype = "CCcam_Card";} - if(card->type == 4) - {crdtype = "Proxy_Card";} - fprintf(fhandle, "CardID:%2d %s %08X Sl:%2d id:%04X\n", - card_count, crdtype, card->provid_1,card->id.slot, card->id.peer); - card_count++; - - } - fclose(fhandle); - return; -} - -void gbox_write_shared_cards_info(void) -{ - int32_t card_count = 0; - //int32_t i = 0; - char *fext= FILE_SHARED_CARDS_INFO; - char *fname = get_gbox_tmp_fname(fext); - FILE *fhandle; - fhandle = fopen(fname, "w"); - if(!fhandle) - { - cs_log("Couldn't open %s: %s", fname, strerror(errno)); - return; - } - LL_ITER it; - struct gbox_card *card; - struct s_client *cl; - for(cl = first_client; cl; cl = cl->next) - //for(i = 0, cl = first_client; cl; cl = cl->next, i++) - { - if(cl->gbox && cl->reader->card_status == CARD_INSERTED && cl->typ == 'p') - { - struct gbox_peer *peer = cl->gbox; - - it = ll_iter_create(peer->gbox.cards); - while((card = ll_iter_next(&it))) - { - fprintf(fhandle, "CardID %2d at %s Card %08X Sl:%2d Lev:%1d dist:%1d id:%04X\n", - card_count, cl->reader->device, card->provid_1, - card->id.slot, card->lvl, card->dist, card->id.peer); - card_count++; - } - } - } - fclose(fhandle); - return; -} - -void gbox_write_stats(void) -{ - int32_t card_count = 0; - int32_t i = 0; - struct gbox_good_srvid *srvid_good = NULL; - struct gbox_bad_srvid *srvid_bad = NULL; - char *fext= FILE_STATS; - char *fname = get_gbox_tmp_fname(fext); - FILE *fhandle; - fhandle = fopen(fname, "w"); - if(!fhandle) - { - cs_log("Couldn't open %s: %s", fname, strerror(errno)); - return; - } - - LL_ITER it; - struct gbox_card *card; - - struct s_client *cl; - for(i = 0, cl = first_client; cl; cl = cl->next, i++) - { - if(cl->gbox && cl->reader->card_status == CARD_INSERTED && cl->typ == 'p') - { - struct gbox_peer *peer = cl->gbox; - - it = ll_iter_create(peer->gbox.cards); - while((card = ll_iter_next(&it))) - { - fprintf(fhandle, "CardID %4d Card %08X id:%04X #CWs:%d AVGtime:%d ms\n", - card_count, card->provid_1, card->id.peer, card->no_cws_returned, card->average_cw_time); - fprintf(fhandle, "Good SIDs:\n"); - LL_ITER it2 = ll_iter_create(card->goodsids); - while((srvid_good = ll_iter_next(&it2))) - { fprintf(fhandle, "%04X\n", srvid_good->srvid.sid); } - fprintf(fhandle, "Bad SIDs:\n"); - it2 = ll_iter_create(card->badsids); - while((srvid_bad = ll_iter_next(&it2))) - { fprintf(fhandle, "%04X #%d\n", srvid_bad->srvid.sid, srvid_bad->bad_strikes); } - card_count++; - } // end of while ll_iter_next - } // end of if cl->gbox INSERTED && 'p' - } // end of for cl->next - fclose(fhandle); - return; -} - void hostname2ip(char *hostname, IN_ADDR_T *ip) { cs_resolve(hostname, ip, NULL, NULL); @@ -327,102 +187,20 @@ return (((password >> 24) & 0xff) ^ ((password >> 8) & 0xff)) << 8 | (((password >> 16) & 0xff) ^ (password & 0xff)); } -static int8_t gbox_remove_all_bad_sids(struct gbox_peer *peer, ECM_REQUEST *er, uint16_t sid) +static int8_t gbox_remove_all_bad_sids(ECM_REQUEST *er, uint16_t sid) { - if (!peer || !er) { return -1; } + if (!er) { return -1; } - struct gbox_card *card = NULL; - struct gbox_bad_srvid *srvid = NULL; struct gbox_card_pending *pending = NULL; LL_ITER it = ll_iter_create(er->gbox_cards_pending); while ((pending = ll_iter_next(&it))) - { - LL_ITER it2 = ll_iter_create(peer->gbox.cards); - while((card = ll_iter_next(&it2))) - { - if(card->id.peer == pending->id.peer && card->id.slot == pending->id.slot) - { - LL_ITER it3 = ll_iter_create(card->badsids); - while((srvid = ll_iter_next(&it3))) - { - if(srvid->srvid.sid == sid) - { - ll_iter_remove_data(&it3); // remove sid_ok from badsids - break; - } - } - } - } - } + { gbox_remove_bad_sid(pending->id.peer, pending->id.slot, sid); } return 0; } -void gbox_add_good_card(struct s_client *cl, uint16_t id_card, uint16_t caid, uint8_t slot, uint16_t sid_ok, uint32_t cw_time) -{ - if (!cl || !cl->gbox) { return; } - - struct gbox_peer *peer = cl->gbox; - struct gbox_card *card = NULL; - struct gbox_good_srvid *srvid = NULL; - uint8_t factor = 0; - LL_ITER it = ll_iter_create(peer->gbox.cards); - while((card = ll_iter_next(&it))) - { - if(card->id.peer == id_card && card->caid == caid && card->id.slot == slot) - { - card->no_cws_returned++; - if (!card->no_cws_returned) - { card->no_cws_returned = 10; } //wrap around - if (card->no_cws_returned < 10) - { factor = card->no_cws_returned; } - else - { factor = 10; } - card->average_cw_time = ((card->average_cw_time * (factor-1)) + cw_time) / factor; - cl->reader->currenthops = card->dist; - LL_ITER it2 = ll_iter_create(card->goodsids); - while((srvid = ll_iter_next(&it2))) - { - if(srvid->srvid.sid == sid_ok) - { - srvid->last_cw_received = time(NULL); - return; // sid_ok is already in the list of goodsids - } - } - - if(!cs_malloc(&srvid, sizeof(struct gbox_good_srvid))) - { return; } - srvid->srvid.sid = sid_ok; - srvid->srvid.provid_id = card->provid; - srvid->last_cw_received = time(NULL); - cs_log_dbg(D_READER, "Adding good SID: %04X for CAID: %04X Provider: %04X on CardID: %04X\n", sid_ok, caid, card->provid, id_card); - ll_append(card->goodsids, srvid); - break; - } - }//end of ll_iter_next - //return dist_c; -} - -void gbox_free_card(struct gbox_card *card) -{ - ll_destroy_data_NULL(card->badsids); - ll_destroy_data_NULL(card->goodsids); - add_garbage(card); - return; -} - -void gbox_free_cardlist(LLIST *card_list) -{ - if(card_list) - { - LL_ITER it = ll_iter_create(card_list); - struct gbox_card *card; - while((card = ll_iter_next_remove(&it))) - { - gbox_free_card(card); - } - ll_destroy_NULL(card_list); - } - return; +void gbox_free_cards_pending(ECM_REQUEST *er) +{ + ll_destroy_free_data(&er->gbox_cards_pending); } void gbox_init_ecm_request_ext(struct gbox_ecm_request_ext *ere) @@ -475,13 +253,14 @@ static int8_t gbox_reinit_peer(struct gbox_peer *peer) { + if (!peer) + { return -1; } NULLFREE(peer->hostname); peer->online = 0; peer->ecm_idx = 0; peer->hello_stat = GBOX_STAT_HELLOL; peer->next_hello = 0; - gbox_free_cardlist(peer->gbox.cards); - peer->gbox.cards = ll_create("peer.cards"); + gbox_delete_cards_from_peer(peer->gbox.id); // peer->my_user = NULL; return 0; @@ -489,9 +268,11 @@ static int8_t gbox_reinit_proxy(struct s_client *proxy) { + if (!proxy) { return -1; } + struct gbox_peer *peer = proxy->gbox; - if (peer) - { gbox_reinit_peer(peer); } + gbox_reinit_peer(peer); + if (!proxy->reader) { return -1; } proxy->reader->tcp_connected = 0; proxy->reader->card_status = NO_CARD; proxy->reader->last_s = proxy->reader->last_g = 0; @@ -531,9 +312,7 @@ if(!client) { return "anonymous"; } if(client->reader) if(client->reader->r_usr[0]) - { - return client->reader->r_usr; - } + { return client->reader->r_usr; } return "anonymous"; } @@ -601,99 +380,29 @@ int8_t gbox_message_header(uchar *buf, uint16_t cmd, uint32_t peer_password, uint32_t local_password) { if (!buf) { return -1; } - buf[0] = cmd >> 8; - buf[1] = cmd & 0xff; + i2b_buf(2, cmd, buf); if (cmd == MSG_GSMS_1) { return 0; } - buf[2] = (peer_password >> 24) & 0xff; - buf[3] = (peer_password >> 16) & 0xff; - buf[4] = (peer_password >> 8) & 0xff; - buf[5] = peer_password & 0xff; + i2b_buf(4, peer_password, buf + 2); if (cmd == MSG_CW) { return 0; } - buf[6] = (local_password >> 24) & 0xff; - buf[7] = (local_password >> 16) & 0xff; - buf[8] = (local_password >> 8) & 0xff; - buf[9] = local_password & 0xff; - return 0; -} - -int8_t get_card_action(struct gbox_card *card, uint32_t provid1, uint16_t peer_id, uint8_t slot, LLIST *cards) -{ - LL_ITER it; - struct gbox_card *card_s; - if (!card) { return 1; } //insert - if (card->provid_1 < provid1) { return -1; } //remove - if (card->id.peer == peer_id && card->provid_1 == provid1 && card->id.slot == slot) - { return 0; } //keep - else - { - it = ll_iter_create(cards); - while ((card_s = ll_iter_next(&it))) - { - //card is still somewhere else we need to remove current - if (card_s->id.peer == peer_id && card_s->provid_1 == provid1 && card_s->id.slot == slot) - { return -1; } //remove - } - return 1; //insert - } -} - -static int8_t gbox_init_card(struct gbox_card *card, uint16_t caid, uint32_t provid, uint32_t provid1, uint8_t *ptr) -{ - if (!card || !ptr) { return -1; } - - card->caid = caid; - card->provid = provid; - card->provid_1 = provid1; - card->id.slot = ptr[0]; - card->dist = ptr[1] & 0xf; - card->lvl = ptr[1] >> 4; - card->id.peer = ptr[2] << 8 | ptr[3]; - card->badsids = ll_create("badsids"); - card->goodsids = ll_create("goodsids"); - card->no_cws_returned = 0; - card->average_cw_time = 0; - + i2b_buf(4, local_password, buf + 6); return 0; } //returns number of cards in a hello packet or -1 in case of error -int16_t read_cards_from_hello(uint8_t *ptr, uint8_t *len, CAIDTAB *ctab, uint8_t maxdist, LL_ITER *it, LLIST *cards, uint8_t last_packet) +int16_t read_cards_from_hello(uint8_t *ptr, uint8_t *len, CAIDTAB *ctab, uint8_t maxdist, struct gbox_peer *peer) { uint8_t *current_ptr = 0; - uint16_t caid; - uint32_t provid; - uint32_t provid1; - struct gbox_card *card_s; - struct gbox_card *card; + uint32_t caprovid; int16_t ncards_in_msg = 0; - LL_ITER *previous_it; while(ptr < len) { - switch(ptr[0]) - { - //Viaccess - case 0x05: - caid = ptr[0] << 8; - provid = ptr[1] << 16 | ptr[2] << 8 | ptr[3]; - break; - //Cryptoworks - case 0x0D: - caid = ptr[0] << 8 | ptr[1]; - provid = ptr[2]; - break; - default: - caid = ptr[0] << 8 | ptr[1]; - provid = ptr[2] << 8 | ptr[3]; - break; - } + caprovid = ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3]; ncards_in_msg += ptr[4]; //caid check - if(chk_ctab(caid, ctab)) + if(chk_ctab(gbox_get_caid(caprovid), ctab)) { - provid1 = ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3]; - current_ptr = ptr; ptr += 5; @@ -701,76 +410,19 @@ while (ptr < current_ptr + 5 + current_ptr[4] * 4) { if ((ptr[1] & 0xf) <= maxdist) - { - previous_it = it; - card_s = ll_iter_next(it); - switch (get_card_action(card_s, provid1, ptr[2] << 8 | ptr[3], ptr[0], cards)) - { - case -1: - //IDEA: Later put card to a list of temporary not available cards - //reason: not loose good/bad sids - //can be later removed by daily garbage collector for example - cs_log_dbg(D_READER, "delete card: caid=%04X, provid=%06X, slot=%d, level=%d, dist=%d, peer=%04X", - card_s->caid, card_s->provid, card_s->id.slot, card_s->lvl, card_s->dist, card_s->id.peer); - //delete card because not send anymore - ll_iter_remove(it); - gbox_free_card(card_s); - break; - case 0: - ptr += 4; - break; - case 1: - // create card info from data and add card to peer.cards - if(!cs_malloc(&card, sizeof(struct gbox_card))) - { - cs_log("Can't allocate gbox card"); - continue; - } - gbox_init_card(card,caid,provid,provid1,ptr); - if (!card_s) - { ll_append(cards, card); } - else - { - ll_iter_insert(previous_it, card); - it = previous_it; - } - ll_iter_next(it); - cs_log_dbg(D_READER, "new card: caid=%04X, provid=%06X, slot=%d, level=%d, dist=%d, peer=%04X", - card->caid, card->provid, card->id.slot, card->lvl, card->dist, card->id.peer); - ptr += 4; - break; - default: - ptr += 4; - break; - } //switch - } // if <= maxdist - else - { ptr += 4; } //ignore because of maxdist + { gbox_add_card(ptr[2] << 8 | ptr[3], caprovid, ptr[0], ptr[1] >> 4, ptr[1] & 0xf, GBOX_CARD_TYPE_GBOX, peer); } + ptr += 4; //next card } // end while cards for provider } else { ptr += 5 + ptr[4] * 4; } //skip cards because caid } // end while caid/provid - - if (last_packet) - { - //delete cards at the end of the list if there are some - while ((card_s = ll_iter_next(it))) - { - cs_log_dbg(D_READER, "delete card: caid=%04X, provid=%06X, slot=%d, level=%d, dist=%d, peer=%04X", - card_s->caid, card_s->provid, card_s->id.slot, card_s->lvl, card_s->dist, card_s->id.peer); - //delete card because not send anymore - ll_iter_remove(it); - gbox_free_card(card_s); - } - } - return ncards_in_msg; } int32_t gbox_cmd_hello(struct s_client *cli, uchar *data, int32_t n) { - if (!cli || !cli->gbox || !cli->reader || !data) { return -1; }; + if (!cli || !cli->gbox || !cli->reader || !data) { return -1; } struct gbox_peer *peer = cli->gbox; int16_t cards_number = 0; @@ -778,7 +430,6 @@ int32_t hostname_len = 0; int32_t footer_len = 0; uint8_t *ptr = 0; - LL_ITER it; if(!(gbox_decode_cmd(data) == MSG_HELLO1)) { @@ -801,9 +452,7 @@ if (!(data[11] & 0xf)) //is first packet { - if(!peer->gbox.cards) - { peer->gbox.cards = ll_create("peer.cards"); } - it = ll_iter_create(peer->gbox.cards); + gbox_delete_cards_from_peer(peer->gbox.id); hostname_len = data[payload_len - 1]; footer_len = hostname_len + 2 + 7; if(!peer->hostname || memcmp(peer->hostname, data + payload_len - 1 - hostname_len, hostname_len)) @@ -822,13 +471,10 @@ peer->gbox.cpu_api = data[payload_len - footer_len + 7]; peer->total_cards = 0; } - else - { it = peer->last_it; } cs_log_dbg(D_READER, "-> Hello packet no. %d received", (data[11] & 0xF) + 1); - // read cards from hello - cards_number = read_cards_from_hello(ptr, data + payload_len - footer_len - 1, &cli->reader->ctab, cli->reader->gbox_maxdist, &it, peer->gbox.cards, data[11] & 0x80); + cards_number = read_cards_from_hello(ptr, data + payload_len - footer_len - 1, &cli->reader->ctab, cli->reader->gbox_maxdist, peer); if (cards_number < 0) { return -1; } else @@ -848,36 +494,33 @@ else //last packet of Hello { peer->online = 1; + peer->filtered_cards = gbox_count_peer_cards(peer->gbox.id); if(!data[0xA]) { - cs_log("-> HelloS in %d packets from %s (%s:%d) V2.%02X with %d cards filtered to %d cards", (data[0x0B] & 0x0f)+1, cli->reader->label, cs_inet_ntoa(cli->ip), cli->reader->r_port, peer->gbox.minor_version, peer->total_cards, ll_count(peer->gbox.cards)); + cs_log("-> HelloS in %d packets from %s (%s:%d) V2.%02X with %d cards filtered to %d cards", (data[0x0B] & 0x0f)+1, cli->reader->label, cs_inet_ntoa(cli->ip), cli->reader->r_port, peer->gbox.minor_version, peer->total_cards, peer->filtered_cards); peer->hello_stat = GBOX_STAT_HELLOR; gbox_send_hello(cli); } else { - cs_log("-> HelloR in %d packets from %s (%s:%d) V2.%02X with %d cards filtered to %d cards", (data[0x0B] & 0x0f)+1, cli->reader->label, cs_inet_ntoa(cli->ip), cli->reader->r_port, peer->gbox.minor_version, peer->total_cards, ll_count(peer->gbox.cards)); + cs_log("-> HelloR in %d packets from %s (%s:%d) V2.%02X with %d cards filtered to %d cards", (data[0x0B] & 0x0f)+1, cli->reader->label, cs_inet_ntoa(cli->ip), cli->reader->r_port, peer->gbox.minor_version, peer->total_cards, peer->filtered_cards); gbox_send_checkcode(cli); } if(peer->hello_stat == GBOX_STAT_HELLOS) - { - gbox_send_hello(cli); - } + { gbox_send_hello(cli); } cli->reader->tcp_connected = 2; //we have card - if(ll_count(peer->gbox.cards) == 0) + if(!peer->filtered_cards) { cli->reader->card_status = NO_CARD; } else { cli->reader->card_status = CARD_INSERTED; } peer->next_hello = 0; - gbox_write_local_cards_info(); - gbox_write_shared_cards_info(); + gbox_write_cards_info(); gbox_write_peer_onl(); cli->last = time((time_t *)0); //hello is activity on proxy } } else { peer->next_hello++; } - peer->last_it = it; //save position for next hello return 0; } @@ -943,23 +586,23 @@ er->idx = peer->ecm_idx++; er->ecmlen = (((ecm[1] & 0x0f) << 8) | ecm[2]) + 3; - er->pid = data[10] << 8 | data[11]; - er->srvid = data[12] << 8 | data[13]; + er->pid = b2i(2, data + 10); + er->srvid = b2i(2, data + 12); if(ecm[er->ecmlen + 5] == 0x05) { er->caid = (ecm[er->ecmlen + 5] << 8); } else - { er->caid = (ecm[er->ecmlen + 5] << 8 | ecm[er->ecmlen + 6]); } + { er->caid = b2i(2, ecm + er->ecmlen + 5); } // ei->extra = data[14] << 8 | data[15]; memcpy(er->ecm, data + 18, er->ecmlen); - ere->gbox_peer = ecm[er->ecmlen] << 8 | ecm[er->ecmlen + 1]; + ere->gbox_peer = b2i(2, ecm + er->ecmlen); ere->gbox_version = ecm[er->ecmlen + 2]; ere->gbox_unknown = ecm[er->ecmlen + 3]; ere->gbox_type = ecm[er->ecmlen + 4]; - ere->gbox_caid = ecm[er->ecmlen + 5] << 8 | ecm[er->ecmlen + 6]; - ere->gbox_prid = ecm[er->ecmlen + 7] << 8 | ecm[er->ecmlen + 8]; - ere->gbox_mypeer = ecm[er->ecmlen + 10] << 8 | ecm[er->ecmlen + 11]; + ere->gbox_caid = b2i(2, ecm + er->ecmlen + 5); + ere->gbox_prid = b2i(2, ecm + er->ecmlen + 7); + ere->gbox_mypeer = b2i(2, ecm + er->ecmlen + 10); ere->gbox_slot = ecm[er->ecmlen + 12]; diffcheck = gbox_checkcode_recv(cl, data + n - 14); @@ -969,7 +612,7 @@ memcpy(&ere->gbox_routing_info[0], &data[n - 15 - ere->gbox_hops + 1], ere->gbox_hops - 1); er->prid = chk_provid(er->ecm, er->caid); - cs_log_dbg(D_READER, "<- ECM (%d<-) from server (%s:%d) to cardserver (%04X) SID %04X", ere->gbox_hops, peer->hostname, cli->port, ere->gbox_peer, er->srvid); + cs_log_dbg(D_READER, "<- ECM (distance: %d) from %04X via peer (%s:%d) for SID %04X", ere->gbox_hops, ere->gbox_peer, peer->hostname, cli->port, er->srvid); get_cw(cl, er); //checkcode did not match gbox->peer checkcode @@ -1112,9 +755,8 @@ cs_log_dbg(D_READER, "Authentication failed. Please check user in oscam.server and oscam.user"); return -1; } - //NEEDFIX: Pretty sure this should not be done here authentication_done = 1; - gbox_local_cards(cli); + gbox_local_cards(cli); proxy = get_gbox_proxy(cli->gbox_peer_id); if (proxy) { peer = proxy->gbox; } if (peer) { peer->my_user = cli; } @@ -1162,51 +804,6 @@ return authentication_done; } -static void gbox_calc_checkcode(void) -{ - int32_t i = 0; - struct s_client *cl; - - local_gbox.checkcode[0] = 0x15; - local_gbox.checkcode[1] = 0x30; - local_gbox.checkcode[2] = 0x02; - local_gbox.checkcode[3] = 0x04; - local_gbox.checkcode[4] = 0x19; - local_gbox.checkcode[5] = 0x19; - local_gbox.checkcode[6] = 0x66; - - LL_ITER it = ll_iter_create(local_gbox.cards); - struct gbox_card *card; - while((card = ll_iter_next(&it))) - { - local_gbox.checkcode[0] ^= (0xFF & (card->provid_1 >> 24)); - local_gbox.checkcode[1] ^= (0xFF & (card->provid_1 >> 16)); - local_gbox.checkcode[2] ^= (0xFF & (card->provid_1 >> 8)); - local_gbox.checkcode[3] ^= (0xFF & (card->provid_1)); - local_gbox.checkcode[4] ^= (0xFF & (card->id.slot)); - local_gbox.checkcode[5] ^= (0xFF & (card->id.peer >> 8)); - local_gbox.checkcode[6] ^= (0xFF & (card->id.peer)); - } - for(i = 0, cl = first_client; cl; cl = cl->next, i++) - { - if (cl->gbox && cl->typ == 'p') - { - struct gbox_peer *peer = cl->gbox; - it = ll_iter_create(peer->gbox.cards); - while((card = ll_iter_next(&it))) - { - local_gbox.checkcode[0] ^= (0xFF & (card->provid_1 >> 24)); - local_gbox.checkcode[1] ^= (0xFF & (card->provid_1 >> 16)); - local_gbox.checkcode[2] ^= (0xFF & (card->provid_1 >> 8)); - local_gbox.checkcode[3] ^= (0xFF & (card->provid_1)); - local_gbox.checkcode[4] ^= (0xFF & (card->id.slot)); - local_gbox.checkcode[5] ^= (0xFF & (card->id.peer >> 8)); - local_gbox.checkcode[6] ^= (0xFF & (card->id.peer)); - } - } - } -} - //returns 1 if checkcode changed / 0 if not static int32_t gbox_checkcode_recv(struct s_client *cli, uchar *checkcode) { @@ -1222,27 +819,6 @@ return 0; } -uint32_t gbox_get_ecmchecksum(uchar *ecm, uint16_t ecmlen) -{ - uint8_t checksum[4]; - int32_t counter; - - checksum[3] = ecm[0]; - checksum[2] = ecm[1]; - checksum[1] = ecm[2]; - checksum[0] = ecm[3]; - - for(counter = 1; counter < (ecmlen / 4) - 4; counter++) - { - checksum[3] ^= ecm[counter * 4]; - checksum[2] ^= ecm[counter * 4 + 1]; - checksum[1] ^= ecm[counter * 4 + 2]; - checksum[0] ^= ecm[counter * 4 + 3]; - } - - return checksum[3] << 24 | checksum[2] << 16 | checksum[1] << 8 | checksum[0]; -} - void gbox_send(struct s_client *cli, uchar *buf, int32_t l) { struct gbox_peer *peer = cli->gbox; @@ -1258,7 +834,7 @@ cs_log_dump_dbg(D_READER, buf, l, "<- encrypted data (%d bytes):", l); } -static void gbox_send_hello_packet(struct s_client *cli, int8_t number, uchar *outbuf, uchar *ptr, int32_t nbcards) +void gbox_send_hello_packet(struct s_client *cli, int8_t number, uchar *outbuf, uchar *ptr, int32_t nbcards) { struct gbox_peer *peer = cli->gbox; int32_t hostname_len = strlen(cfg.gbox_hostname); @@ -1273,7 +849,7 @@ if((number & 0x0F) == 0) { - gbox_calc_checkcode(); + gbox_calc_checkcode(&local_gbox.checkcode[0]); if(peer->hello_stat != GBOX_STAT_HELLOL) { memcpy(++ptr, local_gbox.checkcode, 7); } else @@ -1314,66 +890,12 @@ gbox_send(cli, outbuf, len); } -static void gbox_send_hello(struct s_client *cli) -{ - struct gbox_peer *peer = cli->gbox; - - int32_t nbcards = 0; - int32_t packet; - uchar buf[2048]; - /* - int32_t ok = 0; - #ifdef WEBIF - ok = check_ip(cfg.http_allowed, cli->ip) ? 1 : 0; - #endif - */ - packet = 0; - uchar *ptr = buf + 11; - if(ll_count(local_gbox.cards) != 0 && peer->hello_stat > GBOX_STAT_HELLOL) - { - memset(buf, 0, sizeof(buf)); - - LL_ITER it = ll_iter_create(local_gbox.cards); - struct gbox_card *card; - while((card = ll_iter_next(&it))) - { - //send to user only cards which matching CAID from account and lvl > 0 - if(chk_ctab(card->caid, &peer->my_user->account->ctab) && card->lvl > 0) - { - *(++ptr) = card->provid_1 >> 24; - *(++ptr) = card->provid_1 >> 16; - *(++ptr) = card->provid_1 >> 8; - *(++ptr) = card->provid_1 & 0xff; - *(++ptr) = 1; //note: original gbx is more efficient and sends all cards of one caid as package - *(++ptr) = card->id.slot; - //If you modify the next line you are going to destroy the community - //It will be recognized by original gbx and you will get banned - *(++ptr) = ((card->lvl - 1) << 4) + card->dist + 1; - *(++ptr) = card->id.peer >> 8; - *(++ptr) = card->id.peer & 0xff; - nbcards++; - if(nbcards == 100) //check if 100 is good or we need more sophisticated algorithm - { - gbox_send_hello_packet(cli, packet, buf, ptr, nbcards); - packet++; - nbcards = 0; - ptr = buf + 11; - memset(buf, 0, sizeof(buf)); - } - } - } - } // end if local card exists - - //last packet has bit 0x80 set - gbox_send_hello_packet(cli, 0x80 | packet, buf, ptr, nbcards); -} - static void gbox_send_checkcode(struct s_client *cli) { struct gbox_peer *peer = cli->gbox; uchar outbuf[20]; - gbox_calc_checkcode(); + gbox_calc_checkcode(&local_gbox.checkcode[0]); gbox_message_header(outbuf, MSG_CHECKCODE, peer->gbox.password, local_gbox.password); memcpy(outbuf + 10, local_gbox.checkcode, 7); @@ -1457,27 +979,17 @@ struct gbox_ecm_request_ext *ere = er->src_data; gbox_message_header(buf, MSG_CW , peer->gbox.password, 0); - buf[6] = er->pid >> 8; //PID - buf[7] = er->pid & 0xff; //PID - buf[8] = er->srvid >> 8; //SrvID - buf[9] = er->srvid & 0xff; //SrvID - buf[10] = ere->gbox_mypeer >> 8; //From peer - buf[11] = ere->gbox_mypeer & 0xff; //From peer + i2b_buf(2, er->pid, buf + 6); //PID + i2b_buf(2, er->srvid, buf + 8); //SrvID + i2b_buf(2, ere->gbox_mypeer, buf + 10); //From peer buf[12] = (ere->gbox_slot << 4) | (er->ecm[0] & 0x0f); //slot << 4 | even/odd buf[13] = ere->gbox_caid >> 8; //CAID first byte memcpy(buf + 14, er->cw, 16); //CW - buf[30] = er->gbox_crc >> 24; //CRC - buf[31] = er->gbox_crc >> 16; //CRC - buf[32] = er->gbox_crc >> 8; //CRC - buf[33] = er->gbox_crc & 0xff; //CRC - buf[34] = ere->gbox_caid >> 8; //CAID - buf[35] = ere->gbox_caid & 0xff; //CAID + i2b_buf(4, er->gbox_crc, buf + 30); //CRC + i2b_buf(2, ere->gbox_caid, buf + 34); //CAID buf[36] = ere->gbox_slot; //Slot if (buf[34] == 0x06) //if irdeto - { - buf[37] = er->chid >> 8; //CHID - buf[38] = er->chid & 0xff; //CHID - } + { i2b_buf(2, er->chid, buf + 37); } //CHID else { if (local_gbox.minor_version == 0x2A) @@ -1491,8 +1003,7 @@ buf[38] = 0; //gbox sends 0 } } - buf[39] = ere->gbox_peer >> 8; //Target peer - buf[40] = ere->gbox_peer & 0xff; //Target peer + i2b_buf(2, ere->gbox_peer, buf + 39); //Target peer if (er->rc == E_CACHE1 || er->rc == E_CACHE2 || er->rc == E_CACHEEX) { buf[41] = 0x03; } //cache else @@ -1510,65 +1021,7 @@ */ gbox_send(cli, buf, ere->gbox_hops + 44); - cs_log_dbg(D_READER, "<- CW (distance: %d) from %s/%d (%04X) ", ere->gbox_hops, cli->reader->label, cli->port, ere->gbox_peer); -} - -static uint8_t gbox_next_free_slot(uint16_t id) -{ - LL_ITER it = ll_iter_create(local_gbox.cards); - struct gbox_card *c; - uint8_t lastslot = 0; - - while((c = ll_iter_next(&it))) - { - if(id == c->id.peer && c->id.slot > lastslot) - { lastslot = c->id.slot; } - } - return ++lastslot; -} - -static void gbox_add_local_card(uint16_t id, uint16_t caid, uint32_t prid, uint8_t slot, uint8_t card_reshare, uint8_t dist, uint8_t type) -{ - struct gbox_card *c; - - //don't insert 0100:000000 - if((caid >> 8 == 0x01) && (!prid)) - { - return; - } - //skip CAID 18XX providers - if((caid >> 8 == 0x18) && (prid)) - { - return; - } - if(!cs_malloc(&c, sizeof(struct gbox_card))) - { - return; - } - c->caid = caid; - switch(caid >> 8) - { - // Viaccess - case 0x05: - c->provid_1 = (caid >> 8) << 24 | (prid & 0xFFFFFF); - break; - // Cryptoworks - case 0x0D: - c->provid_1 = (caid >> 8) << 24 | (caid & 0xFF) << 16 | - ((prid << 8) & 0xFF00); - break; - default: - c->provid_1 = (caid >> 8) << 24 | (caid & 0xFF) << 16 | - (prid & 0xFFFF); - break; - } - c->provid = prid; - c->id.peer = id; - c->id.slot = slot; - c->lvl = card_reshare; - c->dist = dist; - c->type = type; - ll_append(local_gbox.cards, c); + cs_log_dbg(D_READER, "<- CW (distance: %d) to %04X via %s/%d", ere->gbox_hops, ere->gbox_peer, cli->reader->label, cli->port); } static void gbox_local_cards(struct s_client *cli) @@ -1587,10 +1040,6 @@ uint8_t min_reshare = 0; #endif - if(!local_gbox.cards) - { gbox_free_cardlist(local_gbox.cards); } - local_gbox.cards = ll_create("local_cards"); - struct s_client *cl; for(cl = first_client; cl; cl = cl->next) { @@ -1605,50 +1054,54 @@ { prid = cl->reader->prid[i][1] << 16 | cl->reader->prid[i][2] << 8 | cl->reader->prid[i][3]; - gbox_add_local_card(local_gbox.id, cl->reader->caid, prid, slot, cli->reader->gbox_reshare, 0, 1); + gbox_add_card(local_gbox.id, gbox_get_caprovid(cl->reader->caid, prid), slot, cli->reader->gbox_reshare, 0, GBOX_CARD_TYPE_LOCAL, NULL); } } else { - gbox_add_local_card(local_gbox.id, cl->reader->caid, 0, slot, cli->reader->gbox_reshare, 0, 1); + gbox_add_card(local_gbox.id, gbox_get_caprovid(cl->reader->caid, 0), slot, cli->reader->gbox_reshare, 0, GBOX_CARD_TYPE_LOCAL, NULL); //Check for Betatunnel on gbox account in oscam.user - if (chk_is_betatunnel_caid(cl->reader->caid) == 1 && cli->ttab.n && cl->reader->caid == cli->ttab.bt_caidto[0]) - { - //For now only first entry in tunnel tab. No sense in iteration? - //Add betatunnel card to transmitted list - gbox_add_local_card(local_gbox.id, cli->ttab.bt_caidfrom[0], 0, slot, cli->reader->gbox_reshare, 0, 2); - cs_log_dbg(D_READER, "gbox created betatunnel card for caid: %04X->%04X",cli->ttab.bt_caidfrom[0],cl->reader->caid); - } + if (chk_is_betatunnel_caid(cl->reader->caid) == 1 && cli->ttab.ttdata && cl->reader->caid == cli->ttab.ttdata[0].bt_caidto) + { + //For now only first entry in tunnel tab. No sense in iteration? + //Add betatunnel card to transmitted list + gbox_add_card(local_gbox.id, gbox_get_caprovid(cli->ttab.ttdata[0].bt_caidfrom, 0), slot, cli->reader->gbox_reshare, 0, GBOX_CARD_TYPE_BETUN, NULL); + cs_log_dbg(D_READER, "gbox created betatunnel card for caid: %04X->%04X",cli->ttab.ttdata[0].bt_caidfrom,cl->reader->caid); + } } } //end local readers #ifdef MODULE_CCCAM - if((cfg.cc_reshare > -1) && cl->typ == 'p' && cl->reader && cl->reader->typ == R_CCCAM && cl->cc) + if((cfg.cc_reshare > -1) && (cli->reader->gbox_cccam_reshare) && cl->typ == 'p' && cl->reader && cl->reader->typ == R_CCCAM && cl->cc) { cc = cl->cc; it = ll_iter_create(cc->cards); while((card = ll_iter_next(&it))) { //calculate gbox id from cc node - //1st node is orgin, shorten to 32Bit by CRC, the GBX-ID like from PW node1 = ll_has_elements(card->remote_nodes); - checksum = (uint32_t)crc32(0L, node1, 8); + checksum = ((node1[0] ^ node1[7]) << 8) | + ((node1[1] ^ node1[6]) << 24) | + (node1[2] ^ node1[5]) | + ((node1[3] ^ node1[4]) << 16); cc_peer_id = ((((checksum >> 24) & 0xFF) ^((checksum >> 8) & 0xFF)) << 8 | (((checksum >> 16) & 0xFF) ^(checksum & 0xFF))); slot = gbox_next_free_slot(cc_peer_id); min_reshare = cfg.cc_reshare; if (card->reshare < min_reshare) - { min_reshare = card->reshare; } + { min_reshare = card->reshare; } min_reshare++; //strange CCCam logic. 0 means direct peers + if (cli->reader->gbox_cccam_reshare < min_reshare) + { min_reshare = cli->reader->gbox_cccam_reshare; } if((card->caid >> 8 == 0x01) || (card->caid >> 8 == 0x05) || (card->caid >> 8 == 0x0D)) { it2 = ll_iter_create(card->providers); while((provider = ll_iter_next(&it2))) - { gbox_add_local_card(cc_peer_id, card->caid, provider->prov, slot, min_reshare, card->hop, 3); } + { gbox_add_card(cc_peer_id, gbox_get_caprovid(card->caid, provider->prov), slot, min_reshare, card->hop, GBOX_CARD_TYPE_CCCAM, NULL); } } else - { gbox_add_local_card(cc_peer_id, card->caid, 0, slot, min_reshare, card->hop, 3); } + { gbox_add_card(cc_peer_id, gbox_get_caprovid(card->caid, 0), slot, min_reshare, card->hop, GBOX_CARD_TYPE_CCCAM, NULL); } } } //end cccam #endif @@ -1658,120 +1111,19 @@ { for (i = 0; i < cfg.gbox_proxy_cards_num; i++) { + slot = gbox_next_free_slot(local_gbox.id); + gbox_add_card(local_gbox.id, cfg.gbox_proxy_card[i], slot, cli->reader->gbox_reshare, 0, GBOX_CARD_TYPE_PROXY, NULL); if ((cfg.gbox_proxy_card[i] >> 24) == 0x05) - { - slot = gbox_next_free_slot(local_gbox.id); - gbox_add_local_card(local_gbox.id, (cfg.gbox_proxy_card[i] >> 16) & 0xFFF0, cfg.gbox_proxy_card[i] & 0xFFFFF, slot, cli->reader->gbox_reshare, 0, 4); + { cs_log_dbg(D_READER,"add proxy card: slot %d %04lX:%06lX",slot, (cfg.gbox_proxy_card[i] >> 16) & 0xFFF0, cfg.gbox_proxy_card[i] & 0xFFFFF); - } - else - { - slot = gbox_next_free_slot(local_gbox.id); - gbox_add_local_card(local_gbox.id, cfg.gbox_proxy_card[i] >> 16, cfg.gbox_proxy_card[i] & 0xFFFF, slot, cli->reader->gbox_reshare, 0, 4); + } else + { cs_log_dbg(D_READER,"add proxy card: slot %d %04lX:%06lX",slot, cfg.gbox_proxy_card[i] >> 16, cfg.gbox_proxy_card[i] & 0xFFFF); - } + } } } // end add proxy reader cards } //end add local gbox cards -static int32_t gbox_client_init(struct s_client *cli) -{ - if(!cfg.gbx_port[0] || cfg.gbx_port[0] > 65535) - { - cs_log("error, no/invalid port=%d configured in oscam.conf!", - cfg.gbx_port[0] ? cfg.gbx_port[0] : 0); - return -1; - } - - if(!cfg.gbox_hostname || strlen(cfg.gbox_hostname) > 128) - { - cs_log("error, no/invalid hostname '%s' configured in oscam.conf!", - cfg.gbox_hostname ? cfg.gbox_hostname : ""); - return -1; - } - - if(!local_gbox.id) - { - cs_log("error, no/invalid password '%s' configured in oscam.conf!", - cfg.gbox_my_password ? cfg.gbox_my_password : ""); - return -1; - } - - if(!cs_malloc(&cli->gbox, sizeof(struct gbox_peer))) - { return -1; } - - struct gbox_peer *peer = cli->gbox; - struct s_reader *rdr = cli->reader; - - rdr->card_status = CARD_NEED_INIT; - rdr->tcp_connected = 0; - - memset(peer, 0, sizeof(struct gbox_peer)); - - peer->gbox.password = a2i(rdr->r_pwd, 4); - cs_log_dbg(D_READER, "gbox peer password: %s:", rdr->r_pwd); - - peer->gbox.id = gbox_convert_password_to_id(peer->gbox.password); - if (get_gbox_proxy(peer->gbox.id) || peer->gbox.id == NO_GBOX_ID || peer->gbox.id == local_gbox.id) - { - cs_log("error, double/invalid gbox id: %04X", peer->gbox.id); - return -1; - } - cli->gbox_peer_id = peer->gbox.id; - - cli->pfd = 0; - cli->crypted = 1; - - set_null_ip(&cli->ip); - - if((cli->udp_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) - { - cs_log("socket creation failed (errno=%d %s)", errno, strerror(errno)); - cs_disconnect_client(cli); - } - - int32_t opt = 1; - setsockopt(cli->udp_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); - - set_so_reuseport(cli->udp_fd); - - set_socket_priority(cli->udp_fd, cfg.netprio); - - memset((char *)&cli->udp_sa, 0, sizeof(cli->udp_sa)); - - if(!hostResolve(rdr)) - { return 0; } - - cli->port = rdr->r_port; - SIN_GET_FAMILY(cli->udp_sa) = AF_INET; - SIN_GET_PORT(cli->udp_sa) = htons((uint16_t)rdr->r_port); - hostname2ip(cli->reader->device, &SIN_GET_ADDR(cli->udp_sa)); - - cs_log("proxy %s (fd=%d, peer id=%04X, my id=%04X, my hostname=%s, peer's listen port=%d)", - rdr->device, cli->udp_fd, peer->gbox.id, local_gbox.id, cfg.gbox_hostname, rdr->r_port); - - cli->pfd = cli->udp_fd; - - cs_lock_create(&peer->lock, "gbox_lock", 5000); - - gbox_reinit_peer(peer); - - cli->reader->card_status = CARD_NEED_INIT; - gbox_send_hello(cli); - - if(!cli->reader->gbox_maxecmsend) - { cli->reader->gbox_maxecmsend = DEFAULT_GBOX_MAX_ECM_SEND; } - - if(!cli->reader->gbox_maxdist) - { cli->reader->gbox_maxdist = DEFAULT_GBOX_MAX_DIST; } - - //value > 5 not allowed in gbox network - if(!cli->reader->gbox_reshare || cli->reader->gbox_reshare > 5) - { cli->reader->gbox_reshare = 5; } - - return 0; -} - static uint32_t gbox_get_pending_time(ECM_REQUEST *er, uint16_t peer_id, uint8_t slot) { if (!er) { return 0; } @@ -1789,47 +1141,50 @@ static int32_t gbox_recv_chk(struct s_client *cli, uchar *dcw, int32_t *rc, uchar *data, int32_t n) { - if(gbox_decode_cmd(data) == MSG_CW && n > 43) - { - int i; - uint16_t id_card = 0; - struct s_client *proxy; - if(cli->typ != 'p') - { proxy = switch_client_proxy(cli, cli->gbox_peer_id); } - else - { proxy = cli; } - proxy->last = time((time_t *)0); - *rc = 1; - memcpy(dcw, data + 14, 16); - uint32_t crc = data[30] << 24 | data[31] << 16 | data[32] << 8 | data[33]; - char tmp[32]; - cs_log_dbg(D_READER, "-> cws=%s, peer=%04X, ecm_pid=%04X, sid=%04X, crc=%08X, type=%02X, dist=%01X, unkn1=%01X, unkn2=%02X, chid/0x0000/0xffff=%04X", - cs_hexdump(0, dcw, 32, tmp, sizeof(tmp)), - data[10] << 8 | data[11], data[6] << 8 | data[7], data[8] << 8 | data[9], crc, data[41], data[42] & 0x0f, data[42] >> 4, data[43], data[37] << 8 | data[38]); - struct timeb t_now; - cs_ftime(&t_now); - int64_t cw_time = GBOX_DEFAULT_CW_TIME; - for(i = 0; i < cfg.max_pending; i++) - { - if(proxy->ecmtask[i].gbox_crc == crc) - { - id_card = data[10] << 8 | data[11]; - cw_time = comp_timeb(&t_now, &proxy->ecmtask[i].tps) - gbox_get_pending_time(&proxy->ecmtask[i], id_card, data[36]); - gbox_add_good_card(proxy, id_card, proxy->ecmtask[i].caid, data[36], proxy->ecmtask[i].srvid, cw_time); - gbox_remove_all_bad_sids(proxy->gbox, &proxy->ecmtask[i], proxy->ecmtask[i].srvid); - if(proxy->ecmtask[i].gbox_ecm_status == GBOX_ECM_NOT_ASKED || proxy->ecmtask[i].gbox_ecm_status == GBOX_ECM_ANSWERED) - { return -1; } + if(!cli || gbox_decode_cmd(data) != MSG_CW || n < 44) + { return -1; } + + int i; + uint16_t id_card = 0; + struct s_client *proxy; + if(cli->typ != 'p') + { proxy = switch_client_proxy(cli, cli->gbox_peer_id); } + else + { proxy = cli; } + if (!proxy || !proxy->reader) + { return -1; } + proxy->last = time((time_t *)0); + *rc = 1; + memcpy(dcw, data + 14, 16); + uint32_t crc = data[30] << 24 | data[31] << 16 | data[32] << 8 | data[33]; + char tmp[32]; + cs_log_dbg(D_READER, "-> cws=%s, peer=%04X, ecm_pid=%04X, sid=%04X, crc=%08X, type=%02X, dist=%01X, unkn1=%01X, unkn2=%02X, chid/0x0000/0xffff=%04X", + cs_hexdump(0, dcw, 32, tmp, sizeof(tmp)), + data[10] << 8 | data[11], data[6] << 8 | data[7], data[8] << 8 | data[9], crc, data[41], data[42] & 0x0f, data[42] >> 4, data[43], data[37] << 8 | data[38]); + struct timeb t_now; + cs_ftime(&t_now); + int64_t cw_time = GBOX_DEFAULT_CW_TIME; + for(i = 0; i < cfg.max_pending; i++) + { + if(proxy->ecmtask[i].gbox_crc == crc) + { + id_card = data[10] << 8 | data[11]; + cw_time = comp_timeb(&t_now, &proxy->ecmtask[i].tps) - gbox_get_pending_time(&proxy->ecmtask[i], id_card, data[36]); + gbox_add_good_sid(id_card, proxy->ecmtask[i].caid, data[36], proxy->ecmtask[i].srvid, cw_time); + proxy->reader->currenthops = data[42] & 0x0f; + gbox_remove_all_bad_sids(&proxy->ecmtask[i], proxy->ecmtask[i].srvid); + if(proxy->ecmtask[i].gbox_ecm_status == GBOX_ECM_NOT_ASKED || proxy->ecmtask[i].gbox_ecm_status == GBOX_ECM_ANSWERED) + { return -1; } proxy->ecmtask[i].gbox_ecm_status = GBOX_ECM_ANSWERED; proxy->ecmtask[i].gbox_ecm_id = id_card; *rc = 1; return proxy->ecmtask[i].idx; } } - //late answers from other peers,timing not possible - gbox_add_good_card(proxy, id_card, data[34] << 8 | data[35], data[36], data[8] << 8 | data[9], GBOX_DEFAULT_CW_TIME); - cs_log_dbg(D_READER, "no task found for crc=%08x", crc); - } - return -1; + //late answers from other peers,timing not possible + gbox_add_good_sid(id_card, data[34] << 8 | data[35], data[36], data[8] << 8 | data[9], GBOX_DEFAULT_CW_TIME); + cs_log_dbg(D_READER, "no task found for crc=%08x", crc); + return -1; } static int8_t gbox_cw_received(struct s_client *cli, uchar *data, int32_t n) @@ -1845,9 +1200,9 @@ { if(cli->ecmtask[i].idx == idx) { - cli->pending--; - casc_check_dcw(cli->reader, i, rc, dcw); - return 0; + cli->pending--; + casc_check_dcw(cli->reader, i, rc, dcw); + return 0; } } return -1; @@ -1870,8 +1225,15 @@ struct gbox_peer *peer = cli->gbox; - //ecm is not answered yet - if (er->rc >= E_NOTFOUND) + struct timeb t_now, tbc; + cs_ftime(&t_now); + + tbc = er->tps; + add_ms_to_timeb_diff(&tbc, cfg.ctimeout); + int32_t time_to_timeout = (int32_t) comp_timeb(&tbc, &t_now); + + //ecm is not answered yet and still chance to get CW + if (er->rc >= E_NOTFOUND && time_to_timeout > GBOX_DEFAULT_CW_TIME) { cs_writelock(&peer->lock); gbox_send_ecm(cli, er, NULL); @@ -1881,23 +1243,6 @@ return NULL; } -static int8_t is_already_pending(ECM_REQUEST *er, struct gbox_card_id *searched_id) -{ - if (!er || !searched_id) - { return -1; } - - LL_ITER it = ll_iter_create(er->gbox_cards_pending); - struct gbox_card_id *current_id; - while ((current_id = ll_iter_next(&it))) - { - if (current_id->peer == searched_id->peer && - current_id->slot == searched_id->slot) - { return 1; } - } - - return 0; -} - static int32_t gbox_send_ecm(struct s_client *cli, ECM_REQUEST *er, uchar *UNUSED(buf)) { if(!cli || !er || !cli->reader) @@ -1912,9 +1257,8 @@ struct gbox_peer *peer = cli->gbox; int32_t cont_1; - uint32_t sid_verified = 0; - if(!ll_count(peer->gbox.cards)) + if(!peer->filtered_cards) { cs_log_dbg(D_READER, "%s NO CARDS!", cli->reader->label); write_ecm_answer(cli->reader, er, E_NOTFOUND, E2_CCCAM_NOCARD, NULL, NULL); @@ -1942,26 +1286,6 @@ return 0; } - uint16_t ercaid = er->caid; - uint32_t erprid = er->prid; - - switch(ercaid >> 8) - { - //Viaccess - case 0x05: - ercaid = (ercaid & 0xFF00) | ((erprid >> 16) & 0xFF); - erprid = erprid & 0xFFFF; - break; - //Cryptoworks - case 0x0D: - erprid = erprid << 8; - break; - //Nagra - case 0x18: - erprid = 0; - break; - } - uchar send_buf_1[1024]; int32_t len2; @@ -1972,21 +1296,14 @@ memset(send_buf_1, 0, sizeof(send_buf_1)); - LL_ITER it = ll_iter_create(peer->gbox.cards); - LL_ITER it2; - struct gbox_card *card; - - int32_t cont_send = 0; - uint32_t cont_card_1 = 0; - uint8_t max_ecm_reached = 0; - + uint8_t cont_card_1 = 0; + uint8_t max_ecm_reached = 0; + uint32_t current_avg_card_time = 0; + gbox_message_header(send_buf_1, MSG_ECM , peer->gbox.password, local_gbox.password); - send_buf_1[10] = (er->pid >> 8) & 0xFF; - send_buf_1[11] = er->pid & 0xFF; - - send_buf_1[12] = (er->srvid >> 8) & 0xFF; - send_buf_1[13] = er->srvid & 0xFF; + i2b_buf(2, er->pid, send_buf_1 + 10); + i2b_buf(2, er->srvid, send_buf_1 + 12); send_buf_1[14] = 0x00; send_buf_1[15] = 0x00; @@ -1995,145 +1312,23 @@ memcpy(send_buf_1 + 18, er->ecm, er->ecmlen); - send_buf_1[len2] = (local_gbox.id >> 8) & 0xff; - send_buf_1[len2 + 1] = local_gbox.id & 0xff; + i2b_buf(2, local_gbox.id, send_buf_1 + len2); + send_buf_1[len2 + 2] = gbox_get_my_vers(); send_buf_1[len2 + 3] = 0x00; send_buf_1[len2 + 4] = gbox_get_my_cpu_api(); - send_buf_1[len2 + 5] = ercaid >> 8; - send_buf_1[len2 + 6] = ercaid & 0xFF; + uint32_t caprovid = gbox_get_caprovid(er->caid, er->prid); + i2b_buf(4, caprovid, send_buf_1 + len2 + 5); - send_buf_1[len2 + 7] = (erprid >> 8) & 0xFF; - send_buf_1[len2 + 8] = erprid & 0xFF; send_buf_1[len2 + 9] = 0x00; cont_1 = len2 + 10; - struct gbox_good_srvid *srvid_good = NULL; - struct gbox_bad_srvid *srvid_bad = NULL; - struct gbox_card_id current_id; - uint8_t enough = 0; - time_t time_since_lastcw; - uint32_t current_avg_card_time = 0; - //loop over good only - while((card = ll_iter_next(&it))) - { - current_id.peer = card->id.peer; - current_id.slot = card->id.slot; - if(card->caid == er->caid && card->provid == er->prid && !is_already_pending(er, ¤t_id)) - { - sid_verified = 0; - - //check if sid is good - it2 = ll_iter_create(card->goodsids); - while((srvid_good = ll_iter_next(&it2))) - { - if(srvid_good->srvid.provid_id == er->prid && srvid_good->srvid.sid == er->srvid) - { - if (!enough || current_avg_card_time > card->average_cw_time) - { - time_since_lastcw = abs(srvid_good->last_cw_received - time(NULL)); - current_avg_card_time = card->average_cw_time; - - if (enough) - { cont_1 = cont_1 - 3; } - else - { - cont_card_1++; - cont_send++; - if (time_since_lastcw < GBOX_SID_CONFIRM_TIME && er->gbox_ecm_status == GBOX_ECM_NOT_ASKED) - { enough = 1; } - } - send_buf_1[cont_1] = card->id.peer >> 8; - send_buf_1[cont_1 + 1] = card->id.peer; - send_buf_1[cont_1 + 2] = card->id.slot; - cont_1 = cont_1 + 3; - sid_verified = 1; - break; - } - } - } - - if(cont_send == cli->reader->gbox_maxecmsend) - { - max_ecm_reached = 1; - break; - } - } - } + cont_card_1 = gbox_get_cards_for_ecm(&send_buf_1[0], len2 + 10, cli->reader->gbox_maxecmsend, er, ¤t_avg_card_time, peer->gbox.id); + if (cont_card_1 == cli->reader->gbox_maxecmsend) + { max_ecm_reached = 1; } + cont_1 += cont_card_1 * 3; - //loop over bad and unknown cards - it = ll_iter_create(peer->gbox.cards); - while((card = ll_iter_next(&it))) - { - current_id.peer = card->id.peer; - current_id.slot = card->id.slot; - if(card->caid == er->caid && card->provid == er->prid && !is_already_pending(er, ¤t_id) && !enough) - { - sid_verified = 0; - - //check if sid is good - it2 = ll_iter_create(card->goodsids); - while((srvid_good = ll_iter_next(&it2))) - { - if(srvid_good->srvid.provid_id == er->prid && srvid_good->srvid.sid == er->srvid) - { - sid_verified = 1; - cs_log_dbg(D_READER, "ID: %04X SL: %02X SID: %04X is good", card->id.peer, card->id.slot, srvid_good->srvid.sid); - } - } - if(!sid_verified) - { - //check if sid is bad - LL_ITER itt = ll_iter_create(card->badsids); - while((srvid_bad = ll_iter_next(&itt))) - { - if(srvid_bad->srvid.provid_id == er->prid && srvid_bad->srvid.sid == er->srvid) - { - if (srvid_bad->bad_strikes < 3) - { - sid_verified = 2; - srvid_bad->bad_strikes++; - } - else - { sid_verified = 1; } - cs_log_dbg(D_READER, "ID: %04X SL: %02X SID: %04X is bad %d", card->id.peer, card->id.slot, srvid_bad->srvid.sid, srvid_bad->bad_strikes); - break; - } - } - - //sid is neither good nor bad - if(sid_verified != 1) - { - send_buf_1[cont_1] = card->id.peer >> 8; - send_buf_1[cont_1 + 1] = card->id.peer; - send_buf_1[cont_1 + 2] = card->id.slot; - cont_1 = cont_1 + 3; - cont_card_1++; - cont_send++; - - if (!sid_verified) - { - if(!cs_malloc(&srvid_bad, sizeof(struct gbox_bad_srvid))) - { return 0; } - - srvid_bad->srvid.sid = er->srvid; - srvid_bad->srvid.provid_id = card->provid; - srvid_bad->bad_strikes = 1; - ll_append(card->badsids, srvid_bad); - cs_log_dbg(D_READER, "ID: %04X SL: %02X SID: %04X is not checked", card->id.peer, card->id.slot, srvid_bad->srvid.sid); - } - } - } - - if(cont_send == cli->reader->gbox_maxecmsend) - { - max_ecm_reached = 1; - break; - } - } - } - if(!cont_card_1 && er->gbox_ecm_status == GBOX_ECM_NOT_ASKED) { cs_log_dbg(D_READER, "no valid card found for CAID: %04X PROVID: %04X", er->caid, er->prid); @@ -2172,7 +1367,7 @@ cs_log_dbg(D_READER, "gbox card %d: ID: %04X, Slot: %02X", i+1, (send_buf_1[len2+10+i*3] << 8) | send_buf_1[len2+11+i*3], send_buf_1[len2+12+i*3]); } - it = ll_iter_create(er->gbox_cards_pending); + LL_ITER it = ll_iter_create(er->gbox_cards_pending); while ((pending = ll_iter_next(&it))) { cs_log_dbg(D_READER, "Pending Card ID: %04X Slot: %02X Time: %d", pending->id.peer, pending->id.slot, pending->pending_time); } @@ -2231,6 +1426,7 @@ memset(&local_gbox.checkcode[0], 0, 7); local_gbox.minor_version = gbox_get_my_vers(); local_gbox.cpu_api = gbox_get_my_cpu_api(); + init_gbox_cards(); if(!cfg.gbox_my_password || strlen(cfg.gbox_my_password) != 8) { return; } @@ -2244,6 +1440,111 @@ } last_stats_written = time(NULL); gbox_write_version(); + local_gbox_initialized = 1; +} + +static int32_t gbox_client_init(struct s_client *cli) +{ + if (!local_gbox_initialized) + { init_local_gbox(); } + + if(!cfg.gbx_port[0] || cfg.gbx_port[0] > 65535) + { + cs_log("error, no/invalid port=%d configured in oscam.conf!", + cfg.gbx_port[0] ? cfg.gbx_port[0] : 0); + return -1; + } + + if(!cfg.gbox_hostname || strlen(cfg.gbox_hostname) > 128) + { + cs_log("error, no/invalid hostname '%s' configured in oscam.conf!", + cfg.gbox_hostname ? cfg.gbox_hostname : ""); + return -1; + } + + if(!local_gbox.id) + { + cs_log("error, no/invalid password '%s' configured in oscam.conf!", + cfg.gbox_my_password ? cfg.gbox_my_password : ""); + return -1; + } + + if(!cs_malloc(&cli->gbox, sizeof(struct gbox_peer))) + { return -1; } + + struct gbox_peer *peer = cli->gbox; + struct s_reader *rdr = cli->reader; + + rdr->card_status = CARD_NEED_INIT; + rdr->tcp_connected = 0; + + memset(peer, 0, sizeof(struct gbox_peer)); + + peer->gbox.password = a2i(rdr->r_pwd, 4); + cs_log_dbg(D_READER, "gbox peer password: %s:", rdr->r_pwd); + + peer->gbox.id = gbox_convert_password_to_id(peer->gbox.password); + if (get_gbox_proxy(peer->gbox.id) || peer->gbox.id == NO_GBOX_ID || peer->gbox.id == local_gbox.id) + { + cs_log("error, double/invalid gbox id: %04X", peer->gbox.id); + return -1; + } + cli->gbox_peer_id = peer->gbox.id; + + cli->pfd = 0; + cli->crypted = 1; + + set_null_ip(&cli->ip); + + if((cli->udp_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) + { + cs_log("socket creation failed (errno=%d %s)", errno, strerror(errno)); + cs_disconnect_client(cli); + } + + int32_t opt = 1; + setsockopt(cli->udp_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + + set_so_reuseport(cli->udp_fd); + + set_socket_priority(cli->udp_fd, cfg.netprio); + + memset((char *)&cli->udp_sa, 0, sizeof(cli->udp_sa)); + + if(!hostResolve(rdr)) + { return 0; } + + cli->port = rdr->r_port; + SIN_GET_FAMILY(cli->udp_sa) = AF_INET; + SIN_GET_PORT(cli->udp_sa) = htons((uint16_t)rdr->r_port); + hostname2ip(cli->reader->device, &SIN_GET_ADDR(cli->udp_sa)); + + cs_log("proxy %s (fd=%d, peer id=%04X, my id=%04X, my hostname=%s, peer's listen port=%d)", + rdr->device, cli->udp_fd, peer->gbox.id, local_gbox.id, cfg.gbox_hostname, rdr->r_port); + + cli->pfd = cli->udp_fd; + + cs_lock_create(&peer->lock, "gbox_lock", 5000); + + gbox_reinit_peer(peer); + + cli->reader->card_status = CARD_NEED_INIT; + gbox_send_hello(cli); + + if(!cli->reader->gbox_maxecmsend) + { cli->reader->gbox_maxecmsend = DEFAULT_GBOX_MAX_ECM_SEND; } + + if(!cli->reader->gbox_maxdist) + { cli->reader->gbox_maxdist = DEFAULT_GBOX_MAX_DIST; } + + //value > DEFAULT_GBOX_RESHARE not allowed in gbox network + if(!cli->reader->gbox_reshare || cli->reader->gbox_reshare > DEFAULT_GBOX_RESHARE) + { cli->reader->gbox_reshare = DEFAULT_GBOX_RESHARE; } + + if(!cli->reader->gbox_cccam_reshare || cli->reader->gbox_cccam_reshare > DEFAULT_GBOX_RESHARE) + { cli->reader->gbox_cccam_reshare = DEFAULT_GBOX_RESHARE; } + + return 0; } static void gbox_s_idle(struct s_client *cl) @@ -2315,8 +1616,9 @@ void gbox_cleanup(struct s_client *cl) { - if(cl && cl->gbox && cl->typ == 'p') - { gbox_send_peer_good_night(cl); } + gbox_free_cardlist(); + if(cl && cl->gbox && cl->typ == 'p') + { gbox_send_peer_good_night(cl); } } /* @@ -2365,7 +1667,6 @@ */ void module_gbox(struct s_module *ph) { - init_local_gbox(); int32_t i; for(i = 0; i < CS_MAXPORTS; i++) { diff -Nru oscam-1.20-10584~r10356/module-gbox-cards.c oscam-1.20-10797~r10569/module-gbox-cards.c --- oscam-1.20-10584~r10356/module-gbox-cards.c 1970-01-01 00:00:00.000000000 +0000 +++ oscam-1.20-10797~r10569/module-gbox-cards.c 2015-02-20 11:57:49.000000000 +0000 @@ -0,0 +1,596 @@ +#define MODULE_LOG_PREFIX "gbox" + +#include "globals.h" + +#ifdef MODULE_GBOX +#include "module-gbox.h" +#include "module-gbox-helper.h" +#include "oscam-lock.h" +#include "oscam-garbage.h" +#include "oscam-files.h" +#include "oscam-chk.h" +#include "oscam-string.h" +#include "oscam-time.h" + +LLIST *gbox_cards; +LLIST *gbox_backup_cards; //NEEDFIX: this list has to be cleaned from time to time +CS_MUTEX_LOCK gbox_cards_lock; + +void gbox_write_cards_info(void) +{ + uint16_t card_count_local = 0; + uint16_t card_count_shared = 0; + FILE *fhandle_local; + fhandle_local = fopen(get_gbox_tmp_fname(FILE_LOCAL_CARDS_INFO), "w"); + if(!fhandle_local) + { + cs_log("Couldn't open %s: %s", get_gbox_tmp_fname(FILE_LOCAL_CARDS_INFO), strerror(errno)); + return; + } + FILE *fhandle_shared; + fhandle_shared = fopen(get_gbox_tmp_fname(FILE_SHARED_CARDS_INFO), "w"); + if(!fhandle_shared) + { + cs_log("Couldn't open %s: %s", get_gbox_tmp_fname(FILE_SHARED_CARDS_INFO), strerror(errno)); + return; + } + + struct gbox_card *card; + + cs_readlock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(gbox_cards); + while((card = ll_iter_next(&it))) + { + switch (card->type) + { + case GBOX_CARD_TYPE_GBOX: + fprintf(fhandle_shared, "CardID %2d at %s Card %08X Sl:%2d Lev:%1d dist:%1d id:%04X\n", + card_count_shared, card->origin_peer->hostname, card->caprovid, + card->id.slot, card->lvl, card->dist, card->id.peer); + card_count_shared++; + break; + case GBOX_CARD_TYPE_LOCAL: + fprintf(fhandle_local, "CardID:%2d %s %08X Sl:%2d id:%04X\n", + card_count_local, "Local_Card", card->caprovid, card->id.slot, card->id.peer); + card_count_local++; + break; + case GBOX_CARD_TYPE_BETUN: + fprintf(fhandle_local, "CardID:%2d %s %08X Sl:%2d id:%04X\n", + card_count_local, "Betun_Card", card->caprovid, card->id.slot, card->id.peer); + card_count_local++; + break; + case GBOX_CARD_TYPE_CCCAM: + fprintf(fhandle_local, "CardID:%2d %s %08X Sl:%2d id:%04X\n", + card_count_local, "CCcam_Card", card->caprovid, card->id.slot, card->id.peer); + card_count_local++; + break; + case GBOX_CARD_TYPE_PROXY: + fprintf(fhandle_local, "CardID:%2d %s %08X Sl:%2d id:%04X\n", + card_count_local, "Proxy_Card", card->caprovid, card->id.slot, card->id.peer); + card_count_local++; + break; + default: + break; + } + } + cs_readunlock(&gbox_cards_lock); + + fclose(fhandle_local); + fclose(fhandle_shared); + return; +} + +void gbox_write_stats(void) +{ + int32_t card_count = 0; + struct gbox_good_srvid *srvid_good = NULL; + struct gbox_bad_srvid *srvid_bad = NULL; + FILE *fhandle; + fhandle = fopen(get_gbox_tmp_fname(FILE_STATS), "w"); + if(!fhandle) + { + cs_log("Couldn't open %s: %s", get_gbox_tmp_fname(FILE_STATS), strerror(errno)); + return; + } + + struct gbox_card *card; + + cs_readlock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(gbox_cards); + while((card = ll_iter_next(&it))) + { + if (card->type == GBOX_CARD_TYPE_GBOX) + { + fprintf(fhandle, "CardID %4d Card %08X id:%04X #CWs:%d AVGtime:%d ms\n", + card_count, card->caprovid, card->id.peer, card->no_cws_returned, card->average_cw_time); + fprintf(fhandle, "Good SIDs:\n"); + LL_ITER it2 = ll_iter_create(card->goodsids); + while((srvid_good = ll_iter_next(&it2))) + { fprintf(fhandle, "%04X\n", srvid_good->srvid.sid); } + fprintf(fhandle, "Bad SIDs:\n"); + it2 = ll_iter_create(card->badsids); + while((srvid_bad = ll_iter_next(&it2))) + { fprintf(fhandle, "%04X #%d\n", srvid_bad->srvid.sid, srvid_bad->bad_strikes); } + card_count++; + } + } // end of while ll_iter_next + cs_readunlock(&gbox_cards_lock); + + fclose(fhandle); + return; +} + +void init_gbox_cards(void) +{ + gbox_cards = ll_create("gbox.cards"); + gbox_backup_cards = ll_create("gbox_backup_cards"); + cs_lock_create(&gbox_cards_lock, "gbox_cards_lock", 5000); +} + +static void gbox_free_card(struct gbox_card *card) +{ + ll_destroy_data(&card->badsids); + ll_destroy_data(&card->goodsids); + add_garbage(card); + return; +} + +static int8_t closer_path_known(uint32_t caprovid, uint16_t id_peer, uint8_t slot, uint8_t distance) +{ + cs_readlock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(gbox_cards); + struct gbox_card *card; + while((card = ll_iter_next(&it))) + { + if (card->caprovid == caprovid && card->id.peer == id_peer && card->id.slot == slot && card->dist <= distance) + { + cs_readunlock(&gbox_cards_lock); + return 1; + } + } + cs_readunlock(&gbox_cards_lock); + return 0; +} + +static int8_t got_from_backup(uint32_t caprovid, uint16_t id_peer, uint8_t slot, struct gbox_peer *origin_peer) +{ + cs_writelock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(gbox_backup_cards); + struct gbox_card *card; + while((card = ll_iter_next(&it))) + { + if (card->caprovid == caprovid && card->id.peer == id_peer && card->id.slot == slot) + { + ll_iter_remove(&it); + card->origin_peer = origin_peer; + ll_append(gbox_cards, card); + cs_writeunlock(&gbox_cards_lock); + return 1; + } + } + cs_writeunlock(&gbox_cards_lock); + + return 0; +} + +void gbox_add_card(uint16_t id_peer, uint32_t caprovid, uint8_t slot, uint8_t level, uint8_t distance, uint8_t type, struct gbox_peer *origin_peer) +{ + uint16_t caid = gbox_get_caid(caprovid); + uint32_t provid = gbox_get_provid(caprovid); + + //don't insert 0100:000000 + if((caid >> 8 == 0x01) && (!provid)) + { return; } + //skip CAID 18XX providers + if((caid >> 8 == 0x18) && (provid)) + { return; } + + if (!closer_path_known(caprovid, id_peer, slot, distance) && !got_from_backup(caprovid, id_peer, slot, origin_peer)) + { + struct gbox_card *card; + if(!cs_malloc(&card, sizeof(struct gbox_card))) + { + cs_log("Card allocation failed"); + return; + } + card->caprovid = caprovid; + card->id.peer = id_peer; + card->id.slot = slot; + card->dist = distance; + card->lvl = level; + card->badsids = ll_create("badsids"); + card->goodsids = ll_create("goodsids"); + card->no_cws_returned = 0; + card->average_cw_time = 0; + card->type = type; + card->origin_peer = origin_peer; + cs_writelock(&gbox_cards_lock); + ll_append(gbox_cards, card); + cs_writeunlock(&gbox_cards_lock); + } + + return; +} + +void gbox_calc_checkcode(uint8_t *checkcode) +{ + checkcode[0] = 0x15; + checkcode[1] = 0x30; + checkcode[2] = 0x02; + checkcode[3] = 0x04; + checkcode[4] = 0x19; + checkcode[5] = 0x19; + checkcode[6] = 0x66; + + cs_readlock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(gbox_cards); + struct gbox_card *card; + while((card = ll_iter_next(&it))) + { + checkcode[0] ^= (0xFF & (card->caprovid >> 24)); + checkcode[1] ^= (0xFF & (card->caprovid >> 16)); + checkcode[2] ^= (0xFF & (card->caprovid >> 8)); + checkcode[3] ^= (0xFF & (card->caprovid)); + checkcode[4] ^= (0xFF & (card->id.slot)); + checkcode[5] ^= (0xFF & (card->id.peer >> 8)); + checkcode[6] ^= (0xFF & (card->id.peer)); + } + cs_readunlock(&gbox_cards_lock); + + return; +} + +uint16_t gbox_count_peer_cards(uint16_t peer_id) +{ + uint16_t counter = 0; + struct gbox_card *card; + + cs_readlock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(gbox_cards); + while((card = ll_iter_next(&it))) + { + if (card->origin_peer && card->origin_peer->gbox.id == peer_id) + { counter++; } + } + cs_readunlock(&gbox_cards_lock); + + return counter; +} + +void gbox_delete_cards_from_peer(uint16_t peer_id) +{ + struct gbox_card *card; + + cs_writelock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(gbox_cards); + while((card = ll_iter_next(&it))) + { + if (card->origin_peer && card->origin_peer->gbox.id == peer_id) + { + ll_iter_remove(&it); + ll_append(gbox_backup_cards, card); + } + } + cs_writeunlock(&gbox_cards_lock); + + return; +} + +static void gbox_free_list(LLIST *card_list) +{ + if(card_list) + { + cs_writelock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(card_list); + struct gbox_card *card; + while((card = ll_iter_next_remove(&it))) + { gbox_free_card(card); } + ll_destroy(&gbox_cards); + cs_writeunlock(&gbox_cards_lock); + } + return; +} + +void gbox_free_cardlist(void) +{ + gbox_free_list(gbox_cards); + gbox_free_list(gbox_backup_cards); + return; +} + +void gbox_send_hello(struct s_client *cli) +{ + struct gbox_peer *peer = cli->gbox; + + uint16_t nbcards = 0; + uint8_t packet; + uchar buf[2048]; + + packet = 0; + uchar *ptr = buf + 11; + if(ll_count(gbox_cards) != 0 && peer->hello_stat > GBOX_STAT_HELLOL) + { + memset(buf, 0, sizeof(buf)); + + cs_readlock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(gbox_cards); + struct gbox_card *card; + while((card = ll_iter_next(&it))) + { + //send to user only cards which matching CAID from account and lvl > 0 + //do not send peer cards back + if(chk_ctab(gbox_get_caid(card->caprovid), &peer->my_user->account->ctab) && (card->lvl > 0) && (!card->origin_peer || card->origin_peer->gbox.id != peer->gbox.id)) + { + *(++ptr) = card->caprovid >> 24; + *(++ptr) = card->caprovid >> 16; + *(++ptr) = card->caprovid >> 8; + *(++ptr) = card->caprovid & 0xff; + *(++ptr) = 1; //note: original gbx is more efficient and sends all cards of one caid as package + *(++ptr) = card->id.slot; + //If you modify the next line you are going to destroy the community + //It will be recognized by original gbx and you will get banned + *(++ptr) = ((card->lvl - 1) << 4) + card->dist + 1; + *(++ptr) = card->id.peer >> 8; + *(++ptr) = card->id.peer & 0xff; + nbcards++; + if(nbcards == 100) //check if 100 is good or we need more sophisticated algorithm + { + //NEEDFIX: Try toget rid of send hello in cards function + gbox_send_hello_packet(cli, packet, buf, ptr, nbcards); + packet++; + nbcards = 0; + ptr = buf + 11; + memset(buf, 0, sizeof(buf)); + } + } + } + cs_readunlock(&gbox_cards_lock); + } // end if local card exists + + //last packet has bit 0x80 set + gbox_send_hello_packet(cli, 0x80 | packet, buf, ptr, nbcards); + + return; +} + +void gbox_add_good_sid(uint16_t id_card, uint16_t caid, uint8_t slot, uint16_t sid_ok, uint32_t cw_time) +{ + struct gbox_card *card = NULL; + struct gbox_good_srvid *srvid = NULL; + uint8_t factor = 0; + + cs_writelock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(gbox_cards); + while((card = ll_iter_next(&it))) + { + if(card->id.peer == id_card && gbox_get_caid(card->caprovid) == caid && card->id.slot == slot) + { + card->no_cws_returned++; + if (!card->no_cws_returned) + { card->no_cws_returned = 10; } //wrap around + if (card->no_cws_returned < 10) + { factor = card->no_cws_returned; } + else + { factor = 10; } + card->average_cw_time = ((card->average_cw_time * (factor-1)) + cw_time) / factor; + LL_ITER it2 = ll_iter_create(card->goodsids); + while((srvid = ll_iter_next(&it2))) + { + if(srvid->srvid.sid == sid_ok) + { + srvid->last_cw_received = time(NULL); + cs_writeunlock(&gbox_cards_lock); + return; // sid_ok is already in the list of goodsids + } + } + + if(!cs_malloc(&srvid, sizeof(struct gbox_good_srvid))) + { + cs_writeunlock(&gbox_cards_lock); + cs_log("Good SID allocation failed"); + return; + } + srvid->srvid.sid = sid_ok; + srvid->srvid.provid_id = gbox_get_provid(card->caprovid); + srvid->last_cw_received = time(NULL); + cs_log_dbg(D_READER, "Adding good SID: %04X for CAID: %04X Provider: %04X on CardID: %04X\n", sid_ok, caid, gbox_get_provid(card->caprovid), id_card); + ll_append(card->goodsids, srvid); + break; + } + }//end of ll_iter_next + //return dist_c; + cs_writeunlock(&gbox_cards_lock); + return; +} + +void gbox_remove_bad_sid(uint16_t id_peer, uint8_t id_slot, uint16_t sid) +{ + struct gbox_card *card = NULL; + struct gbox_bad_srvid *srvid = NULL; + + cs_writelock(&gbox_cards_lock); + LL_ITER it2 = ll_iter_create(gbox_cards); + while((card = ll_iter_next(&it2))) + { + if(card->id.peer == id_peer && card->id.slot == id_slot) + { + LL_ITER it3 = ll_iter_create(card->badsids); + while((srvid = ll_iter_next(&it3))) + { + if(srvid->srvid.sid == sid) + { + ll_iter_remove_data(&it3); // remove sid_ok from badsids + break; + } + } + } + } + cs_writeunlock(&gbox_cards_lock); +} + +uint8_t gbox_next_free_slot(uint16_t id) +{ + struct gbox_card *c; + uint8_t lastslot = 0; + + cs_readlock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(gbox_cards); + while((c = ll_iter_next(&it))) + { + if(id == c->id.peer && c->id.slot > lastslot) + { lastslot = c->id.slot; } + } + cs_readunlock(&gbox_cards_lock); + return ++lastslot; +} + +static int8_t is_already_pending(LLIST *pending_cards, uint16_t peer_id, uint8_t slot) +{ + if (!pending_cards) + { return -1; } + + LL_ITER it = ll_iter_create(pending_cards); + struct gbox_card_id *current_id; + while ((current_id = ll_iter_next(&it))) + { + if (current_id->peer == peer_id && current_id->slot == slot) + { return 1; } + } + + return 0; +} + +uint8_t gbox_get_cards_for_ecm(uchar *send_buf_1, int32_t cont_1, uint8_t max_cards, ECM_REQUEST *er, uint32_t *current_avg_card_time, uint16_t peer_id) +{ + if (!send_buf_1 || !er) + { return 0; } + + uint8_t cont_card_1 = 0; + struct gbox_good_srvid *srvid_good = NULL; + struct gbox_bad_srvid *srvid_bad = NULL; + uint8_t enough = 0; + uint8_t sid_verified = 0; + time_t time_since_lastcw; + + //loop over good only + cs_readlock(&gbox_cards_lock); + LL_ITER it = ll_iter_create(gbox_cards); + LL_ITER it2; + struct gbox_card *card; + + while((card = ll_iter_next(&it))) + { + if(card->origin_peer && card->origin_peer->gbox.id == peer_id && card->type == GBOX_CARD_TYPE_GBOX && + gbox_get_caid(card->caprovid) == er->caid && gbox_get_provid(card->caprovid) == er->prid && !is_already_pending(er->gbox_cards_pending, card->id.peer, card->id.slot)) + { + sid_verified = 0; + + //check if sid is good + it2 = ll_iter_create(card->goodsids); + while((srvid_good = ll_iter_next(&it2))) + { + if(srvid_good->srvid.provid_id == er->prid && srvid_good->srvid.sid == er->srvid) + { + if (!enough || *current_avg_card_time > card->average_cw_time) + { + time_since_lastcw = abs(srvid_good->last_cw_received - time(NULL)); + *current_avg_card_time = card->average_cw_time; + if (enough) + { cont_1 = cont_1 - 3; } + else + { + cont_card_1++; + if (time_since_lastcw < GBOX_SID_CONFIRM_TIME && er->gbox_ecm_status == GBOX_ECM_NOT_ASKED) + { enough = 1; } + } + i2b_buf(2, card->id.peer, send_buf_1 + cont_1); + send_buf_1[cont_1 + 2] = card->id.slot; + cont_1 = cont_1 + 3; + sid_verified = 1; + break; + } + } + } + + if(cont_card_1 == max_cards) + { break; } + } + } + cs_readunlock(&gbox_cards_lock); + + //loop over bad and unknown cards + cs_writelock(&gbox_cards_lock); + it = ll_iter_create(gbox_cards); + while((card = ll_iter_next(&it))) + { + if(card->origin_peer && card->origin_peer->gbox.id == peer_id && card->type == GBOX_CARD_TYPE_GBOX && + gbox_get_caid(card->caprovid) == er->caid && gbox_get_provid(card->caprovid) == er->prid && !is_already_pending(er->gbox_cards_pending, card->id.peer, card->id.slot) && !enough) + { + sid_verified = 0; + + //check if sid is good + it2 = ll_iter_create(card->goodsids); + while((srvid_good = ll_iter_next(&it2))) + { + if(srvid_good->srvid.provid_id == er->prid && srvid_good->srvid.sid == er->srvid) + { + sid_verified = 1; + cs_log_dbg(D_READER, "ID: %04X SL: %02X SID: %04X is good", card->id.peer, card->id.slot, srvid_good->srvid.sid); + } + } + if(!sid_verified) + { + //check if sid is bad + LL_ITER itt = ll_iter_create(card->badsids); + while((srvid_bad = ll_iter_next(&itt))) + { + if(srvid_bad->srvid.provid_id == er->prid && srvid_bad->srvid.sid == er->srvid) + { + if (srvid_bad->bad_strikes < 3) + { + sid_verified = 2; + srvid_bad->bad_strikes++; + } + else + { sid_verified = 1; } + cs_log_dbg(D_READER, "ID: %04X SL: %02X SID: %04X is bad %d", card->id.peer, card->id.slot, srvid_bad->srvid.sid, srvid_bad->bad_strikes); + break; + } + } + + //sid is neither good nor bad + if(sid_verified != 1) + { + i2b_buf(2, card->id.peer, send_buf_1 + cont_1); + send_buf_1[cont_1 + 2] = card->id.slot; + cont_1 = cont_1 + 3; + cont_card_1++; + + if (!sid_verified) + { + if(!cs_malloc(&srvid_bad, sizeof(struct gbox_bad_srvid))) + { + cs_log("ServID allocation failed"); + cs_writeunlock(&gbox_cards_lock); + return 0; + } + + srvid_bad->srvid.sid = er->srvid; + srvid_bad->srvid.provid_id = gbox_get_provid(card->caprovid); + srvid_bad->bad_strikes = 1; + ll_append(card->badsids, srvid_bad); + cs_log_dbg(D_READER, "ID: %04X SL: %02X SID: %04X is not checked", card->id.peer, card->id.slot, srvid_bad->srvid.sid); + } + } + } + + if(cont_card_1 == max_cards) + { break; } + } + } + cs_writeunlock(&gbox_cards_lock); + return cont_card_1; +} + +#endif + diff -Nru oscam-1.20-10584~r10356/module-gbox-cards.h oscam-1.20-10797~r10569/module-gbox-cards.h --- oscam-1.20-10584~r10356/module-gbox-cards.h 1970-01-01 00:00:00.000000000 +0000 +++ oscam-1.20-10797~r10569/module-gbox-cards.h 2015-02-20 11:57:49.000000000 +0000 @@ -0,0 +1,20 @@ +#ifndef MODULE_GBOX_CARDS_H_ +#define MODULE_GBOX_CARDS_H_ + +#ifdef MODULE_GBOX +void gbox_write_cards_info(void); +void gbox_write_stats(void); +void init_gbox_cards(void); +void gbox_add_card(uint16_t id_peer, uint32_t caprovid, uint8_t slot, uint8_t level, uint8_t distance, uint8_t type, struct gbox_peer *origin_peer); +void gbox_calc_checkcode(uint8_t *checkcode); +uint16_t gbox_count_peer_cards(uint16_t peer_id); +void gbox_delete_cards_from_peer(uint16_t peer_id); +void gbox_free_cardlist(void); +void gbox_send_hello(struct s_client *cli); +void gbox_add_good_sid(uint16_t id_card, uint16_t caid, uint8_t slot, uint16_t sid_ok, uint32_t cw_time); +void gbox_remove_bad_sid(uint16_t id_peer, uint8_t id_slot, uint16_t sid); +uint8_t gbox_next_free_slot(uint16_t id); +uint8_t gbox_get_cards_for_ecm(uchar *send_buf_1, int32_t cont_1, uint8_t max_cards, ECM_REQUEST *er, uint32_t *current_avg_card_time, uint16_t peer_id); +#endif + +#endif diff -Nru oscam-1.20-10584~r10356/module-gbox.h oscam-1.20-10797~r10569/module-gbox.h --- oscam-1.20-10584~r10356/module-gbox.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-gbox.h 2015-02-20 11:57:49.000000000 +0000 @@ -1,15 +1,24 @@ #ifndef MODULE_GBOX_H_ #define MODULE_GBOX_H_ +/* + * WARNING! Enabling this will make gbox call external programs for OSD with parameters + * received from the network. this means that a rogue server that sends you SMS messages + * may execute code on your machine. do not enable this unless you know what you are + * doing and accept the posssible *BAD* consequences +*/ +//#define GBOX_ENABLE_UNSAFE_OSD 1 + #ifdef MODULE_GBOX #define NO_GBOX_ID 0 #define GBOX_MAXHOPS 10 #define DEFAULT_GBOX_MAX_DIST 2 #define DEFAULT_GBOX_MAX_ECM_SEND 3 +#define DEFAULT_GBOX_RESHARE 5 #define DEFAULT_GBOX_RECONNECT 300 #define CS_GBOX_MAX_LOCAL_CARDS 16 -#define GBOX_REBROADCAST_TIMEOUT 1250 +#define GBOX_REBROADCAST_TIMEOUT 1250 #define GBOX_SID_CONFIRM_TIME 3600 #define GBOX_DEFAULT_CW_TIME 500 @@ -32,6 +41,26 @@ #define GBOX_ECM_SENT_ALL_TWICE 3 #define GBOX_ECM_ANSWERED 4 +#define GBOX_CARD_TYPE_GBOX 0 +#define GBOX_CARD_TYPE_LOCAL 1 +#define GBOX_CARD_TYPE_BETUN 2 +#define GBOX_CARD_TYPE_CCCAM 3 +#define GBOX_CARD_TYPE_PROXY 4 + +#define FILE_GBOX_VERSION "gbox.ver" +#define FILE_SHARED_CARDS_INFO "share.info" +#define FILE_ATTACK_INFO "attack.txt" +#define FILE_GBOX_PEER_ONL "share.onl" +#define FILE_STATS "stats.info" +#define FILE_GOODNIGHT_OSD "goodnight.osd" +#define FILE_LOCAL_CARDS_INFO "sc.info" + +#define GBOX_STAT_HELLOL 0 +#define GBOX_STAT_HELLOS 1 +#define GBOX_STAT_HELLOR 2 +#define GBOX_STAT_HELLO3 3 +#define GBOX_STAT_HELLO4 4 + struct gbox_rbc_thread_args { struct s_client *cli; @@ -72,9 +101,7 @@ struct gbox_card { struct gbox_card_id id; - uint16_t caid; - uint32_t provid; - uint32_t provid_1; + uint32_t caprovid; uint8_t slot; uint8_t dist; uint8_t lvl; @@ -83,16 +110,16 @@ LLIST *goodsids; //sids that could be decoded (struct gbox_srvid) uint32_t no_cws_returned; uint32_t average_cw_time; + struct gbox_peer *origin_peer; }; struct gbox_data { uint16_t id; - uint32_t password; + uint32_t password; uchar checkcode[7]; uint8_t minor_version; uint8_t cpu_api; - LLIST *cards; }; struct gbox_peer @@ -105,8 +132,8 @@ uchar ecm_idx; CS_MUTEX_LOCK lock; struct s_client *my_user; + uint16_t filtered_cards; uint16_t total_cards; - LL_ITER last_it; }; struct gbox_ecm_request_ext @@ -131,12 +158,8 @@ uint32_t gbox_get_local_gbox_password(void); void gbox_send(struct s_client *cli, uchar *buf, int32_t l); int8_t gbox_message_header(uchar *buf, uint16_t cmd, uint32_t peer_password, uint32_t local_password); -static inline void gbox_free_cards_pending(ECM_REQUEST *er) -{ - LLIST *l = er->gbox_cards_pending; - er->gbox_cards_pending = NULL; - ll_destroy_free_data(l); -} +void gbox_free_cards_pending(ECM_REQUEST *er); +void gbox_send_hello_packet(struct s_client *cli, int8_t number, uchar *outbuf, uchar *ptr, int32_t nbcards); #else static inline void gbox_free_cards_pending(ECM_REQUEST *UNUSED(er)) { } #endif diff -Nru oscam-1.20-10584~r10356/module-gbox-helper.c oscam-1.20-10797~r10569/module-gbox-helper.c --- oscam-1.20-10584~r10356/module-gbox-helper.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-gbox-helper.c 2015-02-20 11:57:49.000000000 +0000 @@ -6,6 +6,62 @@ #include "minilzo/minilzo.h" #include "oscam-string.h" + +uint16_t gbox_get_caid(uint32_t caprovid) +{ + if ((caprovid >> 24) == 0x05) + { return 0x0500; } + else + { return caprovid >> 16; } +} + +uint32_t gbox_get_provid(uint32_t caprovid) +{ + uint32_t provid = 0; + + switch(caprovid >> 24) + { + //ViXS + case 0x05: + provid = caprovid & 0xFFFFFF; + break; + //Cryptoworx + case 0x0D: + provid = (caprovid >> 8) & 0xFF; + break; + default: + provid = caprovid & 0xFFFF; + break; + } + return provid; +} + +uint32_t gbox_get_caprovid(uint16_t caid, uint32_t prid) +{ + uint32_t caprovid = 0; + + switch(caid >> 8) + { + // ViXS + case 0x05: + caprovid = (caid >> 8) << 24 | (prid & 0xFFFFFF); + break; + // Cryptoworx + case 0x0D: + caprovid = (caid >> 8) << 24 | (caid & 0xFF) << 16 | + ((prid << 8) & 0xFF00); + break; + // N@gr@ + case 0x18: + caprovid = (caid >> 8) << 24 | (caid & 0xFF) << 16; + default: + caprovid = (caid >> 8) << 24 | (caid & 0xFF) << 16 | + (prid & 0xFFFF); + break; + } + return caprovid; +} + static void gbox_convert_pw(uchar *password, uint32_t pw) { int32_t i; @@ -15,6 +71,27 @@ } } +uint32_t gbox_get_ecmchecksum(uchar *ecm, uint16_t ecmlen) +{ + uint8_t checksum[4]; + int32_t counter; + + checksum[3] = ecm[0]; + checksum[2] = ecm[1]; + checksum[1] = ecm[2]; + checksum[0] = ecm[3]; + + for(counter = 1; counter < (ecmlen / 4) - 4; counter++) + { + checksum[3] ^= ecm[counter * 4]; + checksum[2] ^= ecm[counter * 4 + 1]; + checksum[1] ^= ecm[counter * 4 + 2]; + checksum[0] ^= ecm[counter * 4 + 3]; + } + + return checksum[3] << 24 | checksum[2] << 16 | checksum[1] << 8 | checksum[0]; +} + //////////////////////////////////////////////////////////////////////////////// // GBOX BUFFER ENCRYPTION/DECRYPTION (thanks to dvbcrypt@gmail.com) //////////////////////////////////////////////////////////////////////////////// diff -Nru oscam-1.20-10584~r10356/module-gbox-helper.h oscam-1.20-10797~r10569/module-gbox-helper.h --- oscam-1.20-10584~r10356/module-gbox-helper.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-gbox-helper.h 2015-02-20 11:57:49.000000000 +0000 @@ -2,6 +2,10 @@ #define MODULE_GBOX_HELPER_H_ #ifdef MODULE_GBOX +uint16_t gbox_get_caid(uint32_t caprovid); +uint32_t gbox_get_provid(uint32_t caprovid); +uint32_t gbox_get_caprovid(uint16_t caid, uint32_t prid); +uint32_t gbox_get_ecmchecksum(uchar *ecm, uint16_t ecmlen); void gbox_encrypt(uchar *buffer, int bufsize, uint32_t key); void gbox_decrypt(uchar *buffer, int bufsize, uint32_t localkey); void gbox_compress(uchar *buf, int32_t unpacked_len, int32_t *packed_len); diff -Nru oscam-1.20-10584~r10356/module-gbox-sms.c oscam-1.20-10797~r10569/module-gbox-sms.c --- oscam-1.20-10584~r10356/module-gbox-sms.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-gbox-sms.c 2015-02-20 11:57:49.000000000 +0000 @@ -57,6 +57,7 @@ } static void write_gsms_to_osd_file(struct s_client *cli, unsigned char *gsms) { +#ifdef GBOX_ENABLE_UNSAFE_OSD char *fext= FILE_OSD_MSG; char *fname = get_gbox_tmp_fname(fext); if (file_exists(fname)) @@ -74,6 +75,10 @@ } pclose(p); } +#else + cs_log("OSD: username=%s dev=%s msg=%s", username(cli), cli->reader->device, gsms); + cs_log_dbg(D_READER, "OSD is disabled because it is a security risk, to enable it recompile OSCAM."); +#endif return; } diff -Nru oscam-1.20-10584~r10356/module-ghttp.c oscam-1.20-10797~r10569/module-ghttp.c --- oscam-1.20-10584~r10356/module-ghttp.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-ghttp.c 2015-02-20 11:57:49.000000000 +0000 @@ -59,15 +59,20 @@ if(context->ssl_handle == NULL) { ERR_print_errors_fp(stderr); + ERR_remove_state(0); return false; } if(!SSL_set_fd(context->ssl_handle, fd)) { ERR_print_errors_fp(stderr); + ERR_remove_state(0); return false; } if(SSL_connect(context->ssl_handle) != 1) - { ERR_print_errors_fp(stderr); } + { + ERR_print_errors_fp(stderr); + ERR_remove_state(0); + } if(context->ssl_handle) { @@ -84,6 +89,16 @@ int32_t handle; char *str = NULL; + ghttp_ignored_contexts = ll_create("ignored contexts"); +#ifdef WITH_SSL + ghttp_ssl_context = SSL_CTX_new(SSLv23_client_method()); + if(ghttp_ssl_context == NULL) + { + ERR_print_errors_fp(stderr); + ERR_remove_state(0); + } +#endif + if(cl->reader->r_port == 0) { cl->reader->r_port = cl->reader->ghttp_use_ssl ? 443 : 80; } @@ -651,19 +666,22 @@ { s_ghttp *context = (s_ghttp *)client->ghttp; + ll_destroy_data(&ghttp_ignored_contexts); + if(context) { NULLFREE(context->session_id); NULLFREE(context->host_id); NULLFREE(context->fallback_id); - if(context->ecm_q) { ll_destroy(context->ecm_q); } - if(context->post_contexts) { ll_destroy_data(context->post_contexts); } + ll_destroy(&context->ecm_q); + ll_destroy_data(&context->post_contexts); #ifdef WITH_SSL if(context->ssl_handle) { SSL_shutdown(context->ssl_handle); SSL_free(context->ssl_handle); } + SSL_CTX_free(ghttp_ssl_context); #endif NULLFREE(context); } @@ -755,12 +773,5 @@ ph->c_capmt = ghttp_capmt_notify; #endif ph->num = R_GHTTP; - ghttp_ignored_contexts = ll_create("ignored contexts"); -#ifdef WITH_SSL - SSL_load_error_strings(); - SSL_library_init(); - ghttp_ssl_context = SSL_CTX_new(SSLv23_client_method()); - if(ghttp_ssl_context == NULL) { ERR_print_errors_fp(stderr); } -#endif } #endif diff -Nru oscam-1.20-10584~r10356/module-monitor.c oscam-1.20-10797~r10569/module-monitor.c --- oscam-1.20-10584~r10356/module-monitor.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-monitor.c 2015-02-20 11:57:49.000000000 +0000 @@ -5,6 +5,7 @@ #include "cscrypt/md5.h" #include "module-monitor.h" #include "oscam-aes.h" +#include "oscam-array.h" #include "oscam-client.h" #include "oscam-config.h" #include "oscam-conf-chk.h" @@ -121,11 +122,15 @@ nanosleep(&req_ts, NULL); //avoid lost udp-pakkets if(!cl->crypted) { return sendto(cl->udp_fd, txt, strlen(txt), 0, (struct sockaddr *)&cl->udp_sa, cl->udp_sa_len); } + l = strlen(txt); + if(l > 255) + { l = 255; } buf[0] = '&'; - buf[9] = l = strlen(txt); + buf[9] = l; l = boundary(4, l + 5) + 5; memcpy(buf + 1, module_data->ucrc, 4); cs_strncpy((char *)buf + 10, txt, sizeof(buf) - 10); + memset(buf+10+buf[9], 0, l-10-buf[9]); uchar tmp[10]; memcpy(buf + 5, i2b_buf(4, crc32(0L, buf + 10, l - 10), tmp), 4); aes_encrypt_idx(&module_data->aes_keys, buf + 5, l - 5); @@ -734,11 +739,11 @@ { case 6: - clear_tuntab(&account->ttab); + tuntab_clear(&account->ttab); break; //betatunnel case 8: - clear_caidtab(&account->ctab); + caidtab_clear(&account->ctab); break; //Caid } found = i; diff -Nru oscam-1.20-10584~r10356/module-newcamd.c oscam-1.20-10797~r10569/module-newcamd.c --- oscam-1.20-10584~r10356/module-newcamd.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-newcamd.c 2015-02-20 11:57:49.000000000 +0000 @@ -5,6 +5,8 @@ #include "cscrypt/des.h" #include "cscrypt/md5.h" #include "module-newcamd.h" +#include "oscam-array.h" +#include "oscam-conf-chk.h" #include "oscam-chk.h" #include "oscam-client.h" #include "oscam-ecm.h" @@ -572,74 +574,71 @@ return (rc); } -static FILTER mk_user_au_ftab(struct s_reader *aureader) +static void mk_user_au_ftab(struct s_reader *aureader, FILTER *filt) { int32_t i, j, found; struct s_client *cl = cur_client(); - FILTER filt; - FILTER *pufilt; + FILTER client_filter; + FILTER *pufilt = &client_filter; - filt.caid = aureader->caid; - if(filt.caid == 0) { filt.caid = cl->ftab.filts[0].caid; } - filt.nprids = 0; - memset(&filt.prids, 0, sizeof(filt.prids)); - pufilt = &cl->ftab.filts[0]; + memset(filt, 0, sizeof(*filt)); + memset(&client_filter, 0, sizeof(client_filter)); + + if(cl->ftab.filts) client_filter = cl->ftab.filts[0]; + + filt->caid = aureader->caid; + if(filt->caid == 0) + filt->caid = client_filter.caid; for(i = 0; i < aureader->nprov; i++) - { filt.prids[filt.nprids++] = b2i(3, &aureader->prid[i][1]); } + { filt->prids[filt->nprids++] = b2i(3, &aureader->prid[i][1]); } for(i = 0; i < pufilt->nprids; i++) { - for(j = found = 0; (!found) && (j < filt.nprids); j++) - if(pufilt->prids[i] == filt.prids[j]) { found = 1; } + for(j = found = 0; (!found) && (j < filt->nprids); j++) + if(pufilt->prids[i] == filt->prids[j]) { found = 1; } if(!found) - { filt.prids[filt.nprids++] = pufilt->prids[i]; } + { filt->prids[filt->nprids++] = pufilt->prids[i]; } } - - return filt; } -static FILTER mk_user_ftab(void) +static void mk_user_ftab(FILTER *filt) { - FILTER *psfilt = 0; - FILTER filt; int32_t port_idx, i, j, k, c; struct s_client *cl = cur_client(); - filt.caid = 0; - filt.nprids = 0; - memset(&filt.prids, 0, sizeof(filt.prids)); + memset(filt, 0, sizeof(*filt)); port_idx = cl->port_idx; if(!cfg.ncd_ptab.ports[port_idx].ncd) - { return filt; } - psfilt = &cfg.ncd_ptab.ports[port_idx].ncd->ncd_ftab.filts[0]; + return; + FILTER *psfilt = &cfg.ncd_ptab.ports[port_idx].ncd->ncd_ftab.filts[0]; // 1. CAID // search server CAID in client CAID - for(c = i = 0; i < CS_MAXCAIDTAB; i++) + for(c = i = 0; i < cl->ctab.ctnum; i++) { - int32_t ctab_caid; - ctab_caid = cl->ctab.caid[i] & cl->ctab.mask[i]; + CAIDTAB_DATA *d = &cl->ctab.ctdata[i]; + int32_t ctab_caid = d->caid & d->mask; if(ctab_caid) { c++; } if(psfilt->caid == ctab_caid) { - filt.caid = ctab_caid; + filt->caid = ctab_caid; break; } } - if(c && !filt.caid) + if(c && !filt->caid) { cs_log("no valid CAID found in CAID for user '%s'", cl->account->usr); - return filt; + return; } // search CAID in client IDENT cs_log_dbg(D_CLIENT, "client[%8lX].%s nfilts=%d, filt.caid=%04X", (unsigned long)pthread_self(), - cl->account->usr, cl->ftab.nfilts, filt.caid); + cl->account->usr, cl->ftab.nfilts, filt->caid); - if(!filt.caid && cl->ftab.nfilts) + if(!filt->caid && cl->ftab.filts) { int32_t fcaids; for(i = fcaids = 0; i < cl->ftab.nfilts; i++) @@ -648,19 +647,19 @@ if(ucaid) { fcaids++; } if(ucaid && psfilt->caid == ucaid) { - filt.caid = ucaid; + filt->caid = ucaid; break; } } - if(fcaids == cl->ftab.nfilts && !filt.caid) + if(fcaids == cl->ftab.nfilts && !filt->caid) { cs_log("no valid CAID found in IDENT for user '%s'", cl->account->usr); //cs_disconnect_client(); - return filt; + return; } } // empty client CAID - use server CAID - if(!filt.caid) { filt.caid = psfilt->caid; } + if(!filt->caid) { filt->caid = psfilt->caid; } // 2. PROVID if(!cl->ftab.nfilts) @@ -685,7 +684,7 @@ for(j = 0; !add && j < rdr->ftab.nfilts; j++) { uint32_t rcaid = rdr->ftab.filts[j].caid; - if(!rcaid || rcaid == filt.caid) + if(!rcaid || rcaid == filt->caid) { for(k = 0; !add && k < rdr->ftab.filts[j].nprids; k++) if(rdr->ftab.filts[j].prids[k] == psfilt->prids[i]) { add = 1; } @@ -693,10 +692,10 @@ } } } - if(add) { filt.prids[filt.nprids++] = psfilt->prids[i]; } + if(add) { filt->prids[filt->nprids++] = psfilt->prids[i]; } } - memcpy(&filt, psfilt, sizeof(filt)); - return filt; + memcpy(filt, psfilt, sizeof(*filt)); + return; } // search in client IDENT @@ -704,7 +703,7 @@ { uint32_t ucaid = cl->ftab.filts[j].caid; cs_log_dbg(D_CLIENT, "client caid #%d: %04X", j, ucaid); - if(!ucaid || ucaid == filt.caid) + if(!ucaid || ucaid == filt->caid) { for(i = 0; i < psfilt->nprids; i++) { @@ -713,24 +712,22 @@ { for(k = 0; k < cl->ftab.filts[j].nprids; k++) if(cl->ftab.filts[j].prids[k] == psfilt->prids[i]) - { filt.prids[filt.nprids++] = cl->ftab.filts[j].prids[k]; } + { filt->prids[filt->nprids++] = cl->ftab.filts[j].prids[k]; } } else { - filt.prids[filt.nprids++] = psfilt->prids[i]; + filt->prids[filt->nprids++] = psfilt->prids[i]; // allow server PROVID(s) if no PROVID(s) specified in IDENT } } } } - if(!filt.nprids) + if(!filt->nprids) { cs_log("no valid PROVID(s) found in CAID for user '%s'", cl->account->usr); //cs_disconnect_client(); } - - return filt; } static int8_t newcamd_auth_client(IN_ADDR_T ip, uint8_t *deskey) @@ -894,7 +891,8 @@ if(ok) { - FILTER *pufilt = 0; + FILTER usr_filter; + FILTER *pufilt = &usr_filter; des_login_key_get(deskey, passwdcrypt, strlen((char *)passwdcrypt), key); memcpy(cl->ncd_skey, key, 16); @@ -910,18 +908,14 @@ return -1; } - // set userfilter - cl->ftab.filts[0] = mk_user_ftab(); - // set userfilter for au enabled clients if(aureader) - { cl->ftab.filts[0] = mk_user_au_ftab(aureader); } - - pufilt = &cl->ftab.filts[0]; - if(cfg.ncd_mgclient) - { cl->ftab.nfilts = 0; } //We cannot filter all cards! + mk_user_au_ftab(aureader, &usr_filter); else - { cl->ftab.nfilts = 1; } + mk_user_ftab(&usr_filter); + + if(!cfg.ncd_mgclient) + ftab_add(&cl->ftab, &usr_filter); //We cannot filter all cards! mbuf[0] = MSG_CARD_DATA; mbuf[1] = 0x00; @@ -1067,7 +1061,7 @@ cl_msgid = er->msgid; mbuf[0] = er->ecm[0]; - if(client->ftab.filts[0].nprids == 0 || er->rc >= E_NOTFOUND /*not found*/) + if((client->ftab.filts && client->ftab.filts[0].nprids == 0) || (er->rc >= E_NOTFOUND /*not found*/)) { len = 3; mbuf[1] = mbuf[2] = 0x00; @@ -1114,14 +1108,15 @@ static void newcamd_process_emm(uchar *buf) { int32_t ok = 1; - uint16_t caid; + uint16_t caid = 0; struct s_client *cl = cur_client(); EMM_PACKET epg; memset(&epg, 0, sizeof(epg)); epg.emmlen = buf[2] + 3; - caid = cl->ftab.filts[0].caid; + if (cl->ftab.filts) + caid = cl->ftab.filts[0].caid; epg.caid[0] = (uchar)(caid >> 8); epg.caid[1] = (uchar)(caid); @@ -1183,7 +1178,7 @@ if(!(rdr->grp & client->grp)) { continue; } //test - skip unaccesible readers if(rdr->ftab.filts) { - for(j = 0; j < CS_MAXFILTERS; j++) + for(j = 0; j < rdr->ftab.nfilts; j++) { if(rdr->ftab.filts[j].caid) { diff -Nru oscam-1.20-10584~r10356/module-scam.c oscam-1.20-10797~r10569/module-scam.c --- oscam-1.20-10584~r10356/module-scam.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-scam.c 2015-02-20 11:57:49.000000000 +0000 @@ -824,8 +824,9 @@ static void scam_server_send_caidlist(struct s_client *cl) { uchar mbuf[5]; - uint32_t i = 0, j = 0; - uint16_t caid = 0, caids[55]; + int32_t j; + uint32_t i = 0; + uint16_t caids[55]; uint32_t cardcount = 0; struct s_reader *rdr = NULL; @@ -833,19 +834,19 @@ for(rdr = first_active_reader; rdr; rdr = rdr->next) { if(rdr->caid && chk_ctab(rdr->caid, &cl->ctab)) { - scam_caidlist_add(caids, 55, &cardcount, rdr->caid); + scam_caidlist_add(caids, ARRAY_SIZE(caids), &cardcount, rdr->caid); } - for(j=0; jctab.caid[j]; - if(caid && chk_ctab(caid, &cl->ctab)) { - scam_caidlist_add(caids, 55, &cardcount, caid); - } - } + for(j = 0; j < rdr->ctab.ctnum; j++) { + CAIDTAB_DATA *d = &rdr->ctab.ctdata[j]; + if(d->caid && chk_ctab(d->caid, &cl->ctab)) { + scam_caidlist_add(caids, ARRAY_SIZE(caids), &cardcount, d->caid); + } + } } cs_readunlock(&readerlist_lock); - for(j=0; jcaid; if(!tcaid) { break; } if((tcaid == caid) || (tcaid < 0x0100 && (caid >> 8) == tcaid)) { @@ -99,7 +102,6 @@ { fname = cfg.lb_savepath; } file = fopen(fname, "r"); - if(!file) { cs_log("loadbalancer: can't read from file %s", fname); @@ -224,8 +226,7 @@ if(!rdr->lb_stat) return; cs_lock_destroy(&rdr->lb_stat_lock); - ll_destroy_data(rdr->lb_stat); - rdr->lb_stat = NULL; + ll_destroy_data(&rdr->lb_stat); } /** @@ -739,13 +740,7 @@ static int32_t get_retrylimit(ECM_REQUEST *er) { - int32_t i; - for(i = 0; i < cfg.lb_retrylimittab.n; i++) - { - if(cfg.lb_retrylimittab.caid[i] == er->caid || cfg.lb_retrylimittab.caid[i] == er->caid >> 8) - { return cfg.lb_retrylimittab.value[i]; } - } - return cfg.lb_retrylimit; + return caidvaluetab_get_value(&cfg.lb_retrylimittab, er->caid, cfg.lb_retrylimit); } @@ -762,20 +757,10 @@ static int32_t get_nbest_readers(ECM_REQUEST *er) { - int32_t nbest_readers = er->client->account->lb_nbest_readers == -1 ? cfg.lb_nbest_readers : er->client->account->lb_nbest_readers; - CAIDVALUETAB nbest_readers_tab = er->client->account->lb_nbest_readers_tab.n == 0 ? cfg.lb_nbest_readers_tab : er->client->account->lb_nbest_readers_tab; - + CAIDVALUETAB *nbest_readers_tab = er->client->account->lb_nbest_readers_tab.cvnum == 0 ? &cfg.lb_nbest_readers_tab : &er->client->account->lb_nbest_readers_tab; if(nbest_readers <= 0) { nbest_readers = 1; } - - int32_t i; - for(i = 0; i < nbest_readers_tab.n; i++) - { - if(nbest_readers_tab.caid[i] == er->caid || nbest_readers_tab.caid[i] == er->caid >> 8) - { return nbest_readers_tab.value[i]; } - } - - return nbest_readers; + return caidvaluetab_get_value(nbest_readers_tab, er->caid, nbest_readers); } static void convert_to_beta_int(ECM_REQUEST *er, uint16_t caid_to) @@ -1864,89 +1849,27 @@ static int8_t stat_in_ecmlen(struct s_reader *rdr, READER_STAT *s) { - struct s_ecmWhitelist *tmp; - struct s_ecmWhitelistIdent *tmpIdent; - struct s_ecmWhitelistLen *tmpLen; - for(tmp = rdr->ecmWhitelist; tmp; tmp = tmp->next) + int32_t i; + for (i = 0; i < rdr->ecm_whitelist.ewnum; i++) { - if(tmp->caid == 0 || (tmp->caid == s->caid)) - { - for(tmpIdent = tmp->idents; tmpIdent; tmpIdent = tmpIdent->next) - { - if(tmpIdent->ident == 0 || tmpIdent->ident == s->prid) - { - for(tmpLen = tmpIdent->lengths; tmpLen; tmpLen = tmpLen->next) - { - if(tmpLen->len == s->ecmlen) - { - return 1; - } - } - } - } - } + ECM_WHITELIST_DATA *d = &rdr->ecm_whitelist.ewdata[i]; + if ((d->caid == 0 || d->caid == s->caid) && (d->ident == 0 || d->ident == s->prid) && (d->len == s->ecmlen)) + return 1; } return 0; } static int8_t add_to_ecmlen(struct s_reader *rdr, READER_STAT *s) { - struct s_ecmWhitelist *tmp = NULL; - struct s_ecmWhitelistIdent *tmpIdent = NULL; - struct s_ecmWhitelistLen *tmpLen = NULL; - - for(tmp = rdr->ecmWhitelist; tmp; tmp = tmp->next) - { - if(tmp->caid == s->caid) - { - for(tmpIdent = tmp->idents; tmpIdent; tmpIdent = tmpIdent->next) - { - if(tmpIdent->ident == s->prid) - { - for(tmpLen = tmpIdent->lengths; tmpLen; tmpLen = tmpLen->next) - { - if(tmpLen->len == s->ecmlen) - { - return 1; - } - } - break; - } - } - break; - } - } - - if(!tmp) - { - if(cs_malloc(&tmp, sizeof(struct s_ecmWhitelist))) - { - tmp->caid = s->caid; - tmp->next = rdr->ecmWhitelist; - rdr->ecmWhitelist = tmp; - } - } - - if(!tmpIdent && tmp) - { - if(cs_malloc(&tmpIdent, sizeof(struct s_ecmWhitelistIdent))) - { - tmpIdent->ident = s->prid; - tmpIdent->next = tmp->idents; - tmp->idents = tmpIdent; - } - } - - if(!tmpLen && tmpIdent) + int32_t i; + for (i = 0; i < rdr->ecm_whitelist.ewnum; i++) { - if(cs_malloc(&tmpLen, sizeof(struct s_ecmWhitelistLen))) - { - tmpLen->len = s->ecmlen; - tmpLen->next = tmpIdent->lengths; - tmpIdent->lengths = tmpLen; - } + ECM_WHITELIST_DATA *d = &rdr->ecm_whitelist.ewdata[i]; + if ((d->caid == s->caid) && (d->ident == s->prid) && (d->len == s->ecmlen)) + return 1; } - + ECM_WHITELIST_DATA d = { .caid = s->caid, .ident = s->prid, .len = s->ecmlen }; + ecm_whitelist_add(&rdr->ecm_whitelist, &d); return 0; } diff -Nru oscam-1.20-10584~r10356/module-webif.c oscam-1.20-10797~r10569/module-webif.c --- oscam-1.20-10584~r10356/module-webif.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-webif.c 2015-02-20 11:57:49.000000000 +0000 @@ -37,6 +37,7 @@ extern uint8_t cs_http_use_utf8; extern uint32_t cfg_sidtab_generation; extern int32_t exit_oscam; +extern uint8_t cacheex_peer_id[8]; extern char *entitlement_type[]; extern char *RDR_CD_TXT[]; @@ -1082,6 +1083,9 @@ tpl_addVar(vars, TPLADD, "HTTPHELPLANG", cfg.http_help_lang); tpl_addVar(vars, TPLADD, "HTTPLOCALE", cfg.http_locale); + tpl_printf(vars, TPLADD, "HTTPEMMUCLEAN", "%d", cfg.http_emmu_clean); + tpl_printf(vars, TPLADD, "HTTPEMMSCLEAN", "%d", cfg.http_emms_clean); + tpl_printf(vars, TPLADD, "HTTPEMMGCLEAN", "%d", cfg.http_emmg_clean); tpl_printf(vars, TPLADD, "HTTPREFRESH", "%d", cfg.http_refresh); tpl_printf(vars, TPLADD, "HTTPPOLLREFRESH", "%d", cfg.poll_refresh); tpl_addVar(vars, TPLADD, "HTTPTPL", cfg.http_tpl); @@ -1532,7 +1536,7 @@ tpl_addVar(vars, TPLADD, "READERCLASS", rdr->enable ? "enabledreader" : "disabledreader"); if(rdr->description) - tpl_printf(vars, TPLADD, "DESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, rdr->description)); + tpl_printf(vars, TPLADD, "DESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, rdr->description)); else tpl_addVar(vars, TPLADD, "DESCRIPTION", ""); @@ -1600,14 +1604,14 @@ if(rdr->enable == 0) { tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICENA"); - tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Enable this reader"); + tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Enable"); tpl_addVar(vars, TPLADD, "SWITCH", "enable"); tpl_addVar(vars, TPLADD, "WRITEEMM", ""); } else { tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICDIS"); - tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Disable this reader"); + tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Disable"); tpl_addVar(vars, TPLADD, "SWITCH", "disable"); tpl_addVar(vars, TPLADD, "EMMICO", "image?i=ICEMM"); @@ -2018,12 +2022,12 @@ { tpl_printf(vars, TPLAPPEND, "ATR", "%02X", rdr->atr[i]); } // ECM Whitelist - value = mk_t_ecmwhitelist(rdr->ecmWhitelist); + value = mk_t_ecm_whitelist(&rdr->ecm_whitelist); tpl_addVar(vars, TPLADD, "ECMWHITELIST", value); free_mk_t(value); // ECM Header Whitelist - value = mk_t_ecmheaderwhitelist(rdr->ecmHeaderwhitelist); + value = mk_t_ecm_hdr_whitelist(&rdr->ecm_hdr_whitelist); tpl_addVar(vars, TPLADD, "ECMHEADERWHITELIST", value); free_mk_t(value); @@ -2077,6 +2081,15 @@ tpl_addVar(vars, TPLADD, "SC8IN1DTRRTSPATCHVALUE", (rdr->sc8in1_dtrrts_patch == 1) ? "1" : "0"); } + if(!apicall) + { + tpl_addVar(vars, TPLADD, "READOLDCLASSES", (rdr->read_old_classes == 1) ? "checked" : ""); + } + else + { + tpl_addVar(vars, TPLADD, "READOLDCLASSES", (rdr->read_old_classes == 1) ? "1" : "0"); + } + // Detect if(rdr->detect & 0x80) { tpl_printf(vars, TPLADD, "DETECT", "!%s", RDR_CD_TXT[rdr->detect & 0x7f]); } @@ -2290,6 +2303,9 @@ tpl_printf(vars, TPLADD, "TMP", "NDSVERSION%d", rdr->ndsversion); tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected"); + tpl_printf(vars, TPLADD, "TMP", "NDSREADTIERS%d", rdr->readtiers); + tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected"); + tpl_printf(vars, TPLADD, "TMP", "NAGRAREAD%d", rdr->nagra_read); tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected"); @@ -2364,7 +2380,6 @@ #endif default : tpl_addMsg(vars, "Error: protocol not resolvable"); - tpl_addMsg(vars, tpl_printf(vars, TPLADD, "TMP", "Error: protocol number: %d readername: %s", rdr->typ, xml_encode(vars, rdr->label))); break; } @@ -3402,7 +3417,7 @@ expired = " (disabled)"; classname = "disabled"; tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICENA"); - tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Enable this account"); + tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Enable"); tpl_addVar(vars, TPLADD, "SWITCH", "enable"); disabled_users++; isactive = 0; @@ -3410,7 +3425,7 @@ else { tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICDIS"); - tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Disable this account"); + tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Disable"); tpl_addVar(vars, TPLADD, "SWITCH", "disable"); } if((account->expirationdate && account->expirationdate < now)||account->disabled != 0) @@ -3610,7 +3625,7 @@ } if(account->description) - tpl_printf(vars, TPLADD, "DESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, account->description)); + tpl_printf(vars, TPLADD, "DESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, account->description)); else tpl_addVar(vars, TPLADD, "DESCRIPTION", ""); @@ -3954,7 +3969,7 @@ } unlock_sharelist(); struct cc_card **cardarray = get_sorted_card_copy(sharelist2, 0, &cardsize); - ll_destroy(sharelist2); + ll_destroy(&sharelist2); print_cards(vars, params, cardarray, cardsize, 1, NULL, offset, apicall); NULLFREE(cardarray); } @@ -4233,14 +4248,22 @@ cs_strncpy(str_out, p_txt, pos1); uint64_t id = b2ll(8, (uchar *) (loghistid + ((ptr1-loghist)/3))); + size_t b64_str_in = strlen(xml_encode(vars, str_out)); + size_t b64_str_out = 32 + BASE64_LENGTH(b64_str_in); + char *b64_str_out_buf; + if(!cs_malloc(&b64_str_out_buf, b64_str_out)) + { continue; } + base64_encode(xml_encode(vars, str_out), b64_str_in, b64_str_out_buf, b64_str_out); + if(id > lastid){ tpl_printf(vars, TPLAPPEND, "DATA","%s{\"id\":\"%" PRIu64 "\",\"usr\":\"%s\",\"line\":\"%s\"}", dot, id, - xml_encode(vars, p_usr), - xml_encode(vars, str_out)); + urlencode(vars, xml_encode(vars, p_usr)), + b64_str_out_buf); dot = ","; // next in Array with leading delimiter } + NULLFREE(b64_str_out_buf); } tpl_addVar(vars, TPLAPPEND, "DATA", "]"); return tpl_getTpl(vars, "POLL"); @@ -4377,8 +4400,8 @@ else { tpl_addVar(vars, TPLADD, "HIDEIDLECLIENTSSELECTED0", "selected"); } int32_t user_count_all = 0, user_count_shown = 0, user_count_active = 0; - int32_t reader_count_all = 0, reader_count_conn = 0; - int32_t proxy_count_all = 0, proxy_count_conn = 0; + int32_t reader_count_all = 0, reader_count_conn = 0, reader_count_off = 0; + int32_t proxy_count_all = 0, proxy_count_conn = 0, proxy_count_off = 0; int32_t server_count_all = 0, server_count_shown = 0, server_count_hidden = 0; int32_t monitor_count_all = 0, monitor_count_shown = 0; int32_t shown; @@ -4410,9 +4433,9 @@ if(cl->typ == 'c') { user_count_all++; } else if(cl->typ == 'p') - { proxy_count_all++; } + { proxy_count_all++; if(cl->reader->card_status != CARD_INSERTED) { proxy_count_off++; } } else if(cl->typ == 'r') - { reader_count_all++; } + { reader_count_all++; if(cl->reader->card_status != CARD_INSERTED) { reader_count_off++; } } else if(cl->typ == 's' || cl->typ == 'h') { server_count_all++; if(cl->wihidden) {server_count_hidden++;} } else if(cl->typ == 'm') @@ -4523,6 +4546,20 @@ } localtime_r(&cl->login, <); + if(cl->typ == 'c' || cl->typ == 'm') + { + if(cl->account && cl->account->description) + tpl_printf(vars, TPLADD, "CLIENTDESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, cl->account->description)); + else + tpl_addVar(vars, TPLADD, "CLIENTDESCRIPTION", ""); + } + else if(cl->typ == 'p' || cl->typ == 'r') + { + if(cl->reader && cl->reader->description) + tpl_printf(vars, TPLADD, "CLIENTDESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, cl->reader->description)); + else + tpl_addVar(vars, TPLADD, "CLIENTDESCRIPTION", ""); + } if(!apicall) { tpl_addVar(vars, TPLADD, "LBL", xml_encode(vars, usr)); @@ -4560,31 +4597,14 @@ tpl_printf(vars, TPLADD, "CLIENTTYPE", "%c", cl->typ); tpl_printf(vars, TPLADD, "CLIENTCNR", "%d", get_threadnum(cl)); tpl_addVar(vars, TPLADD, "CLIENTUSER", xml_encode(vars, usr)); - if(cl->typ == 'c' || cl->typ == 'm') - { - if(cl->account && cl->account->description) - tpl_printf(vars, TPLADD, "CLIENTDESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, cl->account->description)); - else - tpl_addVar(vars, TPLADD, "CLIENTDESCRIPTION", ""); - } - else if(cl->typ == 'p' || cl->typ == 'r') - { - if(cl->reader && cl->reader->description) - tpl_printf(vars, TPLADD, "CLIENTDESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, cl->reader->description)); - else - tpl_addVar(vars, TPLADD, "CLIENTDESCRIPTION", ""); - } tpl_addVar(vars, TPLADD, "STATUSUSERICON", xml_encode(vars, usr)); if (cl->typ == 'c' || cl->typ == 'm') { tpl_addVar(vars, TPLADD, "USERNAME", xml_encode(vars, usr)); tpl_addVar(vars, TPLADD, "USERENC", urlencode(vars, usr)); - tpl_addVar(vars, TPLADD, "READERNAMEENC", ""); - tpl_addVar(vars, TPLADD, "READERNAME",""); } else if (cl->typ == 'p' || cl->typ == 'r') { tpl_addVar(vars, TPLADD, "READERNAME", xml_encode(vars, usr)); tpl_addVar(vars, TPLADD, "READERNAMEENC", urlencode(vars, usr)); - tpl_addVar(vars, TPLADD, "USERNAME", ""); } bool picon_shown = false; @@ -4603,7 +4623,7 @@ } } else - tpl_printf(vars, TPLADD, "UPICMISSING", "%smissing icon: IC_%s.tpl",!apicall?" ":"",xml_encode(vars, usr)); + tpl_printf(vars, TPLADD, "UPICMISSING", "%smissing icon: IC_%s.tpl",!apicall?" ":"",xml_encode(vars, usr)); } if (!picon_shown) { @@ -4939,7 +4959,7 @@ { tpl_printf(vars, TPLADD, "UCAC", "%d", user_count_active); tpl_printf(vars, TPLADD, "CFGH", "%d", cfg.hideclient_to); - tpl_addVar(vars, TPLADD, "CHEADADD", tpl_getTpl(vars, "CLIENTHEADLINEWITH")); + tpl_addVar(vars, TPLADD, "CHEADADD", tpl_getTpl(vars, "CLIENTHEADLINEADD")); } tpl_printf(vars, TPLADD, "UCS", "%d", user_count_shown); tpl_printf(vars, TPLADD, "UCA", "%d", user_count_all); @@ -4955,6 +4975,10 @@ if(shown) { tpl_addVar(vars, TPLAPPEND, "READERSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT")); } tpl_printf(vars, TPLADD, "RCC", "%d", reader_count_conn); tpl_printf(vars, TPLADD, "RCA", "%d", reader_count_all); + if(reader_count_off) { + tpl_printf(vars, TPLADD, "RCO", "%d", reader_count_all-reader_count_off); + tpl_addVar(vars, TPLADD, "RHEADADD", tpl_getTpl(vars, "CLIENTRHEADLINEADD")); + } tpl_addVar(vars, TPLADD, "HIDEIDLE", "3"); tpl_addVar(vars, TPLADD, "SHOWHIDDEN", "Reader"); tpl_addVar(vars, TPLADD, "XHEAD", tpl_getTpl(vars, "CLIENTRHEADLINE")); @@ -4965,6 +4989,10 @@ if(shown) { tpl_addVar(vars, TPLAPPEND, "PROXYSTATUS", tpl_getTpl(vars, "CLIENTSTATUSBIT")); } tpl_printf(vars, TPLADD, "PCC", "%d", proxy_count_conn); tpl_printf(vars, TPLADD, "PCA", "%d", proxy_count_all); + if(proxy_count_off) { + tpl_printf(vars, TPLADD, "PCO", "%d", proxy_count_all-proxy_count_off); + tpl_addVar(vars, TPLADD, "PHEADADD", tpl_getTpl(vars, "CLIENTPHEADLINEADD")); + } tpl_addVar(vars, TPLADD, "HIDEIDLE", "4"); tpl_addVar(vars, TPLADD, "SHOWHIDDEN", "Proxy"); tpl_addVar(vars, TPLADD, "XHEAD", tpl_getTpl(vars, "CLIENTPHEADLINE")); @@ -5255,7 +5283,11 @@ tpl_printf(vars, TPLADD, "SCH", "%d", server_count_hidden); tpl_printf(vars, TPLADD, "SCA", "%d", server_count_all); tpl_printf(vars, TPLADD, "RCC", "%d", reader_count_conn); + tpl_printf(vars, TPLADD, "RCO", "%d", reader_count_off); + tpl_printf(vars, TPLADD, "RCA", "%d", reader_count_all); tpl_printf(vars, TPLADD, "PCC", "%d", proxy_count_conn); + tpl_printf(vars, TPLADD, "PCO", "%d", proxy_count_off); + tpl_printf(vars, TPLADD, "PCA", "%d", proxy_count_all); tpl_printf(vars, TPLADD, "PICONENABLED", "%d", cfg.http_showpicons?1:0); return tpl_getTpl(vars, "JSONSTATUS"); } @@ -6212,7 +6244,7 @@ struct s_cardsystem *cs = NULL; int32_t proxy = is_cascading_reader(rdr); - if((proxy || !rdr->csystem.active) && caid) // network reader (R_CAMD35 R_NEWCAMD R_CS378X R_CCCAM) + if((proxy || !rdr->csystem_active) && caid) // network reader (R_CAMD35 R_NEWCAMD R_CS378X R_CCCAM) { if(proxy && !rdr->ph.c_send_emm) { @@ -6227,7 +6259,7 @@ caid = 0; } } - else if(!proxy && rdr->csystem.active) // local active reader + else if(!proxy && rdr->csystem_active) // local active reader { cs = &rdr->csystem; caid = rdr->caid; @@ -6285,95 +6317,116 @@ } FILE *fp; - char buffer[512]; + struct stat sb; + char buffer[1024]; + char emm_hex[1024]; + char filename[128]; char targetfile[256]; - const char *slash = "/"; - struct dirent **namelist; - int count = -1, i; + char tmpstr[20]; + char emm_txt[32]; + char emm_title[32]; char *emm_path; + char *emm_types[] = { "unique_emm", "shared_emm", "global_emm" }; + char *emm_names[] = { "RDREMMUNIQUE", "RDREMMSHARED", "RDREMMGLOBAL" }; + char *emm_cfg_names[] = { "httpemmuclean", "httpemmsclean", "httpemmgclean" }; + int32_t emm_max_size[] = { cfg.http_emmu_clean, cfg.http_emms_clean, cfg.http_emmg_clean }; + int num_emm_types = 3; + int i; emm_path = cfg.emmlogdir ? cfg.emmlogdir : cs_confdir; - if (emm_path) + for( i = 0 ; i < num_emm_types; i++ ) { - count = scandir(emm_path, &namelist, 0, alphasort ); - } + snprintf(filename, sizeof(filename), "%s%s%s%s", getParam(params, "label"), "_", emm_types[i], ".log"); + snprintf(targetfile, sizeof(targetfile), "%s%s%s", emm_path, emm_path[strlen(emm_path) - 1] == '/' ? "" : "/", filename); + snprintf(emm_txt, sizeof(emm_txt), "%s_TXT", emm_names[i]); + tpl_addVar(vars, TPLADD, emm_txt, filename); - if( count >= 0 ) - { - for( i = 0 ; i < count; i++ ) + if((fp = fopen(targetfile, "r")) != NULL) { - if(strstr(namelist[i]->d_name, getParam(params, "label")) && is_ext(namelist[i]->d_name, ".log")) - { - if(emm_path[strlen(emm_path) - 1] == '/') { slash = ""; } - snprintf(targetfile, sizeof(targetfile), "%s%s%s", emm_path, slash, namelist[i]->d_name); + stat(targetfile, &sb); + tpl_printf(vars, TPLAPPEND, emm_txt, " (Size: %'.2f kB)", (double)sb.st_size/1024); - if((fp = fopen(targetfile, "r")) == NULL) { continue; } + if(emm_max_size[i]>=0) + { + snprintf(emm_title, sizeof(emm_title), "%s_TITLE", emm_names[i]); + tpl_addVar(vars, TPLADD, emm_title, "title=\"Klick Line to Copy EMM in Single EMM Write Field\""); + } - char emm_date[11],emm_time[9],emm_hex[512]; - int emms=0, emm_d; + if(emm_max_size[i]>0) + { + uint32_t emms=0, emm_d, emmrs=0; + char *ptr, *saveptr1 = NULL; while(fgets(buffer, sizeof(buffer), fp) != NULL) { emms++; - tpl_printf(vars, TPLADD, "TMP_LINE", "LINE_%d", emms); - tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP_LINE"), buffer); + snprintf(tmpstr, sizeof(tmpstr), "LINE_%d", emms); + tpl_addVar(vars, TPLADD, tmpstr, buffer); } - tpl_addVar(vars, TPLADD, "EMM_TMP",""); - tpl_addVar(vars, TPLADD, "EMM_DATE",""); + for(emm_d=emms;emm_d>0;--emm_d) { - tpl_printf(vars, TPLADD, "TMP_LINE", "LINE_%d", emm_d); - if(sscanf(tpl_getVar(vars, tpl_getVar(vars, "TMP_LINE")), "%s %s %*s %s",&emm_date[0],&emm_time[0],&emm_hex[0])==3) + snprintf(tmpstr, sizeof(tmpstr), "LINE_%d", emm_d); + if(sscanf(tpl_getVar(vars, tmpstr), "%*s %*s %*s %s", &emm_hex[0])==1) { - if(emm_d==1) - tpl_printf(vars, TPLADD, "EMM_DATE", "%s %s", emm_date,emm_time); if(strstr(tpl_getVar(vars, "EMM_TMP"),emm_hex)==0) - tpl_addVar(vars, TPLAPPEND, "EMM_TMP", tpl_getVar(vars, tpl_getVar(vars, "TMP_LINE"))); + { tpl_addVar(vars, TPLAPPEND, "EMM_TMP", tpl_getVar(vars, tmpstr)); } + tpl_addVar(vars, TPLADD, tmpstr, ""); } } - char *ptr, *saveptr1 = NULL; - char emm_tmp[strlen(tpl_getVar(vars, "EMM_TMP"))]; - cs_strncpy(emm_tmp, tpl_getVar(vars, "EMM_TMP"), sizeof(emm_tmp)); - int emmrs=0; - for(ptr = strtok_r(emm_tmp,"\n", &saveptr1); ptr; ptr = strtok_r(NULL,"\n", &saveptr1)) + for(ptr = strtok_r(tpl_getVar(vars, "EMM_TMP"),"\n", &saveptr1); ptr; ptr = strtok_r(NULL,"\n", &saveptr1)) { emmrs++; - tpl_printf(vars, TPLADD, "TMP_LINE", "LINE_%d", emmrs); - tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP_LINE"), ptr); + snprintf(tmpstr, sizeof(tmpstr), "LINE_%d", emmrs); + tpl_addVar(vars, TPLADD, tmpstr, ptr); } + tpl_addVar(vars, TPLADD, "EMM_TMP", ""); + + tpl_printf(vars, TPLAPPEND, emm_txt, ": %'d different EMMs from a total off %'d Entrys", emmrs,emms); for(emm_d=emmrs;emm_d>0;--emm_d) { - tpl_printf(vars, TPLADD, "TMP_LINE", "LINE_%d", emm_d); - if (strstr(namelist[i]->d_name, "unique_emm")) - { - if(emm_d==1) - tpl_printf(vars, TPLADD, "RDREMMUNIQUE_TXT", "First Entry: %s; %d different EMMs from a total off %d Entrys", tpl_getVar(vars, "EMM_DATE"),emmrs,emms); - tpl_printf(vars, TPLAPPEND, "RDREMMUNIQUE", "%s\n", tpl_getVar(vars, tpl_getVar(vars, "TMP_LINE"))); - } - else if (strstr(namelist[i]->d_name, "shared_emm")) - { - if(emm_d==1) - tpl_printf(vars, TPLADD, "RDREMMSHARED_TXT", "First Entry: %s; %d different EMMs from a total off %d Entrys", tpl_getVar(vars, "EMM_DATE"),emmrs,emms); - tpl_printf(vars, TPLAPPEND, "RDREMMSHARED", "%s\n", tpl_getVar(vars, tpl_getVar(vars, "TMP_LINE"))); - } - else if (strstr(namelist[i]->d_name, "global_emm")) + snprintf(tmpstr, sizeof(tmpstr), "LINE_%d", emm_d); + tpl_printf(vars, TPLAPPEND, emm_names[i], "%s\n", tpl_getVar(vars, tmpstr)); + if(sb.st_size>emm_max_size[i]*1024) { tpl_printf(vars, TPLAPPEND, "EMM_TMP", "%s\n", tpl_getVar(vars, tmpstr)); } + tpl_addVar(vars, TPLADD, tmpstr, ""); + } + + if(sb.st_size>emm_max_size[i]*1024) + { + char orgfile[256]; + int f=0; + do { + snprintf(orgfile, sizeof(orgfile), "%s.%d", targetfile, f); + f++; + } while(access(orgfile, 0|F_OK) != -1); + + if(rename(targetfile, orgfile) == 0) { - if(emm_d==1) - tpl_printf(vars, TPLADD, "RDREMMGLOBAL_TXT", "First Entry: %s; %d different EMMs from a total off %d Entrys", tpl_getVar(vars, "EMM_DATE"),emmrs,emms); - tpl_printf(vars, TPLAPPEND, "RDREMMGLOBAL", "%s\n", tpl_getVar(vars, tpl_getVar(vars, "TMP_LINE"))); + FILE *fs = fopen(targetfile, "w"); + fprintf(fs, "%s", tpl_getVar(vars, "EMM_TMP")); + fclose(fs); + tpl_printf(vars, TPLAPPEND, emm_txt, "
New reduced File created! Size of Original File is higher as %d kB, saved to %s", emm_max_size[i], orgfile); } } - fclose(fp); + tpl_addVar(vars, TPLADD, "EMM_TMP", ""); } - free( namelist[i] ); + else if (emm_max_size[i]==0) + { + while(fgets(buffer, sizeof(buffer), fp) != NULL) + { + tpl_printf(vars, TPLAPPEND, emm_names[i], "%s", buffer); + } + } + else + { + tpl_printf(vars, TPLADD, emm_names[i],"Viewing of EMM File deactivated.
Set %s in Config Webif to 0 or higher for viewing or filtering EMM File.", emm_cfg_names[i]); + } + fclose(fp); } - free(namelist); + if(strcmp(tpl_getVar(vars, emm_names[i]),"")==0) { tpl_addVar(vars, TPLADD, emm_names[i],"no saved EMMs"); } } - if(strcmp(tpl_getVar(vars, "RDREMMUNIQUE"),"")==0) tpl_addVar(vars, TPLADD, "RDREMMUNIQUE","no saved EMMs"); - if(strcmp(tpl_getVar(vars, "RDREMMSHARED"),"")==0) tpl_addVar(vars, TPLADD, "RDREMMSHARED","no saved EMMs"); - if(strcmp(tpl_getVar(vars, "RDREMMGLOBAL"),"")==0) tpl_addVar(vars, TPLADD, "RDREMMGLOBAL","no saved EMMs"); return tpl_getTpl(vars, "ASKEMM"); } @@ -6452,7 +6505,7 @@ tpl_addVar(vars, TPLADD, "USERNAME", xml_encode(vars, cl->account->usr)); tpl_addVar(vars, TPLADD, "USERENC", urlencode(vars, cl->account->usr)); if(cl->account->description) { - tpl_printf(vars, TPLADD, "CLIENTDESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, cl->account->description)); + tpl_printf(vars, TPLADD, "CLIENTDESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, cl->account->description)); } } else { tpl_addVar(vars, TPLADD, "NAME", cl->account->usr); @@ -6481,7 +6534,7 @@ tpl_addVar(vars, TPLADD, "READERNAME", xml_encode(vars, cl->reader->label)); tpl_addVar(vars, TPLADD, "READERNAMEENC", urlencode(vars, cl->reader->label)); if(cl->reader->description) { - tpl_printf(vars, TPLADD, "CLIENTDESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, cl->reader->description)); + tpl_printf(vars, TPLADD, "CLIENTDESCRIPTION","%s(%s)",!apicall?" ":"",xml_encode(vars, cl->reader->description)); } } else { tpl_addVar(vars, TPLADD, "NAME", cl->reader->label); @@ -7202,6 +7255,7 @@ if(!cs_realloc(result, bufsize + n + 1)) { send_error500(f); + NULLFREE(*result); return -1; } @@ -7519,6 +7573,13 @@ tpl_addVar(vars, TPLADD, "CS_SVN_VERSION", CS_SVN_VERSION); tpl_addVar(vars, TPLADD, "CS_TARGET", CS_TARGET); tpl_addVar(vars, TPLADD, "HTTPOSCAMLABEL", xml_encode(vars,cfg.http_oscam_label)); + if (!boxtype_is("generic")) + { + if (!boxname_is("generic")) + tpl_printf(vars, TPLADD, "DETECTED_BOXTYPE", "%s (%s)", boxtype_get(), boxname_get()); + else + tpl_addVar(vars, TPLADD, "DETECTED_BOXTYPE", boxtype_get()); + } if(cfg.http_locale){ float decimal_point = 0.0; @@ -7593,7 +7654,7 @@ tpl_addVar(vars, TPLADD, "RUNTIME", sec2timeformat(vars, (now - first_client->login))); time_t uptime = oscam_get_uptime(); if(uptime > 0){ - tpl_addVar(vars, TPLADD, "UPTIMETXT", "Up Time: "); + tpl_printf(vars, TPLADD, "UPTIMETXT", "%s Up Time: ", strcmp(tpl_getVar(vars, "DETECTED_BOXTYPE"),"")==0 ? "System" : tpl_getVar(vars, "DETECTED_BOXTYPE")); tpl_addVar(vars, TPLADD, "UPTIME", sec2timeformat(vars, uptime)); } tpl_addVar(vars, TPLADD, "CURIP", cs_inet_ntoa(addr)); @@ -7817,6 +7878,7 @@ { send_error(f, 200, "Bad Request", NULL, "This web server is running in SSL mode.", 1); } fflush(f); fclose(f); + NULLFREE(filebuf); } else { @@ -8050,17 +8112,14 @@ // Wait a bit so that we don't close ressources while http threads are active cs_sleepms(300); #ifdef WITH_SSL - if(ssl_active) - { - SSL_CTX_free(ctx); - CRYPTO_set_dynlock_create_callback(NULL); - CRYPTO_set_dynlock_lock_callback(NULL); - CRYPTO_set_dynlock_destroy_callback(NULL); - CRYPTO_set_locking_callback(NULL); - CRYPTO_set_id_callback(NULL); - OPENSSL_free(lock_cs); - lock_cs = NULL; - } + SSL_CTX_free(ctx); + CRYPTO_set_dynlock_create_callback(NULL); + CRYPTO_set_dynlock_lock_callback(NULL); + CRYPTO_set_dynlock_destroy_callback(NULL); + CRYPTO_set_locking_callback(NULL); + CRYPTO_set_id_callback(NULL); + OPENSSL_free(lock_cs); + lock_cs = NULL; #endif cs_log("HTTP Server stopped"); free_client(cl); diff -Nru oscam-1.20-10584~r10356/module-webif-lib.c oscam-1.20-10797~r10569/module-webif-lib.c --- oscam-1.20-10584~r10356/module-webif-lib.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-webif-lib.c 2015-02-20 11:57:49.000000000 +0000 @@ -375,7 +375,7 @@ { pos += snprintf(pos, sizeof(buf) - (pos - buf), "Connection: Keep-Alive\r\n"); } else { pos += snprintf(pos, sizeof(buf) - (pos - buf), "Connection: close\r\n"); } - pos += snprintf(pos, sizeof(buf) - (pos - buf), "\r\n"); + snprintf(pos, sizeof(buf) - (pos - buf), "\r\n"); if(forcePlain == 1) { fwrite(buf, 1, strlen(buf), f); } else { webif_write(buf, f); } } @@ -387,7 +387,7 @@ pos += snprintf(pos, sizeof(buf) - (pos - buf), "%d %s\r\n", status, title); pos += snprintf(pos, sizeof(buf) - (pos - buf), "

%d %s

\r\n", status, title); pos += snprintf(pos, sizeof(buf) - (pos - buf), "%s\r\n", text); - pos += snprintf(pos, sizeof(buf) - (pos - buf), "\r\n"); + snprintf(pos, sizeof(buf) - (pos - buf), "\r\n"); send_headers(f, status, title, extra, "text/html", 0, strlen(buf), NULL, forcePlain); if(forcePlain == 1) { fwrite(buf, 1, strlen(buf), f); } else { webif_write(buf, f); } @@ -844,11 +844,6 @@ /* Init necessary structures for SSL in WebIf*/ SSL_CTX *SSL_Webif_Init(void) { - SSL_library_init(); - SSL_load_error_strings(); - ERR_load_BIO_strings(); - ERR_load_SSL_strings(); - SSL_CTX *ctx; static const char *cs_cert = "oscam.pem"; @@ -896,30 +891,28 @@ { cs_strncpy(path, cfg.http_cert, sizeof(path)); } if(!ctx) - { - ERR_print_errors_fp(stderr); - return NULL; - } + goto out_err; if(SSL_CTX_use_certificate_file(ctx, path, SSL_FILETYPE_PEM) <= 0) - { - ERR_print_errors_fp(stderr); - return NULL; - } + goto out_err; if(SSL_CTX_use_PrivateKey_file(ctx, path, SSL_FILETYPE_PEM) <= 0) - { - ERR_print_errors_fp(stderr); - return NULL; - } + goto out_err; if(!SSL_CTX_check_private_key(ctx)) { cs_log("SSL: Private key does not match the certificate public key"); - return NULL; + goto out_err; } + cs_log("load ssl certificate file %s", path); return ctx; + +out_err: + ERR_print_errors_fp(stderr); + ERR_remove_state(0); + SSL_CTX_free(ctx); + return NULL; } #endif diff -Nru oscam-1.20-10584~r10356/module-webif-tpl.c oscam-1.20-10797~r10569/module-webif-tpl.c --- oscam-1.20-10584~r10356/module-webif-tpl.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-webif-tpl.c 2015-02-20 11:57:49.000000000 +0000 @@ -122,9 +122,9 @@ /* Adds a name->value-mapping or appends to it. You will get a reference back which you may freely use (but you should not call free/realloc on this!)*/ -char *tpl_addVar(struct templatevars *vars, uint8_t addmode, char *name, char *value) +void tpl_addVar(struct templatevars *vars, uint8_t addmode, const char *name, const char *value) { - if(name == NULL) { return ""; } + if(name == NULL) { return; } if(value == NULL) { value = ""; } int32_t i; char *tmp = NULL, *result = NULL; @@ -140,20 +140,20 @@ { if((*vars).varsalloc <= (*vars).varscnt) { - if(!cs_realloc(&(*vars).names, (*vars).varsalloc * 2 * sizeof(char **))) { return ""; } - if(!cs_realloc(&(*vars).values, (*vars).varsalloc * 2 * sizeof(char **))) { return ""; } - if(!cs_realloc(&(*vars).vartypes, (*vars).varsalloc * 2 * sizeof(uint8_t *))) { return ""; } + if(!cs_realloc(&(*vars).names, (*vars).varsalloc * 2 * sizeof(char **))) { return; } + if(!cs_realloc(&(*vars).values, (*vars).varsalloc * 2 * sizeof(char **))) { return; } + if(!cs_realloc(&(*vars).vartypes, (*vars).varsalloc * 2 * sizeof(uint8_t *))) { return; } (*vars).varsalloc = (*vars).varscnt * 2; } int32_t len = strlen(name) + 1; - if(!cs_malloc(&tmp, len)) { return ""; } + if(!cs_malloc(&tmp, len)) { return; } memcpy(tmp, name, len); (*vars).names[(*vars).varscnt] = tmp; len = strlen(value) + 1; if(!cs_malloc(&tmp, len)) { NULLFREE((*vars).names[(*vars).varscnt]); - return ""; + return; } memcpy(tmp, value, len); (*vars).values[(*vars).varscnt] = tmp; @@ -164,25 +164,25 @@ { int32_t oldlen = 0, newlen = strlen(value); if(addmode == TPLAPPEND || addmode == TPLAPPENDONCE) { oldlen = strlen((*vars).values[i]); } - if(!cs_realloc(&((*vars).values[i]), oldlen + newlen + 1)) { return value; } + if(!cs_realloc(&((*vars).values[i]), oldlen + newlen + 1)) { return; } memcpy((*vars).values[i] + oldlen, value, newlen + 1); (*vars).vartypes[i] = addmode; } - return tmp; + return; } /* Adds a message to be output on the page using the TPLMESSAGE template. */ -char *tpl_addMsg(struct templatevars *vars, char *value) +void tpl_addMsg(struct templatevars *vars, const char *value) { tpl_addVar(vars, TPLADDONCE, "MESSAGE", value); (*vars).messages++; - return tpl_addVar(vars, TPLAPPEND, "MESSAGES", tpl_getTpl(vars, "MESSAGEBIT")); + tpl_addVar(vars, TPLAPPEND, "MESSAGES", tpl_getTpl(vars, "MESSAGEBIT")); } /* Allows to add a char array which has been allocated by malloc. It will automatically get freed when calling tpl_clear(). Please do NOT free the memory yourself or realloc it after having added the array here! */ -char *tpl_addTmp(struct templatevars *vars, char *value) +static char *tpl_addTmp(struct templatevars *vars, char *value) { if(value == NULL) { return ""; } if((*vars).tmpalloc <= (*vars).tmpcnt) @@ -199,7 +199,7 @@ varname, the printf-result will be added/appended to the varlist, if varname=NULL it will only be returned. In either case you will always get a reference back which you may freely use (but you should not call free/realloc on this as it will be automatically cleaned!)*/ -char *tpl_printf(struct templatevars *vars, uint8_t addmode, char *varname, char *fmtstring, ...) +void tpl_printf(struct templatevars *vars, uint8_t addmode, const char *varname, const char *fmtstring, ...) { uint32_t needed; char test[1]; @@ -210,7 +210,7 @@ va_end(argptr); char *result; - if(!cs_malloc(&result, needed + 1)) { return ""; } + if(!cs_malloc(&result, needed + 1)) { return; } va_start(argptr, fmtstring); vsnprintf(result, needed + 1, fmtstring, argptr); va_end(argptr); @@ -218,15 +218,14 @@ if(varname == NULL) { tpl_addTmp(vars, result); } else { - char *tmp = tpl_addVar(vars, addmode, varname, result); - NULLFREE(result); - result = tmp; + tpl_addVar(vars, addmode, varname, result); + free(result); } - return result; + return; } /* Returns the value for a name or an empty string if nothing was found. */ -char *tpl_getVar(struct templatevars *vars, char *name) +char *tpl_getVar(struct templatevars *vars, const char *name) { int32_t i; char *result = NULL; @@ -723,7 +722,7 @@ char *pstr = str, *pbuf = buf; while(*pstr) { - if(isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') { *pbuf++ = *pstr; } + if(isalnum((uchar)*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') { *pbuf++ = *pstr; } else if(*pstr == ' ') { *pbuf++ = '+'; } else { @@ -741,7 +740,7 @@ /* XML-Escapes a char array. The returned reference will be automatically cleaned through the templatevars-mechanism tpl_clear(). Do not call free() or realloc on the returned reference or you will get memory corruption! */ -char *xml_encode(struct templatevars *vars, char *chartoencode) +char *xml_encode(struct templatevars *vars, const char *chartoencode) { if(!chartoencode) { return ""; } int32_t i, pos = 0, len = strlen(chartoencode); diff -Nru oscam-1.20-10584~r10356/module-webif-tpl.h oscam-1.20-10797~r10569/module-webif-tpl.h --- oscam-1.20-10584~r10356/module-webif-tpl.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/module-webif-tpl.h 2015-02-20 11:57:49.000000000 +0000 @@ -34,12 +34,11 @@ struct templatevars *tpl_create(void); void tpl_clear(struct templatevars *vars); -char *tpl_addVar(struct templatevars *vars, uint8_t addmode, char *name, char *value); -char *tpl_addMsg(struct templatevars *vars, char *value); -char *tpl_addTmp(struct templatevars *vars, char *value); -char *tpl_printf(struct templatevars *vars, uint8_t addmode, char *varname, char *fmtstring, ...) __attribute__((format(printf, 4, 5))); +void tpl_addVar(struct templatevars *vars, uint8_t addmode, const char *name, const char *value); +void tpl_addMsg(struct templatevars *vars, const char *value); +void tpl_printf(struct templatevars *vars, uint8_t addmode, const char *varname, const char *fmtstring, ...) __attribute__((format(printf, 4, 5))); -char *tpl_getVar(struct templatevars *vars, char *name); +char *tpl_getVar(struct templatevars *vars, const char *name); char *tpl_getFilePathInSubdir(const char *path, const char *subdir, const char *name, const char *ext, char *result, uint32_t resultsize); char *tpl_getTplPath(const char *name, const char *path, char *result, uint32_t resultsize); char *tpl_getTpl(struct templatevars *vars, const char *name); @@ -51,7 +50,7 @@ void tpl_checkDiskRevisions(void); char *urlencode(struct templatevars *vars, char *str); -char *xml_encode(struct templatevars *vars, char *chartoencode); +char *xml_encode(struct templatevars *vars, const char *chartoencode); char *sec2timeformat(struct templatevars *vars, int32_t seconds); #else diff -Nru oscam-1.20-10584~r10356/oscam-aes.c oscam-1.20-10797~r10569/oscam-aes.c --- oscam-1.20-10584~r10356/oscam-aes.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-aes.c 2015-02-20 11:57:49.000000000 +0000 @@ -11,6 +11,14 @@ AES_set_encrypt_key((const unsigned char *)key, 128, &aes->aeskey_encrypt); } +bool aes_set_key_alloc(struct aes_keys **aes, char *key) +{ + if (!cs_malloc(aes, sizeof(struct aes_keys))) + return false; + aes_set_key(*aes, key); + return true; +} + void aes_decrypt(struct aes_keys *aes, uchar *buf, int32_t n) { int32_t i; diff -Nru oscam-1.20-10584~r10356/oscam-aes.h oscam-1.20-10797~r10569/oscam-aes.h --- oscam-1.20-10584~r10356/oscam-aes.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-aes.h 2015-02-20 11:57:49.000000000 +0000 @@ -2,6 +2,7 @@ #define OSCAM_AES_H_ void aes_set_key(struct aes_keys *aes, char *key); +bool aes_set_key_alloc(struct aes_keys **aes, char *key); void aes_decrypt(struct aes_keys *aes, uchar *buf, int32_t n); void aes_encrypt_idx(struct aes_keys *aes, uchar *buf, int32_t n); diff -Nru oscam-1.20-10584~r10356/oscam-array.c oscam-1.20-10797~r10569/oscam-array.c --- oscam-1.20-10584~r10356/oscam-array.c 1970-01-01 00:00:00.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-array.c 2015-02-20 11:57:49.000000000 +0000 @@ -0,0 +1,72 @@ +#define MODULE_LOG_PREFIX "array" + +#include "globals.h" +#include "oscam-string.h" + +void array_clear(void **arr_data, int32_t *arr_num_entries) +{ + *arr_num_entries = 0; + if (arr_data) + { + free(*arr_data); + *arr_data = NULL; + } +} + +bool array_clone(void **src_arr_data, int32_t *src_arr_num_entries, uint32_t entry_size, void **dst_arr_data, int32_t *dst_arr_num_entries) +{ + array_clear(dst_arr_data, dst_arr_num_entries); + if (!src_arr_data || !dst_arr_data || !*src_arr_data) + return false; + if (!cs_malloc(dst_arr_data, *src_arr_num_entries * entry_size)) + return false; + memcpy(*dst_arr_data, *src_arr_data, *src_arr_num_entries * entry_size); + *dst_arr_num_entries = *src_arr_num_entries; + return true; +} + +bool array_add(void **arr_data, int32_t *arr_num_entries, uint32_t entry_size, void *new_entry) +{ + if (!cs_realloc(arr_data, (*arr_num_entries + 1) * entry_size)) + return false; + memcpy(*arr_data + (*arr_num_entries * entry_size), new_entry, entry_size); + *arr_num_entries += 1; + return true; +} + +/* Array functions for different types */ +#define DECLARE_ARRAY_FUNCS(NAME, BASE_TYPE, DATA_TYPE, DATA_FIELD, NUM_FIELD) \ + void NAME##_clear(BASE_TYPE *in) \ + { \ + if (!in) return; \ + void *pin = in->DATA_FIELD; /* Prevent warnings about strict-aliasing rules */ \ + array_clear(&pin, &in->NUM_FIELD); \ + in->DATA_FIELD = pin; \ + } \ + \ + bool NAME##_clone(BASE_TYPE *src, BASE_TYPE *dst) \ + { \ + if (!src || !dst) return false; \ + void *psrc = src->DATA_FIELD, *pdst = dst->DATA_FIELD; /* Prevent warnings about strict-aliasing rules */ \ + bool ret = array_clone(&psrc, &src->NUM_FIELD, sizeof(*src->DATA_FIELD), &pdst, &dst->NUM_FIELD); \ + dst->DATA_FIELD = pdst; \ + return ret; \ + } \ + \ + bool NAME##_add(BASE_TYPE *in, DATA_TYPE *td) \ + { \ + if (!in) return false; \ + void *pin = in->DATA_FIELD; /* Prevent warnings about strict-aliasing rules */ \ + bool ret = array_add(&pin, &in->NUM_FIELD, sizeof(*in->DATA_FIELD), td); \ + in->DATA_FIELD = pin; \ + return ret; \ + } + +DECLARE_ARRAY_FUNCS(ftab, FTAB, FILTER, filts, nfilts); // Declare ftab_clear(), ftab_clone(), ftab_add() +DECLARE_ARRAY_FUNCS(tuntab, TUNTAB, TUNTAB_DATA, ttdata, ttnum); // Declare tuntab_clear(), tuntab_clone(), tuntab_add() +DECLARE_ARRAY_FUNCS(ecm_whitelist, ECM_WHITELIST, ECM_WHITELIST_DATA, ewdata, ewnum); // Declare ecm_whitelist_clear(), ecm_whitelist_clone(), ecm_whitelist_add() +DECLARE_ARRAY_FUNCS(ecm_hdr_whitelist, ECM_HDR_WHITELIST, ECM_HDR_WHITELIST_DATA, ehdata, ehnum); // Declare ecm_hdr_whitelist_clear(), ecm_hdr_whitelist_clone(), ecm_hdr_whitelist_add() +DECLARE_ARRAY_FUNCS(caidvaluetab, CAIDVALUETAB, CAIDVALUETAB_DATA, cvdata, cvnum); // Declare caidvaluetab_clear(), caidvaluetab_clone(), caidvaluetab_add() +DECLARE_ARRAY_FUNCS(caidtab, CAIDTAB, CAIDTAB_DATA, ctdata, ctnum); // Declare caidtab_clear(), caidtab_clone(), caidtab_add() + +#undef DECLARE_ARRAY_FUNCS diff -Nru oscam-1.20-10584~r10356/oscam-array.h oscam-1.20-10797~r10569/oscam-array.h --- oscam-1.20-10584~r10356/oscam-array.h 1970-01-01 00:00:00.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-array.h 2015-02-20 11:57:49.000000000 +0000 @@ -0,0 +1,30 @@ +#ifndef OSCAM_ARRAY_H +#define OSCAM_ARRAY_H + +/* Functions for manipulating dynamic arrays */ + +/* Frees array data and reset array num_entries */ +void array_clear(void **arr_data, int32_t *arr_num_entries); + +/* Initializes dst array with src array data. dst array is cleared first */ +bool array_clone(void **src_arr_data, int32_t *src_arr_num_entries, uint32_t entry_size, void **dst_arr_data, int32_t *dst_arr_num_entries); + +/* Add element at the end of array */ +bool array_add(void **arr_data, int32_t *arr_num_entries, uint32_t entry_size, void *new_entry); + +/* Array functions for different types */ +#define DECLARE_ARRAY_FUNCS(NAME, BASE_TYPE, DATA_TYPE, DATA_FIELD, NUM_FIELD) \ + void NAME##_clear(BASE_TYPE *in); \ + bool NAME##_clone(BASE_TYPE *src, BASE_TYPE *dst); \ + bool NAME##_add(BASE_TYPE *in, DATA_TYPE *td); \ + +DECLARE_ARRAY_FUNCS(ftab, FTAB, FILTER, filts, nfilts); // Declare ftab_clear(), ftab_clone(), ftab_add() +DECLARE_ARRAY_FUNCS(tuntab, TUNTAB, TUNTAB_DATA, ttdata, ttnum); // Declare tuntab_clear(), tuntab_clone(), tuntab_add() +DECLARE_ARRAY_FUNCS(ecm_whitelist, ECM_WHITELIST, ECM_WHITELIST_DATA, ewdata, ewnum); // Declare ecm_whitelist_clear(), ecm_whitelist_clone(), ecm_whitelist_add() +DECLARE_ARRAY_FUNCS(ecm_hdr_whitelist, ECM_HDR_WHITELIST, ECM_HDR_WHITELIST_DATA, ehdata, ehnum); // Declare ecm_hdr_whitelist_clear(), ecm_hdr_whitelist_clone(), ecm_hdr_whitelist_add() +DECLARE_ARRAY_FUNCS(caidvaluetab, CAIDVALUETAB, CAIDVALUETAB_DATA, cvdata, cvnum); // Declare caidvaluetab_clear(), caidvaluetab_clone(), caidvaluetab_add() +DECLARE_ARRAY_FUNCS(caidtab, CAIDTAB, CAIDTAB_DATA, ctdata, ctnum); // Declare caidtab_clear(), caidtab_clone(), caidtab_add() + +#undef DECLARE_ARRAY_FUNCS + +#endif diff -Nru oscam-1.20-10584~r10356/oscam.c oscam-1.20-10797~r10569/oscam.c --- oscam-1.20-10584~r10356/oscam.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam.c 2015-02-20 11:57:49.000000000 +0000 @@ -28,6 +28,7 @@ #include "oscam-config.h" #include "oscam-ecm.h" #include "oscam-emm.h" +#include "oscam-emm-cache.h" #include "oscam-files.h" #include "oscam-garbage.h" #include "oscam-lock.h" @@ -39,6 +40,32 @@ #include "reader-common.h" #include "module-gbox.h" +#ifdef WITH_SSL +#include +#include +#include + +static void ssl_init(void) +{ + SSL_load_error_strings(); + ERR_load_BIO_strings(); + ERR_load_SSL_strings(); + SSL_library_init(); +} + +static void ssl_done(void) +{ + ERR_remove_state(0); + ERR_free_strings(); + EVP_cleanup(); + CRYPTO_cleanup_all_ex_data(); +} + +#else +static void ssl_init(void) { } +static void ssl_done(void) { } +#endif + extern char *config_mak; /***************************************************************************** @@ -95,7 +122,8 @@ int log_remove_sensitive = 1; static char *prog_name; -char *stb_boxtype = NULL; +static char *stb_boxtype; +static char *stb_boxname; /***************************************************************************** Statics @@ -110,7 +138,7 @@ "| |_| |___) | |_| (_| | | | | | |\n" " \\___/|____/ \\___\\__,_|_| |_| |_|\n\n"); printf("OSCam cardserver v%s, build r%s (%s)\n", CS_VERSION, CS_SVN_VERSION, CS_TARGET); - printf("Copyright (C) 2009-2013 OSCam developers.\n"); + printf("Copyright (C) 2009-2015 OSCam developers.\n"); printf("This program is distributed under GPLv3.\n"); printf("OSCam is based on Streamboard mp-cardserver v0.9d written by dukat\n"); printf("Visit http://www.streamboard.tv/oscam/ for more details.\n\n"); @@ -703,18 +731,26 @@ // Linux only functionality char boxtype[128]; + boxtype[0] = 0; char model[128]; + model[0] = 0; char vumodel[128]; + vumodel[0] = 0; + int8_t azmodel = 0; + FILE *f; + if ((f = fopen("/proc/stb/info/azmodel", "r"))){ azmodel = 1; fclose(f);} read_line_from_file("/proc/stb/info/model", model, sizeof(model)); read_line_from_file("/proc/stb/info/boxtype", boxtype, sizeof(boxtype)); - if (read_line_from_file("/proc/stb/info/vumodel", vumodel, sizeof(vumodel))) + read_line_from_file("/proc/stb/info/vumodel", vumodel, sizeof(vumodel)); + if (vumodel[0] && !boxtype[0] && !azmodel) snprintf(boxtype, sizeof(boxtype), "vu%s", vumodel); + if (!boxtype[0] && azmodel) + snprintf(boxtype, sizeof(boxtype), "Azbox-%s", model); // Detect dreambox type if (strcasecmp(buffer.machine, "ppc") == 0 && !model[0] && !boxtype[0]) { - FILE *f; char line[128], *p; int have_dreambox = 0; if ((f = fopen("/proc/cpuinfo", "r"))) @@ -745,12 +781,37 @@ if (!boxtype[0] && !strcasecmp(model, "dm800") && !strcasecmp(buffer.machine, "armv7l")) snprintf(boxtype, sizeof(boxtype), "%s", "su980"); + + if (!boxtype[0]) + { + uchar *pos; + pos = (uchar*) memchr(buffer.release, 'd', sizeof(buffer.release)); + if(pos) + { + if((!memcmp(pos, "dbox2", sizeof("dbox2"))) && !strcasecmp(buffer.machine, "ppc")) + { + snprintf(boxtype, sizeof(boxtype), "%s", "dbox2"); + } + } + } if (model[0]) cs_log("Stb model = %s", model); + if (vumodel[0]) + cs_log("Stb vumodel = vu%s", vumodel); + if (boxtype[0]) + { + char boxname[128]; + if(!strcasecmp(boxtype,"ini-8000am")){snprintf(boxname, sizeof(boxname), "%s", "Atemio Nemesis");} + else if(!strcasecmp(boxtype,"ini-9000ru")){snprintf(boxname, sizeof(boxname), "%s", "Sezam Marvel");} + else if(!strcasecmp(boxtype,"ini-8000sv")){snprintf(boxname, sizeof(boxname), "%s", "Miraclebox Ultra");} + else if(!strcasecmp(boxtype,"ini-9000de")){snprintf(boxname, sizeof(boxname), "%s", "Xpeed LX3");} + else boxname[0] = 0; + if(boxname[0]){cs_log("Stb boxname = %s", boxname); stb_boxname = cs_strdup(boxname);} cs_log("Stb boxtype = %s", boxtype); + } if (boxtype[0]) stb_boxtype = cs_strdup(boxtype); @@ -758,6 +819,26 @@ stb_boxtype = cs_strdup(model); } +const char *boxtype_get(void) +{ + return stb_boxtype ? stb_boxtype : "generic"; +} + +const char *boxname_get(void) +{ + return stb_boxname ? stb_boxname : "generic"; +} + +bool boxtype_is(const char *boxtype) +{ + return strcasecmp(boxtype_get(), boxtype) == 0; +} + +bool boxname_is(const char *boxname) +{ + return strcasecmp(boxname_get(), boxname) == 0; +} + /* Checks if the date of the system is correct and waits if necessary. */ static void init_check(void) { @@ -859,11 +940,7 @@ { struct s_module *module = &modules[i]; if(module->num && module->num == rdr->typ) - { rdr->ph = *module; - if(rdr->device[0]) - { rdr->ph.active = 1; } - } } } @@ -1154,6 +1231,38 @@ return NULL; } +static pthread_cond_t card_poll_sleep_cond; + +static void * card_poll(void) { + struct s_client *cl; + struct s_reader *rdr; + pthread_mutex_t card_poll_sleep_cond_mutex; + pthread_mutex_init(&card_poll_sleep_cond_mutex, NULL); + pthread_cond_init(&card_poll_sleep_cond, NULL); + set_thread_name(__func__); + while (!exit_oscam) { + cs_readlock(&readerlist_lock); + for (rdr=first_active_reader; rdr; rdr=rdr->next) { + if (rdr->enable && rdr->card_status == CARD_INSERTED) { + cl = rdr->client; + if (cl && !cl->kill) + { add_job(cl, ACTION_READER_POLL_STATUS, 0, 0); } + } + } + cs_readunlock(&readerlist_lock); + struct timespec ts; + struct timeval tv; + gettimeofday(&tv, NULL); + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = tv.tv_usec * 1000; + ts.tv_sec += 1; + pthread_mutex_lock(&card_poll_sleep_cond_mutex); + pthread_cond_timedwait(&card_poll_sleep_cond, &card_poll_sleep_cond_mutex, &ts); // sleep on card_poll_sleep_cond + pthread_mutex_unlock(&card_poll_sleep_cond_mutex); + } + return NULL; +} + #ifdef WEBIF static pid_t pid; @@ -1247,8 +1356,41 @@ } } +static bool running_under_valgrind; + +static void detect_valgrind(void) +{ +#ifdef __linux__ + char fname[32]; + snprintf(fname, sizeof(fname), "/proc/%d/maps", getpid()); + FILE *f = fopen(fname, "r"); + if (f) { + char line[256]; + while (fgets(line, sizeof(line), f)) { + if (strstr(line, "/valgrind/")) { + running_under_valgrind = true; + break; + } + } + } + fclose(f); +#endif +} + +#ifdef BUILD_TESTS +extern void run_all_tests(void); +__attribute__ ((noreturn)) static void run_tests(void) +{ + run_all_tests(); + exit(0); +} +#else +static void run_tests(void) { } +#endif + int32_t main(int32_t argc, char *argv[]) { + run_tests(); int32_t i, j; prog_name = argv[0]; struct timespec start_ts; @@ -1423,7 +1565,7 @@ cs_lock_create(&readdir_lock, "readdir_lock", 5000); cs_lock_create(&cwcycle_lock, "cwcycle_lock", 5000); init_cache(); - init_hitcache(); + cacheex_init_hitcache(); init_config(); cs_init_log(); init_machine_info(); @@ -1439,6 +1581,7 @@ cs_init_statistics(); coolapi_open_all(); init_stat(); + ssl_init(); // These initializations *MUST* be called after init_config() // because modules depend on config values. @@ -1513,11 +1656,16 @@ init_cardreader(); cs_waitforcardinit(); + + emm_load_cache(); + load_emmstat_from_file(); led_status_starting(); ac_init(); + start_thread((void *) &card_poll, "card poll"); + for(i = 0; i < CS_MAX_MOD; i++) { struct s_module *module = &modules[i]; @@ -1528,6 +1676,7 @@ // main loop function process_clients(); + pthread_cond_signal(&card_poll_sleep_cond); // Stop card_poll thread cw_process_thread_wakeup(); // Stop cw_process thread pthread_cond_signal(&reader_check_sleep_cond); // Stop reader_check thread @@ -1546,6 +1695,8 @@ stat_finish(); dvbapi_save_channel_cache(); + emm_save_cache(); + save_emmstat_to_file(); cccam_done_share(); @@ -1572,6 +1723,8 @@ if(oscam_pidfile) { unlink(oscam_pidfile); } + free_cache(); + cacheex_free_hitcache(); webif_tpls_free(); init_free_userdb(cfg.account); cfg.account = NULL; @@ -1579,15 +1732,23 @@ free_readerdb(); free_irdeto_guess_tab(); config_free(); + ssl_done(); - cs_log("cardserver down"); + detect_valgrind(); + if (!running_under_valgrind) + cs_log("cardserver down"); + else + cs_log("running under valgrind, waiting 5 seconds before stopping cardserver"); log_free(); + if (running_under_valgrind) sleep(5); // HACK: Wait a bit for things to settle + stop_garbage_collector(); NULLFREE(first_client->account); NULLFREE(first_client); free(stb_boxtype); + free(stb_boxname); // This prevents the compiler from removing config_mak from the final binary syslog_ident = config_mak; diff -Nru oscam-1.20-10584~r10356/oscam-cache.c oscam-1.20-10797~r10569/oscam-cache.c --- oscam-1.20-10584~r10356/oscam-cache.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-cache.c 2015-02-20 11:57:49.000000000 +0000 @@ -3,6 +3,7 @@ #include "globals.h" #include "module-cacheex.h" #include "module-cw-cycle-check.h" +#include "oscam-cache.h" #include "oscam-chk.h" #include "oscam-client.h" #include "oscam-ecm.h" @@ -25,9 +26,7 @@ uint8_t odd_even; //odd/even byte (0x80 0x81) uint8_t cwc_cycletime; uint8_t cwc_next_cw_cycle; -#ifdef CW_CYCLE_CHECK - uint8_t got_bad_cwc; -#endif + uint8_t got_bad_cwc; //used by cycle check uint16_t caid; //first caid received uint32_t prid; //first prid received uint16_t srvid; //first srvid received @@ -63,9 +62,9 @@ } ECMHASH; -pthread_rwlock_t cache_lock; -hash_table ht_cache; -list ll_cache; +static pthread_rwlock_t cache_lock; +static hash_table ht_cache; +static list ll_cache; void init_cache(void){ init_hash_table(&ht_cache, &ll_cache); @@ -73,18 +72,25 @@ cs_log("Error creating lock cache_lock!"); } +void free_cache(void){ + cleanup_cache(true); + deinitialize_hash_table(&ht_cache); + pthread_rwlock_destroy(&cache_lock); +} + uint32_t cache_size(void){ return count_hash_table(&ht_cache); } -uint8_t count_sort(CW *a, CW *b){ +static uint8_t count_sort(CW *a, CW *b){ if (a->count == b->count) return 0; return (a->count > b->count) ? -1 : 1; //DESC order by count } -uint8_t check_is_pushed(CW *cw, struct s_client *cl){ +uint8_t check_is_pushed(void *cwp, struct s_client *cl){ struct s_pushclient *cl_tmp; + CW* cw = (CW*)cwp; bool pushed=false; pthread_rwlock_rdlock(&cw->pushout_client_lock); @@ -130,14 +136,8 @@ while (j) { cw = get_data_from_node(j); - if(cw - && cw->odd_even==get_odd_even(er) -#ifdef CW_CYCLE_CHECK - && !cw->got_bad_cwc -#endif - ){ + if(cw && cw->odd_even == get_odd_even(er) && !cw->got_bad_cwc) return cw; - } j = j->next; } @@ -145,15 +145,34 @@ return NULL; } -int compare_csp_hash(const void *arg, const void *obj){ +static int compare_csp_hash(const void *arg, const void *obj){ int32_t h = ((const ECMHASH*)obj)->csp_hash; return memcmp(arg, &h, 4); } -int compare_cw(const void *arg, const void *obj){ +static int compare_cw(const void *arg, const void *obj){ return memcmp(arg, ((const CW*)obj)->cw, 16); } +static bool cwcycle_check_cache(struct s_client *cl, ECM_REQUEST *er, CW *cw) +{ + (void)cl; (void)er; (void)cw; +#ifdef CW_CYCLE_CHECK + if(cw->got_bad_cwc) + return 0; + uint8_t cwc_ct = cw->cwc_cycletime > 0 ? cw->cwc_cycletime : 0; + uint8_t cwc_ncwc = cw->cwc_next_cw_cycle < 2 ? cw->cwc_next_cw_cycle : 2; + if(checkcwcycle(cl, er, NULL, cw->cw, 0, cwc_ct, cwc_ncwc) != 0) + { + cs_log_dbg(D_CWC | D_LB, "{client %s, caid %04X, srvid %04X} [check_cache] cyclecheck passed ecm in INT. cache.", (cl ? cl->account->usr : "-"), er->caid, er->srvid); + }else{ + cs_log_dbg(D_CWC, "cyclecheck [BAD CW Cycle] from Int. Cache detected.. {client %s, caid %04X, srvid %04X} [check_cache] -> skip cache answer", (cl ? cl->account->usr : "-"), er->caid, er->srvid); + cw->got_bad_cwc = 1; // no need to check it again + return 0; + } +#endif + return 1; +} /* * This function returns cw (mostly received) in cache for er, or NULL if not found. @@ -177,11 +196,10 @@ result = find_hash_table(&ht_cache, &er->csp_hash, sizeof(int32_t),&compare_csp_hash); cw = get_first_cw(result, er); + if (!cw) + goto out_err; if( - cw - && - ( cw->csp //csp have no grp! || !grp //csp client(no grp) searching for cache @@ -192,7 +210,6 @@ cw->grp //ecm group --> only when readers/ex-clients answer (e_found) it && (grp & cw->grp) ) - ) ){ @@ -200,8 +217,7 @@ //if preferlocalcards=2 for this ecm request, we can server ONLY cw from localcards readers until stage<3 if(er->preferlocalcards==2 && !cw->localcards && er->stage<3){ - pthread_rwlock_unlock(&cache_lock); - return NULL; + goto out_err; } CWCHECK check_cw = get_cwcheck(er); @@ -210,29 +226,12 @@ && cw->count < check_cw.counter && (check_cw.mode || !er->cacheex_wait_time_expired) ){ - pthread_rwlock_unlock(&cache_lock); - return NULL; + goto out_err; } #endif - -#ifdef CW_CYCLE_CHECK - uint8_t cwc_ct = cw->cwc_cycletime > 0 ? cw->cwc_cycletime : 0; - uint8_t cwc_ncwc = cw->cwc_next_cw_cycle < 2 ? cw->cwc_next_cw_cycle : 2; - if(cw->got_bad_cwc) - { - pthread_rwlock_unlock(&cache_lock); - return NULL; - } - if(checkcwcycle(cl, er, NULL, cw->cw, 0, cwc_ct, cwc_ncwc) != 0){ - cs_log_dbg(D_CWC | D_LB, "{client %s, caid %04X, srvid %04X} [check_cache] cyclecheck passed ecm in INT. cache, ecm->rc %d", (cl ? cl->account->usr : "-"), er->caid, er->srvid, ecm ? ecm->rc : -1); - }else{ - cs_log_dbg(D_CWC, "cyclecheck [BAD CW Cycle] from Int. Cache detected.. {client %s, caid %04X, srvid %04X} [check_cache] -> skip cache answer", (cl ? cl->account->usr : "-"), er->caid, er->srvid); - cw->got_bad_cwc = 1; // no need to check it again - pthread_rwlock_unlock(&cache_lock); - return NULL; - } -#endif + if (!cwcycle_check_cache(cl, er, cw)) + goto out_err; if (cs_malloc(&ecm, sizeof(ECM_REQUEST))){ ecm->rc = E_FOUND; @@ -242,26 +241,74 @@ ecm->selected_reader = cw->selected_reader; ecm->cwc_cycletime = cw->cwc_cycletime; ecm->cwc_next_cw_cycle = cw->cwc_next_cw_cycle; -#ifdef CS_CACHEEX ecm->cacheex_src = cw->cacheex_src; -#endif ecm->cw_count = cw->count; } } - pthread_rwlock_unlock(&cache_lock); - return ecm; +out_err: + pthread_rwlock_unlock(&cache_lock); + return ecm; } +static void cacheex_cache_add(ECM_REQUEST *er, ECMHASH *result, CW *cw, bool add_new_cw) +{ + (void)er; (void)result; (void)cw; (void)add_new_cw; +#ifdef CS_CACHEEX + er->cw_cache = cw; + cacheex_cache_push(er); + + //cacheex debug log lines and cw diff stuff + if(!check_client(er->cacheex_src)) + return; + + if(!add_new_cw) + { + debug_ecm(D_CACHEEX| D_CSP, "got duplicate pushed ECM %s from %s", buf, er->from_csp ? "csp" : username(er->cacheex_src)); + return; + } + + debug_ecm(D_CACHEEX|D_CSP, "got pushed ECM %s from %s", buf, er->from_csp ? "csp" : username(er->cacheex_src)); + CW *cw_first = get_first_cw(result, er); + if(!cw_first) + return; + + //compare er cw with mostly counted cached cw + if(memcmp(er->cw, cw_first->cw, sizeof(er->cw)) != 0) + { + er->cacheex_src->cwcacheexerrcw++; + if (er->cacheex_src->account) + er->cacheex_src->account->cwcacheexerrcw++; + + if (((0x0200| 0x0800) & cs_dblevel)) //avoid useless operations if debug is not enabled + { + char cw1[16*3+2], cw2[16*3+2]; + cs_hexdump(0, er->cw, 16, cw1, sizeof(cw1)); + cs_hexdump(0, cw_first->cw, 16, cw2, sizeof(cw2)); + + char ip1[20]="", ip2[20]=""; + if (check_client(er->cacheex_src)) + cs_strncpy(ip1, cs_inet_ntoa(er->cacheex_src->ip), sizeof(ip1)); + if (check_client(cw_first->cacheex_src)) + cs_strncpy(ip2, cs_inet_ntoa(cw_first->cacheex_src->ip), sizeof(ip2)); + else if (cw_first->selected_reader && check_client(cw_first->selected_reader->client)) + cs_strncpy(ip2, cs_inet_ntoa(cw_first->selected_reader->client->ip), sizeof(ip2)); + + debug_ecm(D_CACHEEX| D_CSP, "WARNING: Different CWs %s from %s(%s)<>%s(%s): %s<>%s ", buf, + er->from_csp ? "csp" : username(er->cacheex_src), ip1, + check_client(cw_first->cacheex_src)?username(cw_first->cacheex_src):(cw_first->selected_reader?cw_first->selected_reader->label:"unknown/csp"), ip2, + cw1, cw2); + } + } +#endif +} void add_cache(ECM_REQUEST *er){ if(!er->csp_hash) return; ECMHASH *result = NULL; CW *cw = NULL; -#ifdef CS_CACHEEX bool add_new_cw=false; -#endif pthread_rwlock_wrlock(&cache_lock); @@ -311,9 +358,7 @@ cw->prid = er->prid; cw->srvid = er->srvid; cw->selected_reader=er->selected_reader; - #ifdef CS_CACHEEX cw->cacheex_src=er->cacheex_src; - #endif cw->pushout_client = NULL; while(1){ @@ -327,9 +372,7 @@ add_hash_table(&result->ht_cw, &cw->ht_node, &result->ll_cw, &cw->ll_node, cw, cw->cw, sizeof(er->cw)); - #ifdef CS_CACHEEX add_new_cw=true; - #endif break; } @@ -341,14 +384,10 @@ //update if answered from csp/cacheex/local_proxy if(er->from_cacheex) cw->cacheex = 1; if(er->from_csp) cw->csp = 1; -#ifdef CS_CACHEEX if(!er->cacheex_src){ -#endif if(is_localreader(er->selected_reader, er)) cw->localcards=1; else cw->proxy = 1; -#ifdef CS_CACHEEX } -#endif //always update group and counter cw->grp |= er->grp; @@ -360,57 +399,10 @@ pthread_rwlock_unlock(&cache_lock); - -#ifdef CS_CACHEEX - - er->cw_cache=cw; - cacheex_cache_push(er); - - - //cacheex debug log lines and cw diff stuff - if(check_client(er->cacheex_src)){ - if(add_new_cw){ - debug_ecm(D_CACHEEX|D_CSP, "got pushed ECM %s from %s", buf, er->from_csp ? "csp" : username(er->cacheex_src)); - - CW *cw_first = get_first_cw(result, er); - - if(er && cw_first){ - - //compare er cw with mostly counted cached cw - if(memcmp(er->cw, cw_first->cw, sizeof(er->cw)) != 0) { - er->cacheex_src->cwcacheexerrcw++; - if (er->cacheex_src->account) - er->cacheex_src->account->cwcacheexerrcw++; - - if (((0x0200| 0x0800) & cs_dblevel)) { //avoid useless operations if debug is not enabled - char cw1[16*3+2], cw2[16*3+2]; - cs_hexdump(0, er->cw, 16, cw1, sizeof(cw1)); - cs_hexdump(0, cw_first->cw, 16, cw2, sizeof(cw2)); - - char ip1[20]="", ip2[20]=""; - if (check_client(er->cacheex_src)) - cs_strncpy(ip1, cs_inet_ntoa(er->cacheex_src->ip), sizeof(ip1)); - if (check_client(cw_first->cacheex_src)) - cs_strncpy(ip2, cs_inet_ntoa(cw_first->cacheex_src->ip), sizeof(ip2)); - else if (cw_first->selected_reader && check_client(cw_first->selected_reader->client)) - cs_strncpy(ip2, cs_inet_ntoa(cw_first->selected_reader->client->ip), sizeof(ip2)); - - debug_ecm(D_CACHEEX| D_CSP, "WARNING: Different CWs %s from %s(%s)<>%s(%s): %s<>%s ", buf, - er->from_csp ? "csp" : username(er->cacheex_src), ip1, - check_client(cw_first->cacheex_src)?username(cw_first->cacheex_src):(cw_first->selected_reader?cw_first->selected_reader->label:"unknown/csp"), ip2, - cw1, cw2); - } - } - - } - }else - debug_ecm(D_CACHEEX| D_CSP, "got duplicate pushed ECM %s from %s", buf, er->from_csp ? "csp" : username(er->cacheex_src)); - } - -#endif + cacheex_cache_add(er, result, cw, add_new_cw); } -void cleanup_cache(void){ +void cleanup_cache(bool force){ ECMHASH *ecmhash; CW *cw; struct s_pushclient *pc, *nxt; @@ -427,15 +419,20 @@ i_next = i->next; ecmhash = get_data_from_node(i); + if(!ecmhash){ + i = i_next; + continue; + } + cs_ftime(&now); gone_first = comp_timeb(&now, &ecmhash->first_recv_time); gone_upd = comp_timeb(&now, &ecmhash->upd_time); - if(ecmhash && gone_first<=(cfg.max_cache_time*1000)){ //not continue, useless check for nexts one! + if(!force && gone_first<=(cfg.max_cache_time*1000)){ //not continue, useless check for nexts one! break; } - if(ecmhash && gone_upd>(cfg.max_cache_time*1000)){ + if(force || gone_upd>(cfg.max_cache_time*1000)){ j = get_first_node_list(&ecmhash->ll_cw); while (j) { @@ -463,7 +460,7 @@ deinitialize_hash_table(&ecmhash->ht_cw); remove_elem_list(&ll_cache, &ecmhash->ll_node); remove_elem_hash_table(&ht_cache, &ecmhash->ht_node); - NULLFREE(ecmhash); + NULLFREE(ecmhash); } i = i_next; @@ -471,180 +468,3 @@ pthread_rwlock_unlock(&cache_lock); } - -#ifdef CS_CACHEEX -// HIT CACHE functions ************************************************************** - -typedef struct hit_key_t { - uint16_t caid; - uint32_t prid; - uint16_t srvid; -} HIT_KEY; - -typedef struct cache_hit_t { - HIT_KEY key; - struct timeb time; - uint64_t grp; - - node ht_node; - node ll_node; -} CACHE_HIT; - - -pthread_rwlock_t hitcache_lock; -hash_table ht_hitcache; -list ll_hitcache; - -void init_hitcache(void){ - init_hash_table(&ht_hitcache, &ll_hitcache); - if (pthread_rwlock_init(&hitcache_lock,NULL) != 0) - cs_log("Error creating lock hitcache_lock!"); -} - -uint32_t hitcache_size(void){ - return count_hash_table(&ht_hitcache); -} - -int compare_hitkey(const void *arg, const void *obj){ - if( ((const HIT_KEY*)arg)->caid==((const CACHE_HIT*)obj)->key.caid - && ((const HIT_KEY*)arg)->prid==((const CACHE_HIT*)obj)->key.prid - && ((const HIT_KEY*)arg)->srvid==((const CACHE_HIT*)obj)->key.srvid ) - return 0; - return 1; -} - -int32_t check_hitcache(ECM_REQUEST *er, struct s_client *cl) { - CACHE_HIT *result; - HIT_KEY search; - - memset(&search, 0, sizeof(HIT_KEY)); - search.caid = er->caid; - search.prid = er->prid; - search.srvid = er->srvid; - - pthread_rwlock_rdlock(&hitcache_lock); - result = find_hash_table(&ht_hitcache, &search, sizeof(HIT_KEY), &compare_hitkey); - if(result){ - - struct timeb now; - cs_ftime(&now); - int64_t gone = comp_timeb(&now, &result->time); - uint64_t grp = cl?cl->grp:0; - - if( - gone <= (cfg.max_hitcache_time*1000) - && - (!grp || !result->grp || (grp & result->grp)) - ){ - pthread_rwlock_unlock(&hitcache_lock); - return 1; - } - } - - pthread_rwlock_unlock(&hitcache_lock); - return 0; -} - - -void add_hitcache(struct s_client *cl, ECM_REQUEST *er) { - if (!cfg.max_hitcache_time) //we don't want check/save hitcache - return; - if (!cfg.cacheex_wait_timetab.n) - return; - uint32_t cacheex_wait_time = get_cacheex_wait_time(er,NULL); - if (!cacheex_wait_time) - return; - - CACHE_HIT *result; - HIT_KEY search; - - memset(&search, 0, sizeof(HIT_KEY)); - search.caid = er->caid; - search.prid = er->prid; - search.srvid = er->srvid; - - pthread_rwlock_wrlock(&hitcache_lock); - - result = find_hash_table(&ht_hitcache, &search, sizeof(HIT_KEY), &compare_hitkey); - if(!result){ //not found, add it! - - if(cs_malloc(&result, sizeof(CACHE_HIT))){ - memset(result, 0, sizeof(CACHE_HIT)); - result->key.caid = er->caid; - result->key.prid = er->prid; - result->key.srvid = er->srvid; - - add_hash_table(&ht_hitcache, &result->ht_node, &ll_hitcache, &result->ll_node, result, &result->key, sizeof(HIT_KEY)); - } - } - - if(result){ - if(cl) result->grp |= cl->grp; - cs_ftime(&result->time); //always update time; - } - - pthread_rwlock_unlock(&hitcache_lock); -} - - -void del_hitcache(ECM_REQUEST *er) { - HIT_KEY search; - - memset(&search, 0, sizeof(HIT_KEY)); - search.caid = er->caid; - search.prid = er->prid; - search.srvid = er->srvid; - - pthread_rwlock_wrlock(&hitcache_lock); - search_remove_elem_hash_table(&ht_hitcache, &search, sizeof(HIT_KEY), &compare_hitkey); - pthread_rwlock_unlock(&hitcache_lock); -} - - -void cleanup_hitcache(void) { - CACHE_HIT *cachehit; - node *i,*i_next; - struct timeb now; - int64_t gone; - - int32_t timeout = (cfg.max_hitcache_time + (cfg.max_hitcache_time / 2))*1000; //1,5 - - pthread_rwlock_wrlock(&hitcache_lock); - - i = get_first_node_list(&ll_hitcache); - while (i) { - i_next = i->next; - cachehit = get_data_from_node(i); - - cs_ftime(&now); - gone = comp_timeb(&now, &cachehit->time); - - if(cachehit && gone>timeout){ - remove_elem_list(&ll_hitcache, &cachehit->ll_node); - remove_elem_hash_table(&ht_hitcache, &cachehit->ht_node); - NULLFREE(cachehit); - } - - i = i_next; - } - - pthread_rwlock_unlock(&hitcache_lock); -} -#endif - - -// CSP HASH functions ************************************************************** -static int32_t cacheex_ecm_hash_calc(uchar *buf, int32_t n) -{ - int32_t i, h = 0; - for(i = 0; i < n; i++) - { - h = 31 * h + buf[i]; - } - return h; -} - -void cacheex_update_hash(ECM_REQUEST *er) -{ - er->csp_hash = cacheex_ecm_hash_calc(er->ecm + 3, er->ecmlen - 3); -} diff -Nru oscam-1.20-10584~r10356/oscam-cache.h oscam-1.20-10797~r10569/oscam-cache.h --- oscam-1.20-10584~r10356/oscam-cache.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-cache.h 2015-02-20 11:57:49.000000000 +0000 @@ -2,25 +2,13 @@ #define OSCAM_CACHE_H_ void init_cache(void); +void free_cache(void); void add_cache(ECM_REQUEST *er); struct ecm_request_t *check_cache(ECM_REQUEST *er, struct s_client *cl); -void cleanup_cache(void); +void cleanup_cache(bool force); void remove_client_from_cache(struct s_client *cl); uint32_t cache_size(void); -void cacheex_update_hash(ECM_REQUEST *er); uint8_t get_odd_even(ECM_REQUEST *er); - -#ifdef CS_CACHEEX uint8_t check_is_pushed(void *cw, struct s_client *cl); -void init_hitcache(void); -void add_hitcache(struct s_client *cl, ECM_REQUEST *er); -void del_hitcache(ECM_REQUEST *er); -struct csp_ce_hit_t *check_hitcache(ECM_REQUEST *er, struct s_client *cl); -void cleanup_hitcache(void); -uint32_t hitcache_size(void); -#else -static inline void init_hitcache(void) { } -#endif - #endif diff -Nru oscam-1.20-10584~r10356/oscam-chk.c oscam-1.20-10797~r10569/oscam-chk.c --- oscam-1.20-10584~r10356/oscam-chk.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-chk.c 2015-02-20 11:57:49.000000000 +0000 @@ -16,16 +16,7 @@ uint32_t get_fallbacktimeout(uint16_t caid) { - uint32_t ftimeout = 0; - int32_t i; - for(i = 0; i < cfg.ftimeouttab.n; i++) - { - if(cfg.ftimeouttab.caid[i] == caid || cfg.ftimeouttab.caid[i] == caid >> 8) - { - ftimeout = cfg.ftimeouttab.value[i]; - break; - } - } + uint32_t ftimeout = caidvaluetab_get_value(&cfg.ftimeouttab, caid, 0); if(ftimeout == 0) { ftimeout = cfg.ftimeout; } @@ -265,15 +256,15 @@ TUNTAB *ttab; ttab = &cl->ttab; - if(ttab->n) + if(ttab->ttdata) { - for(i = 0; i < ttab->n; i++) + for(i = 0; i < ttab->ttnum; i++) { - if(er->caid == ttab->bt_caidfrom[i]) + if(er->caid == ttab->ttdata[i].bt_caidfrom) { - if(er->srvid == ttab->bt_srvid[i]) { return ttab->bt_caidto[i]; } - if(chk_sx && ttab->bt_srvid[i] == 0xFFFF) { return ttab->bt_caidto[i]; } - if(!chk_sx && !ttab->bt_srvid[i]) { return ttab->bt_caidto[i]; } + if(er->srvid == ttab->ttdata[i].bt_srvid) { return ttab->ttdata[i].bt_caidto; } + if(chk_sx && ttab->ttdata[i].bt_srvid == 0xFFFF) { return ttab->ttdata[i].bt_caidto; } + if(!chk_sx && !ttab->ttdata[i].bt_srvid) { return ttab->ttdata[i].bt_caidto; } } } } @@ -552,17 +543,18 @@ int32_t chk_ctab(uint16_t caid, CAIDTAB *ctab) { - if(!caid || !ctab->caid[0]) + if(!caid || !ctab->ctnum) { return 1; } int32_t i; - for(i = 0; i < CS_MAXCAIDTAB; i++) + for(i = 0; i < ctab->ctnum; i++) { - if(!ctab->caid[i]) + CAIDTAB_DATA *d = &ctab->ctdata[i]; + if(!d->caid) { return 0; } - if((caid & ctab->mask[i]) == ctab->caid[i]) + if((caid & d->mask) == d->caid) { return 1; } } return 0; @@ -570,17 +562,18 @@ int32_t chk_ctab_ex(uint16_t caid, CAIDTAB *ctab) { - if(!caid || !ctab->caid[0]) + if(!caid || !ctab->ctnum) { return 0; } int32_t i; - for(i = 0; i < CS_MAXCAIDTAB; i++) + for(i = 0; i < ctab->ctnum; i++) { - if(!ctab->caid[i]) + CAIDTAB_DATA *d = &ctab->ctdata[i]; + if(!d->caid) { return 0; } - if((caid & ctab->mask[i]) == ctab->caid[i]) + if((caid & d->mask) == d->caid) { return 1; } } return 0; @@ -819,30 +812,20 @@ } //Checking ecmlength: - if(rdr->ecmWhitelist && er->ecmlen) + if(rdr->ecm_whitelist.ewnum && er->ecmlen) { - struct s_ecmWhitelist *tmp; - struct s_ecmWhitelistIdent *tmpIdent; - struct s_ecmWhitelistLen *tmpLen; + int32_t i; int8_t ok = 0, foundident = 0; - for(tmp = rdr->ecmWhitelist; tmp; tmp = tmp->next) + for (i = 0; i < rdr->ecm_whitelist.ewnum; i++) { - if(tmp->caid == 0 || tmp->caid == er->caid) + ECM_WHITELIST_DATA *d = &rdr->ecm_whitelist.ewdata[i]; + if ((d->caid == 0 || d->caid == er->caid) && (d->ident == 0 || d->ident == er->prid)) { - for(tmpIdent = tmp->idents; tmpIdent; tmpIdent = tmpIdent->next) + foundident = 1; + if (d->len == er->ecmlen) { - if(tmpIdent->ident == 0 || tmpIdent->ident == er->prid) - { - foundident = 1; - for(tmpLen = tmpIdent->lengths; tmpLen; tmpLen = tmpLen->next) - { - if(tmpLen->len == er->ecmlen) - { - ok = 1; - break; - } - } - } + ok = 1; + break; } } } @@ -855,7 +838,7 @@ } // ECM Header Check - if(rdr->ecmHeaderwhitelist && er->ecmlen) + if(rdr->ecm_hdr_whitelist.ehdata && er->ecmlen) { int8_t byteok = 0; int8_t entryok = 0; @@ -864,9 +847,10 @@ int16_t len = 0; int32_t i = 0; int8_t skip = 0; - struct s_ecmHeaderwhitelist *tmp; - for(tmp = rdr->ecmHeaderwhitelist; tmp; tmp = tmp->next) + int32_t r; + for(r = 0; r < rdr->ecm_hdr_whitelist.ehnum; r++) { + ECM_HDR_WHITELIST_DATA *tmp = &rdr->ecm_hdr_whitelist.ehdata[r]; skip = 0; byteok = 0; entryok = 0; @@ -967,11 +951,15 @@ int32_t chk_caid(uint16_t caid, CAIDTAB *ctab) { - int32_t n, rc; - for(rc = -1, n = 0; (n < CS_MAXCAIDTAB) && (rc < 0); n++) - if((caid & ctab->mask[n]) == ctab->caid[n]) - { rc = ctab->cmap[n] ? ctab->cmap[n] : caid; } - return rc; + int32_t i; + if (!ctab->ctnum) return caid; + for(i = 0; i < ctab->ctnum; i++) + { + CAIDTAB_DATA *d = &ctab->ctdata[i]; + if((caid & d->mask) == d->caid) + return d->cmap ? d->cmap : caid; + } + return -1; } int32_t chk_caid_rdr(struct s_reader *rdr, uint16_t caid) @@ -1082,3 +1070,15 @@ { return true; } return false; } + +uint16_t caidvaluetab_get_value(CAIDVALUETAB *cv, uint16_t caid, uint16_t default_value) +{ + int32_t i; + for(i = 0; i < cv->cvnum; i++) + { + CAIDVALUETAB_DATA *cvdata = &cv->cvdata[i]; + if(cvdata->caid == caid || cvdata->caid == caid >> 8) + return cvdata->value; + } + return default_value; +} diff -Nru oscam-1.20-10584~r10356/oscam-chk.h oscam-1.20-10797~r10569/oscam-chk.h --- oscam-1.20-10584~r10356/oscam-chk.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-chk.h 2015-02-20 11:57:49.000000000 +0000 @@ -36,5 +36,6 @@ int8_t chk_halfCW(ECM_REQUEST *er, uchar *cw); int32_t chk_is_null_nodeid(uint8_t node_id[], uint8_t len); bool check_client(struct s_client *cl); +uint16_t caidvaluetab_get_value(CAIDVALUETAB *cv, uint16_t caid, uint16_t default_value); #endif diff -Nru oscam-1.20-10584~r10356/oscam-client.c oscam-1.20-10797~r10569/oscam-client.c --- oscam-1.20-10584~r10356/oscam-client.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-client.c 2015-02-20 11:57:49.000000000 +0000 @@ -6,6 +6,8 @@ #include "module-anticasc.h" #include "module-cccam.h" #include "module-webif.h" +#include "oscam-array.h" +#include "oscam-conf-chk.h" #include "oscam-client.h" #include "oscam-ecm.h" #include "oscam-failban.h" @@ -70,7 +72,7 @@ const char *client_get_proto(struct s_client *cl) { - char *ctyp; + const char *ctyp; switch(cl->typ) { case 's': @@ -264,15 +266,13 @@ } while(found || cl->tid == 0); } - for(last = first_client; last->next != NULL; last = last->next) + for(last = first_client; last && last->next; last = last->next) { ; } //ends with cl on last client - last->next = cl; + if (last) + last->next = cl; int32_t bucket = (uintptr_t)cl / 16 % CS_CLIENT_HASHBUCKETS; cl->nexthashed = first_client_hashed[bucket]; first_client_hashed[bucket] = cl; -#ifdef MODULE_GBOX - cl->gbox_peer_id = 0; -#endif cs_writeunlock(&clientlist_lock); return cl; } @@ -420,15 +420,15 @@ client->autoau = account->autoau; client->tosleep = (60 * account->tosleep); client->c35_sleepsend = account->c35_sleepsend; - memcpy(&client->ctab, &account->ctab, sizeof(client->ctab)); + caidtab_clone(&account->ctab, &client->ctab); if(account->uniq) { cs_fake_client(client, account->usr, account->uniq, client->ip); } - client->ftab = account->ftab; // IDENT filter client->cltab = account->cltab; // CLASS filter - client->fchid = account->fchid; // CHID filter + ftab_clone(&account->ftab, &client->ftab); // IDENT filter + ftab_clone(&account->fchid, &client->fchid); // CHID filter client->sidtabs.ok = account->sidtabs.ok; // services client->sidtabs.no = account->sidtabs.no; // services - memcpy(&client->ttab, &account->ttab, sizeof(client->ttab)); + tuntab_clone(&account->ttab, &client->ttab); ac_init_client(client, account); } } @@ -532,18 +532,21 @@ cl->c35_sleepsend = account->c35_sleepsend; cl->monlvl = account->monlvl; cl->disabled = account->disabled; - cl->fchid = account->fchid; // CHID filters cl->cltab = account->cltab; // Class // newcamd module doesn't like ident reloading if(!cl->ncd_server) - { cl->ftab = account->ftab; } // Ident + { + ftab_clone(&account->ftab, &cl->ftab); // IDENT filter + ftab_clone(&account->fchid, &cl->fchid); // CHID filter + } cl->sidtabs.ok = account->sidtabs.ok; // services cl->sidtabs.no = account->sidtabs.no; // services cl->failban = account->failban; - memcpy(&cl->ctab, &account->ctab, sizeof(cl->ctab)); - memcpy(&cl->ttab, &account->ttab, sizeof(cl->ttab)); + caidtab_clone(&account->ctab, &cl->ctab); + + tuntab_clone(&account->ttab, &cl->ttab); webif_client_reset_lastresponsetime(cl); if(account->uniq) @@ -678,7 +681,7 @@ // Clean reader. The cleaned structures should be only used by the reader thread, so we should be save without waiting if(rdr) { - add_garbage(rdr->emmcache); + ll_destroy_data(&rdr->emmstat); remove_reader_from_active(rdr); cs_sleepms(1000); //just wait a bit that really really nobody is accessing client data @@ -721,11 +724,16 @@ cl->ecmtask = NULL; } - if(cl->cascadeusers) - { - ll_destroy_data(cl->cascadeusers); - cl->cascadeusers = NULL; - } + ll_destroy_data(&cl->cascadeusers); + + ftab_clear(&cl->ftab); + ftab_clear(&cl->fchid); + tuntab_clear(&cl->ttab); + caidtab_clear(&cl->ctab); + + NULLFREE(cl->cw_rass); + NULLFREE(cl->via_rass); + NULLFREE(cl->aes_keys); #ifdef MODULE_CCCAM add_garbage(cl->cc); diff -Nru oscam-1.20-10584~r10356/oscam-conf-chk.c oscam-1.20-10797~r10569/oscam-conf-chk.c --- oscam-1.20-10584~r10356/oscam-conf-chk.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-conf-chk.c 2015-02-20 11:57:49.000000000 +0000 @@ -1,6 +1,7 @@ #define MODULE_LOG_PREFIX "config" #include "globals.h" +#include "oscam-array.h" #include "oscam-conf-chk.h" #include "oscam-garbage.h" #include "oscam-net.h" @@ -45,62 +46,55 @@ clear_sip(&lip); } -void chk_caidtab(char *caidasc, CAIDTAB *ctab) +void chk_caidtab(char *value, CAIDTAB *caidtab) { - int32_t i; - char *ptr1, *ptr2, *ptr3, *saveptr1 = NULL; - CAIDTAB newctab; - memset(&newctab, 0, sizeof(CAIDTAB)); - for(i = 1; i < CS_MAXCAIDTAB; newctab.mask[i++] = 0xffff) { ; } - - for(i = 0, ptr1 = strtok_r(caidasc, ",", &saveptr1); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1)) - { - uint32_t caid, mask, cmap; - if((ptr3 = strchr(trim(ptr1), ':'))) - { * ptr3++ = '\0'; } - else - { ptr3 = ""; } - - if((ptr2 = strchr(trim(ptr1), '&'))) - { * ptr2++ = '\0'; } - else - { ptr2 = ""; } - - if(((caid = a2i(ptr1, 2)) | (mask = a2i(ptr2, -2)) | (cmap = a2i(ptr3, 2))) < 0x10000) - { - newctab.caid[i] = caid; - newctab.mask[i] = mask; - newctab.cmap[i++] = cmap; - } + caidtab_clear(caidtab); + char *ptr, *saveptr1 = NULL; + for(ptr = strtok_r(value, ",", &saveptr1); ptr; ptr = strtok_r(NULL, ",", &saveptr1)) + { + CAIDTAB_DATA d; + memset(&d, 0, sizeof(d)); + d.mask = 0xffff; + char *caid_end_ptr = strchr(ptr, ':'); // caid_end_ptr + 1 -> cmap + if(caid_end_ptr) { + *caid_end_ptr++ = '\0'; + d.cmap = a2i(caid_end_ptr, 2); + if (errno == EINVAL) continue; + } + char *mask_start_ptr = strchr(ptr, '&'); // mask_start_ptr + 1 -> mask + errno = 0; + if(mask_start_ptr) { // Mask is optional + *mask_start_ptr++ = '\0'; + d.mask = a2i(mask_start_ptr, 2); + if (errno == EINVAL) continue; + } + d.caid = a2i(ptr, 2); + if (errno == EINVAL) continue; + if (d.caid || d.cmap) + caidtab_add(caidtab, &d); } - memcpy(ctab, &newctab, sizeof(CAIDTAB)); } -void chk_caidvaluetab(char *lbrlt, CAIDVALUETAB *tab, int32_t minvalue) +void chk_caidvaluetab(char *value, CAIDVALUETAB *caidvaluetab) { - int32_t i; - char *ptr1, *ptr2, *saveptr1 = NULL; - CAIDVALUETAB newtab; - memset(&newtab, 0, sizeof(CAIDVALUETAB)); - - for(i = 0, ptr1 = strtok_r(lbrlt, ",", &saveptr1); (i < CS_MAX_CAIDVALUETAB) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1)) + caidvaluetab_clear(caidvaluetab); + char *ptr, *saveptr1 = NULL; + for(ptr = strtok_r(value, ",", &saveptr1); ptr; ptr = strtok_r(NULL, ",", &saveptr1)) { - int32_t caid, value; - - if((ptr2 = strchr(trim(ptr1), ':'))) - { * ptr2++ = '\0'; } - else - { ptr2 = ""; } - - if(((caid = a2i(ptr1, 2)) < 0xFFFF) | ((value = atoi(ptr2)) < 10000)) - { - newtab.caid[i] = caid; - if(value < minvalue) { value = minvalue; } - newtab.value[i] = value; - newtab.n = ++i; - } + CAIDVALUETAB_DATA d; + memset(&d, 0, sizeof(d)); + char *caid_end_ptr = strchr(ptr, ':'); // caid_end_ptr + 1 -> value + if(!caid_end_ptr) + continue; + *caid_end_ptr++ = '\0'; + errno = 0; + d.caid = a2i(ptr, 2); + if (errno == EINVAL) + continue; + d.value = atoi(caid_end_ptr); + if (d.caid && d.value < 10000) + caidvaluetab_add(caidvaluetab, &d); } - memcpy(tab, &newtab, sizeof(CAIDVALUETAB)); } void chk_cacheex_valuetab(char *lbrlt, CECSPVALUETAB *tab) @@ -273,32 +267,29 @@ void chk_tuntab(char *tunasc, TUNTAB *ttab) { int32_t i; - char *ptr1, *ptr2, *ptr3, *saveptr1 = NULL; - TUNTAB newttab; - memset(&newttab, 0 , sizeof(TUNTAB)); - - for(i = 0, ptr1 = strtok_r(tunasc, ",", &saveptr1); (i < CS_MAXTUNTAB) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1)) - { - uint32_t bt_caidfrom, bt_caidto, bt_srvid; - if((ptr3 = strchr(trim(ptr1), ':'))) - { * ptr3++ = '\0'; } - else - { ptr3 = ""; } - - if((ptr2 = strchr(trim(ptr1), '.'))) - { * ptr2++ = '\0'; } - else - { ptr2 = ""; } - - if((bt_caidfrom = a2i(ptr1, 2)) | (bt_srvid = a2i(ptr2, -2)) | (bt_caidto = a2i(ptr3, 2))) - { - newttab.bt_caidfrom[i] = bt_caidfrom; - newttab.bt_caidto[i] = bt_caidto; - newttab.bt_srvid[i++] = bt_srvid; - newttab.n = i; - } + tuntab_clear(ttab); + errno = 0; + char *caid_ptr, *savecaid_ptr = NULL; + for(i = 0, caid_ptr = strtok_r(tunasc, ",", &savecaid_ptr); (caid_ptr); caid_ptr = strtok_r(NULL, ",", &savecaid_ptr), i++) + { + TUNTAB_DATA d; + char *srvid_ptr = strchr(trim(caid_ptr), '.'); + char *caidto_ptr = strchr(trim(caid_ptr), ':'); + if (!srvid_ptr) + continue; + *srvid_ptr++ = '\0'; + if (caidto_ptr) + *caidto_ptr++ = '\0'; + d.bt_caidfrom = a2i(caid_ptr, 2); + d.bt_srvid = a2i(srvid_ptr, 2); + d.bt_caidto = 0; + if (caidto_ptr) + d.bt_caidto = a2i(caidto_ptr, 2); + if (errno == EINVAL) + continue; + if (d.bt_caidfrom | d.bt_srvid | d.bt_caidto) + tuntab_add(ttab, &d); } - memcpy(ttab, &newttab, sizeof(TUNTAB)); } void chk_services(char *labels, SIDTABS *sidtabs) @@ -320,53 +311,40 @@ sidtabs->no = newsidno; } -void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName) +void chk_ftab(char *value, FTAB *ftab) { - int32_t i, j; - char *ptr1, *ptr2, *ptr3, *saveptr1 = NULL; - char *ptr[CS_MAXFILTERS] = {0}; - FTAB newftab; - memset(&newftab, 0, sizeof(FTAB)); - - for(i = 0, ptr1 = strtok_r(zFilterAsc, ";", &saveptr1); (i < CS_MAXFILTERS) && (ptr1); ptr1 = strtok_r(NULL, ";", &saveptr1), i++) - { - ptr[i] = ptr1; - if((ptr2 = strchr(trim(ptr1), ':'))) - { - *ptr2++ = '\0'; - newftab.filts[i].caid = (uint16_t)a2i(ptr1, 4); - ptr[i] = ptr2; - } - else if(zFiltName && zFiltName[0] == 'c') - { - cs_log("PANIC: CAID field not found in CHID parameter!"); - return; - } - else if(zFiltName && (zFiltName[0] == 'f' || zFiltName[0] == 'l') ) - { - newftab.filts[i].caid = (uint16_t)a2i(ptr1, 4); - ptr[i] = NULL; - } - newftab.nfilts++; - } - - if(newftab.nfilts) - { - cs_log_dbg(D_CLIENT, "%s '%s' %s filter(s):", zType, zName, zFiltName); - } - for(i = 0; i < newftab.nfilts; i++) + ftab_clear(ftab); + char *ptr1, *saveptr1 = NULL; + errno = 0; + for(ptr1 = strtok_r(value, ";", &saveptr1); (ptr1); ptr1 = strtok_r(NULL, ";", &saveptr1)) { - cs_log_dbg(D_CLIENT, "CAID #%d: %04X", i, newftab.filts[i].caid); - if(zFiltName && (zFiltName[0] == 'f' || zFiltName[0] == 'l') && ptr[i] == NULL) { continue; } - for(j = 0, ptr3 = strtok_r(ptr[i], ",", &saveptr1); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok_r(NULL, ",", &saveptr1), j++) + FILTER d; + memset(&d, 0, sizeof(d)); + char *caid_end_ptr = strchr(ptr1, ':'); // caid_end_ptr + 1 -> headers + if(!caid_end_ptr) + continue; + caid_end_ptr[0] = '\0'; + d.caid = a2i(ptr1, 4); + if (!d.caid || errno == EINVAL) + { + errno = 0; + continue; + } + ptr1 = caid_end_ptr + 1; // -> headers + char *ident_ptr, *saveident_ptr = NULL; + for(ident_ptr = strtok_r(ptr1, ",", &saveident_ptr); ident_ptr && d.nprids < ARRAY_SIZE(d.prids); ident_ptr = strtok_r(NULL, ",", &saveident_ptr)) { - newftab.filts[i].prids[j] = a2i(ptr3, 6); - newftab.filts[i].nprids++; - cs_log_dbg(D_CLIENT, "%s #%d: %06X", zFiltName, j, newftab.filts[i].prids[j]); + uint32_t ident = a2i(ident_ptr, 4); + if (errno == EINVAL) + { + errno = 0; + continue; + } + d.prids[d.nprids++] = ident; } + if (d.nprids) + ftab_add(ftab, &d); } - - memcpy(ftab, &newftab, sizeof(FTAB)); } void chk_cltab(char *classasc, CLASSTAB *clstab) @@ -459,28 +437,97 @@ NULLFREE(newptab); } -/* Clears the s_ip structure provided. The pointer will be set to NULL so everything is cleared.*/ -void clear_sip(struct s_ip **sip) +void chk_ecm_whitelist(char *value, ECM_WHITELIST *ecm_whitelist) { - struct s_ip *cip = *sip; - for(*sip = NULL; cip != NULL; cip = cip->next) + ecm_whitelist_clear(ecm_whitelist); + char *ptr, *saveptr1 = NULL; + for(ptr = strtok_r(value, ";", &saveptr1); ptr; ptr = strtok_r(NULL, ";", &saveptr1)) { - add_garbage(cip); + ECM_WHITELIST_DATA d; + memset(&d, 0, sizeof(d)); + char *caid_end_ptr = strchr(ptr, ':'); // caid_end_ptr + 1 -> headers + char *provid_ptr = strchr(ptr, '@'); // provid_ptr + 1 -> provid + char *headers = ptr; + if(caid_end_ptr) + { + caid_end_ptr[0] = '\0'; + if (provid_ptr) + { + provid_ptr[0] = '\0'; + provid_ptr++; + d.ident = a2i(provid_ptr, 6); + } + d.caid = dyn_word_atob(ptr); + headers = caid_end_ptr + 1; // -> headers + } else if(provid_ptr) { + provid_ptr[0] = '\0'; + d.ident = a2i(provid_ptr, 6); + } + if (d.caid == 0xffff) d.caid = 0; + if (d.ident == 0xffff) d.ident = 0; + char *len_ptr, *savelen_ptr = NULL; + for(len_ptr = strtok_r(headers, ",", &savelen_ptr); len_ptr; len_ptr = strtok_r(NULL, ",", &savelen_ptr)) + { + d.len = dyn_word_atob(len_ptr); + if (d.len == 0xffff) + continue; + ecm_whitelist_add(ecm_whitelist, &d); + } + } +} + +void chk_ecm_hdr_whitelist(char *value, ECM_HDR_WHITELIST *ecm_hdr_whitelist) +{ + ecm_hdr_whitelist_clear(ecm_hdr_whitelist); + char *ptr, *saveptr = NULL; + for(ptr = strtok_r(value, ";", &saveptr); ptr; ptr = strtok_r(NULL, ";", &saveptr)) + { + ECM_HDR_WHITELIST_DATA d; + memset(&d, 0, sizeof(d)); + char *caid_end_ptr = strchr(ptr, ':'); // caid_end_ptr + 1 -> headers + char *provid_ptr = strchr(ptr, '@'); // provid_ptr + 1 -> provid + char *headers = ptr; + if(caid_end_ptr) + { + caid_end_ptr[0] = '\0'; + if (provid_ptr) + { + provid_ptr[0] = '\0'; + provid_ptr++; + d.provid = a2i(provid_ptr, 6); + } + d.caid = dyn_word_atob(ptr); + headers = caid_end_ptr + 1; // -> headers + } else if(provid_ptr) { + provid_ptr[0] = '\0'; + d.provid = a2i(provid_ptr, 6); + } + if (d.caid == 0xffff) d.caid = 0; + if (d.provid == 0xffff) d.provid = 0; + char *hdr_ptr, *savehdr_ptr = NULL; + for(hdr_ptr = strtok_r(headers, ",", &savehdr_ptr); hdr_ptr; hdr_ptr = strtok_r(NULL, ",", &savehdr_ptr)) + { + hdr_ptr = trim(hdr_ptr); + d.len = strlen(hdr_ptr); + if (d.len / 2 > sizeof(d.header)) + d.len = sizeof(d.header) * 2; + if (d.len > 1) + { + key_atob_l(hdr_ptr, d.header, d.len); + ecm_hdr_whitelist_add(ecm_hdr_whitelist, &d); + } + } } } -/* Clears the s_ftab struct provided by setting nfilts and nprids to zero. */ -void clear_ftab(struct s_ftab *ftab) +/* Clears the s_ip structure provided. The pointer will be set to NULL so everything is cleared.*/ +void clear_sip(struct s_ip **sip) { - int32_t i, j; - for(i = 0; i < CS_MAXFILTERS; i++) + struct s_ip *cip = *sip; + for(*sip = NULL; cip != NULL; cip = cip->next) { - ftab->filts[i].caid = 0; - for(j = 0; j < CS_MAXPROV; j++) - { ftab->filts[i].prids[j] = 0; } - ftab->filts[i].nprids = 0; + add_garbage(cip); } - ftab->nfilts = 0; } /* Clears the s_ptab struct provided by setting nfilts and nprids to zero. */ @@ -500,23 +547,9 @@ } } -/* Clears given caidtab */ -void clear_caidtab(struct s_caidtab *ctab) -{ - memset(ctab, 0, sizeof(struct s_caidtab)); - int32_t i; - for(i = 1; i < CS_MAXCAIDTAB; ctab->mask[i++] = 0xffff) { ; } -} - /* Clears given csptab */ void clear_cacheextab(CECSPVALUETAB *ctab) { memset(ctab, -1, sizeof(CECSPVALUETAB)); ctab->n = 0; } - -/* Clears given tuntab */ -void clear_tuntab(struct s_tuntab *ttab) -{ - memset(ttab, 0, sizeof(struct s_tuntab)); -} diff -Nru oscam-1.20-10584~r10356/oscam-conf-chk.h oscam-1.20-10797~r10569/oscam-conf-chk.h --- oscam-1.20-10584~r10356/oscam-conf-chk.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-conf-chk.h 2015-02-20 11:57:49.000000000 +0000 @@ -2,22 +2,21 @@ #define OSCAM_CONF_CHK_H void chk_iprange(char *value, struct s_ip **base); -void chk_caidtab(char *caidasc, CAIDTAB *ctab); -void chk_caidvaluetab(char *lbrlt, CAIDVALUETAB *tab, int32_t minvalue); +void chk_caidtab(char *value, CAIDTAB *caidtab); +void chk_caidvaluetab(char *value, CAIDVALUETAB *tab); void chk_cacheex_valuetab(char *lbrlt, CECSPVALUETAB *tab); void chk_cacheex_cwcheck_valuetab(char *lbrlt, CWCHECKTAB *tab); void chk_cacheex_hitvaluetab(char *lbrlt, CECSPVALUETAB *tab); void chk_tuntab(char *tunasc, TUNTAB *ttab); void chk_services(char *labels, SIDTABS *sidtabs); -void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName); +void chk_ftab(char *value, FTAB *ftab); void chk_cltab(char *classasc, CLASSTAB *clstab); void chk_port_tab(char *portasc, PTAB *ptab); +void chk_ecm_whitelist(char *value, ECM_WHITELIST *ecm_whitelist); +void chk_ecm_hdr_whitelist(char *value, ECM_HDR_WHITELIST *ecm_hdr_whitelist); void clear_sip(struct s_ip **sip); -void clear_ftab(struct s_ftab *ftab); void clear_ptab(struct s_ptab *ptab); -void clear_caidtab(struct s_caidtab *ctab); void clear_cacheextab(CECSPVALUETAB *ctab); -void clear_tuntab(struct s_tuntab *ttab); #endif diff -Nru oscam-1.20-10584~r10356/oscam-config-account.c oscam-1.20-10797~r10569/oscam-config-account.c --- oscam-1.20-10584~r10356/oscam-config-account.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-config-account.c 2015-02-20 11:57:49.000000000 +0000 @@ -2,6 +2,7 @@ #include "globals.h" #include "module-anticasc.h" +#include "oscam-array.h" #include "oscam-client.h" #include "oscam-conf.h" #include "oscam-conf-chk.h" @@ -240,7 +241,7 @@ { if(strlen(value) == 0) { - clear_tuntab(ttab); + tuntab_clear(ttab); } else { @@ -248,7 +249,7 @@ } return; } - if(ttab->bt_caidfrom[0] || cfg.http_full_cfg) + if((ttab->ttdata && ttab->ttdata[0].bt_caidfrom) || cfg.http_full_cfg) { value = mk_t_tuntab(ttab); fprintf_conf(f, token, "%s\n", value); @@ -493,9 +494,16 @@ { struct s_auth *ptr_next; ptr_next = ptr->next; - ll_destroy(ptr->aureader_list); + ll_destroy(&ptr->aureader_list); ptr->next = NULL; config_list_gc_values(account_opts, ptr); + ftab_clear(&ptr->ftab); + ftab_clear(&ptr->fchid); + tuntab_clear(&ptr->ttab); + caidtab_clear(&ptr->ctab); +#ifdef WITH_LB + caidvaluetab_clear(&ptr->lb_nbest_readers_tab); +#endif add_garbage(ptr); ptr = ptr_next; } diff -Nru oscam-1.20-10584~r10356/oscam-config-global.c oscam-1.20-10797~r10569/oscam-config-global.c --- oscam-1.20-10584~r10356/oscam-config-global.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-config-global.c 2015-02-20 11:57:49.000000000 +0000 @@ -3,6 +3,7 @@ #include "globals.h" #include "module-dvbapi.h" #include "module-gbox.h" +#include "oscam-array.h" #include "oscam-conf.h" #include "oscam-conf-chk.h" #include "oscam-conf-mk.h" @@ -134,13 +135,14 @@ CAIDTAB *caid_table = setting; if(value) { - if(strlen(value) == 0) - { clear_caidtab(caid_table); } - else - { chk_caidtab(value, caid_table); } + if(strlen(value)) { + chk_caidtab(value, caid_table); + } else { + caidtab_clear(caid_table); + } return; } - if(caid_table->caid[0] || cfg.http_full_cfg) + if(caid_table->ctnum || cfg.http_full_cfg) { value = mk_t_caidtab(caid_table); fprintf_conf(f, token, "%s\n", value); @@ -152,13 +154,25 @@ void caidvaluetab_fn(const char *token, char *value, void *setting, FILE *f) { CAIDVALUETAB *caid_value_table = setting; - int limit = streq(token, "lb_retrylimits") ? 50 : 1; if(value) { - chk_caidvaluetab(value, caid_value_table, limit); + if (strlen(value)) { + chk_caidvaluetab(value, caid_value_table); + if (streq(token, "lb_retrylimits")) + { + int32_t i; + for (i = 0; i < caid_value_table->cvnum; i++) + { + if (caid_value_table->cvdata[i].value < 50) + caid_value_table->cvdata[i].value = 50; + } + } + } else { + caidvaluetab_clear(caid_value_table); + } return; } - if(caid_value_table->n > 0 || cfg.http_full_cfg) + if(caid_value_table->cvnum || cfg.http_full_cfg) { value = mk_t_caidvaluetab(caid_value_table); fprintf_conf(f, token, "%s\n", value); @@ -496,7 +510,7 @@ DEF_OPT_STR("httppiconpath" , OFS(http_piconpath), NULL), DEF_OPT_STR("httphelplang" , OFS(http_help_lang), "en"), DEF_OPT_STR("httplocale" , OFS(http_locale), NULL), - DEF_OPT_INT32("http_prepend_embedded_css" , OFS(http_prepend_embedded_css), 0), + DEF_OPT_INT8("http_prepend_embedded_css" , OFS(http_prepend_embedded_css), 0), DEF_OPT_INT32("httprefresh" , OFS(http_refresh), 0), DEF_OPT_INT32("httppollrefresh" , OFS(poll_refresh), 60), DEF_OPT_INT8("httphideidleclients" , OFS(http_hide_idle_clients), 0), @@ -518,6 +532,9 @@ DEF_OPT_INT32("aulow" , OFS(aulow), 30), DEF_OPT_INT32("hideclient_to" , OFS(hideclient_to), 25), DEF_OPT_STR("httposcamlabel" , OFS(http_oscam_label), "OSCam"), + DEF_OPT_INT32("httpemmuclean" , OFS(http_emmu_clean), 256), + DEF_OPT_INT32("httpemmsclean" , OFS(http_emms_clean), -1), + DEF_OPT_INT32("httpemmgclean" , OFS(http_emmg_clean), -1), #ifdef WEBIF_LIVELOG DEF_OPT_INT8("http_status_log" , OFS(http_status_log), 0), #else @@ -571,7 +588,7 @@ || cfg.cacheex_wait_timetab.n || cfg.cacheex_enable_stats > 0 || cfg.csp_port || cfg.csp.filter_caidtab.n || cfg.csp.allow_request == 0 || cfg.csp.allow_reforward > 0 #endif #ifdef CW_CYCLE_CHECK - || cfg.cwcycle_check_enable || cfg.cwcycle_check_caidtab.caid[0] || cfg.maxcyclelist != 500 || cfg.keepcycletime || cfg.onbadcycle || cfg.cwcycle_dropold || cfg.cwcycle_sensitive || cfg.cwcycle_allowbadfromffb || cfg.cwcycle_usecwcfromce + || cfg.cwcycle_check_enable || cfg.cwcycle_check_caidtab.ctnum || cfg.maxcyclelist != 500 || cfg.keepcycletime || cfg.onbadcycle || cfg.cwcycle_dropold || cfg.cwcycle_sensitive || cfg.cwcycle_allowbadfromffb || cfg.cwcycle_usecwcfromce #endif ; } @@ -1050,6 +1067,19 @@ void config_free(void) { config_sections_free(oscam_conf, &cfg); + caidvaluetab_clear(&cfg.ftimeouttab); + caidtab_clear(&cfg.double_check_caid); +#ifdef WITH_LB + caidvaluetab_clear(&cfg.lb_retrylimittab); + caidvaluetab_clear(&cfg.lb_nbest_readers_tab); + caidtab_clear(&cfg.lb_noproviderforcaid); +#endif +#ifdef CS_CACHEEX + caidvaluetab_clear(&cfg.cacheex_mode1_delay_tab); +#endif +#ifdef CW_CYCLE_CHECK + caidtab_clear(&cfg.cwcycle_check_caidtab); +#endif } int32_t init_config(void) @@ -1075,7 +1105,12 @@ // no oscam.conf but webif is included in build, set it up for lan access and tweak defaults #ifdef WEBIF cfg.http_port = DEFAULT_HTTP_PORT; - chk_iprange(cs_strdup(DEFAULT_HTTP_ALLOW), &cfg.http_allowed); + char *default_allowed; + if ((default_allowed = cs_strdup(DEFAULT_HTTP_ALLOW))) + { + chk_iprange(default_allowed, &cfg.http_allowed); + free(default_allowed); + } #endif NULLFREE(cfg.logfile); cfg.logtostdout = 1; diff -Nru oscam-1.20-10584~r10356/oscam-config-reader.c oscam-1.20-10797~r10569/oscam-config-reader.c --- oscam-1.20-10584~r10356/oscam-config-reader.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-config-reader.c 2015-02-20 11:57:49.000000000 +0000 @@ -4,6 +4,7 @@ #include "module-gbox.h" #include "module-stat.h" #include "oscam-aes.h" +#include "oscam-array.h" #include "oscam-conf.h" #include "oscam-conf-chk.h" #include "oscam-conf-mk.h" @@ -47,127 +48,14 @@ struct s_reader *rdr = setting; if(value) { - char *ptr, *ptr2, *ptr3, *saveptr1 = NULL; - struct s_ecmWhitelist *tmp, *last; - struct s_ecmWhitelistIdent *tmpIdent, *lastIdent; - struct s_ecmWhitelistLen *tmpLen, *lastLen; - for(tmp = rdr->ecmWhitelist; tmp; tmp = tmp->next) - { - for(tmpIdent = tmp->idents; tmpIdent; tmpIdent = tmpIdent->next) - { - for(tmpLen = tmpIdent->lengths; tmpLen; tmpLen = tmpLen->next) - { - add_garbage(tmpLen); - } - add_garbage(tmpIdent); - } - add_garbage(tmp); - } - rdr->ecmWhitelist = NULL; - if(strlen(value) > 0) - { - saveptr1 = NULL; - char *saveptr2 = NULL; - for(ptr = strtok_r(value, ";", &saveptr1); ptr; ptr = strtok_r(NULL, ";", &saveptr1)) - { - int16_t caid = 0, len; - uint32_t ident = 0; - ptr2 = strchr(ptr, ':'); - if(ptr2 != NULL) - { - ptr2[0] = '\0'; - ++ptr2; - ptr3 = strchr(ptr, '@'); - if(ptr3 != NULL) - { - ptr3[0] = '\0'; - ++ptr3; - ident = (uint32_t)a2i(ptr3, 6); - } - caid = (int16_t)dyn_word_atob(ptr); - } - else { ptr2 = ptr; } - for(ptr2 = strtok_r(ptr2, ",", &saveptr2); ptr2; ptr2 = strtok_r(NULL, ",", &saveptr2)) - { - len = (int16_t)dyn_word_atob(ptr2); - last = NULL, tmpIdent = NULL, lastIdent = NULL, tmpLen = NULL, lastLen = NULL; - for(tmp = rdr->ecmWhitelist; tmp; tmp = tmp->next) - { - last = tmp; - if(tmp->caid == caid) - { - for(tmpIdent = tmp->idents; tmpIdent; tmpIdent = tmpIdent->next) - { - lastIdent = tmpIdent; - if(tmpIdent->ident == ident) - { - for(tmpLen = tmpIdent->lengths; tmpLen; tmpLen = tmpLen->next) - { - lastLen = tmpLen; - if(tmpLen->len == len) { break; } - } - break; - } - } - } - } - if(tmp == NULL) - { - if(cs_malloc(&tmp, sizeof(struct s_ecmWhitelist))) - { - tmp->caid = caid; - tmp->idents = NULL; - tmp->next = NULL; - if(last == NULL) - { - rdr->ecmWhitelist = tmp; - } - else - { - last->next = tmp; - } - } - } - if(tmp != NULL && tmpIdent == NULL) - { - if(cs_malloc(&tmpIdent, sizeof(struct s_ecmWhitelistIdent))) - { - tmpIdent->ident = ident; - tmpIdent->lengths = NULL; - tmpIdent->next = NULL; - if(lastIdent == NULL) - { - tmp->idents = tmpIdent; - } - else - { - lastIdent->next = tmpIdent; - } - } - } - if(tmp != NULL && tmpIdent != NULL && tmpLen == NULL) - { - if(cs_malloc(&tmpLen, sizeof(struct s_ecmWhitelistLen))) - { - tmpLen->len = len; - tmpLen->next = NULL; - if(lastLen == NULL) - { - tmpIdent->lengths = tmpLen; - } - else - { - lastLen->next = tmpLen; - } - } - } - } - } - } + if(strlen(value)) + chk_ecm_whitelist(value, &rdr->ecm_whitelist); + else + ecm_whitelist_clear(&rdr->ecm_whitelist); return; } - value = mk_t_ecmwhitelist(rdr->ecmWhitelist); + value = mk_t_ecm_whitelist(&rdr->ecm_whitelist); if(strlen(value) > 0 || cfg.http_full_cfg) { fprintf_conf(f, token, "%s\n", value); } free_mk_t(value); @@ -178,128 +66,14 @@ struct s_reader *rdr = setting; if(value) { - char *ptr, *ptr2, *ptr3; - struct s_ecmHeaderwhitelist *tmp, *last = NULL; - - if(strlen(value) == 0) - { - for(tmp = rdr->ecmHeaderwhitelist; tmp; tmp = tmp->next) - { add_garbage(tmp); } - rdr->ecmHeaderwhitelist = NULL; - } + if(strlen(value)) + chk_ecm_hdr_whitelist(value, &rdr->ecm_hdr_whitelist); else - { - char *ptr4, *ptr5, *ptr6, *saveptr = NULL, *saveptr4 = NULL, *saveptr5 = NULL, *saveptr6 = NULL; - uint16_t caid = 0; - uint32_t provid = 0; - int16_t len = 0; - for(ptr = strtok_r(value, ";", &saveptr); ptr; ptr = strtok_r(NULL, ";", &saveptr)) - { - caid = 0; - provid = 0; - ptr2 = strchr(ptr, '@'); - ptr3 = strchr(ptr, ':'); - if(ptr2 == NULL && ptr3 == NULL) //no Caid no Provid - { - for(ptr4 = strtok_r(ptr, ",", &saveptr4); ptr4; ptr4 = strtok_r(NULL, ",", &saveptr4)) - { - if(cs_malloc(&tmp, sizeof(struct s_ecmHeaderwhitelist))) - { - ptr4 = trim(ptr4); - len = strlen(ptr4); - key_atob_l(ptr4, tmp->header, len); - tmp->len = len; - tmp->caid = 0; - tmp->provid = 0; - tmp->next = NULL; - if(last == NULL) - { - rdr->ecmHeaderwhitelist = tmp; - } - else - { - last->next = tmp; - } - last = tmp; - } - } - } - - if(ptr3 != NULL && ptr2 == NULL) // only with Caid - { - ptr3[0] = '\0'; - ++ptr3; - caid = (int16_t)dyn_word_atob(ptr); - for(ptr5 = strtok_r(ptr3, ",", &saveptr5); ptr5; ptr5 = strtok_r(NULL, ",", &saveptr5)) - { - if(cs_malloc(&tmp, sizeof(struct s_ecmHeaderwhitelist))) - { - tmp->caid = caid; - tmp->provid = 0; - ptr5 = trim(ptr5); - len = strlen(ptr5); - key_atob_l(ptr5, tmp->header, len); - tmp->len = len; - tmp->next = NULL; - if(last == NULL) - { - rdr->ecmHeaderwhitelist = tmp; - } - else - { - last->next = tmp; - } - last = tmp; - } - } - } - - if(ptr3 != NULL && ptr2 != NULL) // with Caid & Provid - { - ptr2[0] = '\0'; - ++ptr2; // -> provid - ptr3[0] = '\0'; - ++ptr3; // -> headers - caid = (int16_t)dyn_word_atob(ptr); - provid = (uint32_t)a2i(ptr2, 6); - for(ptr6 = strtok_r(ptr3, ",", &saveptr6); ptr6; ptr6 = strtok_r(NULL, ",", &saveptr6)) - { - if(cs_malloc(&tmp, sizeof(struct s_ecmHeaderwhitelist))) - { - tmp->caid = caid; - tmp->provid = provid; - ptr6 = trim(ptr6); - len = strlen(ptr6); - key_atob_l(ptr6, tmp->header, len); - tmp->len = len; - tmp->next = NULL; - if(last == NULL) - { - rdr->ecmHeaderwhitelist = tmp; - } - else - { - last->next = tmp; - } - last = tmp; - } - } - } - } - } - /* if (rdr->ecmHeaderwhitelist != NULL) { // debug - cs_log("**********Begin ECM Header List for Reader: %s **************", rdr->label); - - struct s_ecmHeaderwhitelist *tmp; - for(tmp = rdr->ecmHeaderwhitelist; tmp; tmp=tmp->next){ - cs_log("Caid: %i Provid: %i Header: %02X Len: %i", tmp->caid, tmp->provid, tmp->header[0], tmp->len); - } - cs_log("***********End ECM Header List for Reader: %s ***************", rdr->label); - } */ + ecm_hdr_whitelist_clear(&rdr->ecm_hdr_whitelist); return; } - value = mk_t_ecmheaderwhitelist(rdr->ecmHeaderwhitelist); + value = mk_t_ecm_hdr_whitelist(&rdr->ecm_hdr_whitelist); if(strlen(value) > 0 || cfg.http_full_cfg) { fprintf_conf(f, token, "%s\n", value); } free_mk_t(value); @@ -611,46 +385,24 @@ void ftab_fn(const char *token, char *value, void *setting, long ftab_type, FILE *f) { - const char *zType = NULL, *zName = NULL, *zFiltNamef = NULL; - struct s_reader *rdr = NULL; FTAB *ftab = setting; - - if(ftab_type & FTAB_ACCOUNT) + if(value) { - struct s_auth *account = NULL; - zType = "account"; - if(ftab_type & FTAB_PROVID) { account = container_of(setting, struct s_auth, ftab); } - if(ftab_type & FTAB_CHID) { account = container_of(setting, struct s_auth, fchid); } - if(account) { zName = account->usr; } + if(strlen(value)) + chk_ftab(value, ftab); + else + ftab_clear(ftab); + return; } if(ftab_type & FTAB_READER) { - zType = "reader"; + struct s_reader *rdr = NULL; if(ftab_type & FTAB_PROVID) { rdr = container_of(setting, struct s_reader, ftab); } if(ftab_type & FTAB_CHID) { rdr = container_of(setting, struct s_reader, fchid); } if(ftab_type & FTAB_FBPCAID) { rdr = container_of(setting, struct s_reader, fallback_percaid); } if(ftab_type & FTAB_LOCALCARDS) { rdr = container_of(setting, struct s_reader, localcards); } - if(rdr) { zName = rdr->label; } - } - if(ftab_type & FTAB_PROVID) { zFiltNamef = "provid"; } - if(ftab_type & FTAB_CHID) { zFiltNamef = "chid"; } - if(ftab_type & FTAB_FBPCAID) { zFiltNamef = "fallback_percaid"; } - if(ftab_type & FTAB_LOCALCARDS) { zFiltNamef = "localcards"; } - - if(value) - { - if(strlen(value)) - { - strtolower(value); - chk_ftab(value, ftab, zType, zName, zFiltNamef); - } - else - { - clear_ftab(ftab); - } if(rdr) { rdr->changes_since_shareupdate = 1; } - return; } value = mk_t_ftab(ftab); if(strlen(value) > 0 || cfg.http_full_cfg) @@ -725,11 +477,7 @@ if(!strlen(value)) { - if(rdr->blockemmbylen) - { - ll_destroy_data(rdr->blockemmbylen); - rdr->blockemmbylen = NULL; - } + ll_destroy_data(&rdr->blockemmbylen); return; } @@ -998,9 +746,10 @@ DEF_OPT_SSTR("password" , OFS(r_pwd), "", SIZEOF(r_pwd)), DEF_OPT_SSTR("pincode" , OFS(pincode), "none", SIZEOF(pincode)), #ifdef MODULE_GBOX - DEF_OPT_INT8("gbox_max_distance" , OFS(gbox_maxdist), DEFAULT_GBOX_MAX_DIST), - DEF_OPT_INT8("gbox_max_ecm_send" , OFS(gbox_maxecmsend), DEFAULT_GBOX_MAX_ECM_SEND), - DEF_OPT_INT8("gbox_reshare" , OFS(gbox_reshare), 0), + DEF_OPT_UINT8("gbox_max_distance" , OFS(gbox_maxdist), DEFAULT_GBOX_MAX_DIST), + DEF_OPT_UINT8("gbox_max_ecm_send" , OFS(gbox_maxecmsend), DEFAULT_GBOX_MAX_ECM_SEND), + DEF_OPT_UINT8("gbox_reshare" , OFS(gbox_reshare), DEFAULT_GBOX_RESHARE), + DEF_OPT_UINT8("cccam_reshare" , OFS(gbox_cccam_reshare), DEFAULT_GBOX_RESHARE), #endif DEF_OPT_STR("readnano" , OFS(emmfile), NULL), DEF_OPT_FUNC("services" , OFS(sidtabs), reader_services_fn), @@ -1036,6 +785,7 @@ DEF_OPT_FUNC_X("ins2e06" , OFS(ins2e06), ins7E_fn, SIZEOF(ins2e06)), DEF_OPT_INT8("fix07" , OFS(fix_07), 1), DEF_OPT_INT8("fix9993" , OFS(fix_9993), 0), + DEF_OPT_INT8("readtiers" , OFS(readtiers), 1), DEF_OPT_INT8("force_irdeto" , OFS(force_irdeto), 0), DEF_OPT_INT8("needsemmfirst" , OFS(needsemmfirst), 0), DEF_OPT_UINT32("ecmnotfoundlimit" , OFS(ecmnotfoundlimit), 0), @@ -1102,6 +852,7 @@ #ifdef MODULE_CAMD35 DEF_OPT_INT8("via_emm_global" , OFS(via_emm_global), 0), #endif + DEF_OPT_UINT8("read_old_classes" , OFS(read_old_classes), 0), DEF_LAST_OPT }; @@ -1124,7 +875,7 @@ { "readnano", "resetcycle", "smargopatch", "autospeed", "sc8in1_dtrrts_patch", "boxid","fix07", "fix9993", "rsakey", "ins7e", "ins7e11", "ins2e06", "force_irdeto", "needsemmfirst", "boxkey", - "atr", "detect", "nagra_read", "mhz", "cardmhz", + "atr", "detect", "nagra_read", "mhz", "cardmhz", "readtiers", "read_old_classes", #ifdef WITH_AZBOX "mode", #endif @@ -1284,48 +1035,32 @@ { NULLFREE(rdr->emmfile); - struct s_ecmWhitelist *tmp; - struct s_ecmWhitelistIdent *tmpIdent; - struct s_ecmWhitelistLen *tmpLen; - for(tmp = rdr->ecmWhitelist; tmp; tmp = tmp->next) - { - for(tmpIdent = tmp->idents; tmpIdent; tmpIdent = tmpIdent->next) - { - for(tmpLen = tmpIdent->lengths; tmpLen; tmpLen = tmpLen->next) - { - add_garbage(tmpLen); - } - add_garbage(tmpIdent); - } - add_garbage(tmp); - } - rdr->ecmWhitelist = NULL; + ecm_whitelist_clear(&rdr->ecm_whitelist); + ecm_hdr_whitelist_clear(&rdr->ecm_hdr_whitelist); - struct s_ecmHeaderwhitelist *tmp1; - for(tmp1 = rdr->ecmHeaderwhitelist; tmp1; tmp1 = tmp1->next) - { - add_garbage(tmp1); - } - rdr->ecmHeaderwhitelist = NULL; + ftab_clear(&rdr->fallback_percaid); + ftab_clear(&rdr->localcards); + ftab_clear(&rdr->fchid); + ftab_clear(&rdr->ftab); - clear_ftab(&rdr->ftab); + caidtab_clear(&rdr->ctab); lb_destroy_stats(rdr); cs_clear_entitlement(rdr); - if(rdr->ll_entitlements) - { - ll_destroy(rdr->ll_entitlements); - rdr->ll_entitlements = NULL; - } + ll_destroy(&rdr->ll_entitlements); + + if(rdr->csystem.card_done) + rdr->csystem.card_done(rdr); NULLFREE(rdr->csystem_data); - if(rdr->blockemmbylen) - { - ll_destroy_data(rdr->blockemmbylen); - rdr->blockemmbylen = NULL; - } + ll_destroy_data(&rdr->blockemmbylen); + + ll_destroy_data(&rdr->emmstat); + aes_clear_entries(&rdr->aes_list); + + config_list_gc_values(reader_opts, rdr); add_garbage(rdr); } @@ -1340,8 +1075,7 @@ count++; } cs_log("readerdb %d readers freed", count); - ll_destroy(configured_readers); - configured_readers = NULL; + ll_destroy(&configured_readers); return count; } diff -Nru oscam-1.20-10584~r10356/oscam-conf-mk.c oscam-1.20-10797~r10569/oscam-conf-mk.c --- oscam-1.20-10584~r10356/oscam-conf-mk.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-conf-mk.c 2015-02-20 11:57:49.000000000 +0000 @@ -8,63 +8,29 @@ /* * Creates a string ready to write as a token into config or WebIf for CAIDs. You must free the returned value through free_mk_t(). */ -char *mk_t_caidtab(CAIDTAB *ctab) +char *mk_t_caidtab(CAIDTAB *caidtab) { - int32_t i = 0, needed = 1, pos = 0; - while(ctab->caid[i]) - { - if(ctab->mask[i]) { needed += 10; } - else { needed += 5; } - if(ctab->cmap[i]) { needed += 5; } - ++i; - } - char *value; - if(needed == 1 || !cs_malloc(&value, needed)) { return ""; } - char *saveptr = value; - i = 0; - while(ctab->caid[i]) - { - if(ctab->caid[i] < 0x0100) //for "ignore provider for" option, caid-shortcut, just first 2 bytes: - { - if(i == 0) - { - snprintf(value + pos, needed - (value - saveptr), "%02X", ctab->caid[i]); - pos += 2; - } - else - { - snprintf(value + pos, needed - (value - saveptr), ",%02X", ctab->caid[i]); - pos += 3; - } - } + if (!caidtab || !caidtab->ctnum) return ""; + // Max entry length is strlen("1234&ffff:1234,") == 15 + int32_t i, maxlen = 16 * caidtab->ctnum, pos = 0; + char *ret; + if (!cs_malloc(&ret, maxlen)) + return ""; + const char *comma = ""; + for(i = 0; i < caidtab->ctnum; i++) + { + CAIDTAB_DATA *d = &caidtab->ctdata[i]; + if (d->caid < 0x0100) + pos += snprintf(ret + pos, maxlen - pos, "%s%02X", comma, d->caid); else - { - if(i == 0) - { - snprintf(value + pos, needed - (value - saveptr), "%04X", ctab->caid[i]); - pos += 4; - } - else - { - snprintf(value + pos, needed - (value - saveptr), ",%04X", ctab->caid[i]); - pos += 5; - } - } - - if((ctab->mask[i]) && (ctab->mask[i] != 0xFFFF)) - { - snprintf(value + pos, needed - (value - saveptr), "&%04X", ctab->mask[i]); - pos += 5; - } - if(ctab->cmap[i]) - { - snprintf(value + pos, needed - (value - saveptr), ":%04X", ctab->cmap[i]); - pos += 5; - } - ++i; + pos += snprintf(ret + pos, maxlen - pos, "%s%04X", comma, d->caid); + if (d->mask && d->mask != 0xffff) + pos += snprintf(ret + pos, maxlen - pos, "&%04X", d->mask); + if (d->cmap) + pos += snprintf(ret + pos, maxlen - pos, ":%04X", d->cmap); + comma = ","; } - value[pos] = '\0'; - return value; + return ret; } /* @@ -72,45 +38,23 @@ */ char *mk_t_tuntab(TUNTAB *ttab) { - int32_t i, needed = 1, pos = 0; - for(i = 0; i < ttab->n && i <= CS_MAXTUNTAB ; i++) - { - // ttab->bt_srvid[i] or 0000 for EMM-only tunnel - needed += 10; - if(ttab->bt_caidto[i]) { needed += 5; } - } - char *value; - if(needed == 1 || !cs_malloc(&value, needed)) { return ""; } - char *saveptr = value; - for(i = 0; i < ttab->n && i <= CS_MAXTUNTAB; i++) - { - if(i == 0) - { - snprintf(value + pos, needed - (value - saveptr), "%04X", ttab->bt_caidfrom[i]); - pos += 4; - } - else - { - snprintf(value + pos, needed - (value - saveptr), ",%04X", ttab->bt_caidfrom[i]); - pos += 5; - } - if(ttab->bt_srvid[i]) - { - snprintf(value + pos, needed - (value - saveptr), ".%04X", ttab->bt_srvid[i]); - } - else - { - snprintf(value + pos, needed - (value - saveptr), ".%04X", 0); - } - pos += 5; - if(ttab->bt_caidto[i]) - { - snprintf(value + pos, needed - (value - saveptr), ":%04X", ttab->bt_caidto[i]); - pos += 5; - } + if (!ttab || !ttab->ttnum) return ""; + // Each entry max length is strlen("aaaa.bbbb:cccc,") == 15 + int32_t i, maxlen = 16 * ttab->ttnum, pos = 0; + char *ret; + if (!cs_malloc(&ret, maxlen)) + return ""; + const char *comma = ""; + for(i = 0; i < ttab->ttnum; i++) + { + TUNTAB_DATA *d = &ttab->ttdata[i]; + pos += snprintf(ret + pos, maxlen - pos, "%s%04X", comma, d->bt_caidfrom); + pos += snprintf(ret + pos, maxlen - pos, ".%04X", d->bt_srvid); + if (d->bt_caidto) + pos += snprintf(ret + pos, maxlen - pos, ":%04X", d->bt_caidto); + comma = ","; } - value[pos] = '\0'; - return value; + return ret; } /* @@ -159,36 +103,29 @@ */ char *mk_t_ftab(FTAB *ftab) { - int32_t i = 0, j = 0, needed = 1, pos = 0; - - if(ftab->nfilts != 0) - { - needed = ftab->nfilts * 5; - for(i = 0; i < ftab->nfilts && i < CS_MAXFILTERS; ++i) - { needed += ftab->filts[i].nprids * 7; } - } - - char *value; - if(needed == 1 || !cs_malloc(&value, needed)) { return ""; } - char *saveptr = value; - char *dot = ""; - for(i = 0; i < ftab->nfilts && i < CS_MAXFILTERS; ++i) - { - snprintf(value + pos, needed - (value - saveptr), "%s%04X", dot, ftab->filts[i].caid); - pos += 4; - if(i > 0) { pos += 1; } - dot = ":"; - for(j = 0; j < ftab->filts[i].nprids; ++j) + if (!ftab || !ftab->nfilts) return ""; + // Worst case scenario where each entry have different + // caid, ident and only one length in it is strlen("1234:123456,") == 12 + int32_t i, j, maxlen = 13 * ftab->nfilts, pos = 0; + for(i = 0; i < ftab->nfilts; i++) + maxlen += ftab->filts[i].nprids * 7; /* strlen("123456,") == 7 */ + char *ret; + if (!cs_malloc(&ret, maxlen)) + return ""; + const char *semicolon = "", *comma = ""; + for(i = 0; i < ftab->nfilts; i++) + { + FILTER *cur = &ftab->filts[i]; + pos += snprintf(ret + pos, maxlen - pos, "%s%04X:", semicolon, cur->caid); + semicolon = ";"; + comma = ""; + for (j = 0; j < cur->nprids; j++) { - snprintf(value + pos, needed - (value - saveptr), "%s%06X", dot, ftab->filts[i].prids[j]); - pos += 7; - dot = ","; + pos += snprintf(ret + pos, maxlen - pos, "%s%06X", comma, cur->prids[j]); + comma = ","; } - dot = ";"; } - - value[pos] = '\0'; - return value; + return ret; } /* @@ -536,111 +473,79 @@ /* * Creates a string ready to write as a token into config or WebIf for the ecm whitelist. You must free the returned value through free_mk_t(). */ -char *mk_t_ecmwhitelist(struct s_ecmWhitelist *whitelist) +char *mk_t_ecm_whitelist(struct s_ecm_whitelist *ecm_whitelist) { - int32_t needed = 1, pos = 0; - struct s_ecmWhitelist *cip; - struct s_ecmWhitelistIdent *cip2; - struct s_ecmWhitelistLen *cip3; - char *value, *dot = "", *dot2 = ""; - for(cip = whitelist; cip; cip = cip->next) - { - needed += 7; - for(cip2 = cip->idents; cip2; cip2 = cip2->next) - { - needed += 7; - for(cip3 = cip2->lengths; cip3; cip3 = cip3->next) { needed += 3; } - } - } - - char tmp[needed]; - - for(cip = whitelist; cip; cip = cip->next) - { - for(cip2 = cip->idents; cip2; cip2 = cip2->next) - { - if(cip2->lengths != NULL) - { - if(cip->caid != 0) - { - if(cip2->ident == 0) - { pos += snprintf(tmp + pos, needed - pos, "%s%04X:", dot, cip->caid); } - else - { pos += snprintf(tmp + pos, needed - pos, "%s%04X@%06X:", dot, cip->caid, cip2->ident); } - } - else { pos += snprintf(tmp + pos, needed - pos, "%s", dot); } - } - dot2 = ""; - for(cip3 = cip2->lengths; cip3; cip3 = cip3->next) - { - pos += snprintf(tmp + pos, needed - pos, "%s%02X", dot2, cip3->len); - dot2 = ","; - } - dot = ";"; - } + if (!ecm_whitelist || !ecm_whitelist->ewnum) return ""; + // Worst case scenario where each entry have different + // caid, ident and only one length in it is strlen("1234@123456:01;") == 15 + int32_t i, maxlen = 16 * ecm_whitelist->ewnum, pos = 0; + char *ret; + if (!cs_malloc(&ret, maxlen)) + return ""; + const char *semicolon = "", *comma = ""; + ECM_WHITELIST_DATA *last = NULL; + for(i = 0; i < ecm_whitelist->ewnum; i++) + { + ECM_WHITELIST_DATA *cur = &ecm_whitelist->ewdata[i]; + bool change = !last || last->caid != cur->caid || last->ident != cur->ident; + if (change) + { + if (cur->caid && cur->ident) + pos += snprintf(ret + pos, maxlen - pos, "%s%04X@%06X:", semicolon, cur->caid, cur->ident); + else if (cur->caid) + pos += snprintf(ret + pos, maxlen - pos, "%s%04X:", semicolon, cur->caid); + else if (cur->ident) + pos += snprintf(ret + pos, maxlen - pos, "%s@%06X:", semicolon, cur->ident); + else + pos += snprintf(ret + pos, maxlen - pos, "%s", semicolon); + semicolon = ";"; + comma = ""; + } + pos += snprintf(ret + pos, maxlen - pos, "%s%02X", comma, cur->len); + comma = ","; + last = &ecm_whitelist->ewdata[i]; } - if(pos == 0 || !cs_malloc(&value, pos + 1)) { return ""; } - memcpy(value, tmp, pos + 1); - return value; + return ret; } /* * Creates a string ready to write as a token into config or WebIf for the ECM Headerwhitelist. You must free the returned value through free_mk_t(). */ -char *mk_t_ecmheaderwhitelist(struct s_ecmHeaderwhitelist *headerlist) +char *mk_t_ecm_hdr_whitelist(struct s_ecm_hdr_whitelist *ecm_hdr_whitelist) { - int32_t needed = 1, pos = 0; - struct s_ecmHeaderwhitelist *cip; - for(cip = headerlist; cip; cip = cip->next) { needed += 51; } - char *value, *dot = ""; - char tmp[needed]; - int16_t i; - int16_t ccache = 0; - uint32_t pcache = 0; - tmp[0] = '\0'; - for(cip = headerlist; cip; cip = cip->next) - { - dot = ""; - if(ccache == cip->caid && pcache == cip->provid) - { - if(pos) - { pos -= 1; } - if(strlen(tmp)) - { pos += snprintf(tmp + pos, needed - pos, ","); } - } - else - { - if(cip->header != NULL && cip->caid != 0 && cip->provid == 0) - { - pos += snprintf(tmp + pos, needed - pos, "%s%04X:", dot, cip->caid); - ccache = cip->caid; - pcache = 0; - } - - if(cip->header != NULL && cip->caid != 0 && cip->provid != 0) - { - pos += snprintf(tmp + pos, needed - pos, "%s%04X@%06X:", dot, cip->caid, cip->provid); - ccache = cip->caid; - pcache = cip->provid; - } - } - if(cip->header != NULL) - { - for(i = 0; i < cip->len / 2; i++) - { - pos += snprintf(tmp + pos, needed - pos, "%s%02X", dot, cip->header[i]); - if(i == cip->len / 2 - 1) { pos += snprintf(tmp + pos, needed - pos, ","); } - ccache = cip->caid; - pcache = cip->provid; - } - } - if(pos) - { pos -= 1; } - pos += snprintf(tmp + pos, needed - pos, ";"); + if (!ecm_hdr_whitelist || !ecm_hdr_whitelist->ehnum) return ""; + // Worst case scenario where each entry have different + // caid, provid and only one header in it is strlen("1234@123456:0102030405060708091011121314151617181920;") == 52 ((sizeof(header) / 2) + 12) + int32_t i, r, maxlen = 53 * ecm_hdr_whitelist->ehnum, pos = 0; + char *ret; + if (!cs_malloc(&ret, maxlen)) + return ""; + const char *semicolon = "", *comma = ""; + ECM_HDR_WHITELIST_DATA *last = NULL; + for(i = 0; i < ecm_hdr_whitelist->ehnum; i++) + { + ECM_HDR_WHITELIST_DATA *cur = &ecm_hdr_whitelist->ehdata[i]; + bool change = !last || last->caid != cur->caid || last->provid != cur->provid; + if (change) + { + if (cur->caid && cur->provid) + pos += snprintf(ret + pos, maxlen - pos, "%s%04X@%06X:", semicolon, cur->caid, cur->provid); + else if (cur->caid) + pos += snprintf(ret + pos, maxlen - pos, "%s%04X:", semicolon, cur->caid); + else if (cur->provid) + pos += snprintf(ret + pos, maxlen - pos, "%s@%06X:", semicolon, cur->provid); + else + pos += snprintf(ret + pos, maxlen - pos, "%s", semicolon); + semicolon = ";"; + comma = ""; + } + pos += snprintf(ret + pos, maxlen - pos, "%s", comma); + for(r = 0; r < cur->len / 2; r++) + pos += snprintf(ret + pos, maxlen - pos, "%02X", cur->header[r]); + comma = ","; + last = &ecm_hdr_whitelist->ehdata[i]; } - if(pos == 0 || !cs_malloc(&value, pos + 1)) { return ""; } - memcpy(value, tmp, pos - 1); - return value; + return ret; } /* @@ -697,24 +602,25 @@ /* * Creates a string ready to write as a token into config or WebIf. You must free the returned value through free_mk_t(). */ -char *mk_t_caidvaluetab(CAIDVALUETAB *tab) +char *mk_t_caidvaluetab(CAIDVALUETAB *caidvaluetab) { - if(!tab->n) { return ""; } - int32_t i, size = 2 + tab->n * (4 + 1 + 5 + 1); //caid + ":" + time + "," - char *buf; - if(!cs_malloc(&buf, size)) - { return ""; } - char *ptr = buf; - - for(i = 0; i < tab->n && tab->n <= CS_MAX_CAIDVALUETAB; i++) - { - if(tab->caid[i] < 0x0100) //Do not format 0D as 000D, its a shortcut for 0Dxx: - { ptr += snprintf(ptr, size - (ptr - buf), "%s%02X:%d", i ? "," : "", tab->caid[i], tab->value[i]); } + if (!caidvaluetab || !caidvaluetab->cvnum) return ""; + // Max entry length is strlen("1234@65535,") == 11 + int32_t i, maxlen = 12 * caidvaluetab->cvnum, pos = 0; + char *ret; + if (!cs_malloc(&ret, maxlen)) + return ""; + const char *comma = ""; + for(i = 0; i < caidvaluetab->cvnum; i++) + { + CAIDVALUETAB_DATA *d = &caidvaluetab->cvdata[i]; + if (d->caid < 0x0100) + pos += snprintf(ret + pos, maxlen - pos, "%s%02X:%d", comma, d->caid, d->value); else - { ptr += snprintf(ptr, size - (ptr - buf), "%s%04X:%d", i ? "," : "", tab->caid[i], tab->value[i]); } + pos += snprintf(ret + pos, maxlen - pos, "%s%04X:%d", comma, d->caid, d->value); + comma = ","; } - *ptr = 0; - return buf; + return ret; } char *mk_t_cacheex_valuetab(CECSPVALUETAB *tab) diff -Nru oscam-1.20-10584~r10356/oscam-conf-mk.h oscam-1.20-10797~r10569/oscam-conf-mk.h --- oscam-1.20-10584~r10356/oscam-conf-mk.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-conf-mk.h 2015-02-20 11:57:49.000000000 +0000 @@ -19,8 +19,8 @@ extern char *mk_t_service(SIDTABS *sidtabs); extern char *mk_t_logfile(void); extern char *mk_t_iprange(struct s_ip *range); -extern char *mk_t_ecmwhitelist(struct s_ecmWhitelist *whitelist); -extern char *mk_t_ecmheaderwhitelist(struct s_ecmHeaderwhitelist *headerlist); +extern char *mk_t_ecm_whitelist(struct s_ecm_whitelist *ecm_whitelist); +extern char *mk_t_ecm_hdr_whitelist(struct s_ecm_hdr_whitelist *ecm_hdr_whitelist); extern char *mk_t_cltab(CLASSTAB *clstab); extern char *mk_t_emmbylen(struct s_reader *rdr); extern char *mk_t_allowedprotocols(struct s_auth *account); diff -Nru oscam-1.20-10584~r10356/oscam-ecm.c oscam-1.20-10797~r10569/oscam-ecm.c --- oscam-1.20-10584~r10356/oscam-ecm.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-ecm.c 2015-02-20 11:57:49.000000000 +0000 @@ -37,83 +37,6 @@ static pthread_cond_t cw_process_sleep_cond; static int cw_process_wakeups; -#ifdef CS_CACHEEX -void cacheex_mode1_delay(ECM_REQUEST *er){ - if(!er->cacheex_wait_time_expired - && er->cacheex_mode1_delay - && er->cacheex_reader_count > 0 - && !er->stage - && er->rc >= E_UNHANDLED - ) - { - cs_log_dbg(D_LB, "{client %s, caid %04X, prid %06X, srvid %04X} cacheex_mode1_delay timeout! ", (check_client(er->client) ? er->client->account->usr : "-"), er->caid, er->prid, er->srvid); - request_cw_from_readers(er, 1); // setting stop_stage=1, we request only cacheex mode 1 readers. Others are requested at cacheex timeout! - } -} - - -void cacheex_timeout(ECM_REQUEST *er) -{ - if(!er->cacheex_wait_time_expired){ - - er->cacheex_wait_time_expired = 1; - - if(er->rc >= E_UNHANDLED) - { - cs_log_dbg(D_LB, "{client %s, caid %04X, prid %06X, srvid %04X} cacheex timeout! ", (check_client(er->client) ? er->client->account->usr : "-"), er->caid, er->prid, er->srvid); - - - //if check_cw mode=0, first try to get cw from cache without check counter! - CWCHECK check_cw = get_cwcheck(er); - if(!check_cw.mode) - { - struct ecm_request_t *ecm=NULL; - ecm = check_cache(er, er->client); - if(ecm) //found in cache - { - struct s_write_from_cache *wfc=NULL; - if(!cs_malloc(&wfc, sizeof(struct s_write_from_cache))) - { - NULLFREE(ecm); - return; - } - wfc->er_new=er; - wfc->er_cache=ecm; - - if(!add_job(er->client, ACTION_ECM_ANSWER_CACHE, wfc, sizeof(struct s_write_from_cache))) //write_ecm_answer_fromcache - { NULLFREE(ecm); } - - return; - } - } - - - //check if "normal" readers selected, if not send NOT FOUND! - //cacheex1-client (having always no "normal" reader), or not-cacheex-1 client with no normal readers available (or filtered by LB) - if( (er->reader_count + er->fallback_reader_count - er->cacheex_reader_count) <= 0 ) - { - if(!cfg.wait_until_ctimeout){ - er->rc = E_NOTFOUND; - er->selected_reader = NULL; - er->rcEx = 0; - - cs_log_dbg(D_LB, "{client %s, caid %04X, prid %06X, srvid %04X} cacheex timeout: NO \"normal\" readers... not_found! ", (check_client(er->client) ? er->client->account->usr : "-"), er->caid, er->prid, er->srvid); - send_dcw(er->client, er); - return; - } - } - else - { - if(er->stage < 2){ - debug_ecm(D_TRACE, "request for %s %s", username(er->client), buf); - request_cw_from_readers(er, 0); - } - } - } - } -} -#endif - void fallback_timeout(ECM_REQUEST *er) { if(er->rc >= E_UNHANDLED && er->stage < 4) @@ -394,10 +317,8 @@ { - cleanup_cache(); -#ifdef CS_CACHEEX - cleanup_hitcache(); -#endif + cleanup_cache(false); + cacheex_cleanup_hitcache(false); cs_ftime(&cache_time); cache_next = add_ms_to_timeb_diff(&cache_time, 3000); @@ -509,24 +430,22 @@ void cs_betatunnel(ECM_REQUEST *er) { - int32_t n; + int32_t i; struct s_client *cl = cur_client(); uint32_t mask_all = 0xFFFF; + TUNTAB *ttab = &cl->ttab; - TUNTAB *ttab; - ttab = &cl->ttab; - - for(n = 0; n < ttab->n; n++) + for(i = 0; i < ttab->ttnum; i++) { - if((er->caid == ttab->bt_caidfrom[n]) && ((er->srvid == ttab->bt_srvid[n]) || (ttab->bt_srvid[n]) == mask_all)) + if((er->caid == ttab->ttdata[i].bt_caidfrom) && ((er->srvid == ttab->ttdata[i].bt_srvid) || (ttab->ttdata[i].bt_srvid) == mask_all)) { if(chk_is_betatunnel_caid(er->caid) == 1 && er->ocaid == 0x0000) { - convert_to_nagra(cl, er, ttab->bt_caidto[n]); + convert_to_nagra(cl, er, ttab->ttdata[i].bt_caidto); } else if(er->ocaid == 0x0000) { - convert_to_beta(cl, er, ttab->bt_caidto[n]); + convert_to_beta(cl, er, ttab->ttdata[i].bt_caidto); } return; } @@ -610,11 +529,6 @@ if(!cs_malloc(&er, sizeof(ECM_REQUEST))) { return NULL; } cs_ftime(&er->tps); - -#ifdef MODULE_GBOX - er->gbox_ecm_id = 0; - er->gbox_ecm_status = GBOX_ECM_NOT_ASKED; -#endif er->rc = E_UNHANDLED; er->client = cl; er->grp = 0; //no readers/cacheex-clients answers yet @@ -698,12 +612,13 @@ static int32_t is_double_check_caid(ECM_REQUEST *er) { - if(!cfg.double_check_caid.caid[0]) //no caids defined: Check all + if(!cfg.double_check_caid.ctnum) //no caids defined: Check all { return 1; } int32_t i; - for(i = 0; i < CS_MAXCAIDTAB; i++) + for(i = 0; i < cfg.double_check_caid.ctnum; i++) { - uint16_t tcaid = cfg.double_check_caid.caid[i]; + CAIDTAB_DATA *d = &cfg.double_check_caid.ctdata[i]; + uint16_t tcaid = d->caid; if(!tcaid) { break; } if(tcaid == er->caid || (tcaid < 0x0100 && (er->caid >> 8) == tcaid)) @@ -830,7 +745,7 @@ } } if(er->ocaid && ofs < (int32_t)sizeof(sby)) - { ofs += snprintf(sby + ofs, sizeof(sby) - ofs - 1, "(btun %04X)", er->ocaid); } + { snprintf(sby + ofs, sizeof(sby) - ofs - 1, "(btun %04X)", er->ocaid); } #ifdef CS_CACHEEX } @@ -2247,8 +2162,8 @@ } } - //cheks for odd/even byte - if(get_odd_even(er)==0){ + //checks for odd/even byte + if(er->caid>>8 != 0x26 && er->caid != 0xFFFF && get_odd_even(er)==0){ cs_log_dbg(D_TRACE, "warning: ecm with null odd/even byte from %s", (check_client(er->client)?er->client->account->usr:"-")); er->rc = E_INVALID; } @@ -2271,13 +2186,13 @@ //set preferlocalcards for this ecm request (actually, paramter is per user based, maybe in fiture it will be caid based too) er->preferlocalcards = cfg.preferlocalcards; - if(client->account->preferlocalcards > -1){ + if(client->account && client->account->preferlocalcards > -1){ er->preferlocalcards = client->account->preferlocalcards; } if(er->preferlocalcards <0 || er->preferlocalcards >2) {er->preferlocalcards=0;} - if(chk_is_betatunnel_caid(er->caid) && client->ttab.n) + if(chk_is_betatunnel_caid(er->caid) && client->ttab.ttnum) { cs_log_dump_dbg(D_TRACE, er->ecm, 13, "betatunnel? ecmlen=%d", er->ecmlen); cs_betatunnel(er); @@ -2314,6 +2229,7 @@ wfc->er_new = er; wfc->er_cache = ecm; write_ecm_answer_fromcache(wfc); + NULLFREE(wfc); NULLFREE(ecm); free_ecm(er); diff -Nru oscam-1.20-10584~r10356/oscam-ecm.h oscam-1.20-10797~r10569/oscam-ecm.h --- oscam-1.20-10584~r10356/oscam-ecm.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-ecm.h 2015-02-20 11:57:49.000000000 +0000 @@ -45,12 +45,4 @@ int32_t ecmfmt(uint16_t caid, uint16_t onid, uint32_t prid, uint16_t chid, uint16_t pid, uint16_t srvid, uint16_t l, char *ecmd5hex, char *csphash, char *cw, char *result, size_t size, uint16_t origin_peer, uint8_t distance); int32_t format_ecm(ECM_REQUEST *ecm, char *result, size_t size); -#ifdef CS_CACHEEX -void cacheex_mode1_delay(ECM_REQUEST *er); -void cacheex_timeout(ECM_REQUEST *er); -#else -static inline void cacheex_mode1_delay(ECM_REQUEST *UNUSED(er)) { } -static inline void cacheex_timeout(ECM_REQUEST *UNUSED(er)) { } -#endif - #endif diff -Nru oscam-1.20-10584~r10356/oscam-emm.c oscam-1.20-10797~r10569/oscam-emm.c --- oscam-1.20-10584~r10356/oscam-emm.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-emm.c 2015-02-20 11:57:49.000000000 +0000 @@ -12,6 +12,7 @@ #include "oscam-work.h" #include "reader-common.h" #include "oscam-chk.h" +#include "oscam-emm-cache.h" const char *entitlement_type[] = { "", "package", "PPV-Event", "chid", "tier", "class", "PBM", "admin" }; @@ -96,7 +97,7 @@ return 0; //emm filter does not match, illegal emm, return } -static void reader_log_emm(struct s_reader *reader, EMM_PACKET *ep, int32_t i, int32_t rc, struct timeb *tps) +static void reader_log_emm(struct s_reader *reader, EMM_PACKET *ep, int32_t count, int32_t rc, struct timeb *tps) { char *rtxt[] = { @@ -115,9 +116,8 @@ if(!tps) { tps = &tpe; } - rdr_log(reader, "%s emmtype=%s, len=%d, idx=%d, cnt=%d: %s (%"PRId64" ms)", - username(ep->client), typedesc[reader->emmcache[i].type], ep->emm[2], - i, reader->emmcache[i].count, rtxt[rc], comp_timeb(&tpe, tps)); + rdr_log(reader, "%s emmtype=%s, len=%d, cnt=%d: %s (%"PRId64" ms)", + username(ep->client), typedesc[ep->type], ep->emm[2], count, rtxt[rc], comp_timeb(&tpe, tps)); } if(rc) @@ -146,18 +146,6 @@ #endif } -static int32_t reader_store_emm(struct s_reader *reader, uint8_t type, uint8_t *emmd5) -{ - int32_t rc; - memcpy(reader->emmcache[reader->rotate].emmd5, emmd5, CS_EMMSTORESIZE); - reader->emmcache[reader->rotate].type = type; - reader->emmcache[reader->rotate].count = 1; - // cs_log_dbg(D_READER, "EMM stored (index %d)", rotate); - rc = reader->rotate; - reader->rotate = (++reader->rotate < CS_EMMCACHESIZE) ? reader->rotate : 0; - return rc; -} - int32_t emm_reader_match(struct s_reader *reader, uint16_t caid, uint32_t provid) { int32_t i; @@ -308,6 +296,7 @@ char *typtext[] = {"unknown", "unique", "shared", "global"}; char tmp[17]; int32_t emmnok = 0; + bool lastseendone = false; struct s_reader *aureader = NULL; cs_log_dump_dbg(D_EMM, ep->emm, ep->emmlen, "emm:"); @@ -368,7 +357,7 @@ } else // local reader { - if(aureader->csystem.active) + if(aureader->csystem_active) { cs = &aureader->csystem; } } @@ -399,7 +388,7 @@ { if(assemble) { - if(!cs->do_emm_reassembly(client, ep)) + if(!cs->do_emm_reassembly(aureader, client, ep)) { continue; } // skip this reader } else @@ -491,34 +480,37 @@ { client->account->emmok++; } first_client->emmok++; - //Check emmcache early: - int32_t i; - unsigned char md5tmp[CS_EMMSTORESIZE]; - - MD5(ep->emm, ep->emm[2], md5tmp); ep->client = client; int32_t writeemm = 1; // 0= dont write emm, 1=write emm, default = write - for(i = 0; i < CS_EMMCACHESIZE; i++) //check emm cache hits + if(aureader->cachemm) //Check emmcache early: { - if(!memcmp(aureader->emmcache[i].emmd5, md5tmp, CS_EMMSTORESIZE)) + unsigned char md5tmp[MD5_DIGEST_LENGTH]; + + MD5(ep->emm, ep->emm[2], md5tmp); + + struct s_emmcache *emmcache = find_emm_cache(md5tmp); // check emm cache + if(emmcache && !lastseendone) { - rdr_log_dbg(aureader, D_EMM, "emm found in cache: count %d rewrite %d", - aureader->emmcache[i].count, aureader->rewritemm); - if(aureader->cachemm && (aureader->emmcache[i].count > aureader->rewritemm)) - { - aureader->emmcache[i].count++; - reader_log_emm(aureader, ep, i, 2, NULL); - writeemm = 0; // dont write emm! - saveemm(aureader, ep, "emmcache"); - break; // found emm match needs no further handling, stop searching and proceed with next reader! - } - writeemm = 1; // found emm match but rewrite counter not reached: write emm! - break; + cs_ftime(&emmcache->lastseen); + lastseendone = true; // in case several aureaders, only do lastseen once! + } + + struct s_emmstat *emmstat = get_emm_stat(aureader, md5tmp, ep->type); + if(emmstat) + { + rdr_log_dbg(aureader, D_EMM, "emm count %d rewrite %d", emmstat->count, aureader->rewritemm); + } + if(emmstat->count >= aureader->rewritemm) + { + reader_log_emm(aureader, ep, emmstat->count, 2, NULL); + writeemm = 0; // dont write emm! + saveemm(aureader, ep, "emmcache"); + continue; // found emm match needs no further handling, proceed with next reader! } } - + if(writeemm) // only write on no cache hit or cache hit that needs further rewrite { EMM_PACKET *emm_pack; @@ -545,39 +537,62 @@ int32_t reader_do_emm(struct s_reader *reader, EMM_PACKET *ep) { - int32_t i, rc, ecs; + int32_t rc, ecs = 0,count = 0; unsigned char md5tmp[MD5_DIGEST_LENGTH]; struct timeb tps; cs_ftime(&tps); - MD5(ep->emm, ep->emm[2], md5tmp); - - for(i = ecs = 0; i < CS_EMMCACHESIZE; i++) + if(reader->cachemm) { - if(!memcmp(reader->emmcache[i].emmd5, md5tmp, CS_EMMSTORESIZE)) + MD5(ep->emm, ep->emm[2], md5tmp); + count = clean_stale_emm_cache_and_stat(md5tmp, (int64_t)1000*60*60*24*30); // clean after 30 days emm is last seen! + if(count) { - reader->emmcache[i].count++; - if(reader->cachemm) + cs_log_dbg(D_EMM, "Cleaned %d emm stale stats and cache entries", count); + } + + + struct s_emmcache *emmcache = find_emm_cache(md5tmp); // check emm cache + if(!emmcache) + { + emm_edit_cache(md5tmp, ep, true); + } + + struct s_emmstat *emmstat = get_emm_stat(reader, md5tmp, ep->type); + if(emmstat) + { + if(reader->cachemm && emmstat->count >= reader->rewritemm) { - if(reader->emmcache[i].count > reader->rewritemm) + ecs = 2; //skip emm + } + else + { + ecs = 1; //rewrite emm + if(!emmstat->count) { - ecs = 2; //skip emm + cs_ftime(&emmstat->firstwritten); + emmstat->lastwritten = emmstat->firstwritten; } else { - ecs = 1; //rewrite emm + cs_ftime(&emmstat->lastwritten); } + count = ++emmstat->count; } - break; + } + else + { + cs_log("abort: oscam seems out of resources!"); + return 0; } } - + // Ecs=0 not found in cache // Ecs=1 found in cache, rewrite emm // Ecs=2 skip if((rc = ecs) < 2) - { + { if(is_network_reader(reader)) { rdr_log_dbg(reader, D_READER, "network emm reader"); @@ -596,11 +611,9 @@ rdr_log_dbg(reader, D_READER, "local emm reader"); rc = cardreader_do_emm(reader, ep); } - if(!ecs) - { i = reader_store_emm(reader, ep->type, md5tmp); } } - reader_log_emm(reader, ep, i, rc, &tps); + reader_log_emm(reader, ep, count, rc, &tps); return rc; } diff -Nru oscam-1.20-10584~r10356/oscam-emm-cache.c oscam-1.20-10797~r10569/oscam-emm-cache.c --- oscam-1.20-10584~r10356/oscam-emm-cache.c 1970-01-01 00:00:00.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-emm-cache.c 2015-02-20 11:57:49.000000000 +0000 @@ -0,0 +1,518 @@ +#define MODULE_LOG_PREFIX "emmcache" + +#include "globals.h" +#include "oscam-config.h" +#include "oscam-string.h" +#include "oscam-emm-cache.h" +#include "oscam-files.h" +#include "oscam-time.h" +#include "oscam-lock.h" +#include "cscrypt/md5.h" +#define LINESIZE 1024 +#define DEFAULT_LOCK_TIMEOUT 1000000 + +static LLIST *emm_cache; + +bool emm_cache_configured(void) +{ + struct s_reader *rdr; + bool enable = false; + LL_ITER itr = ll_iter_create(configured_readers); + while((rdr = ll_iter_next(&itr))) + { + if(rdr->cachemm == 1) + { + enable = true; + } + } + return enable; +} + +void emm_save_cache(void) +{ + if(boxtype_is("dbox2")) return; // dont save emmcache on these boxes, they lack resources and will crash! + + if(!emm_cache_configured()){ + cs_log("saving emmcache disabled since no reader is using it!"); + return; + } + + char fname[256]; + struct timeb ts, te; + + if(!cfg.emmlogdir) + { + get_tmp_dir_filename(fname, sizeof(fname), "oscam.emmcache"); + } + else + { + get_config_filename(fname, sizeof(fname), "oscam.emmcache"); + } + FILE *file = fopen(fname, "w"); + + if(!file) + { + cs_log("can't write emmcache to file %s", fname); + return; + } + + cs_ftime(&ts); + int32_t count = 0, result = 0; + LL_ITER it = ll_iter_create(emm_cache); + struct s_emmcache *c; + while((c = ll_iter_next(&it))) + { + uchar tmp_emmd5[MD5_DIGEST_LENGTH * 2 + 1]; + char_to_hex(c->emmd5, MD5_DIGEST_LENGTH, tmp_emmd5); + uchar tmp_emm[c->len * 2 + 1]; + char_to_hex(c->emm, c->len, tmp_emm); + result = fprintf(file, "%s,%ld,%ld,%02X,%04X,%s\n", tmp_emmd5, c->firstseen.time, c->lastseen.time, c->type, c->len, tmp_emm); + if(result < 0) + { + fclose(file); + result = remove(fname); + if(!result) + { + cs_log("error writing cache -> cache file removed!"); + } + else + { + cs_log("error writing cache -> cache file could not be removed either!"); + } + return; + } + count++; + } + + fclose(file); + cs_ftime(&te); + int64_t load_time = comp_timeb(&te, &ts); + cs_log("saved %d emmcache records to %s in %"PRId64" ms", count, fname, load_time); +} + +void load_emmstat_from_file(void) +{ + if(boxtype_is("dbox2")) return; // dont load emmstat on these boxes, they lack resources and will crash! + + if(!emm_cache_configured()){ + cs_log("loading emmstats disabled since no reader is using it!"); + return; + } + + char buf[256]; + char fname[256]; + char *line; + FILE *file; + + if(!cfg.emmlogdir) + { + get_tmp_dir_filename(fname, sizeof(fname), "oscam.emmstat"); + } + else + { + get_config_filename(fname, sizeof(fname), "oscam.emmstat"); + } + file = fopen(fname, "r"); + if(!file) + { + cs_log_dbg(D_TRACE, "can't read emmstats from file %s", fname); + return; + } + + if(!cs_malloc(&line, LINESIZE)) + { + fclose(file); + return; + } + + struct timeb ts, te; + cs_ftime(&ts); + + struct s_reader *rdr = NULL; + struct s_emmstat *s; + + int32_t i = 1; + int32_t valid = 0; + int32_t count = 0; + char *ptr, *saveptr1 = NULL; + char *split[7]; + + while(fgets(line, LINESIZE, file)) + { + if(!line[0] || line[0] == '#' || line[0] == ';') + { continue; } + + if(!cs_malloc(&s, sizeof(struct s_emmstat))) + { continue; } + + for(i = 0, ptr = strtok_r(line, ",", &saveptr1); ptr && i < 7 ; ptr = strtok_r(NULL, ",", &saveptr1), i++) + { split[i] = ptr; } + valid = (i == 6); + if(valid) + { + strncpy(buf, split[0], sizeof(buf) - 1); + key_atob_l(split[1], s->emmd5, MD5_DIGEST_LENGTH*2); + s->firstwritten.time = atol(split[2]); + s->lastwritten.time = atol(split[3]); + s->type = a2i(split[4], 2); + s->count = a2i(split[5], 4); + + LL_ITER itr = ll_iter_create(configured_readers); + + while((rdr = ll_iter_next(&itr))) + { + if(rdr->cachemm !=1) + { + cs_log("reader %s skipped since emmcache save is disabled", rdr->label); + continue; + } + if(strcmp(rdr->label, buf) == 0) + { + break; + } + } + + if(rdr != NULL) + { + if(!rdr->emmstat) + { + rdr->emmstat = ll_create("emmstat"); + cs_lock_create(&rdr->emmstat_lock, rdr->label, DEFAULT_LOCK_TIMEOUT); + } + + ll_append(rdr->emmstat, s); + count++; + } + else + { + cs_log("emmstats could not be loaded for %s", buf); + NULLFREE(s); + } + } + else + { + cs_log_dbg(D_EMM, "emmstat ERROR: %s count=%d type=%d", buf, s->count, s->type); + NULLFREE(s); + } + } + + fclose(file); + NULLFREE(line); + + cs_ftime(&te); + int64_t load_time = comp_timeb(&te, &ts); + cs_log("loaded %d emmstat records from %s in %"PRId64" ms", count, fname, load_time); +} + +void save_emmstat_to_file(void) +{ + if(boxtype_is("dbox2")) return; // dont save emmstat on these boxes, they lack resources and will crash! + + if(!emm_cache_configured()){ + cs_log("saving emmstats disabled since no reader is using it!"); + return; + } + + char fname[256]; + + if(!cfg.emmlogdir) + { + get_tmp_dir_filename(fname, sizeof(fname), "oscam.emmstat"); + } + else + { + get_config_filename(fname, sizeof(fname), "oscam.emmstat"); + } + FILE *file = fopen(fname, "w"); + + if(!file) + { + cs_log("can't write to file %s", fname); + return; + } + + struct timeb ts, te; + cs_ftime(&ts); + + int32_t count = 0, result = 0; + struct s_reader *rdr; + LL_ITER itr = ll_iter_create(configured_readers); + while((rdr = ll_iter_next(&itr))) + { + if(!rdr->cachemm || rdr->cachemm == 2) + { + cs_log("reader %s skipped since emmcache save is disabled", rdr->label); + continue; + } + + if(rdr->emmstat) + { + cs_writelock(&rdr->emmstat_lock); + LL_ITER it = ll_iter_create(rdr->emmstat); + struct s_emmstat *s; + while((s = ll_iter_next(&it))) + { + uchar tmp_emmd5[MD5_DIGEST_LENGTH * 2 + 1]; + char_to_hex(s->emmd5, MD5_DIGEST_LENGTH, tmp_emmd5); + result = fprintf(file, "%s,%s,%ld,%ld,%02X,%04X\n", rdr->label, tmp_emmd5, s->firstwritten.time, s->lastwritten.time, s->type, s->count); + if(result < 0) + { + cs_writeunlock(&rdr->emmstat_lock); + fclose(file); + result = remove(fname); + if(!result) + { + cs_log("error writing stats -> stat file removed!"); + } + else + { + cs_log("error writing stats -> stat file could not be removed either!"); + } + return; + } + count++; + } + cs_writeunlock(&rdr->emmstat_lock); + } + } + + fclose(file); + + cs_ftime(&te); + int64_t load_time = comp_timeb(&te, &ts); + + cs_log("saved %d emmstat records to %s in %"PRId64" ms", count, fname, load_time); +} + +void emm_load_cache(void) +{ + if(boxtype_is("dbox2")) return; // dont load emmcache on these boxes, they lack resources and will crash! + + if(!emm_cache_configured()){ + cs_log("loading emmcache disabled since no reader is using it!"); + return; + } + + char fname[256]; + char line[1024]; + FILE *file; + struct s_emmcache *c; + + if(!cfg.emmlogdir) + { + get_tmp_dir_filename(fname, sizeof(fname), "oscam.emmcache"); + } + else + { + get_config_filename(fname, sizeof(fname), "oscam.emmcache"); + } + + file = fopen(fname, "r"); + if(!file) + { + cs_log_dbg(D_TRACE, "can't read emmcache from file %s", fname); + return; + } + + struct timeb ts, te; + cs_ftime(&ts); + + int32_t count = 0; + int32_t i = 1; + int32_t valid = 0; + char *ptr, *saveptr1 = NULL; + char *split[7]; + + memset(line, 0, sizeof(line)); + while(fgets(line, sizeof(line), file)) + { + if(!line[0] || line[0] == '#' || line[0] == ';') + { continue; } + + for(i = 0, ptr = strtok_r(line, ",", &saveptr1); ptr && i < 7 ; ptr = strtok_r(NULL, ",", &saveptr1), i++) + { + split[i] = ptr; + } + + valid = (i == 6); + if(valid) + { + if(!cs_malloc(&c, sizeof(struct s_emmcache))) + { continue; } + key_atob_l(split[0], c->emmd5, MD5_DIGEST_LENGTH*2); + c->firstseen.time = atol(split[1]); + c->lastseen.time = atol(split[2]); + c->type = a2i(split[3], 2); + c->len = a2i(split[4], 4); + key_atob_l(split[5], c->emm, c->len*2); + + if(valid && c->len != 0) + { + if(!emm_cache) + { + emm_cache = ll_create("emm cache"); + } + + ll_append(emm_cache, c); + count++; + } + else + { + NULLFREE(c); + } + } + } + fclose(file); + cs_ftime(&te); + int64_t load_time = comp_timeb(&te, &ts); + cs_log("loaded %d emmcache records from %s in %"PRId64" ms", count, fname, load_time); +} + +struct s_emmcache *find_emm_cache(uchar *emmd5) +{ + struct s_emmcache *c; + LL_ITER it; + + if(!emm_cache) + { emm_cache = ll_create("emm cache"); } + + it = ll_iter_create(emm_cache); + while((c = ll_iter_next(&it))) + { + if(!memcmp(emmd5, c->emmd5, MD5_DIGEST_LENGTH)) + { + cs_log_dump_dbg(D_EMM, c->emmd5, MD5_DIGEST_LENGTH, "found emmcache match"); + return c; + } + } + return NULL; +} + +int32_t clean_stale_emm_cache_and_stat(uchar *emmd5, int64_t gone) +{ + struct timeb now; + cs_ftime(&now); + int32_t count = 0; + + struct s_emmcache *c; + LL_ITER it; + + if(!emm_cache) + { emm_cache = ll_create("emm cache"); } + + it = ll_iter_create(emm_cache); + while((c = ll_iter_next(&it))) + { + + if(comp_timeb(&now, &c->lastseen) > gone && memcmp(c->emmd5, emmd5, MD5_DIGEST_LENGTH)) // clean older than gone ms and dont clean if its the current emm! + { + struct s_reader *rdr; + LL_ITER rdr_itr = ll_iter_create(configured_readers); + while((rdr = ll_iter_next(&rdr_itr))) + { + if(rdr->emmstat) + { + remove_emm_stat(rdr, c->emmd5); // clean stale entry from stats + count++; + } + } + ll_iter_remove_data(&it); // clean stale entry from emmcache + } + } + return count; +} + +int32_t emm_edit_cache(uchar *emmd5, EMM_PACKET *ep, bool add) +{ + struct s_emmcache *c; + LL_ITER it; + int32_t count = 0; + + if(!emm_cache) + { emm_cache = ll_create("emm cache"); } + + it = ll_iter_create(emm_cache); + while((c = ll_iter_next(&it))) + { + if(!memcmp(emmd5, c->emmd5, MD5_DIGEST_LENGTH)) + { + if(add) + { + return 0; //already added + } + ll_iter_remove_data(&it); + count++; + } + } + + if(add) + { + if(!cs_malloc(&c, sizeof(struct s_emmcache))) + { return count; } + memcpy(c->emmd5, emmd5, MD5_DIGEST_LENGTH); + c->type = ep->type; + c->len = ep->emm[2]; + cs_ftime(&c->firstseen); + c->lastseen = c->firstseen; + memcpy(c->emm, ep->emm, c->len); + ll_append(emm_cache, c); +#ifdef WITH_DEBUG + cs_log_dump_dbg(D_EMM, c->emmd5, MD5_DIGEST_LENGTH, "added emm to cache:"); +#endif + count++; + } + + return count; +} +int32_t remove_emm_stat(struct s_reader *rdr, uchar *emmd5) +{ + int32_t count = 0; + if(rdr && rdr->emmstat) + { + cs_writelock(&rdr->emmstat_lock); + struct s_emmstat *c; + LL_ITER itr = ll_iter_create(rdr->emmstat); + while((c = ll_iter_next(&itr))) + { + if(!memcmp(emmd5, c->emmd5, MD5_DIGEST_LENGTH)) + { + ll_iter_remove_data(&itr); + count++; + break; + } + } + + cs_writeunlock(&rdr->emmstat_lock); + } + return count; +} + +struct s_emmstat *get_emm_stat(struct s_reader *rdr, uchar *emmd5, uchar emmtype) +{ + if(!rdr->cachemm) return NULL; + + struct s_emmstat *c; + LL_ITER it; + + if(!rdr->emmstat) + { rdr->emmstat = ll_create("emm stat"); } + + it = ll_iter_create(rdr->emmstat); + while((c = ll_iter_next(&it))) + { + if(!memcmp(emmd5, c->emmd5, MD5_DIGEST_LENGTH)) + { + cs_log_dump_dbg(D_EMM, c->emmd5, MD5_DIGEST_LENGTH, "found emmstat match (reader:%s, count:%d)", rdr->label, c->count); + return c; + } + } + + if(cs_malloc(&c, sizeof(struct s_emmstat))) + { + memcpy(c->emmd5, emmd5, MD5_DIGEST_LENGTH); + c->type = emmtype; + ll_append(rdr->emmstat, c); + cs_log_dump_dbg(D_EMM, c->emmd5, MD5_DIGEST_LENGTH, "added emmstat (reader:%s, count:%d)", rdr->label, c->count); + } + return c; +} diff -Nru oscam-1.20-10584~r10356/oscam-emm-cache.h oscam-1.20-10797~r10569/oscam-emm-cache.h --- oscam-1.20-10584~r10356/oscam-emm-cache.h 1970-01-01 00:00:00.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-emm-cache.h 2015-02-20 11:57:49.000000000 +0000 @@ -0,0 +1,21 @@ +#ifndef OSCAM_EMM_CACHE_H_ +#define OSCAM_EMM_CACHE_H_ + +void emm_save_cache(void); +void load_emmstat_from_file(void); +void save_emmstat_to_file(void); +void emm_load_cache(void); + +// all these functions below use emms md5 hash as indexkey +struct s_emmcache *find_emm_cache(uchar *emmd5); // find a certain emm, e.g. to resend it to reader, returns null if nothing found +int32_t emm_edit_cache(uchar *emmd5, EMM_PACKET *ep, bool add); // add = false: delete a certain emm from cache add = true: update lastseen or add emm to cache +struct s_emmstat *get_emm_stat(struct s_reader *rdr, uchar *emmd5, uchar emmtype); // find a certain emmstat +int32_t remove_emm_stat(struct s_reader *rdr, uchar *emmd5); // remove a certain emmstat +int32_t clean_stale_emm_cache_and_stat(uchar *emmd5, int64_t gone); // remove stale global emmcache + emmstat where emm lastseen is older than gone ms + +#else +static inline void load_emmstat_from_file(void) { } +static inline void save_emmstat_to_file(void) { } +static inline void emm_load_cache(void) { } +static inline void emm_save_cache(void) { } +#endif diff -Nru oscam-1.20-10584~r10356/oscam-garbage.c oscam-1.20-10797~r10569/oscam-garbage.c --- oscam-1.20-10584~r10356/oscam-garbage.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-garbage.c 2015-02-20 11:57:49.000000000 +0000 @@ -5,11 +5,6 @@ #include "oscam-lock.h" #include "oscam-string.h" #include "oscam-time.h" -#ifdef MODULE_GBOX -#include "oscam-files.h" -#include "module-gbox-sms.h" -#include "module-gbox.h" -#endif #define HASH_BUCKETS 16 @@ -136,14 +131,6 @@ garbage = next; } } -#ifdef MODULE_GBOX - char *fext= FILE_GSMS_TXT; - char *fname = get_gbox_tmp_fname(fext); - if (file_exists(fname)) - { - gbox_init_send_gsms(); - } -#endif sleepms_on_cond(&sleep_cond_mutex, &sleep_cond, 1000); } pthread_exit(NULL); diff -Nru oscam-1.20-10584~r10356/oscam-llist.c oscam-1.20-10797~r10569/oscam-llist.c --- oscam-1.20-10584~r10356/oscam-llist.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-llist.c 2015-02-20 11:57:49.000000000 +0000 @@ -47,26 +47,32 @@ return l; } -void ll_destroy(LLIST *l) +void ll_destroy(LLIST **pl) { + LLIST *l = *pl; if(!l || l->flag) { return; } + *pl = NULL; ll_clear(l); _destroy(l); } -void ll_destroy_data(LLIST *l) +void ll_destroy_data(LLIST **pl) { + LLIST *l = *pl; if(!l) { return; } + *pl = NULL; ll_clear_data(l); _destroy(l); } -void ll_destroy_free_data(LLIST *l) +void ll_destroy_free_data(LLIST **pl) { + LLIST *l = *pl; if(!l||l->flag) { return; } + *pl = NULL; //********************************* cs_writelock(&l->lock); diff -Nru oscam-1.20-10584~r10356/oscam-llist.h oscam-1.20-10797~r10569/oscam-llist.h --- oscam-1.20-10584~r10356/oscam-llist.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-llist.h 2015-02-20 11:57:49.000000000 +0000 @@ -40,15 +40,13 @@ }; LLIST *ll_create(const char *name); // create llist, return ptr to llist -void ll_destroy(LLIST *l); // same as ll_clear_abstract() but frees up LLIST mem as well -void ll_destroy_data(LLIST *l); // same as ll_clear_data() but frees up obj allocations as well -void ll_destroy_free_data(LLIST *l); // same as ll_clear_data() but frees up obj allocations as well. More, really free node without use GBC +void ll_destroy(LLIST **pl); // same as ll_clear_abstract() but frees up LLIST mem as well +void ll_destroy_data(LLIST **pl); // same as ll_clear_data() but frees up obj allocations as well +void ll_destroy_free_data(LLIST **pl); // same as ll_clear_data() but frees up obj allocations as well. More, really free node without use GBC + void ll_clear(LLIST *l); // frees up all llnodes nodes but not data held in obj ptrs void ll_clear_data(LLIST *l); // same as ll_clear_data() but frees up obj allocations as well -#define ll_destroy_NULL(X) {if (X) {LLIST *tmpX=X; X=NULL;ll_destroy(tmpX);}} -#define ll_destroy_data_NULL(X) {if (X) {LLIST *tmpX=X; X=NULL;ll_destroy_data(tmpX);}} - void **ll_sort(const LLIST *l, void *compare, int32_t *size); // sorts the list, compare = int func(const T *a, const T *b) LL_NODE *ll_append(LLIST *l, void *obj); // append obj to llist LL_NODE *ll_prepend(LLIST *l, void *obj); // prepend obj to llist diff -Nru oscam-1.20-10584~r10356/oscam-log.c oscam-1.20-10797~r10569/oscam-log.c --- oscam-1.20-10584~r10356/oscam-log.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-log.c 2015-02-20 11:57:49.000000000 +0000 @@ -240,7 +240,7 @@ char *tmp = NULL, *tmp2, *tmp3 = NULL, *tmp4; if(size != cfg.loghistorysize) { - if(size == 0 || (cs_malloc(&tmp, size) && cs_malloc(&tmp3, size/3+8))) + if(cs_malloc(&tmp, size) && cs_malloc(&tmp3, size/3+8)) { cs_writelock(&loghistory_lock); tmp2 = loghist; @@ -639,8 +639,7 @@ sleepms_on_cond(&log_thread_sleep_cond_mutex, &log_thread_sleep_cond, 60 * 1000); } while(log_running); - ll_destroy(log_list); - log_list = NULL; + ll_destroy(&log_list); } int32_t cs_init_log(void) diff -Nru oscam-1.20-10584~r10356/oscam-log-reader.c oscam-1.20-10797~r10569/oscam-log-reader.c --- oscam-1.20-10584~r10356/oscam-log-reader.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-log-reader.c 2015-02-20 11:57:49.000000000 +0000 @@ -25,7 +25,7 @@ } } -static char *reader_desc_txt(struct s_reader *reader) +static const char *reader_desc_txt(struct s_reader *reader) { if(reader->csystem.desc) { return reader->csystem.desc; } diff -Nru oscam-1.20-10584~r10356/oscam-net.c oscam-1.20-10797~r10569/oscam-net.c --- oscam-1.20-10584~r10356/oscam-net.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-net.c 2015-02-20 11:57:49.000000000 +0000 @@ -428,6 +428,7 @@ struct s_client *cl; struct s_port *port = &module->ptab.ports[port_idx]; + memset(&cad, 0, sizeof(struct SOCKADDR)); if(module->type == MOD_CONN_UDP) { uchar *buf; diff -Nru oscam-1.20-10584~r10356/oscam-reader.c oscam-1.20-10797~r10569/oscam-reader.c --- oscam-1.20-10584~r10356/oscam-reader.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-reader.c 2015-02-20 11:57:49.000000000 +0000 @@ -9,6 +9,7 @@ #include "oscam-chk.h" #include "oscam-client.h" #include "oscam-ecm.h" +#include "oscam-garbage.h" #include "oscam-lock.h" #include "oscam-net.h" #include "oscam-reader.h" @@ -478,9 +479,9 @@ return rdr; } -char *reader_get_type_desc(struct s_reader *rdr, int32_t extended) +const char *reader_get_type_desc(struct s_reader *rdr, int32_t extended) { - char *desc = "unknown"; + const char *desc = "unknown"; if(rdr->crdr.desc) { return rdr->crdr.desc; } if(is_network_reader(rdr) || rdr->typ == R_SERIAL) @@ -807,7 +808,7 @@ client->udp_sa.sin_port = htons((uint16_t)client->reader->r_port); #endif - rdr_log_dbg(rdr, D_TRACE, "socket open for %s fd=%d", rdr->ph.desc, client->udp_fd); + rdr_log_dbg(rdr, D_TRACE, "socket open fd=%d", client->udp_fd); if(client->is_udp) { @@ -1095,7 +1096,7 @@ struct s_client *cl = reader->client; if(check_client(cl) && reader->tcp_connected && reader->ph.type == MOD_CONN_TCP) { - cs_log_dbg(D_READER, "%s inactive_timeout, close connection (fd=%d)", reader->ph.desc, cl->pfd); + rdr_log_dbg(reader, D_READER, "inactive_timeout, close connection (fd=%d)", cl->pfd); network_tcp_connection_close(reader, "inactivity"); } else @@ -1116,7 +1117,7 @@ if(!(reader->ph.c_init)) { - rdr_log(reader, "FATAL: %s-protocol not supporting cascading", reader->ph.desc); + rdr_log(reader, "FATAL: protocol not supporting cascading"); return 0; } @@ -1126,6 +1127,12 @@ return 0; } + if(client->ecmtask) + { + add_garbage(client->ecmtask); + client->ecmtask = NULL; + } + if(!cs_malloc(&client->ecmtask, cfg.max_pending * sizeof(ECM_REQUEST))) { return 0; } @@ -1137,11 +1144,7 @@ { return 0; } } - if(!cs_malloc(&reader->emmcache, CS_EMMCACHESIZE * sizeof(struct s_emm))) - { - NULLFREE(client->ecmtask); - return 0; - } + ll_destroy_data(&reader->emmstat); client->login = time((time_t *)0); client->init_done = 1; @@ -1303,7 +1306,6 @@ rdr_log(rdr, "Protocol Support missing. (typ=%d)", rdr->typ); return 0; } - rdr_log_dbg(rdr, D_TRACE, "protocol: %s", rdr->ph.desc); } if(!rdr->enable) diff -Nru oscam-1.20-10584~r10356/oscam-reader.h oscam-1.20-10797~r10569/oscam-reader.h --- oscam-1.20-10584~r10356/oscam-reader.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-reader.h 2015-02-20 11:57:49.000000000 +0000 @@ -3,7 +3,7 @@ struct s_cardsystem *get_cardsystem_by_caid(uint16_t caid); struct s_reader *get_reader_by_label(char *lbl); -char *reader_get_type_desc(struct s_reader *rdr, int32_t extended); +const char *reader_get_type_desc(struct s_reader *rdr, int32_t extended); bool hexserialset(struct s_reader *rdr); void hexserial_to_newcamd(uchar *source, uchar *dest, uint16_t caid); diff -Nru oscam-1.20-10584~r10356/oscam-time.c oscam-1.20-10797~r10569/oscam-time.c --- oscam-1.20-10584~r10356/oscam-time.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-time.c 2015-02-20 11:57:49.000000000 +0000 @@ -180,11 +180,11 @@ signal, place the remaining time left to sleep back into req_ts. */ int rval = nanosleep (&req_ts, &req_ts); if (rval == 0) - return; // Completed the entire sleep time; all done. + break; // Completed the entire sleep time; all done. else if (errno == EINTR) continue; // Interrupted by a signal. Try again. else - return; // Some other error; bail out. + break; // Some other error; bail out. } errno = olderrno; } diff -Nru oscam-1.20-10584~r10356/oscam-work.c oscam-1.20-10797~r10569/oscam-work.c --- oscam-1.20-10584~r10356/oscam-work.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-work.c 2015-02-20 11:57:49.000000000 +0000 @@ -54,8 +54,7 @@ { free_job_data(data); } - ll_destroy(cl->joblist); - cl->joblist = NULL; + ll_destroy(&cl->joblist); cl->account = NULL; if(cl->work_job_data) // Free job_data that was not freed by work_thread { free_job_data(cl->work_job_data); } @@ -277,6 +276,9 @@ case ACTION_READER_CARDINFO: reader_do_card_info(reader); break; + case ACTION_READER_POLL_STATUS: + cardreader_poll_status(reader); + break; case ACTION_READER_INIT: if(!cl->init_done) { reader_init(reader); } diff -Nru oscam-1.20-10584~r10356/oscam-work.h oscam-1.20-10797~r10569/oscam-work.h --- oscam-1.20-10584~r10356/oscam-work.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/oscam-work.h 2015-02-20 11:57:49.000000000 +0000 @@ -15,6 +15,7 @@ ACTION_READER_RESET_FAST = 10, // wr10 ACTION_READER_CHECK_HEALTH = 11, // wr11 ACTION_READER_CAPMT_NOTIFY = 12, // wr12 + ACTION_READER_POLL_STATUS = 13, // wr13 // Client actions ACTION_CLIENT_UDP = 22, // wc22 ACTION_CLIENT_TCP = 23, // wc23 diff -Nru oscam-1.20-10584~r10356/reader-bulcrypt.c oscam-1.20-10797~r10569/reader-bulcrypt.c --- oscam-1.20-10584~r10356/reader-bulcrypt.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/reader-bulcrypt.c 2015-02-20 11:57:49.000000000 +0000 @@ -239,7 +239,7 @@ if(card_serial[i] == ' ') { continue; } // Sanity check - if(!isdigit(card_serial[i])) + if(!isdigit((uchar)card_serial[i])) { card_serial[i] = '*'; } } @@ -627,14 +627,24 @@ // Write emm write_cmd(emm_cmd, emm_cmd + 5); - if(cta_lr != 2 || cta_res[0] != 0x90 || (cta_res[1] != 0x00 && cta_res[1] != 0x0a)) + if(cta_lr != 2 || cta_res[0] != 0x90 || (cta_res[1] != 0x00 && cta_res[1] != 0x0a && cta_res[1] != 0x12)) { rdr_log(reader, "(emm_cmd) Unexpected card answer: %s", cs_hexdump(1, cta_res, cta_lr, tmp, sizeof(tmp))); return ERROR; } - if(ep->emm[0] == BULCRYPT_EMM_UNIQUE_82 && cta_res[0] == 0x90 && cta_res[1] == 0x0a) + // V2 answers of 82 EMM + if(cta_res[0] == 0x90 && cta_res[1] == 0x12) + { + write_cmd(cmd_card_v2_key2, NULL); + if(cta_res[18] == 0x90 && cta_res[19] == 0x12) + { + write_cmd(cmd_card_v2_key2, NULL); + } + } + + if(ep->emm[0] == BULCRYPT_EMM_UNIQUE_82 && cta_res[0] == 0x90 && (cta_res[1] == 0x0a || cta_res[1] == 0x00)) { rdr_log(reader, "Your subscription data was updated."); add_job(reader->client, ACTION_READER_CARDINFO, NULL, 0); @@ -716,9 +726,9 @@ // 5581:0002|Standard // 5581:0004|Premium // 5581:0008|HBO - // 5581:0010|Unknown Package 10 + // 5581:0010|Cinemax // 5581:0020|Unknown Package 20 - // 5581:0040|Unknown Package 40 + // 5581:0040|Film Plus - Sport Plus HD & Hobby TV HD // 5581:0080|Unknown Package 80 for(i = 1; i < 256; i <<= 1) { diff -Nru oscam-1.20-10584~r10356/reader-common.c oscam-1.20-10797~r10569/reader-common.c --- oscam-1.20-10584~r10356/reader-common.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/reader-common.c 2015-02-20 11:57:49.000000000 +0000 @@ -17,7 +17,6 @@ extern struct s_cardsystem cardsystems[CS_MAX_MOD]; extern char *RDR_CD_TXT[]; -extern char *stb_boxtype; int32_t check_sct_len(const uchar *data, int32_t off) { @@ -32,6 +31,7 @@ static void reader_nullcard(struct s_reader *reader) { + reader->csystem_active = false; memset(&reader->csystem , 0 , sizeof(reader->csystem)); memset(reader->hexserial, 0 , sizeof(reader->hexserial)); memset(reader->prid , 0xFF, sizeof(reader->prid)); @@ -117,13 +117,22 @@ if(cl) { cl->last = time((time_t *)0); } - if(reader->csystem.active && reader->csystem.card_info) + if(reader->csystem_active && reader->csystem.card_info) { reader->csystem.card_info(reader); } } } +void cardreader_poll_status(struct s_reader *reader) +{ + if (reader && reader->card_status == CARD_INSERTED) + { + if (reader->csystem_active && reader->csystem.poll_status) + { reader->csystem.poll_status(reader); } + } +} + static int32_t reader_get_cardsystem(struct s_reader *reader, ATR *atr) { int32_t i; @@ -136,25 +145,27 @@ { rdr_log(reader, "found card system %s", cardsystems[i].desc); reader->csystem = cardsystems[i]; - reader->csystem.active = 1; + reader->csystem_active = true; led_status_found_cardsystem(); break; } else { // On error free allocated card system data if any + if(cardsystems[i].card_done) + cardsystems[i].card_done(reader); NULLFREE(reader->csystem_data); } } } - if(reader->csystem.active == 0) + if(!reader->csystem_active) { rdr_log(reader, "card system not supported"); led_status_unsupported_card_system(); } - return (reader->csystem.active); + return (reader->csystem_active); } void cardreader_do_reset(struct s_reader *reader) @@ -245,6 +256,8 @@ { rdr_log(reader, "card ejected"); reader_nullcard(reader); + if(reader->csystem.card_done) + reader->csystem.card_done(reader); NULLFREE(reader->csystem_data); if(cl) { @@ -300,6 +313,17 @@ } else { + if(reader->typ == R_INTERNAL) + { + if(boxtype_is("dm8000") || boxtype_is("dm800") || boxtype_is("dm800se")) + {reader->cardmhz = 2700;} + if(boxtype_is("dm500") || boxtype_is("dm600pvr")) + {reader->cardmhz = 3150;} + if(boxtype_is("dm7025")) + {reader->cardmhz = 8300;} + if((!strncmp(boxtype_get(), "vu", 2 ))||(boxtype_is("ini-8000am"))) + {reader->cardmhz = 2700; reader->mhz = 450;} // only one speed for vu+ and Atemio Nemesis due to usage of TDA8024 + } if((reader->cardmhz > 2000) && (reader->typ != R_SMART)) { rdr_log(reader, "Reader initialized (device=%s, detect=%s%s, pll max=%.2f MHz, wanted mhz=%.2f MHz)", @@ -308,11 +332,12 @@ RDR_CD_TXT[reader->detect & 0x7f], (float)reader->cardmhz / 100, (float)reader->mhz / 100); - rdr_log(reader,"Reader sci internal, detected box type: %s", stb_boxtype ? stb_boxtype : "generic"); + rdr_log(reader,"Reader sci internal, detected box type: %s", boxtype_get()); } else { - if ((reader->typ == R_SMART) || (!strcasecmp(reader->crdr.desc, "smargo")) ){ + if (reader->typ == R_SMART || is_smargo_reader(reader)) + { rdr_log_dbg(reader, D_IFD, "clocking for smartreader with smartreader or smargo protocol"); if (reader->cardmhz >= 2000) reader->cardmhz = 369; else if (reader->cardmhz >= 1600) reader->cardmhz = 1600; else @@ -345,7 +370,8 @@ if (reader->mhz >= 343) reader->mhz = 343; else reader->mhz = 320; } - if (((reader->typ == R_SMART) && (reader->autospeed == 1)) || ((!strcasecmp(reader->crdr.desc, "smargo")) && (reader->autospeed == 1))) { + if ((reader->typ == R_SMART || is_smargo_reader(reader)) && reader->autospeed == 1) + { rdr_log(reader, "Reader initialized (device=%s, detect=%s%s, mhz= AUTO, cardmhz=%d)", reader->device, reader->detect & 0x80 ? "!" : "", @@ -359,7 +385,7 @@ reader->mhz, reader->cardmhz); if (reader->typ == R_INTERNAL && !(reader->cardmhz > 2000)) - {rdr_log(reader,"Reader sci internal, detected box type: %s", stb_boxtype ? stb_boxtype : "generic");} + rdr_log(reader,"Reader sci internal, detected box type: %s", boxtype_get()); } } return true; @@ -375,7 +401,7 @@ { // some systems eg. nagra2/3 needs post process after receiving cw from card // To save ECM/CW time we added this function after writing ecm answer - if(reader->csystem.active && reader->csystem.post_process) + if(reader->csystem_active && reader->csystem.post_process) { reader->csystem.post_process(reader); } @@ -395,7 +421,7 @@ cl->last = time((time_t *)0); } - if(reader->csystem.active && reader->csystem.do_ecm) + if(reader->csystem_active && reader->csystem.do_ecm) { rc = reader->csystem.do_ecm(reader, er, ea); rdr_log_dbg(reader, D_READER, "%s: after csystem.do_ecm rc=%d", __func__, rc); @@ -421,7 +447,7 @@ if((1 << (ep->emm[0] % 0x80)) & reader->b_nano) { return 3; } - if(reader->csystem.active && reader->csystem.do_emm) + if(reader->csystem_active && reader->csystem.do_emm) { rc = reader->csystem.do_emm(reader, ep); } else { rc = 0; } diff -Nru oscam-1.20-10584~r10356/reader-common.h oscam-1.20-10797~r10569/reader-common.h --- oscam-1.20-10584~r10356/reader-common.h 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/reader-common.h 2015-02-20 11:57:49.000000000 +0000 @@ -51,6 +51,7 @@ int32_t cardreader_do_emm(struct s_reader *reader, EMM_PACKET *ep); void cardreader_process_ecm(struct s_reader *reader, struct s_client *cl, ECM_REQUEST *er); void cardreader_get_card_info(struct s_reader *reader); +void cardreader_poll_status(struct s_reader *reader); int32_t check_sct_len(const unsigned char *data, int32_t off); #else static inline void cardreader_init_locks(void) { } @@ -75,6 +76,7 @@ } static inline void cardreader_process_ecm(struct s_reader *UNUSED(reader), struct s_client *UNUSED(cl), ECM_REQUEST *UNUSED(er)) { } static inline void cardreader_get_card_info(struct s_reader *UNUSED(reader)) { } +static inline void cardreader_poll_status(struct s_reader *UNUSED(reader)) { } #endif #endif diff -Nru oscam-1.20-10584~r10356/reader-cryptoworks.c oscam-1.20-10797~r10569/reader-cryptoworks.c --- oscam-1.20-10584~r10356/reader-cryptoworks.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/reader-cryptoworks.c 2015-02-20 11:57:49.000000000 +0000 @@ -743,7 +743,7 @@ return OK; } -static int32_t cryptoworks_reassemble_emm(struct s_client *client, EMM_PACKET *ep) +static int32_t cryptoworks_reassemble_emm(struct s_reader *rdr, struct s_client *client, EMM_PACKET *ep) { uchar *buffer = ep->emm; int16_t *len = &ep->emmlen; @@ -757,31 +757,38 @@ // if(*len > 500) { return 0; } + if (!client->cw_rass && !cs_malloc(&client->cw_rass, sizeof(*client->cw_rass))) + { + cs_log("[cryptoworks] ERROR: Can't allocate EMM reassembly buffer."); + return 0; + } + struct emm_rass *r_emm = client->cw_rass; + switch(buffer[0]) { case 0x82 : // emm-u - cs_log_dbg(D_EMM, "[cryptoworks] unique emm (EMM-U)"); + rdr_log_dbg(rdr, D_EMM, "unique emm (EMM-U)"); break; case 0x84: // emm-sh - cs_log_dbg(D_EMM, "[cryptoworks] shared emm (EMM-SH)"); - if(!memcmp(client->cw_rass_emm, buffer, *len)) + rdr_log_dbg(rdr, D_EMM, "shared emm (EMM-SH)"); + if(!memcmp(r_emm->emm, buffer, *len)) { return 0; } if(ep->emm[11] == ep->emm[2] - 9) { - cs_log_dbg(D_EMM, "[cryptoworks] received assembled EMM-S"); + rdr_log_dbg(rdr, D_EMM, "received assembled EMM-S"); return 1; } - memcpy(client->cw_rass_emm, buffer, *len); - client->cw_rass_emmlen = *len; - cs_log_dbg(D_EMM, "[cryptoworks] EMM-SH only in memcpy"); + memcpy(r_emm->emm, buffer, *len); + r_emm->emmlen = *len; + rdr_log_dbg(rdr, D_EMM, "EMM-SH only in memcpy"); return 0; case 0x86: // emm-sb - cs_log_dbg(D_EMM, "[cryptoworks] shared emm (EMM-SB)"); - if(!client->cw_rass_emmlen) + rdr_log_dbg(rdr, D_EMM, "shared emm (EMM-SB)"); + if(!r_emm->emmlen) { return 0; } // we keep the first 12 bytes of the 0x84 emm (EMM-SH) @@ -794,7 +801,7 @@ // update the emm len (emmBuf[1:2]) // - emm_len = *len - 5 + client->cw_rass_emmlen - 12; + emm_len = *len - 5 + r_emm->emmlen - 12; unsigned char *tmp, *assembled; if(!cs_malloc(&tmp, emm_len)) { return 0; } @@ -811,8 +818,8 @@ return 0; } memcpy(tmp, &buffer[5], *len - 5); - memcpy(tmp + *len - 5, &client->cw_rass_emm[12], client->cw_rass_emmlen - 12); - memcpy(assembled_EMM, client->cw_rass_emm, 12); + memcpy(tmp + *len - 5, &r_emm->emm[12], r_emm->emmlen - 12); + memcpy(assembled_EMM, r_emm->emm, 12); emm_sort_nanos(assembled_EMM + 12, tmp, emm_len); assembled_EMM[1] = ((emm_len + 9) >> 8) | 0x70; @@ -824,13 +831,13 @@ free(tmp); free(assembled); - client->cw_rass_emmlen = 0; + r_emm->emmlen = 0; - cs_log_dump_dbg(D_EMM, buffer, *len, "[cryptoworks] shared emm (assembled):"); + rdr_log_dump_dbg(rdr, D_EMM, buffer, *len, "shared emm (assembled):"); if(assembled_EMM[11] != emm_len) // sanity check { // error in emm assembly - cs_log_dbg(D_EMM, "[cryptoworks] Error assembling Cryptoworks EMM-S"); + rdr_log_dbg(rdr, D_EMM, "Error assembling EMM-S"); free(assembled_EMM); return 0; } @@ -839,7 +846,7 @@ case 0x88: // emm-g case 0x89: // emm-g - cs_log_dbg(D_EMM, "[cryptoworks] global emm (EMM-G)"); + rdr_log_dbg(rdr, D_EMM, "global emm (EMM-G)"); break; } return 1; diff -Nru oscam-1.20-10584~r10356/reader-nagra.c oscam-1.20-10797~r10569/reader-nagra.c --- oscam-1.20-10584~r10356/reader-nagra.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/reader-nagra.c 2015-02-20 11:57:49.000000000 +0000 @@ -609,7 +609,7 @@ reader->caid = (SYSTEM_NAGRA | cta_res[11]); memcpy(reader->irdId, cta_res + 14, 4); - if(reader->csystem.active) // do not output on init but only afterwards in card_info + if(reader->csystem_active) // do not output on init but only afterwards in card_info { rdr_log_sensitive(reader, "IRD ID: {%s}", cs_hexdump(1, reader->irdId, 4, ds, sizeof(ds))); nagra_datetime(reader, cta_res + 24, 0, ds, &reader->card_valid_to); @@ -752,7 +752,7 @@ if(cta_res[0] == 0x61 && cta_res[1] == 0x10) { reader->seca_nagra_card = 1; - if ((reader->typ == R_SMART || reader->typ == R_INTERNAL || !strcasecmp(reader->crdr.desc, "smargo")) && !reader->ins7e11_fast_reset) + if ((reader->typ == R_SMART || reader->typ == R_INTERNAL || is_smargo_reader(reader)) && !reader->ins7e11_fast_reset) { ins7e11_state = 1; reader->ins7e11_fast_reset = 1; @@ -766,7 +766,7 @@ reader->card_atr_length = 14; reader->seca_nagra_card = 2; call(reader->crdr.activate(reader, newatr));// read seca atr to switch back - if ((reader->typ == R_SMART || reader->typ == R_INTERNAL || !strcasecmp(reader->crdr.desc, "smargo")) && ins7e11_state == 1) + if ((reader->typ == R_SMART || reader->typ == R_INTERNAL || is_smargo_reader(reader)) && ins7e11_state == 1) { ins7e11_state = 0; reader->ins7e11_fast_reset = 0; diff -Nru oscam-1.20-10584~r10356/reader-viaccess.c oscam-1.20-10797~r10569/reader-viaccess.c --- oscam-1.20-10584~r10356/reader-viaccess.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/reader-viaccess.c 2015-02-20 11:57:49.000000000 +0000 @@ -1683,13 +1683,16 @@ { def_resp; int32_t i, l; + time_t now; + struct tm timeinfo; + uint16_t tmpdate; uchar insac[] = { 0xca, 0xac, 0x00, 0x00, 0x00 }; // select data uchar insb8[] = { 0xca, 0xb8, 0x00, 0x00, 0x00 }; // read selected data uchar insa4[] = { 0xca, 0xa4, 0x00, 0x00, 0x00 }; // select issuer uchar insc0[] = { 0xca, 0xc0, 0x00, 0x00, 0x00 }; // read data item static const uchar ins24[] = { 0xca, 0x24, 0x00, 0x00, 0x09 }; // set pin - static const uchar cls[] = { 0x00, 0x21, 0xff, 0x9f}; + uchar cls[] = { 0x00, 0x21, 0xff, 0x9f}; static const uchar pin[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04}; struct viaccess_data *csystem_data = reader->csystem_data; @@ -1756,6 +1759,14 @@ // read classes subscription insac[2] = 0xa9; insac[4] = 4; + if(!reader->read_old_classes) + { + now = time(NULL) - (24*60*60); + cs_gmtime_r(&now, &timeinfo); + tmpdate = timeinfo.tm_mday | ((timeinfo.tm_mon + 1) << 5) | ((timeinfo.tm_year - 80) << 9); + cls[0] = tmpdate >> 8; + cls[1] = tmpdate & 0xff; + } write_cmd(insac, cls); // request class subs while((cta_res[cta_lr - 2] == 0x90) && (cta_res[cta_lr - 1] == 0)) { @@ -1782,7 +1793,7 @@ return OK; } -static int32_t viaccess_reassemble_emm(struct s_client *client, EMM_PACKET *ep) +static int32_t viaccess_reassemble_emm(struct s_reader *rdr, struct s_client *client, EMM_PACKET *ep) { uint8_t *buffer = ep->emm; int16_t *len = &ep->emmlen; @@ -1792,34 +1803,41 @@ // Viaccess if(*len > 500) { return 0; } + if (!client->via_rass && !cs_malloc(&client->via_rass, sizeof(*client->via_rass))) + { + cs_log("[viaccess] ERROR: Can't allocate EMM reassembly buffer."); + return 0; + } + struct emm_rass *r_emm = client->via_rass; + switch(buffer[0]) { case 0x8c: case 0x8d: // emm-s part 1 - if(!memcmp(client->via_rass_emm, buffer, *len)) + if(!memcmp(r_emm->emm, buffer, *len)) { return 0; } // copy first part of the emm-s - memcpy(client->via_rass_emm, buffer, *len); - client->via_rass_emmlen = *len; - //cs_log_dump_dbg(D_READER, buffer, len, "viaccess global emm:"); + memcpy(r_emm->emm, buffer, *len); + r_emm->emmlen = *len; + //rdr_log_dump_dbg(rdr, D_READER, buffer, len, "global emm:"); return 0; case 0x8e: // emm-s part 2 - if(!client->via_rass_emmlen) { return 0; } + if(!r_emm->emmlen) { return 0; } //extract nanos from emm-gh and emm-s uchar emmbuf[512]; - cs_log_dbg(D_EMM, "[viaccess] %s: start extracting nanos", __func__); + rdr_log_dbg(rdr, D_EMM, "%s: start extracting nanos", __func__); //extract from emm-gh - for(i = 3; i < client->via_rass_emmlen; i += client->via_rass_emm[i + 1] + 2) + for(i = 3; i < r_emm->emmlen; i += r_emm->emm[i + 1] + 2) { //copy nano (length determined by i+1) - memcpy(emmbuf + pos, client->via_rass_emm + i, client->via_rass_emm[i + 1] + 2); - pos += client->via_rass_emm[i + 1] + 2; + memcpy(emmbuf + pos, r_emm->emm + i, r_emm->emm[i + 1] + 2); + pos += r_emm->emm[i + 1] + 2; } if(buffer[2] == 0x2c) @@ -1845,7 +1863,7 @@ } } - cs_log_dump_dbg(D_EMM, buffer, *len, "[viaccess] %s: %s emm-s", __func__, (buffer[2] == 0x2c) ? "fixed" : "variable"); + rdr_log_dump_dbg(rdr, D_EMM, buffer, *len, "%s: %s emm-s", __func__, (buffer[2] == 0x2c) ? "fixed" : "variable"); emm_sort_nanos(buffer + 7, emmbuf, pos); pos += 7; @@ -1853,8 +1871,8 @@ //calculate emm length and set it on position 2 buffer[2] = pos - 3; - cs_log_dump_dbg(D_EMM, client->via_rass_emm, client->via_rass_emmlen, "[viaccess] %s: emm-gh", __func__); - cs_log_dump_dbg(D_EMM, buffer, pos, "[viaccess] %s: assembled emm", __func__); + rdr_log_dump_dbg(rdr, D_EMM, r_emm->emm, r_emm->emmlen, "%s: emm-gh", __func__); + rdr_log_dump_dbg(rdr, D_EMM, buffer, pos, "%s: assembled emm", __func__); *len = pos; break; diff -Nru oscam-1.20-10584~r10356/reader-videoguard2.c oscam-1.20-10797~r10569/reader-videoguard2.c --- oscam-1.20-10584~r10356/reader-videoguard2.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/reader-videoguard2.c 2015-02-20 11:57:49.000000000 +0000 @@ -235,75 +235,302 @@ static void vg2_read_tiers(struct s_reader *reader) { def_resp; - int32_t l; - - /* ins2a is not needed and causes an error on some cards eg Sky Italy 09CD - check if ins2a is in command table before running it - */ - static const unsigned char ins2a[5] = { 0xD0, 0x2a, 0x00, 0x00, 0x00 }; - if(cmd_exists(reader, ins2a)) + struct videoguard_data *csystem_data = reader->csystem_data; + if (reader->readtiers == 1) { - l = do_cmd(reader, ins2a, NULL, NULL, cta_res); - if(l < 0 || !status_ok(cta_res + l)) + uint8_t ins707f[5] = { 0xD1, 0x70, 0x00, 0x7f, 0x02 }; + if(do_cmd(reader, ins707f, NULL, NULL, cta_res) < 0) { - rdr_log(reader, "classD0 ins2a: failed"); - return; + rdr_log(reader, "classD1 ins707f: failed to get number of classes supported"); } + else + { + cs_clear_entitlement(reader); + rdr_log(reader, "------------------------------------------------------------------"); + rdr_log(reader, "|- class -|-- tier --|----- valid to ------|--- package name ----|"); + rdr_log(reader, "+---------+----------+---------------------+---------------------+"); + if ((reader->VgFuse&5) == 0) + { + rdr_log(reader, "|------- This card is not active, so no package available! ------|"); + } + uint32_t TierClass, ClassSupported; + ClassSupported = cta_res[1]; + uint8_t ins70[5] = { 0xD1, 0x70, 0x00, 0x00, 0x00 }; + for( TierClass=0; TierClass 0x23) + { + rev_date_calc_tm(&cta_res[38], &timeinfo, csystem_data->card_baseyear); + start_t = mktime(&timeinfo); + } + rev_date_calc_tm(&cta_res[34], &timeinfo, csystem_data->card_baseyear); + end_t = mktime(&timeinfo); + for( word=0; word<32; word+=2) + { + for (bitnum=0; bitnum<8; bitnum++) + { + if((cta_res[word+2] >> bitnum) & 1) + { + tier_id = 0; + tier_id = ((TierClass<<8) + (word<<3) + bitnum); + cs_add_entitlement(reader, reader->caid, b2ll(4, reader->prid[0]), tier_id, TierClass, start_t, end_t, 4); + rdr_log(reader, "|-- %02x ---|-- %04x --| %04d/%02d/%02d-%02d:%02d:%02d | %s", TierClass, tier_id, timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, get_tiername(tier_id, reader->caid, tiername)); + } + if((cta_res[word+1+2] >> bitnum) & 1) + { + tier_id = 0; + tier_id = ((TierClass<<8) + (word<<3) + bitnum + 8); + cs_add_entitlement(reader, reader->caid, b2ll(4, reader->prid[0]), tier_id, TierClass, start_t, end_t, 4); + rdr_log(reader, "|-- %02x ---|-- %04x --| %04d/%02d/%02d-%02d:%02d:%02d | %s", TierClass, tier_id, timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, get_tiername(tier_id, reader->caid, tiername)); + } + } + } + } + } + } + rdr_log(reader, "------------------------------------------------------from-ins70--"); } - - static const unsigned char ins76007f[5] = { 0xD0, 0x76, 0x00, 0x7f, 0x02 }; - if(!write_cmd_vg(ins76007f, NULL) || !status_ok(cta_res + 2)) + else if (reader->readtiers == 2) { - rdr_log(reader, "classD0 ins76007f: failed"); - return; - } - int32_t num = cta_res[1]; + int32_t l; + //ins2a is not needed and causes an error on some cards eg Sky Italy 09CD + //check if ins2a is in command table before running it - int32_t i; - unsigned char ins76[5] = { 0xD0, 0x76, 0x00, 0x00, 0x00 }; - struct videoguard_data *csystem_data = reader->csystem_data; + static const unsigned char ins2a[5] = { 0xD0, 0x2a, 0x00, 0x00, 0x00 }; + if(cmd_exists(reader, ins2a)) + { + l = do_cmd(reader, ins2a, NULL, NULL, cta_res); + if(l < 0 || !status_ok(cta_res + l)) + { + rdr_log(reader, "classD0 ins2a: failed"); + return; + } + } - // some cards start real tiers info in middle of tier info - // and have blank tiers between old tiers and real tiers eg 09AC - int32_t starttier = csystem_data->card_tierstart; - bool stopemptytier = 1; - if(!starttier) - { stopemptytier = 0; } + static const unsigned char ins76007f[5] = { 0xD0, 0x76, 0x00, 0x7f, 0x02 }; + if(!write_cmd_vg(ins76007f, NULL) || !status_ok(cta_res + 2)) + { + rdr_log(reader, "classD0 ins76007f: failed"); + return; + } + int32_t num = cta_res[1]; - // check to see if specified start tier is blank and if blank, start at 0 and ignore blank tiers - ins76[2] = starttier; - l = do_cmd(reader, ins76, NULL, NULL, cta_res); - if(l < 0 || !status_ok(cta_res + l)) { return; } - if(cta_res[2] == 0 && cta_res[3] == 0) - { - stopemptytier = 0; - starttier = 0; - } + int32_t i; + unsigned char ins76[5] = { 0xD0, 0x76, 0x00, 0x00, 0x00 }; - cs_clear_entitlement(reader); // reset the entitlements + // some cards start real tiers info in middle of tier info + // and have blank tiers between old tiers and real tiers eg 09AC + int32_t starttier = csystem_data->card_tierstart; + bool stopemptytier = 1; + if(!starttier) + { stopemptytier = 0; } - for(i = starttier; i < num; i++) - { - ins76[2] = i; + // check to see if specified start tier is blank and if blank, start at 0 and ignore blank tiers + ins76[2] = starttier; l = do_cmd(reader, ins76, NULL, NULL, cta_res); if(l < 0 || !status_ok(cta_res + l)) { return; } - if(cta_res[2] == 0 && cta_res[3] == 0 && stopemptytier) { return; } - if(cta_res[2] != 0 || cta_res[3] != 0) + if(cta_res[2] == 0 && cta_res[3] == 0) { - char tiername[83]; - uint16_t tier_id = (cta_res[2] << 8) | cta_res[3]; - // add entitlements to list - struct tm timeinfo; - memset(&timeinfo, 0, sizeof(struct tm)); - rev_date_calc_tm(&cta_res[4], &timeinfo, csystem_data->card_baseyear); - cs_add_entitlement(reader, reader->caid, b2ll(4, reader->prid[0]), tier_id, 0, 0, mktime(&timeinfo), 4); + stopemptytier = 0; + starttier = 0; + } - if(!stopemptytier) + cs_clear_entitlement(reader); // reset the entitlements + rdr_log(reader, "------------------------------------------------------------------"); + rdr_log(reader, "|- class -|-- tier --|----- valid to ------|--- package name ----|"); + rdr_log(reader, "+---------+----------+---------------------+---------------------+"); + if ((reader->VgFuse&5) == 0) + { + rdr_log(reader, "|------- This card is not active, so no package available! ------|"); + } + for(i = starttier; i < num; i++) + { + ins76[2] = i; + l = do_cmd(reader, ins76, NULL, NULL, cta_res); + if(l < 0 || !status_ok(cta_res + l)) { return; } + if(cta_res[2] == 0 && cta_res[3] == 0 && stopemptytier) { return; } + if(cta_res[2] != 0 || cta_res[3] != 0) { - rdr_log_dbg(reader, D_READER, "tier: %04x, tier-number: 0x%02x", tier_id, i); + char tiername[83]; + uint16_t tier_id = (cta_res[2] << 8) | cta_res[3]; + // add entitlements to list + struct tm timeinfo; + memset(&timeinfo, 0, sizeof(struct tm)); + rev_date_calc_tm(&cta_res[4], &timeinfo, csystem_data->card_baseyear); + cs_add_entitlement(reader, reader->caid, b2ll(4, reader->prid[0]), tier_id, 0, 0, mktime(&timeinfo), 4); + + if(!stopemptytier) + { + rdr_log_dbg(reader, D_READER, "tier: %04x, tier-number: 0x%02x", tier_id, i); + } + rdr_log(reader, "|-- %02x ---|-- %04x --| %04d/%02d/%02d-%02d:%02d:%02d | %s", cta_res[2], tier_id, timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, get_tiername(tier_id, reader->caid, tiername)); + } + } + rdr_log(reader, "------------------------------------------------------from-ins76--"); + } + else if (reader->readtiers == 0) + { + rdr_log(reader, "------------------------------------------------------------------"); + rdr_log(reader, "|--- The reading of the tiers is disabled by the configuration --|"); + rdr_log(reader, "------------------------------------------------------------------"); + } +} + +void videoguard2_poll_status(struct s_reader *reader) +{ + const time_t poll_interval = 12; // less is better + time_t now = time(0); + int32_t i; + if (now >= reader->last_poll + poll_interval) + { + static const unsigned char ins5C[5] = { 0xD1, 0x5C, 0x00, 0x00, 0x04 }; + unsigned char cta_res[CTA_RES_LEN]; + int32_t l; + l = do_cmd(reader, ins5C, NULL, NULL, cta_res); + if (l < 0 || !status_ok(cta_res + l)) + { + rdr_log(reader, "classD1 ins5C: failed"); + } else switch (cta_res[1]) { + case 0x14: //loc_43C250 + { + static const unsigned char ins4Ca[5] = { 0xD1, 0x4C, 0x00, 0x00, 0x00 }; + l = do_cmd(reader, ins4Ca, reader->payload4C, NULL, cta_res); + if (l < 0 || !status_ok(cta_res)) + { + rdr_log(reader, "classD1 ins4Ca: failed"); + } + if (reader->ins7E[0x1A]) + { + static const uint8_t ins7E[5] = { 0xD1, 0x7E, 0x10, 0x00, 0x1A }; + l = do_cmd(reader, ins7E, reader->ins7E, NULL, cta_res); + if (l < 0 || !status_ok(cta_res)) + { + rdr_log(reader, "classD1 ins7E: failed"); + } + } + if (reader->ins2e06[4]) + { + static const unsigned char ins2e06[5] = { 0xD1, 0x2E, 0x06, 0x00, 0x04 }; + l = do_cmd(reader, ins2e06, reader->ins2e06, NULL, cta_res); + if(l < 0 || !status_ok(cta_res)) + { + rdr_log(reader, "classD1 ins2E: failed"); + } + } + static const unsigned char ins58a[5] = { 0xD1, 0x58, 0x00, 0x00, 0x00 }; + if ((do_cmd(reader, ins58a, NULL, NULL, cta_res) < 0)) + { + rdr_log(reader, "classD1 ins58: failed"); + } + reader->VgFuse = cta_res[2]; + static const unsigned char ins7403[5] = { 0xD0, 0x74, 0x03, 0x00, 0x00 }; + if ((do_cmd(reader, ins7403, NULL, NULL, cta_res) < 0)) + { + rdr_log(reader, "classD0 ins7403: failed"); + } + else + { + if (((cta_res[2]>>5) & 1)) + { + static const unsigned char ins7423[5] = { 0xD3, 0x74, 0x23, 0x00, 0x00 }; + if (do_cmd(reader, ins7423, NULL, NULL, cta_res) < 0) + { + rdr_log(reader, "classD1 ins7423: failed"); + } + } + } + break; + } + case 0xB: //.text:000000000043C050 + { + unsigned char ins5E[5] = { 0xD1,0x5E,0x00,0x00,0x00 }; + ins5E[2] = cta_res[2]; + ins5E[3] = cta_res[1]; + ins5E[4] = cta_res[3]; + l = do_cmd(reader, ins5E, NULL, NULL, cta_res); + if (l < 0 || !status_ok(cta_res + l)) + { + rdr_log(reader, "Ins5E: failed"); + } + unsigned char ins78[5] = { 0xD1, 0x78, 0x00, 0x00, 0x18 }; + ins78[2] = cta_res[0]; + l = do_cmd(reader, ins78, NULL, NULL, cta_res); + if (l < 0 || !status_ok(cta_res + l)) + { + rdr_log(reader, "classD1 ins78: failed"); + } + unsigned char ins32[5] = { 0xD1, 0x32, 0x00, 0x00, 0x01 }; + const unsigned char payload32[1] = { 0x25 }; + l = do_cmd(reader, ins32, payload32, NULL, cta_res); + if (l < 0 || !status_ok(cta_res + l)) + { + rdr_log(reader, "classD1 ins32: failed"); + } + break; + } + case 0x0C: //loc_43C13F + { + unsigned char ins5E[5] = { 0xD1,0x5E,0x00,0x00,0x00 }; + ins5E[2] = cta_res[2]; + ins5E[3] = cta_res[1]; + ins5E[4] = cta_res[3]; + l = do_cmd(reader, ins5E, NULL, NULL, cta_res); + if (l < 0 || !status_ok(cta_res + l)) + { + rdr_log(reader, "Ins5E: failed"); + } else { + unsigned char ins36[5] = { 0xD1, 0x36, 0x00, 0x00, 0x00 }; + ins36[4] = cta_res[1]; + for (i = 0; i <= cta_res[0]; i++) + { + ins36[3] = i; + l = do_cmd(reader, ins36, NULL, NULL, cta_res); + if (l < 0 || !status_ok(cta_res + l)) + { + rdr_log(reader, "Ins36: failed"); + } + + } + } + break; } - rdr_log(reader, "tier: %04x, expiry date: %04d/%02d/%02d-%02d:%02d:%02d %s", tier_id, timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday, timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, get_tiername(tier_id, reader->caid, tiername)); + case 0x10: //loc_43C203 + { + unsigned char ins7411[5] = { 0xD3,0x74,0x11,0x00,0x00 }; + l = read_cmd_len(reader, ins7411); + ins7411[4] = l + 0x10; + l = do_cmd(reader, ins7411, NULL, NULL, cta_res); + if (l < 0 || !status_ok(cta_res)) + { + rdr_log(reader, "classD3 ins7411: failed"); + } + break; + } + case 0x00: // normal state + { + break; + } + default: + { + rdr_log(reader, "unknown ins5C state: %02X %02X %02X %02X", cta_res[0], cta_res[1], cta_res[2], cta_res[3]); + break; + } } + reader->last_poll = now; } } @@ -1076,12 +1303,22 @@ return OK; } +static void videoguard2_card_done(struct s_reader *reader) +{ + struct videoguard_data *csystem_data = reader->csystem_data; + if (csystem_data) + { + NULLFREE(csystem_data->cmd_table); + } +} + void reader_videoguard2(struct s_cardsystem *ph) { ph->do_emm = videoguard2_do_emm; ph->do_ecm = videoguard2_do_ecm; ph->card_info = videoguard2_card_info; ph->card_init = videoguard2_card_init; + ph->card_done = videoguard2_card_done; ph->get_emm_type = videoguard_get_emm_type; ph->get_emm_filter = videoguard_get_emm_filter; ph->caids[0] = 0x09; diff -Nru oscam-1.20-10584~r10356/reader-videoguard-common.c oscam-1.20-10797~r10569/reader-videoguard-common.c --- oscam-1.20-10584~r10356/reader-videoguard-common.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/reader-videoguard-common.c 2015-02-20 11:57:49.000000000 +0000 @@ -425,7 +425,7 @@ } } -inline void __xxor(unsigned char *data, int32_t len, const unsigned char *v1, const unsigned char *v2) +void __xxor(unsigned char *data, int32_t len, const unsigned char *v1, const unsigned char *v2) { uint32_t i; switch(len) // looks ugly but the cpu don't crash! @@ -769,6 +769,7 @@ void memorize_cmd_table(struct s_reader *reader, const unsigned char *mem, int32_t size) { struct videoguard_data *csystem_data = reader->csystem_data; + NULLFREE(csystem_data->cmd_table); if(cs_malloc(&csystem_data->cmd_table, size)) { memcpy(csystem_data->cmd_table, mem, size); } } @@ -842,7 +843,7 @@ if (len == 0xFF) return -1; } } - else if(mode != 0) { ins2[4] = len; } + else if((mode != 0)&&((ins2[3]!=0x7f)&&(ins2[4]!=0x02))) { ins2[4] = len; } } if(ins2[0] == 0xd3) { diff -Nru oscam-1.20-10584~r10356/README oscam-1.20-10797~r10569/README --- oscam-1.20-10584~r10356/README 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/README 2015-02-20 11:57:49.000000000 +0000 @@ -6,7 +6,7 @@ ======= OSCam: Open Source CAM -Copyright (C) 2009-2013 OSCam developers +Copyright (C) 2009-2015 OSCam developers OSCam is based on the Streamboard mp-cardserver 0.9d by dukat and has been extended and worked on by many more since then. diff -Nru oscam-1.20-10584~r10356/README.build oscam-1.20-10797~r10569/README.build --- oscam-1.20-10584~r10356/README.build 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/README.build 2015-02-20 11:57:49.000000000 +0000 @@ -242,6 +242,9 @@ make static-libcrypto - Builds OSCam with libcrypto linked statically make static-ssl - Builds OSCam with SSL support linked statically + Developer targets: + make tests - Builds 'tests.bin' binary + Examples: Build OSCam for SH4 (the compilers are in the path): make CROSS=sh4-linux- diff -Nru oscam-1.20-10584~r10356/README.dvbapi_protocol oscam-1.20-10797~r10569/README.dvbapi_protocol --- oscam-1.20-10584~r10356/README.dvbapi_protocol 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/README.dvbapi_protocol 2015-02-20 11:57:49.000000000 +0000 @@ -177,6 +177,8 @@ uint16_t PID to stop filtering When the client closes connection, all associated channels are stopped in the OSCam. -Alternatively when there is a need to stop decoding channels on specified demux while -having the connection still open, the following CA_PMT data could be sent to OSCam: + +Alternatively when there is a need to stop decoding channels, while having the connection still open you can send a special +'3f' packed to OSCam. To stop decoding specified demux the following CA_PMT data should be sent to OSCam: 9F 80 3f 04 83 02 00 +If is 0xff, then it is parsed as a wildcard and all demuxers associated with the connection are stopped. diff -Nru oscam-1.20-10584~r10356/tests.c oscam-1.20-10797~r10569/tests.c --- oscam-1.20-10584~r10356/tests.c 1970-01-01 00:00:00.000000000 +0000 +++ oscam-1.20-10797~r10569/tests.c 2015-02-20 11:57:49.000000000 +0000 @@ -0,0 +1,317 @@ +/* + * OSCam self tests + * This file contains tests for different config parsers and generators + * Build this file using `make tests` + */ +#include "globals.h" + +#include "oscam-array.h" +#include "oscam-string.h" +#include "oscam-conf-chk.h" +#include "oscam-conf-mk.h" + +struct test_vec +{ + const char *in; // Input data + const char *out; // Expected output data (if out is NULL, then assume in == out) +}; + +typedef void (CHK_FN) (char *, void *); +typedef char *(MK_T_FN) (void *); +typedef void (CLEAR_FN)(void *); +typedef void (CLONE_FN)(void *, void *); + +struct test_type +{ + char *desc; // Test textual description + void *data; // Pointer to basic data structure + void *data_c; // Pointer to data structure that will hold cloned data (for clone_ tests) + size_t data_sz; // Data structure size + CHK_FN *chk_fn; // chk_XXX() func for the data type + MK_T_FN *mk_t_fn; // mk_t_XXX() func for the data type + CLEAR_FN *clear_fn; // clear_XXX() func for the data type + CLONE_FN *clone_fn; // clone_XXX() func for the data type + const struct test_vec *test_vec; // Array of test vectors +}; + +static void run_parser_test(struct test_type *t) +{ + memset(t->data, 0, t->data_sz); + memset(t->data_c, 0, t->data_sz); + printf("%s\n", t->desc); + const struct test_vec *vec = t->test_vec; + while (vec->in) + { + bool ok; + printf(" Testing \"%s\"", vec->in); + char *input_setting = cs_strdup(vec->in); + t->chk_fn(input_setting, t->data); + t->clone_fn(t->data, t->data_c); // Check if 'clone' works + t->clear_fn(t->data); // Check if 'clear' works + char *generated = t->mk_t_fn(t->data_c); // Use cloned data + if (vec->out) + ok = strcmp(vec->out, generated) == 0; + else + ok = strcmp(vec->in, generated) == 0; + if (ok) + { + printf(" [OK]\n"); + } else { + printf("\n"); + printf(" === ERROR ===\n"); + printf(" Input data: \"%s\"\n", vec->in); + printf(" Got result: \"%s\"\n", generated); + printf(" Expected out: \"%s\"\n", vec->out ? vec->out : vec->in); + printf("\n"); + } + free_mk_t(generated); + free(input_setting); + fflush(stdout); + vec++; + } + t->clear_fn(t->data_c); +} + +void run_all_tests(void) +{ + ECM_WHITELIST ecm_whitelist, ecm_whitelist_c; + struct test_type ecm_whitelist_test = + { + .desc = "ECM whitelist setting (READER: 'ecmwhitelist')", + .data = &ecm_whitelist, + .data_c = &ecm_whitelist_c, + .data_sz = sizeof(ecm_whitelist), + .chk_fn = (CHK_FN *)&chk_ecm_whitelist, + .mk_t_fn = (MK_T_FN *)&mk_t_ecm_whitelist, + .clear_fn = (CLEAR_FN *)&ecm_whitelist_clear, + .clone_fn = (CLONE_FN *)&ecm_whitelist_clone, + .test_vec = (const struct test_vec[]) + { + { .in = "0500@043800:70,6E,6C,66,7A,61,67,75,5D,6B;0600@070800:11,22,33,44,55,66;0700:AA,BB,CC,DD,EE;01,02,03,04;0123@456789:01,02,03,04" }, + { .in = "0500@043800:70,6E,6C,66,7A,61,67,75,5D,6B" }, + { .in = "0500@043800:70,6E,6C,66" }, + { .in = "0500@043800:70,6E,6C" }, + { .in = "0500@043800:70" }, + { .in = "0500:81,82,83;0600:91" }, + { .in = "0500:81,82" }, + { .in = "0500:81" }, + { .in = "@123456:81" }, + { .in = "@123456:81;@000789:AA,BB,CC" }, + { .in = "81" }, + { .in = "81,82,83" }, + { .in = "81,82,83,84" }, + { .in = "0500@043800:70;0600@070800:11;0123@456789:01,02" }, + { .in = "" }, + { .in = "0500:81,32;0600:aa,bb", .out = "0500:81,32;0600:AA,BB" }, + { .in = "500:1,2;60@77:a,b,z,,", .out = "0500:01,02;0060@000077:0A,0B" }, + { .in = "@ff:81;@bb:11,22", .out = "@0000FF:81;@0000BB:11,22" }, + { .in = "@:81", .out = "81" }, + { .in = "81;zzs;;;;;ab", .out = "81,AB" }, + { .in = ":@", .out = "" }, + { .in = ",:,@,", .out = "" }, + { .in = "@:", .out = "" }, + { .in = "@:,,", .out = "" }, + { .in = "@:;;;", .out = "" }, + { .in = ",", .out = "" }, + { .in = NULL }, + }, + }; + run_parser_test(&ecm_whitelist_test); + + ECM_HDR_WHITELIST ecm_hdr_whitelist, ecm_hdr_whitelist_c; + struct test_type ecm_hdr_whitelist_test = + { + .desc = "ECM header whitelist setting (READER: 'ecmhdrwhitelist')", + .data = &ecm_hdr_whitelist, + .data_c = &ecm_hdr_whitelist_c, + .data_sz = sizeof(ecm_hdr_whitelist), + .chk_fn = (CHK_FN *)&chk_ecm_hdr_whitelist, + .mk_t_fn = (MK_T_FN *)&mk_t_ecm_hdr_whitelist, + .clear_fn = (CLEAR_FN *)&ecm_hdr_whitelist_clear, + .clone_fn = (CLONE_FN *)&ecm_hdr_whitelist_clone, + .test_vec = (const struct test_vec[]) + { + { .in = "1830@123456:80308F078D,81308F078D;1702@007878:807090C7000000011010008712078400,817090C7000000011010008713078400" }, + { .in = "1830:80308F078D,81308F078D;1702:807090C7000000011010008712078400,817090C7000000011010008713078400" }, + { .in = "813061006A00075C00,803061006A00075C00" }, + { .in = "813061006A00075C00" }, + { .in = "1122334455667788991011121314151617182021222324252627282930", .out = "1122334455667788991011121314151617182021" }, + { .in = "9999@999999:1122334455667788991011121314151617182021,2233334455667788991011121314151617182021;AAAA@BBBBBB:1122334455667788991011121314151617182021" }, + { .in = "0500:81,82,83;0600:91" }, + { .in = "0500:81,82" }, + { .in = "0500:81" }, + { .in = "@123456:81" }, + { .in = "@123456:81;@000789:AA,BB,CC" }, + { .in = "81" }, + { .in = "81,82,83" }, + { .in = "81,82,83,84" }, + { .in = "0500@043800:70;0600@070800:11;0123@456789:01,02" }, + { .in = "" }, + { .in = "00,82,83" }, + { .in = "0500:81,32;0600:aa,bb", .out = "0500:81,32;0600:AA,BB" }, + { .in = "@ff:81;@bb:11,22", .out = "@0000FF:81;@0000BB:11,22" }, + { .in = "0500:,,,;0060@000077:,,;0700:,;0800", .out = "0800" }, + { .in = "@:81", .out = "81" }, + { .in = "81;zzs;;;;;ab", .out = "81,EF,AB" }, + { .in = "1830@123456:", .out = "" }, + { .in = "500:1,2;60@77:a,b,z,,", .out = "" }, + { .in = ":@", .out = "" }, + { .in = ",:,@,", .out = "" }, + { .in = "@:", .out = "" }, + { .in = "@:,,", .out = "" }, + { .in = "@:;;;", .out = "" }, + { .in = ",", .out = "" }, + { .in = NULL }, + }, + }; + run_parser_test(&ecm_hdr_whitelist_test); + + TUNTAB tuntab, tuntab_c; + struct test_type tuntab_test = + { + .desc = "Beta tunnel (tuntab) (ACCOUNT: 'betatunnel')", + .data = &tuntab, + .data_c = &tuntab_c, + .data_sz = sizeof(tuntab), + .chk_fn = (CHK_FN *)&chk_tuntab, + .mk_t_fn = (MK_T_FN *)&mk_t_tuntab, + .clear_fn = (CLEAR_FN *)&tuntab_clear, + .clone_fn = (CLONE_FN *)&tuntab_clone, + .test_vec = (const struct test_vec[]) + { + { .in = "1833.007A:1702,1833.007B:1702,1833.007C:1702,1833.007E:1702,1833.007F:1702,1833.0080:1702,1833.0081:1702,1833.0082:1702,1833.0083:1702,1833.0084:1702" }, + { .in = "1833.007A:1702,1833.007B:1702,1833.007C:1702,1833.007E:1702" }, + { .in = "1833.007A:1702" }, + { .in = "" }, + { .in = "1833.007A" }, + { .in = "1833:1702", .out = "" }, + { .in = "1833", .out = "" }, + { .in = "zzzz.yyyy:tttt", .out = "" }, + { .in = "zzzz.yyyy", .out = "" }, + { .in = ",", .out = "" }, + { .in = ".:", .out = "" }, + { .in = ":.,", .out = "" }, + { .in = NULL }, + }, + }; + run_parser_test(&tuntab_test); + + FTAB ftab, ftab_c; + struct test_type ftab_test = + { + .desc = "Filters (ftab) (ACCOUNT: 'chid', 'ident'; READER: 'chid', 'ident', 'fallback_percaid', 'localcards')", + .data = &ftab, + .data_c = &ftab_c, + .data_sz = sizeof(ftab), + .chk_fn = (CHK_FN *)&chk_ftab, + .mk_t_fn = (MK_T_FN *)&mk_t_ftab, + .clear_fn = (CLEAR_FN *)&ftab_clear, + .clone_fn = (CLONE_FN *)&ftab_clone, + .test_vec = (const struct test_vec[]) + { + { .in = "0100:123456,234567;0200:345678,456789" }, + { .in = "183D:000000,005411" }, + { .in = "183D:000000" }, + { .in = "0100:000012" }, + { .in = "0100:000012;0604:0000BA,000101,00010E,000141" }, + { .in = "1234:234567;0010:345678,876543" }, + { .in = "" }, + { .in = "0200:eeee,tyut,1234", .out = "0200:00EEEE,001234" }, + { .in = "0200:eeee,tyut", .out = "0200:00EEEE" }, + { .in = "1:0", .out = "0001:000000" }, + { .in = "1:0,1,0", .out = "0001:000000,000001,000000" }, + { .in = "0:0", .out = "" }, + { .in = "zzzz:", .out = "" }, + { .in = "yyyy:rrrr,qqqq", .out = "" }, + { .in = ",", .out = "" }, + { .in = ",;,", .out = "" }, + { .in = ";;;", .out = "" }, + { .in = ".:", .out = "" }, + { .in = ":.,", .out = "" }, + { .in = ":;.,", .out = "" }, + { .in = ".:;,", .out = "" }, + { .in = NULL }, + }, + }; + run_parser_test(&ftab_test); + + CAIDVALUETAB caidvaluetab, caidvaluetab_c; + struct test_type caidvaluetab_test = + { + .desc = "caidvaluetab (ACCOUNT: 'lb_nbest_percaid'; GLOBAL: 'lb_nbest_percaid', 'fallbacktimeout_percaid', 'lb_retrylimits', 'cacheex_mode1_delay')", + .data = &caidvaluetab, + .data_c = &caidvaluetab_c, + .data_sz = sizeof(caidvaluetab), + .chk_fn = (CHK_FN *)&chk_caidvaluetab, + .mk_t_fn = (MK_T_FN *)&mk_t_caidvaluetab, + .clear_fn = (CLEAR_FN *)&caidvaluetab_clear, + .clone_fn = (CLONE_FN *)&caidvaluetab_clone, + .test_vec = (const struct test_vec[]) + { + { .in = "0100:4,0200:3,0300:2,0400:1" }, + { .in = "0100:4,02:3,03:2,04:1,0500:9999" }, + { .in = "0100:4" }, + { .in = "01:4" }, + { .in = "" }, + { .in = "0500:10000", .out = "" }, + { .in = "0200:eeee,tyut,1234", .out = "0200:0" }, + { .in = "0200:eeee,tyut", .out = "0200:0" }, + { .in = "1:0", .out = "01:0" }, + { .in = "1:0,1,0", .out = "01:0" }, + { .in = "0500:10000", .out = "" }, + { .in = "0:0", .out = "" }, + { .in = "zzzz:", .out = "" }, + { .in = "yyyy:rrrr,qqqq", .out = "" }, + { .in = ",", .out = "" }, + { .in = ",:,", .out = "" }, + { .in = ";:;", .out = "" }, + { .in = ".:", .out = "" }, + { .in = ":.,", .out = "" }, + { .in = ":;.,", .out = "" }, + { .in = ".:;,", .out = "" }, + { .in = NULL }, + }, + }; + run_parser_test(&caidvaluetab_test); + + CAIDTAB caidtab, caidtab_c; + struct test_type caidtab_test = + { + .desc = "caidtab (ACCOUNT: 'caid'; READER: 'caid'; GLOBAL: 'lb_noproviderforcaid', 'double_check_caid', 'cwcycle_check_caid')", + .data = &caidtab, + .data_c = &caidtab_c, + .data_sz = sizeof(caidtab), + .chk_fn = (CHK_FN *)&chk_caidtab, + .mk_t_fn = (MK_T_FN *)&mk_t_caidtab, + .clear_fn = (CLEAR_FN *)&caidtab_clear, + .clone_fn = (CLONE_FN *)&caidtab_clone, + .test_vec = (const struct test_vec[]) + { + { .in = "0200&FFEE:0300" }, + { .in = "0200&FF00:0300,0400&00FF:0500" }, + { .in = "0200&FF00:0300,0400,0500:0600,0600&FF0F:1234" }, + { .in = "0400&FF00:0500,0600" }, + { .in = "0702,0722" }, + { .in = "0702&FFDF" }, + { .in = "0100" }, + { .in = "01" }, + { .in = "" }, + { .in = "0500:10000", .out = "0500" }, + { .in = "1000&5FFFF5:0600", .out = "1000&FFF5:0600" }, + { .in = "10000:10000", .out = "" }, + { .in = "rrrr&zzzz:mmmm", .out = "" }, + { .in = "0:0", .out = "" }, + { .in = "zzzz:", .out = "" }, + { .in = "yyyy:rrrr,qqqq", .out = "" }, + { .in = ",", .out = "" }, + { .in = ",:,", .out = "" }, + { .in = "&:&", .out = "" }, + { .in = ".:", .out = "" }, + { .in = ":.,", .out = "" }, + { .in = ":&.,", .out = "" }, + { .in = ".:&,", .out = "" }, + { .in = NULL }, + }, + }; + run_parser_test(&caidtab_test); +} diff -Nru oscam-1.20-10584~r10356/utils/list_smargo.c oscam-1.20-10797~r10569/utils/list_smargo.c --- oscam-1.20-10584~r10356/utils/list_smargo.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/utils/list_smargo.c 2015-02-20 11:57:49.000000000 +0000 @@ -21,6 +21,7 @@ #include #include #include +#include #include "../globals.h" #include "../csctapi/ifd_smartreader_types.h" diff -Nru oscam-1.20-10584~r10356/webif/api.json/status.json oscam-1.20-10797~r10569/webif/api.json/status.json --- oscam-1.20-10584~r10356/webif/api.json/status.json 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/api.json/status.json 2015-02-20 11:57:49.000000000 +0000 @@ -10,7 +10,11 @@ "mcs":"##MCS##", "mca":"##MCA##", "rcc":"##RCC##", + "rca":"##RCA##", + "rco":"##RCO##", "pcc":"##PCC##", + "pca":"##PCA##", + "pco":"##PCO##", "client":[ ##JSONSTATUSBITS## ]} diff -Nru oscam-1.20-10584~r10356/webif/api.json/status_statusbits.json oscam-1.20-10797~r10569/webif/api.json/status_statusbits.json --- oscam-1.20-10584~r10356/webif/api.json/status_statusbits.json 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/api.json/status_statusbits.json 2015-02-20 11:57:49.000000000 +0000 @@ -1,7 +1,6 @@ ##JSONARRAYDELIMITER##{ "thid": "##CSIDX##", "type": "##CLIENTTYPE##", -"name": "##CLIENTUSER##", "name_enc": "##USERENC##", "rname_enc": "##READERNAMEENC##", "upicmissing": "##UPICMISSING##", diff -Nru oscam-1.20-10584~r10356/webif/api.json/userbit.json oscam-1.20-10797~r10569/webif/api.json/userbit.json --- oscam-1.20-10584~r10356/webif/api.json/userbit.json 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/api.json/userbit.json 2015-02-20 11:57:49.000000000 +0000 @@ -1,6 +1,5 @@ ##JSONDELIMITER##{ "user":{ - "name":"##USERNAME##", "usermd5":"##USERMD5##", "status":"##STATUS##", "classname":"##CLASSNAME##", diff -Nru oscam-1.20-10584~r10356/webif/config/webif.html oscam-1.20-10797~r10569/webif/config/webif.html --- oscam-1.20-10584~r10356/webif/config/webif.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/config/webif.html 2015-02-20 11:57:49.000000000 +0000 @@ -34,6 +34,18 @@ + Emm settings + Http emmlog cleanup size: + + + + + + + +
Unique:  kBShared:  kBGlobal:  kB  (0 = disabled)
+ + Css style settings Http prepend embedded css: Http css: diff -Nru oscam-1.20-10584~r10356/webif/emm/emm.html oscam-1.20-10797~r10569/webif/emm/emm.html --- oscam-1.20-10584~r10356/webif/emm/emm.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/emm/emm.html 2015-02-20 11:57:49.000000000 +0000 @@ -6,21 +6,21 @@
- + - + - +
Selected reader : ##READER##
Selected reader: ##READER##
CAID:
Single EMM to write:
Single EMM to write:
File path with EMMs:

Saved EMMs for Reader: ##READER##

UniqueEMM    ##RDREMMUNIQUE_TXT##

-
##RDREMMUNIQUE##
+
##RDREMMUNIQUE##

SharedEMM    ##RDREMMSHARED_TXT##

-
##RDREMMSHARED##
+
##RDREMMSHARED##

GlobalEMM    ##RDREMMGLOBAL_TXT##

-
##RDREMMGLOBAL##
+
##RDREMMGLOBAL##
##TPLFOOTER## diff -Nru oscam-1.20-10584~r10356/webif/emm_running/emm_running.html oscam-1.20-10797~r10569/webif/emm_running/emm_running.html --- oscam-1.20-10584~r10356/webif/emm_running/emm_running.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/emm_running/emm_running.html 2015-02-20 11:57:49.000000000 +0000 @@ -8,17 +8,17 @@ - + - + - - - - - + + + + +
Selected reader : ##READER##
system:##SYSTEM##
System:##SYSTEM##
CAID:##CAID##
SINGLE EMM
EMM:
size: ##SIZE##
Size: ##SIZE##
EMM FILE
file path:
file size: ##FSIZE##
num of
read lines:
##NUMRLINE##
lines with
errors:
##ERRLINE##
num of
written EMMs:
##NUMWEMM##
File path:
File size: ##FSIZE##
Num of read lines: ##NUMRLINE##
Lines with errors: ##ERRLINE##
Num of written EMMs: ##NUMWEMM##
##TPLFOOTER## diff -Nru oscam-1.20-10584~r10356/webif/include/css.css oscam-1.20-10797~r10569/webif/include/css.css --- oscam-1.20-10584~r10356/webif/include/css.css 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/include/css.css 2015-02-20 11:57:49.000000000 +0000 @@ -253,9 +253,13 @@ /* entitlements_bit.html, entitlements_cccambit.html */ table.stats {} /* emm.html */ -table.writeemm {} +table.writeemm { + width:750px +} /* emm_running.html */ -table.emmrunning {} +table.emmrunning { + width:750px +} /* readerstats.html */ table.statsbalance td:last-child { line-height:20px; @@ -573,6 +577,10 @@ width:380px; font-size:12px } +/* textarea for emm.html */ +table.writeemm textarea { + width:597px +} /* generaly settings for all select */ select { padding:2px @@ -679,7 +687,7 @@ #otherdropdown option:first-child { display:none } -/* for extract in script.html */ +/* for extract in script.html and emm.html */ div.extract { width:750px; margin:10px auto; @@ -704,6 +712,9 @@ border:1px dotted #AAA; white-space:pre } +div.extract pre.script { + min-height: 100px; +} /* **************** 13. IMAGE */ /* generaly settings for images */ @@ -838,7 +849,9 @@ margin:1px auto 15px; padding:0px 4px } -#livelogdata {} +#livelogdata { + white-space:pre +} li.regex, li.regexdata_nav, li.regexdata_save{ white-space:nowrap } diff -Nru oscam-1.20-10584~r10356/webif/include/footer.html oscam-1.20-10797~r10569/webif/include/footer.html --- oscam-1.20-10584~r10356/webif/include/footer.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/include/footer.html 2015-02-20 11:57:49.000000000 +0000 @@ -2,10 +2,10 @@ diff -Nru oscam-1.20-10584~r10356/webif/include/jscript.js oscam-1.20-10797~r10569/webif/include/jscript.js --- oscam-1.20-10584~r10356/webif/include/jscript.js 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/include/jscript.js 2015-02-20 11:57:49.000000000 +0000 @@ -96,7 +96,6 @@ return time; } - function runden(value) { var k = (Math.round(value * 100) / 100).toString(); k += (k.indexOf('.') == -1) ? '.00' : '00'; @@ -253,13 +252,13 @@ var img = $(this).children("img"); waitForMsg(); if ($(this).data('next-action') == 'enable') { - $(this).data('next-action', 'disable').attr('title', 'Disable this reader'); + $(this).data('next-action', 'disable').attr('title', 'Disable Reader: ' + $(this).data('reader-name') + $(this).data('desc')); $(rowid).attr('class', 'enabledreader'); - img.attr('src', 'image?i=ICDIS').attr('alt', 'Disable this reader'); + img.attr('src', 'image?i=ICDIS').attr('alt', 'Disable'); } else { - $(this).data('next-action', 'enable').attr('title', 'Enable this reader'); + $(this).data('next-action', 'enable').attr('title', 'Enable Reader: ' + $(this).data('reader-name') + $(this).data('desc')); $(rowid).attr('class', 'disabledreader'); - img.attr('src', 'image?i=ICENA').attr('alt', 'Enable this reader'); + img.attr('src', 'image?i=ICENA').attr('alt', 'Enable'); } parameters = parameters_old; }); @@ -286,15 +285,15 @@ var img = $(this).children("img"); waitForMsg(); if ($(this).data('next-action') == 'enable') { - $(this).data('next-action', 'disable').attr('title', 'Disable this user'); + $(this).data('next-action', 'disable').attr('title', 'Disable User: ' + $(this).data('user-name') + $(this).data('desc')); $(rowid).attr('class', 'offline'); $(rowid + ' > td.usercol2').text('offline'); - img.attr('src', 'image?i=ICDIS').attr('alt', 'Disable this user'); + img.attr('src', 'image?i=ICDIS').attr('alt', 'Disable'); } else { - $(this).data('next-action', 'enable').attr('title', 'Enable this user'); + $(this).data('next-action', 'enable').attr('title', 'Enable User: ' + $(this).data('user-name') + $(this).data('desc')); $(rowid).attr('class', 'disabled'); $(rowid + ' > td.usercol2').text('offline (disabled)'); - img.attr('src', 'image?i=ICENA').attr('alt', 'Enable this user'); + img.attr('src', 'image?i=ICENA').attr('alt', 'Enable'); } parameters = parameters_old; }); @@ -358,6 +357,12 @@ lockpoll = 0; table.removeClass("disabledtable"); }); + + // copy emm to single write emm + $("a.tosingleemm").click(function (e) { + var ins_emm = (/\s+[0-9a-fA-F]+\s+([0-9a-fA-F]+)\s+/).exec($(this).text()); + $('#singleemm').val(ins_emm[1]); + }); }); /* @@ -834,9 +839,9 @@ $.each(data.oscam.lines, function (i, item) { - if (isWhitelisted(item.line)) { - var newcolor = getLogColor(item.line); - var newline = $('
  • ' + item.line + '
  • \n'); + if (isWhitelisted(Base64.decode(item.line))) { + var newcolor = getLogColor(Base64.decode(item.line)); + var newline = $('
  • ' + Base64.decode(item.line) + '
  • \n'); var hiddenline = 0; if (newcolor) { if (newcolor.hidden != '1') { @@ -1056,14 +1061,14 @@ } $(container).append(newrow); - var name1, name2, kill1, kill2, kill3, edit1; + var name1, name2, name3, kill1, kill2, kill3, edit1; switch (item.type) { case 'c': case 'm': name1 = 'User'; name2 = item.name_enc; kill1 = '" href="status.html?action=kill&threadid=' + item.thid.substring(3, item.thid.length); - kill2 = 'Kill the ' + kill2 = 'Kill' kill3 = 'ICKIL'; edit1 = 'user_edit.html?user='; break; @@ -1072,34 +1077,37 @@ case 'x': name1 = (item.type == 'r') ? 'Reader' : 'Proxy'; name2 = item.rname_enc; - kill1 = '" href="status.html?action=restart&label=' + item.name; - kill2 = 'Restart the '; + kill1 = '" href="status.html?action=restart&label=' + name2; + kill2 = 'Restart'; kill3 = 'ICRES'; edit1 = 'readerconfig.html?label='; break; } + name3 = decodeURIComponent(name2); if (!is_nopoll('statuscol0')) { - $(uid + " > td.statuscol0").append(' td.statuscol0").append('Hide the' +
-					name1 + ' ' + item.name + ''); + '">Hide'); } if (!is_nopoll('statuscol1')) { - $(uid + " > td.statuscol1").append('' +
-					kill2 + name1 + ' ' + item.name + ''); + $(uid + " > td.statuscol1").append('' + kill2 + 
+					''); } if (!is_nopoll('statuscol4')) { if (data.oscam.piconenabled == "1" && !item.upicmissing) { $(uid + " > td.statuscol4").append(''); + name1 + ': ' + name3 + (item.desc ? '\n' + item.desc.replace(' ', '') : '') + '" src="image?i=IC_' + name2 + '">'); } else { $(uid + " > td.statuscol4").append('' + item.name + ''); + name3 + (item.desc ? '\n' + item.desc.replace(' ', '') : '') + '\n' + item.upicmissing + '">' + name3 + ''); } } @@ -1133,11 +1141,11 @@ if (!is_nopoll('statuscol4')) { if (data.oscam.piconenabled == "1" && !item.upicmissing) { $(uid + " > td.statuscol4").html(''); } else { $(uid + " > td.statuscol4").html('' + item.name + ''); + decodeURIComponent(item.name_enc) + item.desc + item.upicmissing + '">' + decodeURIComponent(item.name_enc) + ''); } } } @@ -1157,7 +1165,7 @@ } if (!is_nopoll('statuscol4')) { - $(uid + " > td.statuscol4").attr('title', item.name + (item.desc ? '\n' + item.desc.replace(' ', '') : '')); + $(uid + " > td.statuscol4").attr('title', decodeURIComponent(item.type == 'c' ? item.name_enc : item.rname_enc) + (item.desc ? '\n' + item.desc.replace(' ', '') : '')); } if (!is_nopoll('statuscol7')) { $(uid + " > td.statuscol7").text(item.connection.ip); @@ -1229,7 +1237,7 @@ var value = item.type == 'c' ? (item.request.answered ? item.request.answered + ' (' + item.request.msvalue + ' ms)' : '') : item.request.lbvalue; if (data.oscam.lbdefined) { var label = item.rname_enc.replace('+%28cache%29', ''); - var name = item.type == 'c' ? item.request.answered.replace(' (cache)', '') : item.name; + var name = item.type == 'c' ? item.request.answered.replace(' (cache)', '') : decodeURIComponent(label); if (!$(uid + " > td.statuscol14 > a").length) { $(uid + " > td.statuscol14") .text('') @@ -1359,10 +1367,38 @@ } //update reader-headline - $("#rcc").text(data.oscam.status.rcc); + if(data.oscam.status.rco != '0') { + var rcon = (data.oscam.status.rca - data.oscam.status.rco); + if($("#rco").length) { + $("#rcc").text(data.oscam.status.rcc); + $("#rca").text(data.oscam.status.rca); + $("#rco").text(rcon); + } else { + $("#rhead").html('Readers ' + data.oscam.status.rcc + '/' + data.oscam.status.rca + ' (' + rcon + ' of ' + data.oscam.status.rca + ' CARDOK)'); + } + } else if($("#rco").length) { + $("#rhead").html('Readers ' + data.oscam.status.rcc + '/' + data.oscam.status.rca); + } else { + $("#rcc").text(data.oscam.status.rcc); + $("#rca").text(data.oscam.status.rca); + } //update proxy-headline - $("#pcc").text(data.oscam.status.pcc); + if(data.oscam.status.pco != '0') { + var pcon = (data.oscam.status.pca - data.oscam.status.pco); + if($("#pco").length) { + $("#pcc").text(data.oscam.status.pcc); + $("#pca").text(data.oscam.status.pca); + $("#pco").text(pcon); + } else { + $("#phead").html('Proxies ' + data.oscam.status.pcc + '/' + data.oscam.status.pca + ' (' + pcon + ' of ' + data.oscam.status.pca + ' online)'); + } + } else if($("#pco").length) { + $("#phead").html('Proxies ' + data.oscam.status.pcc + '/' + data.oscam.status.pca); + } else { + $("#pcc").text(data.oscam.status.pcc); + $("#pca").text(data.oscam.status.pca); + } // update footer updateFooter(data); @@ -1916,3 +1952,6 @@ } } })(jQuery) + +// Create Base64 Object +var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");var t="";for(var n=0;n127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf8_decode:function(e){var t="";var n=0;var r=c1=c2=0;while(n191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}} diff -Nru oscam-1.20-10584~r10356/webif/pages_gen.c oscam-1.20-10797~r10569/webif/pages_gen.c --- oscam-1.20-10584~r10356/webif/pages_gen.c 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/pages_gen.c 2015-02-20 11:57:49.000000000 +0000 @@ -1,6 +1,6 @@ /* * OSCam WebIf pages generator - * Copyright (C) 2013 Unix Solutions Ltd. + * Copyright (C) 2013-2015 Unix Solutions Ltd. * * Authors: Georgi Chorbadzhiyski (gf@unixsol.org) * @@ -67,7 +67,7 @@ static struct templates templates; static FILE *output_file; -static void die(const char *s, ...) +__attribute__ ((noreturn)) static void die(const char *s, ...) { va_list args; va_start(args, s); @@ -137,19 +137,10 @@ static void parse_index_file(char *filename) { - unsigned long defined_file_exist=0,def_size=0; - struct stat sb; - if(stat(defined_file, &sb) == 0){ - defined_file_exist=1; - def_size = sb.st_size; - } - char is_defined[def_size]; - if(defined_file_exist){ - FILE *def = xfopen(defined_file, "r"); - if(!fread (is_defined, sizeof(is_defined), def_size, def)) - {defined_file_exist=0;} - fclose(def); - } + uint8_t *is_defined = NULL; + size_t is_defined_len = 0; + if(access(defined_file, R_OK) != -1) + readfile(defined_file, &is_defined, &is_defined_len); FILE *f = xfopen(filename, "r"); int max_fields = 3; char line[1024]; @@ -158,7 +149,7 @@ int field = 0, pos = 0; char *ident = "", *file = "", *deps = ""; int len = strlen(line); - if(!len || !isalnum(line[0])) // Skip comments and junk + if(!len || !isalnum((unsigned char)line[0])) // Skip comments and junk { continue; } // Parse text[ ]text[ ]text do @@ -191,21 +182,21 @@ } while(pos < len); - if(deps && strlen(deps) && defined_file_exist){ + if(deps && strlen(deps) && is_defined){ if(strstr(deps, ",")){ int i,def_found=0; char *ptr, *saveptr1 = NULL; char *deps_sep = strdup(deps); for(i = 0, ptr = strtok_r(deps_sep, ",", &saveptr1); ptr; ptr = strtok_r(NULL, ",", &saveptr1), i++) { - if(strstr(is_defined, ptr)) + if(strstr((char *)is_defined, ptr)) { def_found = 1; } } free(deps_sep); if(!def_found) { continue; } } - else if( !strstr(is_defined, deps)) + else if( !strstr((char *)is_defined, deps)) { continue; } } if(!strlen(ident) || !strlen(file)) @@ -441,6 +432,8 @@ // Allocate template data and populate it #define data_len cur_pos + if(!data_len) + die("No defined templates"); uint8_t *data = calloc(1, data_len); if(!data) { die("Can't alloc %u bytes", data_len); } @@ -469,6 +462,8 @@ { fprintf(stderr, "internal error - lzo_init() failed !!!\n"); fprintf(stderr, "(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n"); + free(out); + free(data); return 3; } @@ -483,6 +478,8 @@ { /* this should NEVER happen */ printf("internal error - compression failed: %d\n", r); + free(out); + free(data); return 2; } diff -Nru oscam-1.20-10584~r10356/webif/pages_index.txt oscam-1.20-10797~r10569/webif/pages_index.txt --- oscam-1.20-10584~r10356/webif/pages_index.txt 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/pages_index.txt 2015-02-20 11:57:49.000000000 +0000 @@ -238,7 +238,7 @@ STATUS status/status.html CACHEEXINFOBIT status/status_cacheexinfo.html CS_CACHEEX CLIENTHEADLINE status/status_cheadline.html -CLIENTHEADLINEWITH status/status_cheadlineadd.html +CLIENTHEADLINEADD status/status_cheadlineadd.html CLIENTHEADLINEBIT status/status_clientheadlinebit.html CLIENTSTATUSBIT status/status_clientstatusbit.html CLIENTCURRENTCHANNEL status/status_currentchannel.html @@ -252,10 +252,12 @@ LOGHISTORYBIT status/status_loghistory.html CLIENTMHEADLINE status/status_mheadline.html MODULE_MONITOR CLIENTPHEADLINE status/status_pheadline.html +CLIENTPHEADLINEADD status/status_pheadlineadd.html SREADER status/status_reader.html SREADERICON status/status_readericon.html STATUSRBUTTON status/status_restartbutton.html CLIENTRHEADLINE status/status_rheadline.html +CLIENTRHEADLINEADD status/status_rheadlineadd.html DEBUGSELECT status/status_sdebug.html WITH_DEBUG CLIENTSHEADLINE status/status_sheadline.html SYSTEMINFOBIT status/status_systeminfo.html diff -Nru oscam-1.20-10584~r10356/webif/readerconfig/readerconfig_hwreader_viaccess.html oscam-1.20-10797~r10569/webif/readerconfig/readerconfig_hwreader_viaccess.html --- oscam-1.20-10584~r10356/webif/readerconfig/readerconfig_hwreader_viaccess.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/readerconfig/readerconfig_hwreader_viaccess.html 2015-02-20 11:57:49.000000000 +0000 @@ -1,3 +1,4 @@ Reader specific settings for Viaccess AES Keys: Class: + Read old classes: diff -Nru oscam-1.20-10584~r10356/webif/readerconfig/readerconfig_hwreader_videoguard.html oscam-1.20-10797~r10569/webif/readerconfig/readerconfig_hwreader_videoguard.html --- oscam-1.20-10584~r10356/webif/readerconfig/readerconfig_hwreader_videoguard.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/readerconfig/readerconfig_hwreader_videoguard.html 2015-02-20 11:57:49.000000000 +0000 @@ -12,6 +12,15 @@ + NDS read tiers: + + + + ins7E11 TA1 Byte (1 byte): ins2E06 payload (4 bytes): ins7E payload (26 bytes): diff -Nru oscam-1.20-10584~r10356/webif/readers/readers_readerlist_entitlement.html oscam-1.20-10797~r10569/webif/readers/readers_readerlist_entitlement.html --- oscam-1.20-10584~r10356/webif/readers/readers_readerlist_entitlement.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/readers/readers_readerlist_entitlement.html 2015-02-20 11:57:49.000000000 +0000 @@ -1 +1 @@ -Show Entitlement +Show Entitlement diff -Nru oscam-1.20-10584~r10356/webif/readers/readers_readerlist.html oscam-1.20-10797~r10569/webif/readers/readers_readerlist.html --- oscam-1.20-10584~r10356/webif/readers/readers_readerlist.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/readers/readers_readerlist.html 2015-02-20 11:57:49.000000000 +0000 @@ -1,5 +1,5 @@ - ##SWITCHTITLE## + ##SWITCHTITLE## ##READERBIT## ##CTYP##
    ##GROUPS##
    @@ -11,10 +11,10 @@ ##EMMSKIPPEDUK## / ##EMMSKIPPEDG## / ##EMMSKIPPEDS## / ##EMMSKIPPEDUQ## ##EMMBLOCKEDUK## / ##EMMBLOCKEDG## / ##EMMBLOCKEDS## / ##EMMBLOCKEDUQ## ##TPLREADERLBBIT## - Edit Reader + Edit Reader ##ENTITLEMENT## ##READERREFRESH## ##WRITEEMM## ##TPLREADERLBSTAT## - Delete Reader + Delete Reader diff -Nru oscam-1.20-10584~r10356/webif/readers/readers_readerlist_lbstat.html oscam-1.20-10797~r10569/webif/readers/readers_readerlist_lbstat.html --- oscam-1.20-10584~r10356/webif/readers/readers_readerlist_lbstat.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/readers/readers_readerlist_lbstat.html 2015-02-20 11:57:49.000000000 +0000 @@ -1 +1 @@ - Loadbalancer statistics \ No newline at end of file + Loadbalancer statistics \ No newline at end of file diff -Nru oscam-1.20-10584~r10356/webif/readers/readers_readerlist_refresh.html oscam-1.20-10797~r10569/webif/readers/readers_readerlist_refresh.html --- oscam-1.20-10584~r10356/webif/readers/readers_readerlist_refresh.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/readers/readers_readerlist_refresh.html 2015-02-20 11:57:49.000000000 +0000 @@ -1 +1 @@ -Reset and reload Entitlement +Reset and reload Entitlement diff -Nru oscam-1.20-10584~r10356/webif/readers/readers_readerlist_writeemm.html oscam-1.20-10797~r10569/webif/readers/readers_readerlist_writeemm.html --- oscam-1.20-10584~r10356/webif/readers/readers_readerlist_writeemm.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/readers/readers_readerlist_writeemm.html 2015-02-20 11:57:49.000000000 +0000 @@ -1 +1 @@ -Write EMM +Write EMM diff -Nru oscam-1.20-10584~r10356/webif/script/script.html oscam-1.20-10797~r10569/webif/script/script.html --- oscam-1.20-10584~r10356/webif/script/script.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/script/script.html 2015-02-20 11:57:49.000000000 +0000 @@ -32,6 +32,6 @@

    ##SCRIPTNAME## ##CODE##

    Script Output: (if available)

    -
    ##SCRIPTRESULTOUT##
    +
    ##SCRIPTRESULTOUT##
    ##TPLFOOTER## diff -Nru oscam-1.20-10584~r10356/webif/status/status_clientstatusbit.html oscam-1.20-10797~r10569/webif/status/status_clientstatusbit.html --- oscam-1.20-10584~r10356/webif/status/status_clientstatusbit.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/status/status_clientstatusbit.html 2015-02-20 11:57:49.000000000 +0000 @@ -1,7 +1,7 @@ ##HIDEIDX## ##CSIDX## - ##STATUSUSERICON## + ##STATUSUSERICON## ##CLIENTCAUHTTP## ##CLIENTIP## ##CLIENTPORT## diff -Nru oscam-1.20-10584~r10356/webif/status/status_hidebutton.html oscam-1.20-10797~r10569/webif/status/status_hidebutton.html --- oscam-1.20-10584~r10356/webif/status/status_hidebutton.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/status/status_hidebutton.html 2015-02-20 11:57:49.000000000 +0000 @@ -1 +1 @@ -Hide the ##TARGET## ##LBL## \ No newline at end of file +Hide \ No newline at end of file diff -Nru oscam-1.20-10584~r10356/webif/status/status_killbutton.html oscam-1.20-10797~r10569/webif/status/status_killbutton.html --- oscam-1.20-10584~r10356/webif/status/status_killbutton.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/status/status_killbutton.html 2015-02-20 11:57:49.000000000 +0000 @@ -1 +1 @@ -Kill the ##TARGET## ##LBL## \ No newline at end of file +Kill \ No newline at end of file diff -Nru oscam-1.20-10584~r10356/webif/status/status_pheadlineadd.html oscam-1.20-10797~r10569/webif/status/status_pheadlineadd.html --- oscam-1.20-10584~r10356/webif/status/status_pheadlineadd.html 1970-01-01 00:00:00.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/status/status_pheadlineadd.html 2015-02-20 11:57:49.000000000 +0000 @@ -0,0 +1 @@ + (##PCO## of ##PCA## online) \ No newline at end of file diff -Nru oscam-1.20-10584~r10356/webif/status/status_pheadline.html oscam-1.20-10797~r10569/webif/status/status_pheadline.html --- oscam-1.20-10584~r10356/webif/status/status_pheadline.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/status/status_pheadline.html 2015-02-20 11:57:49.000000000 +0000 @@ -1 +1 @@ -

    Proxies ##PCC##/##PCA##

    \ No newline at end of file +

    Proxies ##PCC##/##PCA## ##PHEADADD##

    \ No newline at end of file diff -Nru oscam-1.20-10584~r10356/webif/status/status_restartbutton.html oscam-1.20-10797~r10569/webif/status/status_restartbutton.html --- oscam-1.20-10584~r10356/webif/status/status_restartbutton.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/status/status_restartbutton.html 2015-02-20 11:57:49.000000000 +0000 @@ -1 +1 @@ -Restart the ##TARGET## ##LBL## +Restart diff -Nru oscam-1.20-10584~r10356/webif/status/status_rheadlineadd.html oscam-1.20-10797~r10569/webif/status/status_rheadlineadd.html --- oscam-1.20-10584~r10356/webif/status/status_rheadlineadd.html 1970-01-01 00:00:00.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/status/status_rheadlineadd.html 2015-02-20 11:57:49.000000000 +0000 @@ -0,0 +1 @@ + (##RCO## of ##RCA## CARDOK) \ No newline at end of file diff -Nru oscam-1.20-10584~r10356/webif/status/status_rheadline.html oscam-1.20-10797~r10569/webif/status/status_rheadline.html --- oscam-1.20-10584~r10356/webif/status/status_rheadline.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/status/status_rheadline.html 2015-02-20 11:57:49.000000000 +0000 @@ -1 +1 @@ -

    Readers ##RCC##/##RCA##

    +

    Readers ##RCC##/##RCA## ##RHEADADD##

    diff -Nru oscam-1.20-10584~r10356/webif/userconfig/userconfig_entry.html oscam-1.20-10797~r10569/webif/userconfig/userconfig_entry.html --- oscam-1.20-10584~r10356/webif/userconfig/userconfig_entry.html 2015-01-30 13:28:13.000000000 +0000 +++ oscam-1.20-10797~r10569/webif/userconfig/userconfig_entry.html 2015-02-20 11:57:49.000000000 +0000 @@ -1,5 +1,5 @@ - ##SWITCHTITLE## + ##SWITCHTITLE## ##USERBIT####CLIENTCOUNTNOTIFIER## ##STATUS##
    ##CLIENTIP## ##CLIENTPROTO## @@ -19,7 +19,7 @@ ##TPLCWCYCLETBV## ##TPLCWANTICASCTBV## ##EXPDATE## - Edit User - Reset Stats - Delete User + Edit User + Reset Stats + Delete User