From: Axel Waggershauser <awagger@web.de>

1) introduce C_PARAMS and C_PARAMS_MSG along the lines of C_MEM

2) replace CHECK_NULL with C_PARAMS

3) replace the pattern

    if ( something ) return GP_ERROR_BAD_PARAMETERS;

with

    C_PARAMS ( !something );

I went over the whole patch again to check that each 'something'
condition is really inverted, so I dare to suggest you don't have to
do that again ;).

4) replaced CHECK_LIST and CHECK_INDEX_RANGE with simple one-line
C_PARAMS(...) expressions

5) a couple of hunks look like this

-      if (!inet_aton (buffer, &inp)) {
-          fprintf(stderr,"failed to scan for addr in %s\n", buffer);
-          return GP_ERROR_BAD_PARAMETERS;
-      }
+     C_PARAMS_MSG (inet_aton (buffer, &inp),

so some 'lost' error messages get now properly piped into the gp_log
mechanism.



git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@15103 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Marcus Meissner
2014-07-22 21:00:32 +00:00
parent 6c5db352a6
commit b06e5d1216
18 changed files with 317 additions and 466 deletions

View File

@@ -1192,14 +1192,12 @@ _put_INT(CONFIG_PUT_ARGS) {
case PTP_DTC_UINT32:
case PTP_DTC_UINT16:
case PTP_DTC_UINT8:
if (1 != sscanf (value, "%u", &u ))
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (1 == sscanf (value, "%u", &u ));
break;
case PTP_DTC_INT32:
case PTP_DTC_INT16:
case PTP_DTC_INT8:
if (1 != sscanf (value, "%d", &i ))
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (1 == sscanf (value, "%d", &i ));
break;
default:
return GP_ERROR;
@@ -2150,7 +2148,7 @@ _put_Canon_CameraOutput(CONFIG_PUT_ARGS) {
if (!strcmp(value,_("Video OUT"))) { u = 2; }
if (!strcmp(value,_("Off"))) { u = 3; }
if (sscanf(value,_("Unknown %d"),&i)) { u = i; }
if (u==-1) return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (u != -1);
if ((u==1) || (u==2)) {
if (ptp_operation_issupported(params, PTP_OC_CANON_ViewfinderOn)) {
@@ -3232,8 +3230,7 @@ _put_FocusDistance(CONFIG_PUT_ARGS) {
propval->u16 = 0xFFFF;
return GP_OK;
}
if (!sscanf(value_str, _("%d mm"), &val))
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (sscanf(value_str, _("%d mm"), &val));
propval->u16 = val;
return GP_OK;
}
@@ -4622,8 +4619,7 @@ _put_Nikon_ChangeAfArea(CONFIG_PUT_ARGS) {
CR (gp_widget_get_value(widget, &val));
if (2 != sscanf(val, "%dx%d", &x, &y))
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (2 == sscanf(val, "%dx%d", &x, &y));
ret = ptp_nikon_changeafarea (&camera->pl->params, x, y);
if (ret == PTP_RC_NIKON_NotLiveView) {
@@ -5731,38 +5727,24 @@ _put_nikon_wifi_profile_write(CONFIG_PUT_ARGS) {
/* fixme: replacement on win32 where we do not have this helper */
#ifdef HAVE_INET_ATON
if (buffer[0] != 0) { /* No DHCP */
if (!inet_aton (buffer, &inp)) {
fprintf(stderr,"failed to scan for addr in %s\n", buffer);
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS_MSG (inet_aton (buffer, &inp), "failed to scan for addr in %s.", buffer);
profile.ip_address = inp.s_addr;
gp_setting_get("ptp2_wifi","netmask",buffer);
if (!inet_aton (buffer, &inp)) {
fprintf(stderr,"failed to scan for netmask in %s\n", buffer);
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS_MSG (inet_aton (buffer, &inp), "failed to scan for netmask in %s.", buffer);
inp.s_addr = be32toh(inp.s_addr); /* Reverse bytes so we can use the code below. */
profile.subnet_mask = 32;
while (((inp.s_addr >> (32-profile.subnet_mask)) & 0x01) == 0) {
profile.subnet_mask--;
if (profile.subnet_mask <= 0) {
fprintf(stderr,"Invalid subnet mask %s: no zeros\n", buffer);
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS_MSG (profile.subnet_mask > 0, "Invalid subnet mask %s: no zeros.", buffer);
}
/* Check there is only ones left */
if ((inp.s_addr | ((0x01 << (32-profile.subnet_mask)) - 1)) != 0xFFFFFFFF) {
fprintf(stderr,"Invalid subnet mask %s: misplaced zeros\n", buffer);
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS_MSG ((inp.s_addr | ((0x01 << (32-profile.subnet_mask)) - 1)) == 0xFFFFFFFF,
"Invalid subnet mask %s: misplaced zeros.", buffer);
/* Gateway (never tested) */
gp_setting_get("ptp2_wifi","gw",buffer);
if (*buffer) {
if (!inet_aton (buffer, &inp)) {
fprintf(stderr,"failed to scan for gw in %s\n", buffer);
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS_MSG (inet_aton (buffer, &inp), "failed to scan for gw in %s", buffer);
profile.gateway_address = inp.s_addr;
}
}
@@ -5787,32 +5769,18 @@ _put_nikon_wifi_profile_write(CONFIG_PUT_ARGS) {
pos = buffer;
keypart[2] = 0;
while (*pos) {
if (!*(pos+1)) {
fprintf(stderr,"Bad key: '%s'\n", buffer);
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS_MSG (*(pos+1), "Bad key: '%s'", buffer);
keypart[0] = *(pos++);
keypart[1] = *(pos++);
profile.key[i++] = strtol(keypart, &endptr, 16);
if (endptr != keypart+2) {
fprintf(stderr,"Bad key: '%s', '%s' is not a number\n", buffer, keypart);
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS_MSG (endptr == keypart+2, "Bad key: '%s', '%s' is not a number.", buffer, keypart);
if (*pos == ':')
pos++;
}
if (profile.encryption == 1) { /* WEP 64-bit */
if (i != 5) { /* 5*8 = 40 bit + 24 bit (IV) = 64 bit */
fprintf(stderr,"Bad key: '%s', %d bit length, should be 40 bit.\n", buffer, i*8);
return GP_ERROR_BAD_PARAMETERS;
}
}
else if (profile.encryption == 2) { /* WEP 128-bit */
if (i != 13) { /* 13*8 = 104 bit + 24 bit (IV) = 128 bit */
fprintf(stderr,"Bad key: '%s', %d bit length, should be 104 bit.\n", buffer, i*8);
return GP_ERROR_BAD_PARAMETERS;
}
}
if (profile.encryption == 1) /* WEP 64-bit */
C_PARAMS_MSG (i == 5, "Bad key: '%s', %d bit length, should be 40 bit.", buffer, i*8); /* 5*8 = 40 bit + 24 bit (IV) = 64 bit */
else if (profile.encryption == 2) /* WEP 128-bit */
C_PARAMS_MSG (i == 13, "Bad key: '%s', %d bit length, should be 104 bit.", buffer, i*8); /* 13*8 = 104 bit + 24 bit (IV) = 128 bit */
}
ptp_nikon_writewifiprofile(&(camera->pl->params), &profile);

View File

@@ -4195,8 +4195,8 @@ canon_theme_get (CameraFilesystem *fs, const char *folder, const char *filename,
C_PTP_REP (ptp_canon_get_customize_data (params, 1, &xdata, &size));
if (size < 42+sizeof(struct canon_theme_entry)*5)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (size >= 42+sizeof(struct canon_theme_entry)*5);
ent = (struct canon_theme_entry*)(xdata+42);
for (i=0;i<5;i++) {
fprintf(stderr,"entry %d: unknown1 = %x\n", i, ent[i].unknown1);
@@ -5373,13 +5373,8 @@ read_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
PTPObject *ob;
SET_CONTEXT_P(params, context);
if (offset64 + *size64 > 0xffffffff) {
GP_LOG_E ("offset + size exceeds 32bit");
return (GP_ERROR_BAD_PARAMETERS); /* file not found */
}
if (!strcmp (folder, "/special"))
return (GP_ERROR_BAD_PARAMETERS); /* file not found */
C_PARAMS_MSG (offset64 + *size64 <= 0xffffffff, "offset + size exceeds 32bit");
C_PARAMS_MSG (strcmp (folder, "/special"), "file not found");
if (!ptp_operation_issupported(params, PTP_OC_GetPartialObject))
return (GP_ERROR_NOT_SUPPORTED);
@@ -5676,8 +5671,7 @@ put_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
gp_context_error (context, _("Metadata only supported for MTP devices."));
return GP_ERROR_NOT_SUPPORTED;
}
if (type != GP_FILE_TYPE_NORMAL)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (type == GP_FILE_TYPE_NORMAL);
/* compute storage ID value from folder patch */
folder_to_storage(folder,storage);
@@ -5838,8 +5832,7 @@ set_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
SET_CONTEXT_P(params, context);
if (!strcmp (folder, "/special"))
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (strcmp (folder, "/special"));
camera->pl->checkevents = TRUE;
/* compute storage ID value from folder patch */
@@ -5884,8 +5877,7 @@ get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
SET_CONTEXT_P(params, context);
if (!strcmp (folder, "/special"))
return (GP_ERROR_BAD_PARAMETERS); /* for now */
C_PARAMS (strcmp (folder, "/special"));
/* compute storage ID value from folder patch */
folder_to_storage(folder,storage);

View File

@@ -55,8 +55,6 @@
# define N_(String) (String)
#endif
/** \internal */
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
/** \internal */
#define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);}
@@ -101,7 +99,7 @@ gp_message_codeset (const char *codeset)
int
gp_abilities_list_new (CameraAbilitiesList **list)
{
CHECK_NULL (list);
C_PARAMS (list);
/*
* We do this here because everybody needs to call this function
@@ -125,7 +123,7 @@ gp_abilities_list_new (CameraAbilitiesList **list)
int
gp_abilities_list_free (CameraAbilitiesList *list)
{
CHECK_NULL (list);
C_PARAMS (list);
CHECK_RESULT (gp_abilities_list_reset (list));
@@ -168,7 +166,7 @@ gp_abilities_list_load_dir (CameraAbilitiesList *list, const char *dir,
int count;
lt_dlhandle lh;
CHECK_NULL (list && dir);
C_PARAMS (list && dir);
GP_LOG_D ("Using ltdl to load camera libraries from '%s'...", dir);
CHECK_RESULT (gp_list_new (&flist));
@@ -304,7 +302,7 @@ gp_abilities_list_load (CameraAbilitiesList *list, GPContext *context)
{
const char *camlib_env = getenv(CAMLIBDIR_ENV);
const char *camlibs = (camlib_env != NULL)?camlib_env:CAMLIBS;
CHECK_NULL (list);
C_PARAMS (list);
CHECK_RESULT (gp_abilities_list_load_dir (list, camlibs, context));
CHECK_RESULT (gp_abilities_list_sort (list));
@@ -407,7 +405,7 @@ gp_abilities_list_detect (CameraAbilitiesList *list,
GPPort *port;
int i, info_count;
CHECK_NULL (list && info_list && l);
C_PARAMS (list && info_list && l);
gp_list_reset (l);
@@ -511,7 +509,7 @@ remove_colon_from_string (char *str)
int
gp_abilities_list_append (CameraAbilitiesList *list, CameraAbilities abilities)
{
CHECK_NULL (list);
C_PARAMS (list);
C_MEM (list->abilities = realloc (list->abilities,
sizeof (CameraAbilities) * (list->count + 1)));
@@ -539,7 +537,7 @@ gp_abilities_list_append (CameraAbilitiesList *list, CameraAbilities abilities)
int
gp_abilities_list_reset (CameraAbilitiesList *list)
{
CHECK_NULL (list);
C_PARAMS (list);
free (list->abilities);
list->abilities = NULL;
@@ -557,7 +555,7 @@ gp_abilities_list_reset (CameraAbilitiesList *list)
int
gp_abilities_list_count (CameraAbilitiesList *list)
{
CHECK_NULL (list);
C_PARAMS (list);
return (list->count);
}
@@ -573,7 +571,7 @@ cmp_abilities (const void *a, const void *b) {
static int
gp_abilities_list_sort (CameraAbilitiesList *list)
{
CHECK_NULL (list);
C_PARAMS (list);
qsort (list->abilities, list->count, sizeof(CameraAbilities), cmp_abilities);
return (GP_OK);
@@ -585,7 +583,7 @@ gp_abilities_list_lookup_id (CameraAbilitiesList *list, const char *id)
{
int x;
CHECK_NULL (list && id);
C_PARAMS (list && id);
for (x = 0; x < list->count; x++)
if (!strcmp (list->abilities[x].id, id))
@@ -606,7 +604,7 @@ gp_abilities_list_lookup_model (CameraAbilitiesList *list, const char *model)
{
int x;
CHECK_NULL (list && model);
C_PARAMS (list && model);
for (x = 0; x < list->count; x++) {
if (!strcasecmp (list->abilities[x].model, model))
@@ -634,10 +632,8 @@ int
gp_abilities_list_get_abilities (CameraAbilitiesList *list, int index,
CameraAbilities *abilities)
{
CHECK_NULL (list && abilities);
if (index < 0 || index >= list->count)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (list && abilities);
C_PARAMS (0 <= index && index < list->count);
memcpy (abilities, &list->abilities[index], sizeof (CameraAbilities));

View File

@@ -57,8 +57,6 @@
# define N_(String) (String)
#endif
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
#define CAMERA_UNUSED(c,ctx) \
{ \
(c)->pc->used--; \
@@ -269,7 +267,7 @@ struct _CameraPrivateCore {
int
gp_camera_exit (Camera *camera, GPContext *context)
{
CHECK_NULL (camera);
C_PARAMS (camera);
GP_LOG_D ("Exiting camera ('%s')...", camera->pc->a.model);
@@ -324,7 +322,7 @@ gp_camera_new (Camera **camera)
{
int result;
CHECK_NULL (camera);
C_PARAMS (camera);
C_MEM (*camera = calloc (1, sizeof (Camera)));
@@ -375,7 +373,7 @@ gp_camera_set_abilities (Camera *camera, CameraAbilities abilities)
{
GP_LOG_D ("Setting abilities ('%s')...", abilities.model);
CHECK_NULL (camera);
C_PARAMS (camera);
/*
* If the camera is currently initialized, terminate that connection.
@@ -401,7 +399,7 @@ gp_camera_set_abilities (Camera *camera, CameraAbilities abilities)
int
gp_camera_get_abilities (Camera *camera, CameraAbilities *abilities)
{
CHECK_NULL (camera && abilities);
C_PARAMS (camera && abilities);
memcpy (abilities, &camera->pc->a, sizeof (CameraAbilities));
@@ -412,7 +410,7 @@ gp_camera_get_abilities (Camera *camera, CameraAbilities *abilities)
int
gp_camera_get_port_info (Camera *camera, GPPortInfo *info)
{
CHECK_NULL (camera && info);
C_PARAMS (camera && info);
CR (camera, gp_port_get_info (camera->port, info), NULL);
@@ -424,7 +422,7 @@ int
gp_camera_set_port_info (Camera *camera, GPPortInfo info)
{
char *name, *path;
CHECK_NULL (camera);
C_PARAMS (camera);
/*
* If the camera is currently initialized, terminate that connection.
@@ -463,17 +461,12 @@ gp_camera_set_port_speed (Camera *camera, int speed)
{
GPPortSettings settings;
CHECK_NULL (camera);
C_PARAMS (camera);
if (!camera->port) {
GP_LOG_E ("You need to set a port prior trying to set the speed");
return (GP_ERROR_BAD_PARAMETERS);
}
if (camera->port->type != GP_PORT_SERIAL) {
GP_LOG_E ("You can specify a speed only with serial ports");
return (GP_ERROR_BAD_PARAMETERS);
}
C_PARAMS_MSG (camera->port,
"You need to set a port prior trying to set the speed");
C_PARAMS_MSG (camera->port->type == GP_PORT_SERIAL,
"You can specify a speed only with serial ports");
/*
* If the camera is currently initialized, terminate that connection.
@@ -501,7 +494,7 @@ gp_camera_set_port_speed (Camera *camera, int speed)
int
gp_camera_get_port_speed (Camera *camera)
{
CHECK_NULL (camera);
C_PARAMS (camera);
return (camera->pc->speed);
}
@@ -517,7 +510,7 @@ gp_camera_get_port_speed (Camera *camera)
int
gp_camera_ref (Camera *camera)
{
CHECK_NULL (camera);
C_PARAMS (camera);
camera->pc->ref_count += 1;
@@ -538,7 +531,7 @@ gp_camera_ref (Camera *camera)
int
gp_camera_unref (Camera *camera)
{
CHECK_NULL (camera);
C_PARAMS (camera);
if (!camera->pc->ref_count) {
GP_LOG_E ("gp_camera_unref on a camera with ref_count == 0 "
@@ -572,7 +565,7 @@ gp_camera_unref (Camera *camera)
int
gp_camera_free (Camera *camera)
{
CHECK_NULL (camera);
C_PARAMS (camera);
GP_LOG_D ("Freeing camera...");
@@ -700,7 +693,7 @@ gp_camera_init (Camera *camera, GPContext *context)
GP_LOG_D ("Initializing camera...");
CHECK_NULL (camera);
C_PARAMS (camera);
/*
* Reset the exit_requested flag. If this flag is set,
* gp_camera_exit will be called as soon as the camera is no
@@ -868,7 +861,7 @@ gp_camera_init (Camera *camera, GPContext *context)
int
gp_camera_get_config (Camera *camera, CameraWidget **window, GPContext *context)
{
CHECK_NULL (camera);
C_PARAMS (camera);
CHECK_INIT (camera, context);
if (!camera->functions->get_config) {
@@ -901,7 +894,7 @@ gp_camera_get_config (Camera *camera, CameraWidget **window, GPContext *context)
int
gp_camera_set_config (Camera *camera, CameraWidget *window, GPContext *context)
{
CHECK_NULL (camera && window);
C_PARAMS (camera && window);
CHECK_INIT (camera, context);
if (!camera->functions->set_config) {
@@ -933,7 +926,7 @@ gp_camera_set_config (Camera *camera, CameraWidget *window, GPContext *context)
int
gp_camera_get_summary (Camera *camera, CameraText *summary, GPContext *context)
{
CHECK_NULL (camera && summary);
C_PARAMS (camera && summary);
CHECK_INIT (camera, context);
if (!camera->functions->summary) {
@@ -964,7 +957,7 @@ gp_camera_get_summary (Camera *camera, CameraText *summary, GPContext *context)
int
gp_camera_get_manual (Camera *camera, CameraText *manual, GPContext *context)
{
CHECK_NULL (camera && manual);
C_PARAMS (camera && manual);
CHECK_INIT (camera, context);
if (!camera->functions->manual) {
@@ -996,7 +989,7 @@ gp_camera_get_manual (Camera *camera, CameraText *manual, GPContext *context)
int
gp_camera_get_about (Camera *camera, CameraText *about, GPContext *context)
{
CHECK_NULL (camera && about);
C_PARAMS (camera && about);
CHECK_INIT (camera, context);
if (!camera->functions->about) {
@@ -1030,7 +1023,7 @@ int
gp_camera_capture (Camera *camera, CameraCaptureType type,
CameraFilePath *path, GPContext *context)
{
CHECK_NULL (camera);
C_PARAMS (camera);
CHECK_INIT (camera, context);
if (!camera->functions->capture) {
@@ -1060,7 +1053,7 @@ gp_camera_capture (Camera *camera, CameraCaptureType type,
int
gp_camera_trigger_capture (Camera *camera, GPContext *context)
{
CHECK_NULL (camera);
C_PARAMS (camera);
CHECK_INIT (camera, context);
if (!camera->functions->trigger_capture) {
@@ -1091,7 +1084,7 @@ int
gp_camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
{
char *xname;
CHECK_NULL (camera && file);
C_PARAMS (camera && file);
CHECK_INIT (camera, context);
CR (camera, gp_file_clean (file), context);
@@ -1138,7 +1131,7 @@ gp_camera_wait_for_event (Camera *camera, int timeout,
CameraEventType *eventtype, void **eventdata,
GPContext *context)
{
CHECK_NULL (camera);
C_PARAMS (camera);
CHECK_INIT (camera, context);
if (!camera->functions->wait_for_event) {
@@ -1168,7 +1161,7 @@ gp_camera_folder_list_files (Camera *camera, const char *folder,
{
GP_LOG_D ("Listing files in '%s'...", folder);
CHECK_NULL (camera && folder && list);
C_PARAMS (camera && folder && list);
CHECK_INIT (camera, context);
CR (camera, gp_list_reset (list), context);
@@ -1196,7 +1189,7 @@ gp_camera_folder_list_folders (Camera *camera, const char* folder,
{
GP_LOG_D ("Listing folders in '%s'...", folder);
CHECK_NULL (camera && folder && list);
C_PARAMS (camera && folder && list);
CHECK_INIT (camera, context);
CR (camera, gp_list_reset (list), context);
@@ -1223,7 +1216,7 @@ gp_camera_folder_delete_all (Camera *camera, const char *folder,
{
GP_LOG_D ("Deleting all files in '%s'...", folder);
CHECK_NULL (camera && folder);
C_PARAMS (camera && folder);
CHECK_INIT (camera, context);
CHECK_RESULT_OPEN_CLOSE (camera, gp_filesystem_delete_all (camera->fs,
@@ -1252,7 +1245,7 @@ gp_camera_folder_put_file (Camera *camera,
GP_LOG_D ("Uploading file into '%s'...",
folder);
CHECK_NULL (camera && folder && file);
C_PARAMS (camera && folder && file);
CHECK_INIT (camera, context);
CHECK_RESULT_OPEN_CLOSE (camera, gp_filesystem_put_file (camera->fs,
@@ -1286,7 +1279,7 @@ gp_camera_file_get_info (Camera *camera, const char *folder,
GP_LOG_D ("Getting file info for '%s' in '%s'...", file, folder);
CHECK_NULL (camera && folder && file && info);
C_PARAMS (camera && folder && file && info);
CHECK_INIT (camera, context);
memset (info, 0, sizeof (CameraFileInfo));
@@ -1344,7 +1337,7 @@ gp_camera_file_set_info (Camera *camera, const char *folder,
const char *file, CameraFileInfo info,
GPContext *context)
{
CHECK_NULL (camera && folder && file);
C_PARAMS (camera && folder && file);
CHECK_INIT (camera, context);
CHECK_RESULT_OPEN_CLOSE (camera, gp_filesystem_set_info (camera->fs,
@@ -1373,7 +1366,7 @@ gp_camera_file_get (Camera *camera, const char *folder, const char *file,
{
GP_LOG_D ("Getting file '%s' in folder '%s'...", file, folder);
CHECK_NULL (camera && folder && file && camera_file);
C_PARAMS (camera && folder && file && camera_file);
CHECK_INIT (camera, context);
CR (camera, gp_file_clean (camera_file), context);
@@ -1417,7 +1410,7 @@ gp_camera_file_read (Camera *camera, const char *folder, const char *file,
{
GP_LOG_D ("Getting file '%s' in folder '%s'...", file, folder);
CHECK_NULL (camera && folder && file && buf && size);
C_PARAMS (camera && folder && file && buf && size);
CHECK_INIT (camera, context);
/* Did we get reasonable foldername/filename? */
@@ -1453,7 +1446,7 @@ gp_camera_file_delete (Camera *camera, const char *folder, const char *file,
{
GP_LOG_D ("Deleting file '%s' in folder '%s'...", file, folder);
CHECK_NULL (camera && folder && file);
C_PARAMS (camera && folder && file);
CHECK_INIT (camera, context);
CHECK_RESULT_OPEN_CLOSE (camera, gp_filesystem_delete_file (
@@ -1477,7 +1470,7 @@ int
gp_camera_folder_make_dir (Camera *camera, const char *folder,
const char *name, GPContext *context)
{
CHECK_NULL (camera && folder && name);
C_PARAMS (camera && folder && name);
CHECK_INIT (camera, context);
CHECK_RESULT_OPEN_CLOSE (camera, gp_filesystem_make_dir (camera->fs,
@@ -1501,7 +1494,7 @@ int
gp_camera_folder_remove_dir (Camera *camera, const char *folder,
const char *name, GPContext *context)
{
CHECK_NULL (camera && folder && name);
C_PARAMS (camera && folder && name);
CHECK_INIT (camera, context);
CHECK_RESULT_OPEN_CLOSE (camera, gp_filesystem_remove_dir (camera->fs,
@@ -1537,7 +1530,7 @@ gp_camera_get_storageinfo (
Camera *camera, CameraStorageInformation **sifs,
int *nrofsifs, GPContext *context)
{
CHECK_NULL (camera && sifs && nrofsifs);
C_PARAMS (camera && sifs && nrofsifs);
CHECK_INIT (camera, context);
CHECK_RESULT_OPEN_CLOSE (camera,
@@ -1594,8 +1587,7 @@ gp_camera_start_timeout (Camera *camera, unsigned int timeout,
{
int id;
if (!camera || !camera->pc)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (camera && camera->pc);
if (!camera->pc->timeout_start_func)
return (GP_ERROR_NOT_SUPPORTED);

View File

@@ -43,7 +43,6 @@
#include <gphoto2/gphoto2-result.h>
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
#define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);}
/* lengt of one path component */
@@ -84,7 +83,7 @@ struct _CameraFile {
int
gp_file_new (CameraFile **file)
{
CHECK_NULL (file);
C_PARAMS (file);
C_MEM (*file = calloc (1, sizeof (CameraFile)));
@@ -104,7 +103,7 @@ gp_file_new (CameraFile **file)
int
gp_file_new_from_fd (CameraFile **file, int fd)
{
CHECK_NULL (file);
C_PARAMS (file);
C_MEM (*file = calloc (1, sizeof (CameraFile)));
@@ -125,7 +124,7 @@ gp_file_new_from_fd (CameraFile **file, int fd)
int
gp_file_new_from_handler (CameraFile **file, CameraFileHandler* handler, void*private)
{
CHECK_NULL (file);
C_PARAMS (file);
C_MEM (*file = calloc (1, sizeof (CameraFile)));
@@ -146,7 +145,7 @@ gp_file_new_from_handler (CameraFile **file, CameraFileHandler* handler, void*pr
**/
int gp_file_free (CameraFile *file)
{
CHECK_NULL (file);
C_PARAMS (file);
CHECK_RESULT (gp_file_clean (file));
@@ -166,7 +165,7 @@ int gp_file_free (CameraFile *file)
int
gp_file_ref (CameraFile *file)
{
CHECK_NULL (file);
C_PARAMS (file);
file->ref_count += 1;
@@ -183,7 +182,7 @@ gp_file_ref (CameraFile *file)
int
gp_file_unref (CameraFile *file)
{
CHECK_NULL (file);
C_PARAMS (file);
file->ref_count -= 1;
@@ -205,7 +204,7 @@ int
gp_file_append (CameraFile *file, const char *data,
unsigned long int size)
{
CHECK_NULL (file);
C_PARAMS (file);
switch (file->accesstype) {
case GP_FILE_ACCESSTYPE_MEMORY:
@@ -232,10 +231,7 @@ gp_file_append (CameraFile *file, const char *data,
case GP_FILE_ACCESSTYPE_HANDLER: {
uint64_t xsize = size;
/* FIXME: assume we write one blob */
if (!file->handler->write) {
GP_LOG_E ("write handler is NULL");
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS (file->handler->write);
return file->handler->write (file->private, (unsigned char*)data, &xsize);
}
default:
@@ -257,7 +253,7 @@ int
gp_file_slurp (CameraFile *file, char *data,
size_t size, size_t *readlen
) {
CHECK_NULL (file);
C_PARAMS (file);
switch (file->accesstype) {
case GP_FILE_ACCESSTYPE_MEMORY:
@@ -289,10 +285,7 @@ gp_file_slurp (CameraFile *file, char *data,
uint64_t xsize = size;
int ret;
if (!file->handler->read) {
GP_LOG_E ("read handler is NULL");
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS (file->handler->read);
ret = file->handler->read (file->private, (unsigned char*)data, &xsize);
*readlen = xsize;
if (ret != GP_OK)
@@ -319,7 +312,7 @@ int
gp_file_set_data_and_size (CameraFile *file, char *data,
unsigned long int size)
{
CHECK_NULL (file);
C_PARAMS (file);
switch (file->accesstype) {
case GP_FILE_ACCESSTYPE_MEMORY:
@@ -361,10 +354,7 @@ gp_file_set_data_and_size (CameraFile *file, char *data,
uint64_t xsize = size;
int ret;
if (!file->handler->write) {
GP_LOG_E ("write handler is NULL");
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS (file->handler->write);
/* FIXME: handle multiple blob writes */
ret = file->handler->write (file->private, (unsigned char*)data, &xsize);
if (ret != GP_OK) {
@@ -403,7 +393,7 @@ int
gp_file_get_data_and_size (CameraFile *file, const char **data,
unsigned long int *size)
{
CHECK_NULL (file);
C_PARAMS (file);
switch (file->accesstype) {
case GP_FILE_ACCESSTYPE_MEMORY:
@@ -455,10 +445,7 @@ gp_file_get_data_and_size (CameraFile *file, const char **data,
uint64_t xsize = 0;
int ret;
if (!file->handler->read) {
GP_LOG_E ("read handler is NULL");
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS (file->handler->read);
ret = file->handler->size (file->private, &xsize);
if (ret != GP_OK) {
GP_LOG_E ("Encountered error %d querying size().", ret);
@@ -496,7 +483,7 @@ gp_file_save (CameraFile *file, const char *filename)
FILE *fp;
struct utimbuf u;
CHECK_NULL (file && filename);
C_PARAMS (file && filename);
switch (file->accesstype) {
case GP_FILE_ACCESSTYPE_MEMORY:
@@ -616,7 +603,7 @@ gp_file_open (CameraFile *file, const char *filename)
struct stat s;
CHECK_NULL (file && filename);
C_PARAMS (file && filename);
CHECK_RESULT (gp_file_clean (file));
@@ -710,7 +697,7 @@ gp_file_clean (CameraFile *file)
* This is used to prep a CameraFile struct to be filled.
*/
CHECK_NULL (file);
C_PARAMS (file);
switch (file->accesstype) {
case GP_FILE_ACCESSTYPE_MEMORY:
@@ -735,7 +722,7 @@ gp_file_clean (CameraFile *file)
int
gp_file_copy (CameraFile *destination, CameraFile *source)
{
CHECK_NULL (destination && source);
C_PARAMS (destination && source);
GP_LOG_D ("Copying '%s' onto '%s'...", source->name, destination->name);
@@ -879,7 +866,7 @@ gp_file_copy (CameraFile *destination, CameraFile *source)
int
gp_file_get_name (CameraFile *file, const char **name)
{
CHECK_NULL (file && name);
C_PARAMS (file && name);
*name = file->name;
@@ -909,7 +896,7 @@ gp_file_get_name_by_type (CameraFile *file, const char *basename, CameraFileType
const char *suffix = NULL;
int i;
CHECK_NULL (file && basename && newname);
C_PARAMS (file && basename && newname);
*newname = NULL;
/* the easy case, always map 1:1, if it has a suffix already. */
@@ -967,7 +954,7 @@ gp_file_get_name_by_type (CameraFile *file, const char *basename, CameraFileType
int
gp_file_get_mime_type (CameraFile *file, const char **mime_type)
{
CHECK_NULL (file && mime_type);
C_PARAMS (file && mime_type);
*mime_type = file->mime_type;
@@ -984,7 +971,7 @@ gp_file_get_mime_type (CameraFile *file, const char **mime_type)
int
gp_file_set_name (CameraFile *file, const char *name)
{
CHECK_NULL (file && name);
C_PARAMS (file && name);
strncpy (file->name, name, sizeof (file->name));
@@ -1001,7 +988,7 @@ gp_file_set_name (CameraFile *file, const char *name)
int
gp_file_set_mime_type (CameraFile *file, const char *mime_type)
{
CHECK_NULL (file && mime_type);
C_PARAMS (file && mime_type);
strncpy (file->mime_type, mime_type, sizeof (file->mime_type));
@@ -1021,7 +1008,7 @@ gp_file_detect_mime_type (CameraFile *file)
(char) 0x00, (char) 0x08, '\0' };
const char JPEG_SOI_MARKER[] = {(char) 0xFF, (char) 0xD8, '\0' };
CHECK_NULL (file);
C_PARAMS (file);
switch (file->accesstype) {
case GP_FILE_ACCESSTYPE_MEMORY:
@@ -1088,7 +1075,7 @@ gp_file_adjust_name_for_mime_type (CameraFile *file)
GP_MIME_CR2, "cr2",
NULL};
CHECK_NULL (file);
C_PARAMS (file);
GP_LOG_D ("Adjusting file name for mime type '%s'...", file->mime_type);
for (x = 0; table[x]; x += 2)
@@ -1116,7 +1103,7 @@ gp_file_adjust_name_for_mime_type (CameraFile *file)
int
gp_file_get_mtime (CameraFile *file, time_t *mtime)
{
CHECK_NULL (file && mtime);
C_PARAMS (file && mtime);
*mtime = file->mtime;
@@ -1133,7 +1120,7 @@ gp_file_get_mtime (CameraFile *file, time_t *mtime)
int
gp_file_set_mtime (CameraFile *file, time_t mtime)
{
CHECK_NULL (file);
C_PARAMS (file);
file->mtime = mtime;

View File

@@ -266,7 +266,6 @@ struct _CameraFilesystem {
#undef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
#define CR(result) {int __r = (result); if (__r < 0) return (__r);}
#define CL(result,list) \
@@ -309,7 +308,7 @@ delete_all_files (CameraFilesystem *fs, CameraFilesystemFolder *folder)
{
CameraFilesystemFile *file;
CHECK_NULL (folder);
C_PARAMS (folder);
GP_LOG_D ("Delete all files in folder %p/%s", folder, folder->name);
file = folder->files;
@@ -354,7 +353,7 @@ static int
delete_folder (CameraFilesystem *fs, CameraFilesystemFolder **folder)
{
CameraFilesystemFolder *next;
CHECK_NULL (folder);
C_PARAMS (folder);
GP_LOG_D ("Delete one folder %p/%s", *folder, (*folder)->name);
next = (*folder)->next;
@@ -497,7 +496,7 @@ delete_all_folders (CameraFilesystem *fs, const char *foldername,
GP_LOG_D ("Internally deleting "
"all folders from '%s'...", foldername);
CHECK_NULL (fs && foldername);
C_PARAMS (fs && foldername);
CC (context);
CA (foldername, context);
@@ -586,8 +585,8 @@ append_folder (CameraFilesystem *fs,
GPContext *context
) {
GP_LOG_D ("Appending folder %s...", folder);
CHECK_NULL (fs);
CHECK_NULL (folder);
C_PARAMS (fs);
C_PARAMS (folder);
CC (context);
CA (folder, context);
return append_to_folder (fs->rootfolder, folder, newfolder);
@@ -598,7 +597,7 @@ append_file (CameraFilesystem *fs, CameraFilesystemFolder *folder, const char *n
{
CameraFilesystemFile **new;
CHECK_NULL (fs && file);
C_PARAMS (fs && file);
GP_LOG_D ("Appending file %s...", name);
new = &folder->files;
@@ -655,7 +654,7 @@ gp_filesystem_reset (CameraFilesystem *fs)
int
gp_filesystem_new (CameraFilesystem **fs)
{
CHECK_NULL (fs);
C_PARAMS (fs);
C_MEM (*fs = calloc (1, sizeof (CameraFilesystem)));
@@ -717,7 +716,7 @@ internal_append (CameraFilesystem *fs, CameraFilesystemFolder *f,
{
CameraFilesystemFile **new;
CHECK_NULL (fs && f);
C_PARAMS (fs && f);
GP_LOG_D ("Internal append %s to folder %s", filename, f->name);
/* Check folder for existence, if not, create it. */
@@ -747,7 +746,7 @@ gp_filesystem_append (CameraFilesystem *fs, const char *folder,
CameraFilesystemFolder *f;
int ret;
CHECK_NULL (fs && folder);
C_PARAMS (fs && folder);
CC (context);
CA (folder, context);
@@ -892,7 +891,7 @@ gp_filesystem_delete_all (CameraFilesystem *fs, const char *folder,
int r;
CameraFilesystemFolder *f;
CHECK_NULL (fs && folder);
C_PARAMS (fs && folder);
CC (context);
CA (folder, context);
@@ -957,7 +956,7 @@ gp_filesystem_list_files (CameraFilesystem *fs, const char *folder,
GP_LOG_D ("Listing files in %s", folder);
CHECK_NULL (fs && list && folder);
C_PARAMS (fs && list && folder);
CC (context);
CA (folder, context);
@@ -1022,7 +1021,7 @@ gp_filesystem_list_folders (CameraFilesystem *fs, const char *folder,
GP_LOG_D ("Listing folders in %s", folder);
CHECK_NULL (fs && folder && list);
C_PARAMS (fs && folder && list);
CC (context);
CA (folder, context);
@@ -1078,7 +1077,7 @@ gp_filesystem_count (CameraFilesystem *fs, const char *folder,
CameraFilesystemFolder *f;
CameraFilesystemFile *file;
CHECK_NULL (fs && folder);
C_PARAMS (fs && folder);
CC (context);
CA (folder, context);
@@ -1114,7 +1113,7 @@ gp_filesystem_delete_file (CameraFilesystem *fs, const char *folder,
CameraFilesystemFolder *f;
CameraFilesystemFile *file;
CHECK_NULL (fs && folder && filename);
C_PARAMS (fs && folder && filename);
CC (context);
CA (folder, context);
@@ -1158,7 +1157,7 @@ gp_filesystem_delete_file_noop (CameraFilesystem *fs, const char *folder,
CameraFilesystemFolder *f;
CameraFilesystemFile *file;
CHECK_NULL (fs && folder && filename);
C_PARAMS (fs && folder && filename);
CC (context);
CA (folder, context);
/* Search the folder and the file */
@@ -1183,7 +1182,7 @@ gp_filesystem_make_dir (CameraFilesystem *fs, const char *folder,
{
CameraFilesystemFolder *f;
CHECK_NULL (fs && folder && name);
C_PARAMS (fs && folder && name);
CC (context);
CA (folder, context);
@@ -1218,7 +1217,7 @@ gp_filesystem_remove_dir (CameraFilesystem *fs, const char *folder,
CameraFilesystemFolder *f;
CameraFilesystemFolder **prev;
CHECK_NULL (fs && folder && name);
C_PARAMS (fs && folder && name);
CC (context);
CA (folder, context);
@@ -1295,7 +1294,7 @@ gp_filesystem_put_file (CameraFilesystem *fs,
CameraFilesystemFolder *f;
int ret;
CHECK_NULL (fs && folder && file);
C_PARAMS (fs && folder && file);
CC (context);
CA (folder, context);
@@ -1339,7 +1338,7 @@ gp_filesystem_name (CameraFilesystem *fs, const char *folder, int filenumber,
CameraFilesystemFolder *f;
CameraFilesystemFile *file;
int count;
CHECK_NULL (fs && folder);
C_PARAMS (fs && folder);
CC (context);
CA (folder, context);
@@ -1387,7 +1386,7 @@ gp_filesystem_number (CameraFilesystem *fs, const char *folder,
CameraList *list;
int num;
CHECK_NULL (fs && folder && filename);
C_PARAMS (fs && folder && filename);
CC (context);
CA (folder, context);
@@ -1427,7 +1426,7 @@ gp_filesystem_scan (CameraFilesystem *fs, const char *folder,
GP_LOG_D ("Scanning %s for %s...", folder, filename);
CHECK_NULL (fs && folder && filename);
C_PARAMS (fs && folder && filename);
CC (context);
CA (folder, context);
@@ -1515,7 +1514,7 @@ gp_filesystem_get_folder (CameraFilesystem *fs, const char *filename,
{
int ret;
CHECK_NULL (fs && filename && folder);
C_PARAMS (fs && filename && folder);
CC (context);
CR (gp_filesystem_scan (fs, "/", filename, context));
@@ -1535,7 +1534,7 @@ gp_filesystem_get_file_impl (CameraFilesystem *fs, const char *folder,
CameraFilesystemFile *xfile;
int ret;
CHECK_NULL (fs && folder && file && filename);
C_PARAMS (fs && folder && file && filename);
CC (context);
CA (folder, context);
@@ -1772,7 +1771,7 @@ gp_filesystem_read_file (CameraFilesystem *fs, const char *folder,
unsigned long xsize;
CameraFile *file;
CHECK_NULL (fs && folder && filename && buf && size);
C_PARAMS (fs && folder && filename && buf && size);
CC (context);
CA (folder, context);
@@ -1821,7 +1820,7 @@ gp_filesystem_set_funcs (CameraFilesystem *fs,
CameraFilesystemFuncs *funcs,
void *data)
{
CHECK_NULL (fs);
C_PARAMS (fs);
fs->get_info_func = funcs->get_info_func;
fs->set_info_func = funcs->set_info_func;
@@ -1860,7 +1859,7 @@ gp_filesystem_get_info (CameraFilesystem *fs, const char *folder,
time_t t;
#endif
CHECK_NULL (fs && folder && filename && info);
C_PARAMS (fs && folder && filename && info);
CC (context);
CA (folder, context);
@@ -1982,7 +1981,7 @@ gp_filesystem_lru_free (CameraFilesystem *fs)
CameraFilesystemFile *ptr;
unsigned long int size;
CHECK_NULL (fs && fs->lru_first);
C_PARAMS (fs && fs->lru_first);
ptr = fs->lru_first;
@@ -2047,7 +2046,7 @@ gp_filesystem_lru_update (CameraFilesystem *fs,
int x;
char cached_images[1024];
CHECK_NULL (fs && folder && file);
C_PARAMS (fs && folder && file);
CR (gp_file_get_data_and_size (file, NULL, &size));
@@ -2204,7 +2203,7 @@ gp_filesystem_set_file_noop (CameraFilesystem *fs,
int r;
time_t t;
CHECK_NULL (fs && folder && file);
C_PARAMS (fs && folder && file);
CC (context);
CA (folder, context);
@@ -2335,7 +2334,7 @@ gp_filesystem_set_info_noop (CameraFilesystem *fs,
CameraFilesystemFolder *f;
CameraFilesystemFile *xfile;
CHECK_NULL (fs && folder);
C_PARAMS (fs && folder);
CC (context);
CA (folder, context);
@@ -2368,7 +2367,7 @@ gp_filesystem_set_info (CameraFilesystem *fs, const char *folder,
CameraFilesystemFolder *f;
CameraFilesystemFile *xfile;
CHECK_NULL (fs && folder && filename);
C_PARAMS (fs && folder && filename);
CC (context);
CA (folder, context);
@@ -2448,7 +2447,7 @@ gp_filesystem_get_storageinfo (
int *nrofstorageinfos,
GPContext *context
) {
CHECK_NULL (fs && storageinfo && nrofstorageinfos);
C_PARAMS (fs && storageinfo && nrofstorageinfos);
CC (context);
if (!fs->storage_info_func) {

View File

@@ -33,21 +33,8 @@
#include <gphoto2/gphoto2-result.h>
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
#define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);}
/** check that the list is valid */
#define CHECK_LIST(list) \
do { \
if (NULL == list) { \
return (GP_ERROR_BAD_PARAMETERS); \
} else if (list->ref_count == 0) { \
/* catch calls to already freed list */ \
return (GP_ERROR_BAD_PARAMETERS); \
} \
} while (0)
/**
* Internal _CameraList data structure
**/
@@ -64,14 +51,6 @@ struct _CameraList {
int ref_count;
};
/* check that the given index is in the valid range for this list */
#define CHECK_INDEX_RANGE(list, index) \
do { \
if (index < 0 || index >= list->used) { \
return (GP_ERROR_BAD_PARAMETERS); \
} \
} while (0)
/**
* \brief Creates a new #CameraList.
@@ -83,7 +62,7 @@ struct _CameraList {
int
gp_list_new (CameraList **list)
{
CHECK_NULL (list);
C_PARAMS (list);
C_MEM (*list = calloc (1, sizeof (CameraList)));
@@ -102,7 +81,7 @@ gp_list_new (CameraList **list)
int
gp_list_ref (CameraList *list)
{
CHECK_LIST (list);
C_PARAMS (list && list->ref_count);
list->ref_count++;
@@ -121,7 +100,7 @@ gp_list_ref (CameraList *list)
int
gp_list_unref (CameraList *list)
{
CHECK_LIST (list);
C_PARAMS (list && list->ref_count);
if (list->ref_count == 1) /* time to free */
gp_list_free (list);
@@ -141,7 +120,7 @@ int
gp_list_free (CameraList *list)
{
int i;
CHECK_LIST (list);
C_PARAMS (list && list->ref_count);
for (i=0;i<list->used;i++) {
free (list->entry[i].name);
@@ -169,7 +148,7 @@ int
gp_list_reset (CameraList *list)
{
int i;
CHECK_LIST (list);
C_PARAMS (list && list->ref_count);
for (i=0;i<list->used;i++) {
free (list->entry[i].name);
@@ -194,7 +173,7 @@ gp_list_reset (CameraList *list)
int
gp_list_append (CameraList *list, const char *name, const char *value)
{
CHECK_LIST (list);
C_PARAMS (list && list->ref_count);
if (list->used == list->max) {
C_MEM (list->entry = realloc(list->entry,(list->max+100)*sizeof(struct _entry)));
@@ -233,7 +212,7 @@ cmp_list (const void *a, const void *b) {
int
gp_list_sort (CameraList *list)
{
CHECK_LIST (list);
C_PARAMS (list && list->ref_count);
qsort (list->entry, list->used, sizeof(list->entry[0]), cmp_list);
return GP_OK;
@@ -249,7 +228,7 @@ gp_list_sort (CameraList *list)
int
gp_list_count (CameraList *list)
{
CHECK_LIST (list);
C_PARAMS (list && list->ref_count);
return (list->used);
}
@@ -270,8 +249,8 @@ int
gp_list_find_by_name (CameraList *list, int *index, const char *name)
{
int i;
CHECK_LIST (list);
CHECK_NULL (name);
C_PARAMS (list && list->ref_count);
C_PARAMS (name);
/* We search backwards because our only known user
* camlibs/ptp2/library.c thinks this is faster
@@ -300,9 +279,9 @@ gp_list_find_by_name (CameraList *list, int *index, const char *name)
int
gp_list_get_name (CameraList *list, int index, const char **name)
{
CHECK_LIST (list);
CHECK_NULL (name);
CHECK_INDEX_RANGE (list, index);
C_PARAMS (list && list->ref_count);
C_PARAMS (name);
C_PARAMS (0 <= index && index < list->used);
*name = list->entry[index].name;
@@ -321,9 +300,9 @@ gp_list_get_name (CameraList *list, int index, const char **name)
int
gp_list_get_value (CameraList *list, int index, const char **value)
{
CHECK_LIST (list);
CHECK_NULL (value);
CHECK_INDEX_RANGE (list, index);
C_PARAMS (list && list->ref_count);
C_PARAMS (value);
C_PARAMS (0 <= index && index < list->used);
*value = list->entry[index].value;
@@ -343,9 +322,9 @@ int
gp_list_set_value (CameraList *list, int index, const char *value)
{
char *newval;
CHECK_LIST (list);
CHECK_NULL (value);
CHECK_INDEX_RANGE (list, index);
C_PARAMS (list && list->ref_count);
C_PARAMS (value);
C_PARAMS (0 <= index && index < list->used);
C_MEM (newval = strdup(value));
free (list->entry[index].value);
@@ -366,9 +345,9 @@ int
gp_list_set_name (CameraList *list, int index, const char *name)
{
char *newname;
CHECK_LIST (list);
CHECK_NULL (name);
CHECK_INDEX_RANGE (list, index);
C_PARAMS (list && list->ref_count);
C_PARAMS (name);
C_PARAMS (0 <= index && index < list->used);
C_MEM (newname = strdup(name));
free (list->entry[index].name);
@@ -396,8 +375,8 @@ gp_list_populate (CameraList *list, const char *format, int count)
int x;
char buf[1024];
CHECK_LIST (list);
CHECK_NULL (format);
C_PARAMS (list && list->ref_count);
C_PARAMS (format);
gp_list_reset (list);
for (x = 0; x < count; x++) {

View File

@@ -51,7 +51,6 @@ static Setting glob_setting[512];
static int save_settings (void);
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
#define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);}
static int load_settings (void);
@@ -71,7 +70,7 @@ gp_setting_get (char *id, char *key, char *value)
{
int x;
CHECK_NULL (id && key);
C_PARAMS (id && key);
if (!glob_setting_count)
load_settings ();
@@ -103,7 +102,7 @@ gp_setting_set (char *id, char *key, char *value)
{
int x;
CHECK_NULL (id && key);
C_PARAMS (id && key);
if (!glob_setting_count)
load_settings ();

View File

@@ -29,8 +29,6 @@
#include <gphoto2/gphoto2-result.h>
#include <gphoto2/gphoto2-port-log.h>
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
/**
* CameraWidget:
*
@@ -97,7 +95,7 @@ gp_widget_new (CameraWidgetType type, const char *label,
{
static int i = 0;
CHECK_NULL (label && widget);
C_PARAMS (label && widget);
C_MEM (*widget = calloc (1, sizeof (CameraWidget)));
@@ -134,7 +132,7 @@ int
gp_widget_free (CameraWidget *widget)
{
int x;
CHECK_NULL (widget);
C_PARAMS (widget);
/* Free children recursively */
if ((widget->type == GP_WIDGET_WINDOW) ||
@@ -161,7 +159,7 @@ gp_widget_free (CameraWidget *widget)
int
gp_widget_ref (CameraWidget *widget)
{
CHECK_NULL (widget);
C_PARAMS (widget);
widget->ref_count += 1;
@@ -178,7 +176,7 @@ gp_widget_ref (CameraWidget *widget)
int
gp_widget_unref (CameraWidget *widget)
{
CHECK_NULL (widget);
C_PARAMS (widget);
widget->ref_count -= 1;
@@ -199,7 +197,7 @@ gp_widget_unref (CameraWidget *widget)
int
gp_widget_get_info (CameraWidget *widget, const char **info)
{
CHECK_NULL (widget && info);
C_PARAMS (widget && info);
*info = widget->info;
return (GP_OK);
@@ -217,7 +215,7 @@ gp_widget_get_info (CameraWidget *widget, const char **info)
int
gp_widget_set_info (CameraWidget *widget, const char *info)
{
CHECK_NULL (widget && info);
C_PARAMS (widget && info);
strcpy (widget->info, info);
return (GP_OK);
@@ -234,7 +232,7 @@ gp_widget_set_info (CameraWidget *widget, const char *info)
int
gp_widget_get_name (CameraWidget *widget, const char **name)
{
CHECK_NULL (widget && name);
C_PARAMS (widget && name);
*name = widget->name;
return (GP_OK);
@@ -251,7 +249,7 @@ gp_widget_get_name (CameraWidget *widget, const char **name)
int
gp_widget_set_name (CameraWidget *widget, const char *name)
{
CHECK_NULL (widget && name);
C_PARAMS (widget && name);
strcpy (widget->name, name);
return (GP_OK);
@@ -270,7 +268,7 @@ gp_widget_set_name (CameraWidget *widget, const char *name)
int
gp_widget_get_id (CameraWidget *widget, int *id)
{
CHECK_NULL (widget && id);
C_PARAMS (widget && id);
*id = widget->id;
return (GP_OK);
@@ -290,7 +288,7 @@ gp_widget_get_id (CameraWidget *widget, int *id)
int
gp_widget_set_changed (CameraWidget *widget, int changed)
{
CHECK_NULL (widget);
C_PARAMS (widget);
widget->changed = changed;
return (GP_OK);
@@ -311,7 +309,7 @@ gp_widget_set_changed (CameraWidget *widget, int changed)
int
gp_widget_set_readonly (CameraWidget *widget, int readonly)
{
CHECK_NULL (widget);
C_PARAMS (widget);
widget->readonly = readonly;
return (GP_OK);
@@ -328,7 +326,7 @@ gp_widget_set_readonly (CameraWidget *widget, int readonly)
int
gp_widget_get_readonly (CameraWidget *widget, int *readonly)
{
CHECK_NULL (widget && readonly);
C_PARAMS (widget && readonly);
*readonly = widget->readonly;
return (GP_OK);
@@ -345,7 +343,7 @@ gp_widget_get_readonly (CameraWidget *widget, int *readonly)
int
gp_widget_get_type (CameraWidget *widget, CameraWidgetType *type)
{
CHECK_NULL (widget && type);
C_PARAMS (widget && type);
*type = widget->type;
return (GP_OK);
@@ -362,7 +360,7 @@ gp_widget_get_type (CameraWidget *widget, CameraWidgetType *type)
int
gp_widget_get_label (CameraWidget *widget, const char **label)
{
CHECK_NULL (widget && label);
C_PARAMS (widget && label);
*label = widget->label;
return (GP_OK);
@@ -385,7 +383,7 @@ gp_widget_get_label (CameraWidget *widget, const char **label)
int
gp_widget_set_value (CameraWidget *widget, const void *value)
{
CHECK_NULL (widget && value);
C_PARAMS (widget && value);
switch (widget->type) {
case GP_WIDGET_BUTTON:
@@ -435,7 +433,7 @@ gp_widget_set_value (CameraWidget *widget, const void *value)
int
gp_widget_get_value (CameraWidget *widget, void *value)
{
CHECK_NULL (widget && value);
C_PARAMS (widget && value);
switch (widget->type) {
case GP_WIDGET_BUTTON:
@@ -471,12 +469,11 @@ gp_widget_get_value (CameraWidget *widget, void *value)
int
gp_widget_append (CameraWidget *widget, CameraWidget *child)
{
CHECK_NULL (widget && child);
C_PARAMS (widget && child);
/* Return if they can't have any children */
if ((widget->type != GP_WIDGET_WINDOW) &&
(widget->type != GP_WIDGET_SECTION))
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS ((widget->type == GP_WIDGET_WINDOW) ||
(widget->type == GP_WIDGET_SECTION));
C_MEM (widget->children = realloc(widget->children, sizeof(CameraWidget*)*(widget->children_count+1)));
widget->children[widget->children_count] = child;
@@ -500,12 +497,11 @@ gp_widget_prepend (CameraWidget *widget, CameraWidget *child)
{
int x;
CHECK_NULL (widget && child);
C_PARAMS (widget && child);
/* Return if they can't have any children */
if ((widget->type != GP_WIDGET_WINDOW) &&
(widget->type != GP_WIDGET_SECTION))
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS ((widget->type == GP_WIDGET_WINDOW) ||
(widget->type == GP_WIDGET_SECTION));
C_MEM (widget->children = realloc(widget->children, sizeof(CameraWidget*)*(widget->children_count+1)));
@@ -532,7 +528,7 @@ gp_widget_prepend (CameraWidget *widget, CameraWidget *child)
int
gp_widget_count_children (CameraWidget *widget)
{
CHECK_NULL (widget);
C_PARAMS (widget);
return (widget->children_count);
}
@@ -550,10 +546,8 @@ int
gp_widget_get_child (CameraWidget *widget, int child_number,
CameraWidget **child)
{
CHECK_NULL (widget && child);
if (child_number >= widget->children_count)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (widget && child);
C_PARAMS (child_number < widget->children_count);
*child = widget->children[child_number];
return (GP_OK);
@@ -574,7 +568,7 @@ gp_widget_get_child_by_label (CameraWidget *widget, const char *label,
{
int x;
CHECK_NULL (widget && label && child);
C_PARAMS (widget && label && child);
if (strcmp (widget->label, label) == 0) {
*child = widget;
@@ -610,7 +604,7 @@ gp_widget_get_child_by_id (CameraWidget *widget, int id, CameraWidget **child)
{
int x;
CHECK_NULL (widget && child);
C_PARAMS (widget && child);
if (widget->id == id) {
*child = widget;
@@ -646,7 +640,7 @@ gp_widget_get_child_by_name (CameraWidget *widget, const char *name,
{
int x;
CHECK_NULL (widget && child);
C_PARAMS (widget && child);
if (!strcmp (widget->name, name)) {
*child = widget;
@@ -679,7 +673,7 @@ gp_widget_get_child_by_name (CameraWidget *widget, const char *name,
int
gp_widget_get_parent (CameraWidget *widget, CameraWidget **parent)
{
CHECK_NULL (widget && parent);
C_PARAMS (widget && parent);
*parent = widget->parent;
@@ -697,7 +691,7 @@ gp_widget_get_parent (CameraWidget *widget, CameraWidget **parent)
int
gp_widget_get_root (CameraWidget *widget, CameraWidget **root)
{
CHECK_NULL (widget && root);
C_PARAMS (widget && root);
if (widget->parent)
return (gp_widget_get_root (widget->parent, root));
@@ -720,10 +714,8 @@ gp_widget_get_root (CameraWidget *widget, CameraWidget **root)
int
gp_widget_set_range (CameraWidget *range, float min, float max, float increment)
{
CHECK_NULL (range);
if (range->type != GP_WIDGET_RANGE)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (range);
C_PARAMS (range->type == GP_WIDGET_RANGE);
range->min = min;
range->max = max;
@@ -746,9 +738,8 @@ int
gp_widget_get_range (CameraWidget *range, float *min, float *max,
float *increment)
{
CHECK_NULL (range && min && max && increment);
if (range->type != GP_WIDGET_RANGE)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (range && min && max && increment);
C_PARAMS (range->type == GP_WIDGET_RANGE);
*min = range->min;
*max = range->max;
@@ -768,10 +759,9 @@ gp_widget_get_range (CameraWidget *range, float *min, float *max,
int
gp_widget_add_choice (CameraWidget *widget, const char *choice)
{
CHECK_NULL (widget && choice);
if ((widget->type != GP_WIDGET_RADIO) &&
(widget->type != GP_WIDGET_MENU))
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (widget && choice);
C_PARAMS ((widget->type == GP_WIDGET_RADIO) ||
(widget->type == GP_WIDGET_MENU));
C_MEM (widget->choice = realloc (widget->choice, sizeof(char*)*(widget->choice_count+1)));
widget->choice[widget->choice_count] = strdup(choice);
@@ -789,10 +779,9 @@ gp_widget_add_choice (CameraWidget *widget, const char *choice)
int
gp_widget_count_choices (CameraWidget *widget)
{
CHECK_NULL (widget);
if ((widget->type != GP_WIDGET_RADIO) &&
(widget->type != GP_WIDGET_MENU))
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (widget);
C_PARAMS ((widget->type == GP_WIDGET_RADIO) ||
(widget->type == GP_WIDGET_MENU));
return (widget->choice_count);
}
@@ -810,13 +799,10 @@ int
gp_widget_get_choice (CameraWidget *widget, int choice_number,
const char **choice)
{
CHECK_NULL (widget && choice);
if ((widget->type != GP_WIDGET_RADIO) &&
(widget->type != GP_WIDGET_MENU))
return (GP_ERROR_BAD_PARAMETERS);
if (choice_number >= widget->choice_count)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (widget && choice);
C_PARAMS ((widget->type == GP_WIDGET_RADIO) ||
(widget->type == GP_WIDGET_MENU));
C_PARAMS (choice_number < widget->choice_count);
*choice = widget->choice[choice_number];
return (GP_OK);
@@ -837,7 +823,7 @@ gp_widget_changed (CameraWidget *widget)
{
int val;
CHECK_NULL (widget);
C_PARAMS (widget);
val = widget->changed;
widget->changed = 0;

View File

@@ -200,6 +200,20 @@ void gp_log_data (const char *domain, const char *data, unsigned int size);
}\
} while(0)
#define C_PARAMS(PARAMS) do {\
if (!(PARAMS)) {\
GP_LOG_E ("Invalid parameters: '%s' is NULL/FALSE.", #PARAMS);\
return GP_ERROR_BAD_PARAMETERS;\
}\
} while(0)
#define C_PARAMS_MSG(PARAMS, MSG, ...) do {\
if (!(PARAMS)) {\
GP_LOG_E ("Invalid parameters: " #MSG " ('%s' is NULL/FALSE.)", ##__VA_ARGS__, #PARAMS);\
return GP_ERROR_BAD_PARAMETERS;\
}\
} while(0)
#endif /* _GPHOTO2_INTERNAL_CODE */
#endif /* __GPHOTO2_PORT_LOG_H__ */

View File

@@ -75,7 +75,6 @@ struct _GPPortInfoList {
unsigned int iolib_count;
};
#define CHECK_NULL(x) {if (!(x)) return (GP_ERROR_BAD_PARAMETERS);}
#define CR(x) {int r=(x);if (r<0) return (r);}
@@ -109,7 +108,7 @@ gp_port_message_codeset (const char *codeset) {
int
gp_port_info_list_new (GPPortInfoList **list)
{
CHECK_NULL (list);
C_PARAMS (list);
/*
* We put this in here because everybody needs to call this function
@@ -133,7 +132,7 @@ gp_port_info_list_new (GPPortInfoList **list)
int
gp_port_info_list_free (GPPortInfoList *list)
{
CHECK_NULL (list);
C_PARAMS (list);
if (list->info) {
unsigned int i;
@@ -174,7 +173,7 @@ gp_port_info_list_free (GPPortInfoList *list)
int
gp_port_info_list_append (GPPortInfoList *list, GPPortInfo info)
{
CHECK_NULL (list);
C_PARAMS (list);
C_MEM (list->info = realloc (list->info, sizeof (GPPortInfo) * (list->count + 1)));
list->count++;
@@ -269,7 +268,7 @@ gp_port_info_list_load (GPPortInfoList *list)
const char *iolibs = (iolibs_env != NULL)?iolibs_env:IOLIBS;
int result;
CHECK_NULL (list);
C_PARAMS (list);
GP_LOG_D ("Using ltdl to load io-drivers from '%s'...", iolibs);
lt_dlinit ();
@@ -298,7 +297,7 @@ gp_port_info_list_count (GPPortInfoList *list)
{
unsigned int count, i;
CHECK_NULL (list);
C_PARAMS (list);
GP_LOG_D ("Counting entries (%i available)...", list->count);
@@ -338,7 +337,7 @@ gp_port_info_list_lookup_path (GPPortInfoList *list, const char *path)
#endif
#endif
CHECK_NULL (list && path);
C_PARAMS (list && path);
GP_LOG_D ("Looking for path '%s' (%i entries available)...", path, list->count);
@@ -424,7 +423,7 @@ gp_port_info_list_lookup_name (GPPortInfoList *list, const char *name)
{
unsigned int i, generic;
CHECK_NULL (list && name);
C_PARAMS (list && name);
GP_LOG_D ("Looking up entry '%s'...", name);
@@ -453,19 +452,17 @@ gp_port_info_list_get_info (GPPortInfoList *list, int n, GPPortInfo *info)
{
int i;
CHECK_NULL (list && info);
C_PARAMS (list && info);
GP_LOG_D ("Getting info of entry %i (%i available)...", n, list->count);
if (n < 0 || n >= list->count)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (n >= 0 && n < list->count);
/* Ignore generic entries */
for (i = 0; i <= n; i++)
if (!strlen (list->info[i]->name)) {
n++;
if (n >= list->count)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (n < list->count);
}
*info = list->info[n];

View File

@@ -81,8 +81,7 @@ static unsigned int log_funcs_count = 0;
int
gp_log_add_func (GPLogLevel level, GPLogFunc func, void *data)
{
if (!func)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (func);
C_MEM (log_funcs = realloc (log_funcs, sizeof (LogFunc) *
(log_funcs_count + 1)));
@@ -107,8 +106,7 @@ gp_log_add_func (GPLogLevel level, GPLogFunc func, void *data)
int
gp_log_remove_func (int id)
{
if (id < 1 || id > log_funcs_count)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (id > 0 && id <= log_funcs_count);
memmove (log_funcs + id - 1, log_funcs + id, log_funcs_count - id);
log_funcs_count--;

View File

@@ -56,7 +56,6 @@
#endif
#define CHECK_RESULT(result) {int r=(result); if (r<0) return (r);}
#define CHECK_NULL(m) {if (!(m)) return (GP_ERROR_BAD_PARAMETERS);}
#define CHECK_SUPP(p,t,o) {if (!(o)) {gp_port_set_error ((p), _("The operation '%s' is not supported by this device"), (t)); return (GP_ERROR_NOT_SUPPORTED);}}
#define CHECK_INIT(p) {if (!(p)->pc->ops) {gp_port_set_error ((p), _("The port has not yet been initialized")); return (GP_ERROR_BAD_PARAMETERS);}}
@@ -87,7 +86,7 @@ struct _GPPortPrivateCore {
int
gp_port_new (GPPort **port)
{
CHECK_NULL (port);
C_PARAMS (port);
GP_LOG_D ("Creating new device...");
@@ -105,7 +104,7 @@ gp_port_new (GPPort **port)
static int
gp_port_init (GPPort *port)
{
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
if (port->pc->ops->init)
@@ -117,7 +116,7 @@ gp_port_init (GPPort *port)
static int
gp_port_exit (GPPort *port)
{
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
if (port->pc->ops->exit)
@@ -144,7 +143,7 @@ gp_port_set_info (GPPort *port, GPPortInfo info)
{
GPPortLibraryOperations ops_func;
CHECK_NULL (port);
C_PARAMS (port);
free (port->pc->info.name);
C_MEM (port->pc->info.name = strdup (info->name));
@@ -223,7 +222,7 @@ gp_port_set_info (GPPort *port, GPPortInfo info)
/* Nothing in here */
break;
}
gp_port_set_settings (port, port->settings);
CHECK_RESULT (gp_port_set_settings (port, port->settings));
return (GP_OK);
}
@@ -240,7 +239,7 @@ gp_port_set_info (GPPort *port, GPPortInfo info)
int
gp_port_get_info (GPPort *port, GPPortInfo *info)
{
CHECK_NULL (port && info);
C_PARAMS (port && info);
*info = &port->pc->info;
return (GP_OK);
@@ -258,7 +257,7 @@ gp_port_get_info (GPPort *port, GPPortInfo *info)
int
gp_port_open (GPPort *port)
{
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
GP_LOG_D ("Opening %s port...",
@@ -284,7 +283,7 @@ gp_port_close (GPPort *port)
{
GP_LOG_D ("Closing port...");
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "close", port->pc->ops->close);
@@ -306,7 +305,7 @@ gp_port_reset (GPPort *port)
{
GP_LOG_D ("Resetting port...");
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "reset", port->pc->ops->reset);
@@ -328,7 +327,7 @@ gp_port_free (GPPort *port)
{
GP_LOG_D ("Freeing port...");
CHECK_NULL (port);
C_PARAMS (port);
if (port->pc) {
if (port->pc->ops) {
@@ -381,7 +380,7 @@ gp_port_write (GPPort *port, const char *data, int size)
GP_LOG_D ("Writing %i=0x%x byte(s) to port...", size, size);
CHECK_NULL (port && data);
C_PARAMS (port && data);
CHECK_INIT (port);
GP_LOG_DATA (data, size);
@@ -415,7 +414,7 @@ gp_port_read (GPPort *port, char *data, int size)
GP_LOG_D ("Reading %i=0x%x bytes from port...", size, size);
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
/* Check if we read as many bytes as expected */
@@ -450,7 +449,7 @@ gp_port_check_int (GPPort *port, char *data, int size)
GP_LOG_D ("Reading %i=0x%x bytes from interrupt endpoint...", size, size);
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
/* Check if we read as many bytes as expected */
@@ -484,7 +483,7 @@ gp_port_check_int_fast (GPPort *port, char *data, int size)
{
int retval;
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
/* Check if we read as many bytes as expected */
@@ -529,7 +528,7 @@ gp_port_check_int_fast (GPPort *port, char *data, int size)
int
gp_port_set_timeout (GPPort *port, int timeout)
{
CHECK_NULL (port);
C_PARAMS (port);
GP_LOG_D ("Setting port timeout to %i milliseconds.", timeout);
port->timeout = timeout;
@@ -563,7 +562,7 @@ int gp_port_timeout_get (GPPort *port, int *timeout)
int
gp_port_get_timeout (GPPort *port, int *timeout)
{
CHECK_NULL (port);
C_PARAMS (port);
GP_LOG_D ("Current port timeout is %i milliseconds.", port->timeout);
*timeout = port->timeout;
@@ -587,7 +586,7 @@ gp_port_set_settings (GPPort *port, GPPortSettings settings)
{
GP_LOG_D ("Setting settings...");
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
/*
@@ -627,7 +626,7 @@ int gp_port_settings_set (GPPort *port, GPPortSettings settings)
int
gp_port_get_settings (GPPort *port, GPPortSettings *settings)
{
CHECK_NULL (port);
C_PARAMS (port);
memcpy (settings, &(port->settings), sizeof (gp_port_settings));
@@ -648,7 +647,7 @@ gp_port_get_pin (GPPort *port, GPPin pin, GPLevel *level)
{
GP_LOG_D ("Getting level of pin %i...", pin);
CHECK_NULL (port && level);
C_PARAMS (port && level);
CHECK_INIT (port);
CHECK_SUPP (port, "get_pin", port->pc->ops->get_pin);
@@ -710,7 +709,7 @@ gp_port_set_pin (GPPort *port, GPPin pin, GPLevel level)
PinTable[i].number, PinTable[i].description_short,
PinTable[i].description_long, _(LevelTable[j].description));
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "set_pin", port->pc->ops->set_pin);
@@ -734,7 +733,7 @@ gp_port_send_break (GPPort *port, int duration)
{
GP_LOG_D ("Sending break (%i milliseconds)...", duration);
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "send_break", port->pc->ops->send_break);
@@ -759,7 +758,7 @@ gp_port_flush (GPPort *port, int direction)
{
GP_LOG_D ("Flushing port...");
CHECK_NULL (port);
C_PARAMS (port);
CHECK_SUPP (port, "flush", port->pc->ops->flush);
CHECK_RESULT (port->pc->ops->flush (port, direction));
@@ -785,7 +784,7 @@ gp_port_flush (GPPort *port, int direction)
int
gp_port_usb_find_device (GPPort *port, int idvendor, int idproduct)
{
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "find_device", port->pc->ops->find_device);
@@ -809,7 +808,7 @@ gp_port_usb_find_device (GPPort *port, int idvendor, int idproduct)
int
gp_port_usb_find_device_by_class (GPPort *port, int mainclass, int subclass, int protocol)
{
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "find_device_by_class", port->pc->ops->find_device_by_class);
@@ -833,7 +832,7 @@ gp_port_usb_clear_halt (GPPort *port, int ep)
{
GP_LOG_D ("Clear USB halt...");
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "clear_halt", port->pc->ops->clear_halt);
@@ -866,7 +865,7 @@ gp_port_usb_msg_write (GPPort *port, int request, int value, int index,
request, value, index, size, size);
GP_LOG_DATA (bytes, size);
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_write", port->pc->ops->msg_write);
@@ -899,7 +898,7 @@ gp_port_usb_msg_read (GPPort *port, int request, int value, int index,
GP_LOG_D ("Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
request, value, index, size, size);
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_read", port->pc->ops->msg_read);
@@ -941,7 +940,7 @@ gp_port_usb_msg_interface_write (GPPort *port, int request,
request, value, index, size, size);
GP_LOG_DATA (bytes, size);
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_build", port->pc->ops->msg_interface_write);
@@ -976,7 +975,7 @@ gp_port_usb_msg_interface_read (GPPort *port, int request, int value, int index,
GP_LOG_D ("Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
request, value, index, size, size);
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_read", port->pc->ops->msg_interface_read);
@@ -1022,7 +1021,7 @@ gp_port_usb_msg_class_write (GPPort *port, int request,
request, value, index, size, size);
GP_LOG_DATA (bytes, size);
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_build", port->pc->ops->msg_class_write);
@@ -1057,7 +1056,7 @@ gp_port_usb_msg_class_read (GPPort *port, int request, int value, int index,
GP_LOG_D ("Reading message (request=0x%x value=0x%x index=0x%x size=%i=0x%x)...",
request, value, index, size, size);
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "msg_read", port->pc->ops->msg_class_read);
@@ -1091,7 +1090,7 @@ gp_port_seek (GPPort *port, int offset, int whence)
GP_LOG_D ("Seeking to: %d whence: %d", offset, whence);
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
CHECK_SUPP (port, "seek", port->pc->ops->seek);
@@ -1133,7 +1132,7 @@ int gp_port_send_scsi_cmd (GPPort *port, int to_dev,
GP_LOG_DATA (data, data_size);
}
CHECK_NULL (port);
C_PARAMS (port);
CHECK_INIT (port);
memset (sense, 0, sense_size);
@@ -1191,8 +1190,7 @@ gp_port_set_error (GPPort *port, const char *format, ...)
{
va_list args;
if (!port)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (port);
if (format) {
va_start (args, format);

View File

@@ -65,12 +65,6 @@
return _r;\
}\
} while(0)
#define C_PARAMS(PARAMS) do {\
if (!(PARAMS)) {\
GP_LOG_E ("Invalid parameters: '%s' is NULL/FALSE.", #PARAMS);\
return GP_ERROR_BAD_PARAMETERS;\
}\
} while(0)
#ifndef HAVE_LIBUSB_STRERROR
static const char *libusb_strerror(int r)
@@ -637,9 +631,7 @@ gp_port_usb_update (GPPort *port)
{
int ifacereleased = FALSE;
if (!port || !port->pl || !port->pl->ctx)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl && port->pl->ctx);
gp_log (GP_LOG_DEBUG, "libusb1", "gp_port_usb_update(old int=%d, conf=%d, alt=%d) port %s, (new int=%d, conf=%d, alt=%d) port %s",
port->settings.usb.interface,
@@ -662,8 +654,8 @@ gp_port_usb_update (GPPort *port)
memcpy(&port->settings.usb.port, &port->settings_pending.usb.port,
sizeof(port->settings.usb.port));
if (!port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
if (!port->pl->dh)
return GP_OK; /* the port might not be opened, yet. that is ok */
memcpy(&port->settings.usb, &port->settings_pending.usb,
sizeof(port->settings.usb));
@@ -815,12 +807,8 @@ gp_port_usb_find_path_lib(GPPort *port)
pl = port->pl;
s = strchr (port->settings.usb.port,':');
if (s && (s[1] != '\0')) { /* usb:%d,%d */
if (sscanf (s+1, "%d,%d", &busnr, &devnr) != 2)
return GP_ERROR_BAD_PARAMETERS;
} else {
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS (s && (s[1] != '\0'));
C_PARAMS (sscanf (s+1, "%d,%d", &busnr, &devnr) == 2); /* usb:%d,%d */
pl->nrofdevs = load_devicelist (port->pl);

View File

@@ -360,8 +360,7 @@ gp_port_library_list (GPPortInfoList *list)
static int
gp_port_serial_init (GPPort *dev)
{
if (!dev)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (dev);
C_MEM (dev->pl = calloc (1, sizeof (GPPortPrivateLibrary)));
@@ -374,8 +373,7 @@ gp_port_serial_init (GPPort *dev)
static int
gp_port_serial_exit (GPPort *dev)
{
if (!dev)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (dev);
free (dev->pl);
dev->pl = NULL;
@@ -462,7 +460,7 @@ gp_port_serial_close (GPPort *dev)
/* Unlock the port */
path = strchr (dev->settings.serial.port, ':');
if (!path) return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (path);
path++;
CHECK (gp_port_serial_unlock (dev, path));
@@ -482,8 +480,7 @@ gp_port_serial_write (GPPort *dev, const char *bytes, int size)
{
int len, ret;
if (!dev)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (dev);
/* The device needs to be opened for that operation */
if (!dev->pl->fd)
@@ -536,8 +533,7 @@ gp_port_serial_read (GPPort *dev, char *bytes, int size)
fd_set readfs; /* file descriptor set */
int readen = 0, now;
if (!dev)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (dev);
/* The device needs to be opened for that operation */
if (!dev->pl->fd)
@@ -647,8 +643,7 @@ gp_port_serial_get_pin (GPPort *dev, GPPin pin, GPLevel *level)
int j, bit;
#endif
if (!dev || !level)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (dev && level);
*level = 0;
@@ -678,8 +673,7 @@ gp_port_serial_set_pin (GPPort *dev, GPPin pin, GPLevel level)
int bit, request;
#endif
if (!dev)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (dev);
#ifdef HAVE_TERMIOS_H
CHECK (get_termios_bit (dev, pin, &bit));

View File

@@ -245,12 +245,10 @@ gp_port_usb_open (GPPort *port)
char name[64];
gp_log (GP_LOG_DEBUG,"libusb","gp_port_usb_open(%p)", port);
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port);
if (!port->pl->d) {
ret = gp_port_usb_find_path_lib(port);
if (!port->pl->d)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port->pl->d);
}
/*
@@ -321,8 +319,7 @@ gp_port_usb_open (GPPort *port)
static int
gp_port_usb_close (GPPort *port)
{
if (!port || !port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh);
if (usb_release_interface (port->pl->dh,
port->settings.usb.interface) < 0) {
@@ -387,8 +384,7 @@ gp_port_usb_clear_halt_lib(GPPort *port, int ep)
{
int ret=0;
if (!port || !port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh);
switch (ep) {
case GP_PORT_USB_ENDPOINT_IN :
@@ -413,8 +409,7 @@ gp_port_usb_write (GPPort *port, const char *bytes, int size)
{
int ret;
if (!port || !port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh);
ret = usb_bulk_write (port->pl->dh, port->settings.usb.outep,
(char *) bytes, size, port->timeout);
@@ -429,8 +424,7 @@ gp_port_usb_read(GPPort *port, char *bytes, int size)
{
int ret;
if (!port || !port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh);
ret = usb_bulk_read(port->pl->dh, port->settings.usb.inep,
bytes, size, port->timeout);
@@ -446,8 +440,7 @@ gp_port_usb_reset(GPPort *port)
int ret;
gp_log (GP_LOG_DEBUG, "libusb", "Reseting port");
if (!port || !port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh);
ret = usb_reset(port->pl->dh);
if (ret < 0) {
@@ -462,8 +455,7 @@ gp_port_usb_check_int (GPPort *port, char *bytes, int size, int timeout)
{
int ret;
if (!port || !port->pl->dh || timeout < 0)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh && timeout >= 0);
ret = usb_interrupt_read(port->pl->dh, port->settings.usb.intep,
bytes, size, timeout);
@@ -479,8 +471,7 @@ static int
gp_port_usb_msg_write_lib(GPPort *port, int request, int value, int index,
char *bytes, int size)
{
if (!port || !port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh);
return usb_control_msg(port->pl->dh,
USB_TYPE_VENDOR | USB_RECIP_DEVICE,
@@ -491,8 +482,7 @@ static int
gp_port_usb_msg_read_lib(GPPort *port, int request, int value, int index,
char *bytes, int size)
{
if (!port || !port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh);
return usb_control_msg(port->pl->dh,
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
@@ -507,8 +497,7 @@ static int
gp_port_usb_msg_interface_write_lib(GPPort *port, int request,
int value, int index, char *bytes, int size)
{
if (!port || !port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh);
return usb_control_msg(port->pl->dh,
USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
@@ -520,8 +509,7 @@ static int
gp_port_usb_msg_interface_read_lib(GPPort *port, int request,
int value, int index, char *bytes, int size)
{
if (!port || !port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh);
return usb_control_msg(port->pl->dh,
USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_ENDPOINT_IN,
@@ -537,8 +525,7 @@ static int
gp_port_usb_msg_class_write_lib(GPPort *port, int request,
int value, int index, char *bytes, int size)
{
if (!port || !port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh);
return usb_control_msg(port->pl->dh,
USB_TYPE_CLASS | USB_RECIP_INTERFACE,
@@ -550,8 +537,7 @@ static int
gp_port_usb_msg_class_read_lib(GPPort *port, int request,
int value, int index, char *bytes, int size)
{
if (!port || !port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port && port->pl->dh);
return usb_control_msg(port->pl->dh,
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_ENDPOINT_IN,
@@ -573,8 +559,7 @@ gp_port_usb_update (GPPort *port)
{
int ret, ifacereleased = FALSE;
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port);
gp_log (GP_LOG_DEBUG, "libusb", "gp_port_usb_update(old int=%d, conf=%d, alt=%d) port %s, (new int=%d, conf=%d, alt=%d), port %s",
port->settings.usb.interface,
@@ -597,8 +582,8 @@ gp_port_usb_update (GPPort *port)
memcpy(&port->settings.usb.port, &port->settings_pending.usb.port,
sizeof(port->settings.usb.port));
if (!port->pl->dh)
return GP_ERROR_BAD_PARAMETERS;
if (!port->pl->dh)
return GP_OK; /* the port might not be opened, yet. that is ok */
memcpy(&port->settings.usb, &port->settings_pending.usb,
sizeof(port->settings.usb));
@@ -748,8 +733,7 @@ gp_port_usb_find_device_lib(GPPort *port, int idvendor, int idproduct)
char *s;
char busname[64], devname[64];
if (!port)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (port);
s = strchr (port->settings.usb.port,':');
busname[0] = devname[0] = '\0';
@@ -867,28 +851,22 @@ gp_port_usb_find_path_lib(GPPort *port)
char *s;
char busname[64], devname[64];
if (!port)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (port);
s = strchr (port->settings.usb.port,':');
busname[0] = devname[0] = '\0';
if (!s || s[1] == '\0') {
/* generic usb: match ... can't do */
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS (s && s[1] != '\0'); /* generic usb: match ... can't do */
if (s && (s[1] != '\0')) { /* usb:%d,%d */
strncpy(busname,s+1,sizeof(busname));
busname[sizeof(busname)-1] = '\0';
s = strchr(busname,',');
if (s) {
strncpy(devname, s+1,sizeof(devname));
devname[sizeof(devname)-1] = '\0';
*s = '\0';
} else {
/* generic usb: match ... can't do */
return GP_ERROR_BAD_PARAMETERS;
}
C_PARAMS (s); /* generic usb: match ... can't do */
strncpy(devname, s+1,sizeof(devname));
devname[sizeof(devname)-1] = '\0';
*s = '\0';
}
for (bus = usb_busses; bus; bus = bus->next) {
if (strcmp(busname, bus->dirname))
@@ -1162,8 +1140,7 @@ gp_port_usb_find_device_by_class_lib(GPPort *port, int class, int subclass, int
char *s;
char busname[64], devname[64];
if (!port)
return (GP_ERROR_BAD_PARAMETERS);
C_PARAMS (port);
busname[0] = devname[0] = '\0';
s = strchr (port->settings.usb.port,':');
@@ -1186,8 +1163,7 @@ gp_port_usb_find_device_by_class_lib(GPPort *port, int class, int subclass, int
* Should the USB layer report that ? I don't know.
* Better to check here.
*/
if (!class)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (class);
for (bus = usb_busses; bus; bus = bus->next) {
if ((busname[0] != '\0') && strcmp(busname, bus->dirname))

View File

@@ -255,8 +255,7 @@ gp_port_usbdiskdirect_init (GPPort *port)
static int
gp_port_usbdiskdirect_exit (GPPort *port)
{
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port);
free (port->pl);
port->pl = NULL;
@@ -316,8 +315,7 @@ static int gp_port_usbdiskdirect_seek (GPPort *port, int offset, int whence)
{
off_t ret;
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (!port);
/* The device needs to be opened for that operation */
if (port->pl->fd == -1)
@@ -339,8 +337,7 @@ gp_port_usbdiskdirect_write (GPPort *port, const char *bytes, int size)
{
int ret;
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port);
/* The device needs to be opened for that operation */
if (port->pl->fd == -1)
@@ -361,8 +358,7 @@ gp_port_usbdiskdirect_read (GPPort *port, char *bytes, int size)
{
int ret;
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port);
/* The device needs to be opened for that operation */
if (port->pl->fd == -1)
@@ -381,8 +377,7 @@ gp_port_usbdiskdirect_read (GPPort *port, char *bytes, int size)
static int
gp_port_usbdiskdirect_update (GPPort *port)
{
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port);
memcpy (&port->settings, &port->settings_pending,
sizeof (port->settings));
@@ -396,12 +391,10 @@ gp_port_usbdiskdirect_find_device(GPPort *port, int idvendor, int idproduct)
unsigned short vendor_id, product_id;
const char *disk;
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port);
disk = strrchr (port->settings.usbdiskdirect.path, '/');
if (!disk)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (disk);
disk++;
CHECK (gp_port_usbdiskdirect_get_usb_id (disk,

View File

@@ -252,8 +252,7 @@ gp_port_usbscsi_init (GPPort *port)
static int
gp_port_usbscsi_exit (GPPort *port)
{
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port);
free (port->pl);
port->pl = NULL;
@@ -314,8 +313,7 @@ static int gp_port_usbscsi_send_scsi_cmd (GPPort *port, int to_dev, char *cmd,
#ifdef HAVE_SCSI_SG_H
sg_io_hdr_t io_hdr;
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port);
/* The device needs to be opened for that operation */
if (port->pl->fd == -1)
@@ -357,8 +355,7 @@ static int gp_port_usbscsi_send_scsi_cmd (GPPort *port, int to_dev, char *cmd,
static int
gp_port_usbscsi_update (GPPort *port)
{
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port);
memcpy (&port->settings, &port->settings_pending,
sizeof (port->settings));
@@ -372,12 +369,10 @@ gp_port_usbscsi_find_device(GPPort *port, int idvendor, int idproduct)
unsigned short vendor_id, product_id;
const char *sg;
if (!port)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (port);
sg = strrchr (port->settings.usbscsi.path, '/');
if (!sg)
return GP_ERROR_BAD_PARAMETERS;
C_PARAMS (sg);
sg++;
CHECK (gp_port_usbscsi_get_usb_id (sg, &vendor_id, &product_id))