summaryrefslogtreecommitdiff
path: root/unrar
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2023-12-19 18:46:18 +0100
committerTomas Bzatek <tbzatek@redhat.com>2023-12-19 18:46:18 +0100
commite9036281ebb3a5be97e42f56667bb8dfebc5b4fe (patch)
tree4db07bedbeeb8b4d690a6bc8e4fe82ded153e701 /unrar
parent6d1c2e642eaf673e9e88ab08eacd5a6873659bcd (diff)
downloadtuxcmd-modules-e9036281ebb3a5be97e42f56667bb8dfebc5b4fe.tar.xz
unrar: Align with the unrar-6.2.12 release
Includes static and shared build.
Diffstat (limited to 'unrar')
-rw-r--r--unrar/Makefile49
-rw-r--r--unrar/Makefile.unrar39
-rw-r--r--unrar/README19
-rw-r--r--unrar/rarlog.cpp73
-rw-r--r--unrar/rarlog.hpp15
-rw-r--r--unrar/unrar.c381
6 files changed, 196 insertions, 380 deletions
diff --git a/unrar/Makefile b/unrar/Makefile
index e822800..77d5f17 100644
--- a/unrar/Makefile
+++ b/unrar/Makefile
@@ -7,7 +7,7 @@ DIR_UNRAR = unrar
# compiler options
CC = gcc
CPP = g++
-CFLAGS = -I. -I/usr/include -I$(DIR_UNRAR) \
+CFLAGS = -I. \
-Wall -Wtype-limits -fPIC -O2 -g -ggdb \
-DG_DISABLE_DEPRECATED -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE \
-D__VERBOSE_DEBUGx
@@ -15,26 +15,28 @@ CFLAGS = -I. -I/usr/include -I$(DIR_UNRAR) \
LIB_SUFFIX = `if test \`uname -m\` = x86_64 -o \`uname -m\` = ppc64; then echo 64; fi`
-UNRAR_LIB_OBJ = $(DIR_UNRAR)/filestr.o $(DIR_UNRAR)/scantree.o $(DIR_UNRAR)/dll.o
+UNRAR_LIB_OBJ = $(DIR_UNRAR)/filestr.o $(DIR_UNRAR)/scantree.o \
+ $(DIR_UNRAR)/dll.o $(DIR_UNRAR)/qopen.o
UNRAR_OBJECTS = $(DIR_UNRAR)/rar.o $(DIR_UNRAR)/strlist.o $(DIR_UNRAR)/strfn.o \
- $(DIR_UNRAR)/pathfn.o $(DIR_UNRAR)/int64.o $(DIR_UNRAR)/savepos.o \
- $(DIR_UNRAR)/global.o $(DIR_UNRAR)/file.o $(DIR_UNRAR)/filefn.o \
- $(DIR_UNRAR)/filcreat.o $(DIR_UNRAR)/archive.o $(DIR_UNRAR)/arcread.o \
- $(DIR_UNRAR)/unicode.o $(DIR_UNRAR)/system.o $(DIR_UNRAR)/isnt.o \
- $(DIR_UNRAR)/crypt.o $(DIR_UNRAR)/crc.o $(DIR_UNRAR)/rawread.o \
- $(DIR_UNRAR)/encname.o $(DIR_UNRAR)/resource.o $(DIR_UNRAR)/match.o \
- $(DIR_UNRAR)/timefn.o $(DIR_UNRAR)/rdwrfn.o $(DIR_UNRAR)/consio.o \
- $(DIR_UNRAR)/options.o $(DIR_UNRAR)/ulinks.o $(DIR_UNRAR)/errhnd.o \
- $(DIR_UNRAR)/rarvm.o $(DIR_UNRAR)/rijndael.o $(DIR_UNRAR)/getbits.o \
- $(DIR_UNRAR)/sha1.o $(DIR_UNRAR)/extinfo.o $(DIR_UNRAR)/extract.o \
- $(DIR_UNRAR)/volume.o $(DIR_UNRAR)/list.o $(DIR_UNRAR)/find.o \
- $(DIR_UNRAR)/unpack.o $(DIR_UNRAR)/cmddata.o
-
+ $(DIR_UNRAR)/pathfn.o $(DIR_UNRAR)/smallfn.o $(DIR_UNRAR)/global.o \
+ $(DIR_UNRAR)/file.o $(DIR_UNRAR)/filefn.o $(DIR_UNRAR)/filcreat.o \
+ $(DIR_UNRAR)/archive.o $(DIR_UNRAR)/arcread.o $(DIR_UNRAR)/unicode.o \
+ $(DIR_UNRAR)/system.o $(DIR_UNRAR)/crypt.o $(DIR_UNRAR)/crc.o \
+ $(DIR_UNRAR)/rawread.o $(DIR_UNRAR)/encname.o $(DIR_UNRAR)/resource.o \
+ $(DIR_UNRAR)/match.o $(DIR_UNRAR)/timefn.o $(DIR_UNRAR)/rdwrfn.o \
+ $(DIR_UNRAR)/consio.o $(DIR_UNRAR)/options.o $(DIR_UNRAR)/errhnd.o \
+ $(DIR_UNRAR)/rarvm.o $(DIR_UNRAR)/secpassword.o $(DIR_UNRAR)/rijndael.o \
+ $(DIR_UNRAR)/getbits.o $(DIR_UNRAR)/sha1.o $(DIR_UNRAR)/sha256.o \
+ $(DIR_UNRAR)/blake2s.o $(DIR_UNRAR)/hash.o $(DIR_UNRAR)/extinfo.o \
+ $(DIR_UNRAR)/extract.o $(DIR_UNRAR)/volume.o $(DIR_UNRAR)/list.o \
+ $(DIR_UNRAR)/find.o $(DIR_UNRAR)/unpack.o $(DIR_UNRAR)/headers.o \
+ $(DIR_UNRAR)/threadpool.o $(DIR_UNRAR)/rs16.o $(DIR_UNRAR)/cmddata.o \
+ $(DIR_UNRAR)/ui.o
VFS_COMMON_OBJECTS = filelist.o filelist-vfs-intf.o strutils.o vfsutils.o
-VFS_OBJECTS = unrar.o rarlog.o
+VFS_OBJECTS = unrar.o
.SUFFIXES: .c .cpp
@@ -44,24 +46,27 @@ VFS_OBJECTS = unrar.o rarlog.o
$(CPP) $(CFLAGS) `pkg-config glib-2.0 gio-2.0 --cflags` -c $<
-all shared static: libunrar_plugin.so
+all: shared
+
+shared: CFLAGS += -DMODULE_SHARED -I/usr/include/libunrar6
+shared: $(VFS_COMMON_OBJECTS) $(VFS_OBJECTS)
+ $(CPP) -shared -o libunrar_plugin.so $(VFS_COMMON_OBJECTS) $(VFS_OBJECTS) $(CFLAGS) `pkg-config glib-2.0 gio-2.0 --libs` -lunrar
-libunrar_plugin.so: libunrar $(VFS_COMMON_OBJECTS) $(VFS_OBJECTS)
+static: CFLAGS += -I$(DIR_UNRAR)
+static: libunrar $(VFS_COMMON_OBJECTS) $(VFS_OBJECTS)
$(CPP) -shared -o libunrar_plugin.so $(VFS_COMMON_OBJECTS) $(VFS_OBJECTS) $(UNRAR_OBJECTS) $(UNRAR_LIB_OBJ) $(CFLAGS) `pkg-config glib-2.0 gio-2.0 --libs`
libunrar:
- ( cd $(DIR_UNRAR) && make -f ../Makefile.unrar ) || exit 1
+ make -C $(DIR_UNRAR) lib
filelist.o: filelist.h filelist.c
filelist-vfs-intf.o: filelist-vfs-intf.h filelist-vfs-intf.c
strutils.o: strutils.h strutils.c
vfsutils.o: vfsutils.h vfsutils.c
-rarlog.o: rarlog.hpp rarlog.cpp
install::
$(INSTALL) ./libunrar_plugin.so $(DESTDIR)/lib$(LIB_SUFFIX)/tuxcmd/
clean:
- ( cd $(DIR_UNRAR) && make -f ../Makefile.unrar clean ) || exit 1
+ make -C $(DIR_UNRAR) clean
rm -f *.o *.d *.gch libunrar_plugin.so
-
diff --git a/unrar/Makefile.unrar b/unrar/Makefile.unrar
deleted file mode 100644
index c017bac..0000000
--- a/unrar/Makefile.unrar
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Makefile for UNIX - unrar
-#
-# Note: you have to 'make clean' before you can build
-# the sfx module
-#
-#
-# Modified for needs of tuxcmd VFS plugin
-#
-
-# Linux using GCC
-CXX=g++
-CXXFLAGS=-O2 -fPIC -g
-DEFINES=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DRARDLL -DGUI
-
-##########################
-
-COMPILE=$(CXX) $(CXXFLAGS) $(DEFINES)
-LINK=$(CXX)
-
-UNRAR_OBJ=filestr.o recvol.o rs.o scantree.o
-LIB_OBJ=filestr.o scantree.o dll.o
-
-OBJECTS=rar.o strlist.o strfn.o pathfn.o int64.o savepos.o global.o file.o filefn.o filcreat.o \
- archive.o arcread.o unicode.o system.o isnt.o crypt.o crc.o rawread.o encname.o \
- resource.o match.o timefn.o rdwrfn.o consio.o options.o ulinks.o errhnd.o rarvm.o \
- rijndael.o getbits.o sha1.o extinfo.o extract.o volume.o list.o find.o unpack.o cmddata.o
-
-.cpp.o:
- $(COMPILE) -c $<
-
-all: lib
-
-clean:
- rm -f *.o *.bak *~ *.so *.d
-
-lib: $(OBJECTS) $(LIB_OBJ)
-# @rm -f libunrar.so
-# $(LINK) -shared -o libunrar.so $(LDFLAGS) $(OBJECTS) $(LIB_OBJ)
diff --git a/unrar/README b/unrar/README
index f5e82c5..f664a02 100644
--- a/unrar/README
+++ b/unrar/README
@@ -1,14 +1,15 @@
UNRAR plugin for Tux Commander
- Version: 0.3.7
- Release date: 2009-Oct-25
+ Version: 0.5
+ Release date: 2023-Dec-19
-Copyright (C) 2007-2009 Tomas Bzatek <tbzatek@users.sourceforge.net>
+Copyright (C) 2007-2023 Tomas Bzatek <tbzatek@users.sourceforge.net>
http://tuxcmd.sourceforge.net
-This plugin uses UNRAR sources v3.8.2
+This plugin uses UNRAR sources v6.2.12
Copyright (C) Alexander L. Roshal
http://www.rarlab.com/
See unrar/license.txt for licensing conditions
+Downloaded from https://www.rarlab.com/rar/unrarsrc-6.2.12.tar.gz
@@ -31,12 +32,4 @@ To be implemented:
The current VFS implementation in Tux Commander lacks some extended features
-for both archiving and remote filesystems. This is one of the main goals for
-the 0.6.x series.
-
-
-For successful compilation you will need working gcc and g++ compiler and
-glib2 library installed with development files. The unrar sources are
-included in the plugin tree, no external files are required.
-
-Compilation has been tested with gcc compiler version 4.4.2
+for both archiving and remote filesystems.
diff --git a/unrar/rarlog.cpp b/unrar/rarlog.cpp
deleted file mode 100644
index c440a2a..0000000
--- a/unrar/rarlog.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include "errhnd.hpp"
-
-#define NM 1024
-#define safebuf static
-
-
-static char LogName[NM];
-
-void InitLogOptions(char *LogName)
-{
- strcpy(::LogName,LogName);
-}
-
-void Log(const char *ArcName,const char *Format,...)
-{
- printf("(WW) RARLog: ");
- va_list ArgPtr;
- va_start(ArgPtr,Format);
- vprintf(Format,ArgPtr);
- va_end(ArgPtr);
- printf("\n");
-}
-
-
-void eprintf(const char *fmt,...)
-{
- printf("(WW) RAReprintf: ");
- va_list ArgPtr;
- va_start(ArgPtr, fmt);
- vprintf(fmt, ArgPtr);
- va_end(ArgPtr);
- printf("\n");
-}
-
-void mprintf(const char *fmt,...)
-{
-/*
- printf("(WW) RARmprintf: ");
- va_list ArgPtr;
- va_start(ArgPtr, fmt);
- vprintf(fmt, ArgPtr);
- va_end(ArgPtr);
- printf("\n");
-*/
-}
-
-int Ask(const char *AskStr)
-{
- return 0;
-}
-
-void ErrorHandler::ErrMsg(const char *ArcName,const char *fmt,...)
-{
- safebuf char Msg[NM+1024];
- va_list argptr;
- va_start(argptr,fmt);
- vsprintf(Msg,fmt,argptr);
- va_end(argptr);
-// Alarm();
- if (*Msg)
- {
- Log(ArcName,"\n%s",Msg);
-// mprintf("\n%s\n",St(MProgAborted));
- }
-}
-
-void GetPasswordText(char *Str,int MaxLength)
-{
- return;
-}
diff --git a/unrar/rarlog.hpp b/unrar/rarlog.hpp
deleted file mode 100644
index b2726f8..0000000
--- a/unrar/rarlog.hpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef _RAR_LOG_
-#define _RAR_LOG_
-
-void InitLogOptions(char *LogName);
-
-void Log(const char *ArcName,const char *Format,...);
-
-void mprintf(const char *fmt,...);
-void eprintf(const char *fmt,...);
-
-int Ask(const char *AskStr);
-
-void GetPasswordText(char *Str,int MaxLength);
-
-#endif
diff --git a/unrar/unrar.c b/unrar/unrar.c
index a022775..afd4dae 100644
--- a/unrar/unrar.c
+++ b/unrar/unrar.c
@@ -1,6 +1,6 @@
/* UNRAR plugin for Tux Commander
- * version 0.4.2, designed for unrar v3.8.2
- * Copyright (C) 2007-2009 Tomas Bzatek <tbzatek@users.sourceforge.net>
+ * version 0.5, designed for unrar v6.2.12
+ * Copyright (C) 2007-2023 Tomas Bzatek <tbzatek@users.sourceforge.net>
* Check for updates on tuxcmd.sourceforge.net
*
* Uses UNRAR sources
@@ -41,8 +41,8 @@
#define _UNIX
-#include "unrar/version.hpp"
-#include "unrar/dll.hpp"
+#include <version.hpp>
+#include <dll.hpp>
/* Compatibility types from headers.hpp */
@@ -57,15 +57,12 @@ enum HOST_SYSTEM {
};
-#define VERSION "0.4.2"
-#define BUILD_DATE "2009-12-12"
+#define VERSION "0.5"
+#define BUILD_DATE "2023-12-19"
#define DEFAULT_BLOCK_SIZE 65536
-
-
-
/* Declaration of the global plugin object */
struct TVFSGlobs {
TVFSLogFunc log_func;
@@ -131,7 +128,6 @@ VFSNew (TVFSLogFunc log_func)
return globs;
}
-
void
VFSSetCallbacks (struct TVFSGlobs *globs,
TVFSAskQuestionCallback ask_question_callback,
@@ -166,14 +162,19 @@ struct TVFSInfo *
VFSGetInfo ()
{
struct TVFSInfo *module_info;
+#ifdef MODULE_SHARED
+ const char *shared_module = "dynamically linked";
+#else
+ const char *shared_module = "statically linked";
+#endif
module_info = g_malloc0 (sizeof (struct TVFSInfo));
module_info->ID = g_strdup ("unrar_plugin");
module_info->Name = g_strdup ("UNRAR plugin");
- module_info->About = g_strdup_printf ("version %s, build date: %s\nusing unrar sources v%d.%d [%d-%.2d-%.2d]\n",
- VERSION, BUILD_DATE, RARVER_MAJOR, RARVER_MINOR, RARVER_YEAR, RARVER_MONTH, RARVER_DAY);
- module_info->Copyright = g_strdup ("Plugin Copyright (C) 2007-2009 Tomáš Bžatek\nUNRAR sources Copyright (C) 2002-2008 Alexander Roshal");
+ module_info->About = g_strdup_printf ("version %s, build date: %s\nusing unrar sources v%d.%d [%d-%.2d-%.2d]\n%s\n",
+ VERSION, BUILD_DATE, RARVER_MAJOR, RARVER_MINOR, RARVER_YEAR, RARVER_MONTH, RARVER_DAY, shared_module);
+ module_info->Copyright = g_strdup ("Plugin Copyright (C) 2007-2023 Tomáš Bžatek\nUNRAR sources Copyright (C) 2002-2023 Alexander Roshal");
return module_info;
}
@@ -199,122 +200,106 @@ VFSGetArchiveExts ()
static int
unrar_callback (UINT msg, LONG UserData, LONG P1, LONG P2)
{
- struct TVFSGlobs *globs;
+ struct TVFSGlobs *globs = (struct TVFSGlobs *) UserData;
-// fprintf(stderr, "(II) unrar_callback called: msg = %d, UserData = %lx, sizeof(UserData) = %ld, P1 = %ld, P2 = %ld\n", msg, UserData, sizeof(UserData), P1, P2);
- if (! UserData) {
- fprintf (stderr, "(WW) unrar_callback: UserData == NULL, exiting!\n");
+ if (globs == NULL) {
+ fprintf (stderr, "(WW) unrar_callback: UserData == NULL, aborting.\n");
return 0;
}
- globs = (struct TVFSGlobs *) UserData;
// >= 0 => Weiter, -1 => Stop
switch (msg) {
- case UCM_CHANGEVOLUME: {
- if (P2 == RAR_VOL_ASK) {
- fprintf (stderr, " (II) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_ASK, P1 = %ld, (char*)P1 = '%s' \n", P1, (char*)P1);
- if (P1) {
- if (globs->callback_ask_question) {
- static const char *choices[] = {
- "Abort", /* response = 0 */
- "Ignore", /* response = 1 */
- NULL
- };
- char *message, *s;
- int choice = -1;
-
- s = g_filename_display_name((char *)P1);
- message = g_strdup_printf ("Archive is incomplete, volume missing: \n\n%s", s ? s : (char *)P1);
- globs->callback_ask_question (message, &choices[0], &choice, 0,
- globs->callback_data);
- g_free (message);
- g_free (s);
-
- if (choice != 1)
- globs->volume_missing_abort = TRUE;
- return -1;
- } else {
- if (access((char*)P1, R_OK) != 0) {
- fprintf (stderr, "(EE) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_ASK: access test failed - missing part? Error = %s \n", strerror (errno));
- return -1;
- }
- }
+ case UCM_CHANGEVOLUME:
+ if (P2 == RAR_VOL_ASK) {
+ fprintf (stderr, " (II) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_ASK, P1='%s'\n", (char *) P1);
+ if (globs->callback_ask_question) {
+ static const char *choices[] = {
+ "Abort", /* response = 0 */
+ "Ignore", /* response = 1 */
+ NULL
+ };
+ char *message;
+ char *s;
+ int choice = -1;
+
+ s = g_filename_display_name (P1 ? (char *) P1 : "<unknown>");
+ message = g_strdup_printf ("Archive is incomplete, volume missing:\n\n%s", s ? s : (char *) P1);
+ globs->callback_ask_question (message, &choices[0], &choice, 0,
+ globs->callback_data);
+ g_free (message);
+ g_free (s);
+
+ if (choice != 1)
+ globs->volume_missing_abort = TRUE;
+ return -1;
+ } else {
+ if (P1 && access ((char *) P1, R_OK) == 0)
+ return 0;
+ fprintf (stderr, "(EE) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_ASK: access test failed: %s\n", strerror (errno));
+ return -1;
}
- } else
- if (P2 == RAR_VOL_NOTIFY) {
- fprintf (stderr, " (II) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_NOTIFY, P1 = %ld, (char*)P1 = '%s' \n", P1, (char*)P1);
- }
- break;
- }
+ return 0;
+ } else
+ if (P2 == RAR_VOL_NOTIFY) {
+ fprintf (stderr, " (II) unrar_callback: UCM_CHANGEVOLUME message, RAR_VOL_NOTIFY, P1='%s'\n", (char *) P1);
+ return 0;
+ }
+ else {
+ fprintf (stderr, " (WW) unrar_callback: UCM_CHANGEVOLUME message, P1='%s', unhandled P2/action %ld, aborting.\n", (char *) P1, P2);
+ return -1;
+ }
+ break;
- case UCM_PROCESSDATA: {
- fprintf (stderr, " (II) unrar_callback: UCM_PROCESSDATA message, P1 = %ld, P2 = %ld \n", P1, P2);
-// printf(" (II) unrar_callback: globs = 0x%lX, UserData = 0x%lX \n", (unsigned long int)globs, UserData);
- if (globs && globs->callback_progress) {
-// printf(" (II) unrar_callback: globs->extract_callback_func = 0x%lX, globs->extract_callback_data = 0x%lX \n", (unsigned long int)globs->extract_callback_func, (unsigned long int)globs->extract_callback_data);
-// long int res = globs->extract_callback_func((u_int64_t)P1, (u_int64_t)((u_int64_t)P1 + (u_int64_t)P2), globs->extract_callback_data);
+ case UCM_PROCESSDATA:
+ fprintf (stderr, " (II) unrar_callback: UCM_PROCESSDATA message, P1/Addr = %p, P2/Count = %ld\n", (void *) P1, P2);
+ if (globs->callback_progress) {
+ gboolean res;
globs->extract_done += P2;
- gboolean res = globs->callback_progress(globs->extract_done, NULL, globs->callback_data);
-
-// fprintf(stderr, " (II) unrar_callback: res = %d \n", res);
- if (! res ) {
+ res = globs->callback_progress (globs->extract_done, NULL, globs->callback_data);
+ if (! res) {
globs->extract_cancelled = TRUE;
fprintf (stderr, "(WW) unrar_callback: received cancellation result\n");
- return -1; // Cancel operation
+ return -1; /* cancel the operation */
}
- }
- break;
- }
+ }
+ return 0;
+
+ case UCM_NEEDPASSWORD:
+ char *passwd = NULL;
+ gboolean res = FALSE;
+
+ fprintf (stderr, " (II) unrar_callback: UCM_NEEDPASSWORD message, P1/buf = %p, P2/bufsize = %ld\n", (void *) P1, P2);
+
+ globs->failed_passwd_callback = TRUE;
+ if (globs->callback_ask_password) {
+ res = globs->callback_ask_password ("The archive is encrypted and needs a password",
+ NULL, NULL, NULL, VFS_ASK_PASSWORD_NEED_PASSWORD | VFS_ASK_PASSWORD_ARCHIVE_MODE,
+ NULL, &passwd, NULL, NULL, NULL,
+ globs->callback_data);
+ if (res && passwd && strlen (passwd) > 0) {
+ strncpy ((char *) P1, passwd, P2);
+ g_free (globs->password);
+ globs->password = g_strdup (passwd);
+ }
+ g_free (passwd);
+ }
+ if (res)
+ return 0;
+ globs->extract_cancelled = TRUE;
+ return -1;
+
+ case UCM_NEEDPASSWORDW:
+ case UCM_CHANGEVOLUMEW:
+ /* deliberately ignoring these due to bogus data in P1 */
+ return 0;
- case UCM_NEEDPASSWORD: {
- fprintf (stderr, " (II) unrar_callback: UCM_NEEDPASSWORD message, P1 = %ld, P2 = %ld, (char*)P1 = '%s', maxlen = %ld \n", P1, P2, (char*)P1, P2);
-
- char *passwd = NULL;
- gboolean res = FALSE;
-
- globs->failed_passwd_callback = TRUE;
- if (globs->callback_ask_password) {
- res = globs->callback_ask_password ("The archive is encrypted and requires password",
- NULL, NULL, NULL, VFS_ASK_PASSWORD_NEED_PASSWORD | VFS_ASK_PASSWORD_ARCHIVE_MODE,
- NULL, &passwd, NULL, NULL, NULL,
- globs->callback_data);
- if (res && passwd) {
- fprintf(stderr, " (II) unrar_callback: setting password to '%s'\n", passwd);
- if (strlen (passwd) > 0) {
- strncpy ((char *)P1, passwd, P2);
- g_free (globs->password);
- globs->password = g_strdup (passwd);
- }
- g_free (passwd);
- }
- }
- if (res)
- return 0;
- else {
- globs->extract_cancelled = TRUE;
- return -1;
- }
- }
+ default:
+ fprintf (stderr, "(WW) unrar_callback: unhandled msg code %u, exiting!\n", msg);
+ return -1;
}
- return 0;
-}
-
-static int PASCAL
-unrar_changevol_proc (char *ArcName, int Mode)
-{
- fprintf (stderr, "(II) unrar_changevol_proc called: ArcName = '%s', Mode = %d\n", ArcName, Mode);
-
- return 0;
-}
-
-static int PASCAL
-unrar_process_data_proc (unsigned char *Addr, int Size)
-{
- fprintf (stderr, "(II) unrar_process_data_proc called: Addr = '%s', Size = %d\n", Addr, Size);
-
- return 0;
+ return -1;
}
/* ----------------------------------------------------------------------------------------------------------- */
@@ -379,6 +364,12 @@ rar_error_to_gerror (int code, GError **error)
case ERAR_MISSING_PASSWORD:
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED, "Missing password.");
break;
+ case ERAR_EREFERENCE:
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Bad reference.");
+ break;
+ case ERAR_BAD_PASSWORD:
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED, "Bad password.");
+ break;
default:
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Operation failed.");
break;
@@ -392,7 +383,7 @@ gboolean
VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error)
{
HANDLE PASCAL handle;
- struct RAROpenArchiveDataEx *archive_data;
+ struct RAROpenArchiveDataEx archive_data = { 0, };
guint64 inode_no;
gboolean Result;
@@ -408,95 +399,74 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error)
inode_no = 0;
fprintf (stderr, "(--) VFSOpenArchive: trying to open archive '%s'...\n", globs->archive_path);
- /* WARNING: do not use g_malloc0() here, leads to memory corruption */
- archive_data = malloc (sizeof (struct RAROpenArchiveDataEx));
- memset (archive_data, 0, sizeof (struct RAROpenArchiveDataEx));
- archive_data->ArcName = globs->archive_path;
- archive_data->CmtBuf = NULL;
- archive_data->CmtBufSize = 0;
- archive_data->OpenMode = RAR_OM_LIST;
-
- handle = RAROpenArchiveEx (archive_data);
-// printf(" handle = %lu \n", (unsigned long int)handle);
-// printf(" archive_data->OpenResult = %d \n", archive_data->OpenResult);
-// printf(" archive_data->CmtState = %d \n", archive_data->CmtState);
-// printf(" archive_data->CmtSize = %d \n", archive_data->CmtSize);
-
- if (handle && ! archive_data->OpenResult) {
- // Set callbacks
- RARSetCallback (handle, unrar_callback, (LONG)globs);
-// RARSetChangeVolProc(handle, unrar_changevol_proc);
-// RARSetProcessDataProc(handle, unrar_process_data_proc);
+ archive_data.ArcName = globs->archive_path;
+ archive_data.CmtBuf = NULL;
+ archive_data.CmtBufSize = 0;
+ archive_data.OpenMode = RAR_OM_LIST;
+
+ handle = RAROpenArchiveEx (&archive_data);
+ if (handle && archive_data.OpenResult == 0) {
+ struct RARHeaderDataEx header = { 0, };
+ int PASCAL res = 0;
+ RARSetCallback (handle, unrar_callback, (LONG) globs);
if (globs->password) {
fprintf (stderr, "(II) VFSOpenArchive: Setting password... \n");
RARSetPassword (handle, globs->password);
}
- struct RARHeaderDataEx *header;
- /* WARNING: do not use g_malloc0() here, leads to memory corruption */
- header = malloc (sizeof (struct RARHeaderDataEx));
- memset (header, 0, sizeof (struct RARHeaderDataEx));
-
- int PASCAL res = 0;
- while ((res = RARReadHeaderEx(handle, header)) == 0) {
-// printf(" header->FileName = '%s', Flags = 0x%x\n", header->FileName, header->Flags);
+ while ((res = RARReadHeaderEx (handle, &header)) == 0) {
+ struct TVFSItem *item;
+ char *s;
+ int PASCAL res2;
+ item = g_malloc0 (sizeof (struct TVFSItem));
+ item->iSize = (guint64)((guint64)(header.UnpSizeHigh * 0x100000000) + (guint64)header.UnpSize);
+ item->iPackedSize = (guint64)((guint64)(header.PackSizeHigh * 0x100000000) + (guint64)header.PackSize);
inode_no++;
-
- /* Create a TVFSItem entry and fill all info */
- struct TVFSItem *item = g_malloc0 (sizeof (struct TVFSItem));
-
- item->iSize = (guint64)((guint64)(header->UnpSizeHigh * 0x100000000) + (guint64)header->UnpSize);
- item->iPackedSize = (guint64)((guint64)(header->PackSizeHigh * 0x100000000) + (guint64)header->PackSize);
item->inode_no = inode_no;
globs->total_size += item->iSize;
- if ((header->Flags & 0x00e0 /* LHD_WINDOWMASK */ ) == 0x00e0 /* LHD_DIRECTORY */)
+ if ((header.Flags & RHDF_DIRECTORY) == RHDF_DIRECTORY)
item->ItemType = vDirectory;
else
item->ItemType = vRegular;
- if ((header->Flags & 0x0004) == 0x0004)
+ if ((header.Flags & RHDF_ENCRYPTED) == RHDF_ENCRYPTED)
globs->need_password = TRUE;
- switch (header->HostOS) {
+ switch (header.HostOS) {
case HOST_MSDOS:
case HOST_OS2:
case HOST_WIN32:
- if (header->FileAttr & 0x10)
- header->FileAttr = 0x41ff | header->FileAttr;
+ if (header.FileAttr & 0x10)
+ header.FileAttr = 0x41ff | header.FileAttr;
else
- if (header->FileAttr & 1)
- header->FileAttr = 0x8124 | header->FileAttr;
+ if (header.FileAttr & 1)
+ header.FileAttr = 0x8124 | header.FileAttr;
else
- header->FileAttr = 0x81b6 | header->FileAttr;
+ header.FileAttr = 0x81b6 | header.FileAttr;
break;
}
- item->iMode = header->FileAttr;
+ item->iMode = header.FileAttr;
item->iUID = geteuid ();
item->iGID = getegid ();
- item->m_time = rar_time_to_unix (header->FileTime);
+ item->m_time = rar_time_to_unix (header.FileTime);
item->c_time = item->m_time;
item->a_time = item->m_time;
-// g_print (" valid = %d\n", g_utf8_validate (header->FileName, -1, NULL));
-
- char *s;
- if (g_utf8_validate (header->FileName, -1, NULL))
- s = g_strdup (header->FileName);
+ if (g_utf8_validate (header.FileName, -1, NULL))
+ s = g_strdup (header.FileName);
else
- s = wide_to_utf8 (header->FileNameW);
-// g_print (" ansi = '%s'\n wide = '%ls'\n utf8 = '%s'\n", header->FileName, header->FileNameW, s);
+ s = wide_to_utf8 (header.FileNameW);
- // Add item to the global list and continue with next file
- filelist_tree_add_item (globs->files, s, item, header->FileName, inode_no);
+ /* Add the item to the global list and continue with next file */
+ filelist_tree_add_item (globs->files, s, item, header.FileName, inode_no);
g_free (s);
- int PASCAL res2 = RARProcessFile (handle, RAR_SKIP, NULL, NULL);
+ res2 = RARProcessFile (handle, RAR_SKIP, NULL, NULL);
if (res2)
printf ("RARProcessFile result = %d\n", res2);
}
-// printf("\nRARReadHeader result = %d\n", res);
if (res != ERAR_END_ARCHIVE || globs->volume_missing_abort) {
fprintf (stderr, "(EE) VFSOpenArchive: RARReadHeader result = %d\n", res);
rar_error_to_gerror (res, error);
@@ -506,21 +476,19 @@ VFSOpenArchive (struct TVFSGlobs *globs, const char *sName, GError **error)
Result = cVFS_BadPassword;
*/
}
- free (header);
- res = RARCloseArchive(handle);
+ res = RARCloseArchive (handle);
if (res)
fprintf (stderr, "(EE) VFSOpenArchive: RARCloseArchive result = %d\n", res);
} else {
- fprintf (stderr, "(EE) VFSOpenArchive: error occured when opening archive: OpenResult = %d\n", archive_data->OpenResult);
- rar_error_to_gerror (archive_data->OpenResult, error);
+ fprintf (stderr, "(EE) VFSOpenArchive: error occured when opening archive: OpenResult = %d\n", archive_data.OpenResult);
+ rar_error_to_gerror (archive_data.OpenResult, error);
Result = FALSE;
}
- free (archive_data);
- fprintf (stderr, "(II) VFSOpenArchive: done. \n");
+ fprintf (stderr, "(II) VFSOpenArchive: done.\n");
if (globs->need_password)
- printf ("Password present.\n");
+ fprintf (stderr, "(II) VFSOpenArchive: Password present.\n");
printf ("\n\nList of items:\n");
filelist_tree_print (globs->files);
@@ -534,9 +502,9 @@ VFSClose (struct TVFSGlobs *globs, GError **error)
if (globs) {
fprintf (stderr, "(II) VFSClose: Freeing objects...\n");
if (globs->vfs_filelist)
- vfs_filelist_free(globs->vfs_filelist);
+ vfs_filelist_free (globs->vfs_filelist);
if (globs->files)
- filelist_tree_free(globs->files);
+ filelist_tree_free (globs->files);
g_free (globs->archive_path);
g_free (globs->curr_dir);
g_free (globs->password);
@@ -760,13 +728,12 @@ VFSTwoSameFiles (struct TVFSGlobs *globs, const char *Path1, const char *Path2,
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////
-
gboolean
VFSStartCopyOperation (struct TVFSGlobs *globs, GError **error)
{
- struct RAROpenArchiveDataEx *archive_data;
+ struct RAROpenArchiveDataEx archive_data = { 0, };
HANDLE PASCAL handle;
- gboolean Result;
+ gboolean Result = FALSE;
if (globs->op_handle != NULL) {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED, "globs->op_handle != NULL");
@@ -774,26 +741,12 @@ VFSStartCopyOperation (struct TVFSGlobs *globs, GError **error)
}
printf ("(II) VFSStartCopyOperation: opening archive '%s'\n", globs->archive_path);
- Result = FALSE;
-
- /* WARNING: do not use g_malloc0() here, leads to memory corruption */
- archive_data = malloc (sizeof (struct RAROpenArchiveDataEx));
- memset (archive_data, 0, sizeof (struct RAROpenArchiveDataEx));
- archive_data->ArcName = globs->archive_path;
- archive_data->OpenMode = RAR_OM_EXTRACT;
-
- handle = RAROpenArchiveEx (archive_data);
-// printf(" handle = %lu \n", (unsigned long int)handle);
-// printf(" archive_data->OpenResult = %d \n", archive_data->OpenResult);
-// printf(" archive_data->CmtState = %d \n", archive_data->CmtState);
-// printf(" archive_data->CmtSize = %d \n", archive_data->CmtSize);
+ archive_data.ArcName = globs->archive_path;
+ archive_data.OpenMode = RAR_OM_EXTRACT;
- if (handle && ! archive_data->OpenResult) {
- /* set callbacks */
-// printf(" setting callback: globs = 0x%lX, (unsigned long int)globs = 0x%lX, (LONG)globs = 0x%lX\n", globs, (unsigned long int)globs, (LONG)globs);
+ handle = RAROpenArchiveEx (&archive_data);
+ if (handle && archive_data.OpenResult == 0) {
RARSetCallback (handle, unrar_callback, (LONG) globs);
-// RARSetChangeVolProc(handle, unrar_changevol_proc);
-// RARSetProcessDataProc(handle, unrar_process_data_proc);
/* set password */
if (globs->password) {
@@ -804,11 +757,10 @@ VFSStartCopyOperation (struct TVFSGlobs *globs, GError **error)
globs->op_handle = handle;
Result = TRUE;
} else {
- fprintf (stderr, "(EE) VFSStartCopyOperation: error occured when opening archive: OpenResult = %d\n", archive_data->OpenResult);
- rar_error_to_gerror (archive_data->OpenResult, error);
+ fprintf (stderr, "(EE) VFSStartCopyOperation: error occured when opening archive: OpenResult = %d\n", archive_data.OpenResult);
+ rar_error_to_gerror (archive_data.OpenResult, error);
Result = FALSE;
}
- free (archive_data);
return Result;
}
@@ -844,8 +796,10 @@ gboolean
VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstName, gboolean Append, GError **error)
{
struct PathTree *node;
- gboolean found;
- gboolean Result;
+ struct RARHeaderDataEx header = { 0, };
+ gboolean found = FALSE;
+ gboolean Result = TRUE;
+ int res = 0;
char *src;
if (globs->op_handle == NULL) {
@@ -874,24 +828,16 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
}
printf ("(II) VFSCopyToLocal: new src path: '%s'\n", src);
- struct RARHeaderDataEx *header;
- /* WARNING: do not use g_malloc0() here, leads to memory corruption */
- header = malloc (sizeof (struct RARHeaderDataEx));
- memset (header, 0, sizeof (struct RARHeaderDataEx));
-
- int res = 0;
- found = FALSE;
- Result = TRUE;
+ while ((res = RARReadHeaderEx (globs->op_handle, &header)) == 0) {
+ int res2;
- while ((res = RARReadHeaderEx(globs->op_handle, header)) == 0) {
- g_print ("VFSCopyToLocal: found '%s'\n", header->FileName);
- if (g_strcmp0 (src, header->FileName) == 0) {
-// fprintf(stderr, "(II) VFSCopyToLocal: extract_file_path(sDstName) = '%s', extract_file_name(sDstName) = '%s' \n", extract_file_path(sDstName), extract_file_name(sDstName));
+ g_print ("VFSCopyToLocal: found '%s'\n", header.FileName);
+ if (g_strcmp0 (src, header.FileName) == 0) {
globs->extract_done = 0;
globs->extract_cancelled = FALSE;
found = TRUE;
- int res2 = RARProcessFile (globs->op_handle, RAR_EXTRACT, NULL, (char *)sDstName);
+ res2 = RARProcessFile (globs->op_handle, RAR_EXTRACT, NULL, (char *)sDstName);
if (globs->extract_cancelled) {
fprintf (stderr, "(WW) VFSCopyToLocal: cancelled !\n");
@@ -906,7 +852,7 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
}
break;
} else {
- int res2 = RARProcessFile (globs->op_handle, RAR_SKIP, NULL, NULL);
+ res2 = RARProcessFile (globs->op_handle, RAR_SKIP, NULL, NULL);
if (res2) {
fprintf (stderr, "(EE) VFSCopyToLocal: RARProcessFile result = %d\n", res2);
rar_error_to_gerror (res2, error);
@@ -927,7 +873,6 @@ VFSCopyToLocal (struct TVFSGlobs *globs, const char *sSrcName, const char *sDstN
rar_error_to_gerror (res, error);
}
}
- free (header);
if (! found && Result) {
fprintf (stderr, "(EE) VFSCopyToLocal: file not found in archive.\n");