The proptype (a.k.a. device property code) is already stored in
dpd.DevicePropertyCode member. This patch introduces the
ptp_find_eos_devicepropdesc() function for the commonly repeated for-loop
looking for the DevicePropDesc* in the cache.
This now allows to completely replace PTPCanon_Property with
PTPDevicePropDesc and then drop the canon_props array altogether and use
the generic one.
PTPDeviceProperty data of EOS cameras is not polled but rather pro-actively
sent by the camera via a PropValueChanged event. The unpack function used
to interpret the data and unpack it into the PTPDevicePropDesc struct
but also copied the raw event data block into an extra member (data, size)
of the special special PTPCanon_Property struct. This data is then never
looked at again.
This patch removes those data members and is a first step to completely
eliminate the special PTPCanon_Property struct.
Move the byte-order-swapping helpers from ptp-pack.c to ptp.h as well as 2
ptp_free_deviceinfo variants and remove all but one ptp-pack.c inclusions.
This speeds up compile time and removes lots of compiler warning
repetitions if one shows up in ptp-pack.c.
The idea is to remove 'manual' offset adjustments:
```
unsigned offset = 0;
unsigned val = dtoh32o(data, offset);
// offset is now 4
```
Also contains some code beautification near the use of dtoh style macros.
Those functions get passed an offset value into the data buffer. This
offset value needed to be updated on the calling side after the call with
internal knowledge of what exactly the unpack function itself was doing.
Now the offset becomes an in/out parameter and in updated internally. This
substantially reduces the complexity of the calling code.
Furthermore, the return value is now an error indicator and the array
length gets set via a pointer.
This further fixes a few places where there was a bug in the bounds
checking or no bounds checking at all.
E.g. the 5Ds:
Friendly Device Name (d402): (ro str) 'Canon EOS 5DS'
Perceived Device Type (d407): (ro u32) 1
Session Initiator Info (d406): (rw str) 'Unknown Initiator'
Enable silent build rules by default.
You can still use verbose build rules by using any of the following
methods:
* run `configure` with the `--disable-silent-rules` argument
* run `make` with the `V=1` argument
This hides the compiler command line which makes debugging users'
problems more difficult. To compensate for that, this prints the
build flags separately, but a lot less frequently:
For each part of the build (`libgphoto2_port.la`, iolibs,
`libgphoto2.la`, camlibs), if something of that part has been
rebuilt, prints the build flags (_CPPFLAGS, _CFLAGS, _LIBADD,
_LDFLAGS) once.
Always prints the environment variables CPPFLAGS CFLAGS LDADD
LIBADD LDFLAGS once, whether they are the defaults the configure
script sets or given on the `make` command line.
Not all make recipes have been converted to be completely silent,
but the majority (especially the Automake standard recipes) are
now silent.
This makes the event entries in the log from an EOS more readable by
removing uninteresting information and layout out interesting information
in a more aligned/table based manner for quick visual parsing of the data.
Example excerpt:
```
event 104: EOS prop d1c9 value changed, size 4 (EOS_ContinousAFMode)
value of d1c9 is 0x00000000 (u32)
event 105: EOS prop d19f value changed, size 4 (EOS_GPSDeviceActive)
EOS prop d19f is unknown
value of d19f is 0x00000001 (u32)
[...]
event 111: EOS prop d177 value changed, size 24 (EOS_SmartphoneShowImageConfig)
0x000: 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x010: 00 00 00 00 00 00 00 00
event 112: EOS prop d105 options changed, type 1, count 0 (EOS_AutoExposureMode)
event 113: EOS prop d108 options changed, type 3, count 3 (EOS_FocusMode)
option[ 0] of d108 is 0x00
option[ 1] of d108 is 0x02
option[ 2] of d108 is 0x01
```
Instead of calling ptp_canon_eos_keepdeviceon() in e.g.
camera_wait_for_event() directly for every invocation (often twice),
which can lead to dozens of those calls per second, this patch limits the
number to 1 every 10 seconds.
The camera_prepare_capture + ptp_check_eos_events + keepdeviceon block in
camera_lookup_by_property has been removed completely as this function is
only called from within camera_wait_for_event() where those checks have
been made just prior to the call to camera_lookup_by_property.
Furthermore: ptp_check_eos_events() will now only be called inside
camera_wait_for_event if the queue of already transmitted events is
drained first.
This is basically an amendment to #1015, I just realized that I overlooked
some places due to a too restrictive regex.
(I hope this subject is not getting old already...)
This is a whitespace only change (if you include newlines as whitespace).
* unused variables
* implicit enum conversion
* sigend <-> unsigned comparison
* left shift negative number
The only warnings left on my setup right now are `-Wstringop-truncation`
from strncpy calls. Those are not trivial to fix. Turns out the code does
regularly not take into account that strncpy may not result in a null
terminated string. Details, see `man string_copying`.
This is basically a continuation of the work from #1002 but her for the
camlibs directory. The purpose was to replace spaces as a means for
indentation with tab characters.
Note: there are some files which are still offending the general
rule but are (mostly) consistent within themselves. I let them be for
the moment. Fixing them would basically replace the whole file.
Also: there are still a ton of whitespace related inconsistencies like
"x=10" vs "x = 10" or "func(10)" vs "func (10)".
This is a whitespace only change (if you include newlines as whitespace).
This replaces the verbose and error prone pattern of calling
str = malloc(strlen("some value is 12345678"));
sprintf(str, "some value is %d", val)
with
str = aprintf(some value is %d", val);
This is similar to the GNU function asprintf() but returns the pointer
instead of assigning it to the first parameter. It uses the existing
gpi_vsnprintf(fmt, va_list) function.
* fix memory leaks related to PTPCanon_changes_entry.u.info
Unpacking canon EOS event data uses heap memory stored in `char *info` for
different types of information (mostly PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN
but also PTP_CANON_EOS_CHANGES_TYPE_FOCUS*). This memory needs to be freed
on every call-sight of ptp_get_one_eos_event, which it wasn't and it needs
to do so for every type using it, but if at all, it only freed it for
PTP_CANON_EOS_CHANGES_TYPE_UNKNOWN data.
This patch replaces `char *info` with `char info[84]` and introduces a
macro called PTP_CANON_SET_INFO() for setting that data. 84 is used,
because the union is at least that large anyway because of the `object`
member and 84 is sufficient for all current use cases. The macro makes
sure there is no buffer overflow in the future.
This change does away with the error prone task of freeing the `info`
memory after every ptp_get_one_eos_event() call.
* fix CodeQL complaint about return value check of sscanf
---------
Co-authored-by: axxel <awagger@web.de>
* improve consistency in standard usecases of ptp_transaction()
* use CHECK_PTP_RC where applicable
* don't perform unnecessary checks for data != NULL
* use stack allocated memory where appropriate (no malloc/free)
* fix a bunch of memory leaks and potential SEGFAULTs in ptp.c
---------
Co-authored-by: axxel <awagger@web.de>
* remove trailing whitespace in *.c/*.h files
This is now 'enforced' via .editoconfig. Do it here once to prevent random
ws changes during editing.
* Cleanup intra-line whitespace in large submenu tables in config.c
Consistently use spaces to layout columns, to make it independent of tab
size.
---------
Co-authored-by: axxel <awagger@web.de>