Stephen Warren wrote:
> On Wed, April 2, 2008 2:36 am, Phil Dibowitz wrote:
>> Stephen Warren wrote:
>>> In congruity, I have some code to identify the action to take for a
>>> specific EzHex/EZUp file, without relying on any facet of the filename.
>> I'm curious as to what you use to figure it out... there are some tells
>> like firmware has '<TYPE>Firmware_Main</TYPE>' ... but not all
>> of them are so straight forward - did you just pick a unique option
>> from each file?
>
>...
> I can post more details (e.g. a patch to just add the libconcord function)
> when I'm back home and have access to the code, since that part is already
> working, except for IR learn.
Here's an early version of the patch. It's not yet suitable for merging;
it doesn't yet do "IR learn" stuff, and I haven't tested it since the
latest CVS updates. That said, it should give an idea where I'm going if
you want to comment on it.
? concordance/.deps
? concordance/.libs
? concordance/Makefile
? concordance/Makefile.in
? concordance/aclocal.m4
? concordance/autom4te.cache
? concordance/concordance
? concordance/config.guess
? concordance/config.h
? concordance/config.h.in
? concordance/config.log
? concordance/config.status
? concordance/config.sub
? concordance/configure
? concordance/depcomp
? concordance/dummy.c
? concordance/install-sh
? concordance/libtool
? concordance/ltmain.sh
? concordance/missing
? concordance/stamp-h1
? libconcord/.deps
? libconcord/.libs
? libconcord/Makefile
? libconcord/Makefile.in
? libconcord/aclocal.m4
? libconcord/autom4te.cache
? libconcord/binaryfile.lo
? libconcord/config.guess
? libconcord/config.h
? libconcord/config.h.in
? libconcord/config.log
? libconcord/config.status
? libconcord/config.sub
? libconcord/configure
? libconcord/depcomp
? libconcord/install-sh
? libconcord/libconcord.la
? libconcord/libconcord.lo
? libconcord/libtool
? libconcord/libusbhid.lo
? libconcord/ltmain.sh
? libconcord/missing
? libconcord/remote.lo
? libconcord/remote_z.lo
? libconcord/stamp-h1
? libconcord/usblan.lo
? libconcord/web.lo
Index: libconcord/libconcord.cpp
===================================================================
RCS file: /cvsroot/concordance/concordance/libconcord/libconcord.cpp,v
retrieving revision 1.22
diff -u -p -r1.22 libconcord.cpp
--- libconcord/libconcord.cpp 3 Apr 2008 02:28:20 -0000 1.22
+++ libconcord/libconcord.cpp 3 Apr 2008 06:04:17 -0000
@@ -320,6 +320,98 @@ void delete_blob(uint8_t *ptr)
delete[] ptr;
}
+int identify_file(uint8_t *in, uint32_t size)
+{
+ int err;
+
+ /*
+ * Validate this is a remotely sane XML file
+ */
+ uint8_t *start_info_ptr;
+ err = GetTag("INFORMATION", in, size, start_info_ptr);
+ if (err == -1) {
+ return TYPE_UNKNOWN;
+ }
+
+ uint8_t *end_info_ptr;
+ err = GetTag("/INFORMATION", in, size, end_info_ptr);
+ if (err == -1) {
+ return TYPE_UNKNOWN;
+ }
+
+ /*
+ * Determine size of binary data following /INFORMATION
+ */
+ uint32_t data_len = size - (end_info_ptr - in);
+ /*
+ * Account for CRLF after /INFORMATION>
+ * But, don't screw up if it's missing
+ */
+ if (data_len >= 2) {
+ data_len -= 2;
+ }
+
+ /*
+ * Search for tag only in "connectivity test" files
+ */
+ bool found_get_zaps_only = false;
+ uint8_t *tmp_data = in;
+ uint32_t tmp_size = size - data_len;
+ while (1) {
+ uint8_t *tag_ptr;
+ string tag_s;
+ err = GetTag("KEY", tmp_data, tmp_size, tag_ptr, &tag_s);
+ if (err == -1) {
+ break;
+ }
+ if (!stricmp(tag_s.c_str(), "GETZAPSONLY")) {
+ found_get_zaps_only = true;
+ break;
+ }
+ tmp_data = tag_ptr + tag_s.length();
+ tmp_size = end_info_ptr - tmp_data;
+ }
+
+ /*
+ * Search for tag only in "firmware" files
+ */
+ bool found_firmware = false;
+ tmp_data = in;
+ tmp_size = size - data_len;
+ while (1) {
+ uint8_t *tag_ptr;
+ string tag_s;
+ err = GetTag("TYPE", tmp_data, tmp_size, tag_ptr, &tag_s);
+ if (err == -1) {
+ break;
+ }
+ if (!stricmp(tag_s.c_str(), "Firmware_Main")) {
+ found_firmware = true;
+ break;
+ }
+ tmp_data = tag_ptr + tag_s.length();
+ tmp_size = end_info_ptr - tmp_data;
+ }
+
+ /*
+ * Check tag search results for consistency, and deduce the file type
+ */
+ if (found_get_zaps_only && !data_len && !found_firmware) {
+ return TYPE_CONNECTIVITY;
+ }
+ if (!found_get_zaps_only && (data_len >= 16) && !found_firmware) {
+ return TYPE_CONFIGURATION;
+ }
+ if (!found_get_zaps_only && !data_len && found_firmware) {
+ return TYPE_FIRMWARE;
+ }
+
+ /*
+ * Findings didn't match a single file type; indicate a problem
+ */
+ return TYPE_UNKNOWN;
+}
+
/*
* Common routine to read contents of file named *file_name into
* byte buffer **out. Get size from file and return out[size]
Index: libconcord/libconcord.h
===================================================================
RCS file: /cvsroot/concordance/concordance/libconcord/libconcord.h,v
retrieving revision 1.15
diff -u -p -r1.15 libconcord.h
--- libconcord/libconcord.h 3 Apr 2008 02:28:20 -0000 1.15
+++ libconcord/libconcord.h 3 Apr 2008 06:04:17 -0000
@@ -152,6 +152,18 @@ const char *lc_strerror(int err);
void delete_blob(uint8_t *ptr);
/*
+ * Attempt to identify the action to perform to process the given file,
+ * given its content.
+ *
+ * This function will return one of the above TYPE_* constants.
+ */
+#define TYPE_UNKNOWN 0
+#define TYPE_CONNECTIVITY 1
+#define TYPE_CONFIGURATION 2
+#define TYPE_FIRMWARE 3
+int identify_file(uint8_t *in, uint32_t size);
+
+/*
* GENERAL REMOTE INTERACTIONS
*/
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
concordance-devel mailing list
concordance-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/concordance-devel