-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move external codec MD5 reading routines to separate source file.
- Loading branch information
Showing
10 changed files
with
273 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* BoCA - BonkEnc Component Architecture | ||
* Copyright (C) 2007-2024 Robert Kausch <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 2 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | ||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ | ||
|
||
#ifndef H_BOCA_EXTERNALUTILITIES | ||
#define H_BOCA_EXTERNALUTILITIES | ||
|
||
#include "../componentspecs.h" | ||
|
||
namespace BoCA | ||
{ | ||
namespace AS | ||
{ | ||
class ExternalUtilities | ||
{ | ||
public: | ||
static String GetMD5(const ComponentSpecs *, const String &); | ||
}; | ||
}; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* BoCA - BonkEnc Component Architecture | ||
* Copyright (C) 2007-2024 Robert Kausch <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 2 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | ||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ | ||
|
||
#include <boca/application/external/utilities.h> | ||
|
||
#include <boca/common/utilities.h> | ||
|
||
#include <signal.h> | ||
#include <sys/wait.h> | ||
|
||
using namespace smooth::IO; | ||
|
||
String BoCA::AS::ExternalUtilities::GetMD5(const ComponentSpecs *specs, const String &encFileName) | ||
{ | ||
if (specs->external_md5_arguments == NIL) return NIL; | ||
|
||
/* Start 3rd party command line decoder. | ||
*/ | ||
String command = String("\"").Append(specs->external_command).Append("\"").Replace("/", Directory::GetDirectoryDelimiter()); | ||
String arguments = String(specs->external_md5_arguments).Replace("%INFILE", String(encFileName).Replace("\\", "\\\\").Replace(" ", "\\ ") | ||
.Replace("\"", "\\\"").Replace("\'", "\\\'").Replace("`", "\\`") | ||
.Replace("(", "\\(").Replace(")", "\\)").Replace("<", "\\<").Replace(">", "\\>") | ||
.Replace("&", "\\&").Replace(";", "\\;").Replace("$", "\\$").Replace("|", "\\|")); | ||
|
||
FILE *rPipe = popen(String(command).Append(" ").Append(arguments).Append(specs->external_md5_stderr ? " 2>&1" : (specs->debug ? NIL : " 2> /dev/null")), "r"); | ||
|
||
/* Read output into buffer. | ||
*/ | ||
Buffer<char> buffer(4096); | ||
Int bytesReadTotal = 0; | ||
Int bytesRead = 0; | ||
|
||
do | ||
{ | ||
bytesRead = fread(buffer + bytesReadTotal, 1, 4096 - bytesReadTotal, rPipe); | ||
|
||
if (bytesRead != 4096 - bytesReadTotal && (ferror(rPipe) || bytesRead == 0)) break; | ||
|
||
bytesReadTotal += bytesRead; | ||
} | ||
while (bytesReadTotal < 4096); | ||
|
||
String output = (bytesReadTotal > 0 ? (char *) buffer : NIL); | ||
|
||
/* Wait until the decoder exits. | ||
*/ | ||
unsigned long exitStatus = pclose(rPipe); | ||
unsigned long exitCode = WIFEXITED(exitStatus) ? WEXITSTATUS(exitStatus) : -1; | ||
unsigned long exitSignal = WIFSIGNALED(exitStatus) ? WTERMSIG(exitStatus) : -1; | ||
|
||
/* Check if anything went wrong. | ||
*/ | ||
if (!specs->external_ignoreExitCode && exitCode != 0 && exitCode != 0x80 + SIGPIPE && exitSignal != SIGPIPE) return NIL; | ||
|
||
/* Extract MD5 from output. | ||
*/ | ||
String md5; | ||
|
||
if (output.Contains(specs->external_md5_require) && | ||
output.Contains(specs->external_md5_prefix)) md5 = output.SubString(output.Find(specs->external_md5_prefix) + specs->external_md5_prefix.Length(), | ||
output.Length() - output.Find(specs->external_md5_prefix) - specs->external_md5_prefix.Length()).Trim().Head(32).ToLower(); | ||
|
||
if (md5.Length() != 32 || md5.Contains("\n") || md5.Contains(" ")) md5 = NIL; | ||
|
||
return md5; | ||
} |
Oops, something went wrong.