Fixes style: make style

This commit is contained in:
Romuald Conty 2012-12-09 20:09:55 +01:00
parent 007b78cbb4
commit 82c41b4fc1
9 changed files with 91 additions and 89 deletions

View file

@ -2387,11 +2387,11 @@ pn53x_InRelease(struct nfc_device *pnd, const uint8_t ui8Target)
// No much choice what to release actually... // No much choice what to release actually...
uint8_t abtCmdRcs360[] = { InRelease, 0x01, 0x01 }; uint8_t abtCmdRcs360[] = { InRelease, 0x01, 0x01 };
res = pn53x_transceive(pnd, abtCmdRcs360, sizeof(abtCmdRcs360), NULL, 0, -1); res = pn53x_transceive(pnd, abtCmdRcs360, sizeof(abtCmdRcs360), NULL, 0, -1);
return (res>=0) ? NFC_SUCCESS : res; return (res >= 0) ? NFC_SUCCESS : res;
} }
uint8_t abtCmd[] = { InRelease, ui8Target }; uint8_t abtCmd[] = { InRelease, ui8Target };
res = pn53x_transceive(pnd, abtCmd, sizeof(abtCmd), NULL, 0, -1); res = pn53x_transceive(pnd, abtCmd, sizeof(abtCmd), NULL, 0, -1);
return (res>=0) ? NFC_SUCCESS : res; return (res >= 0) ? NFC_SUCCESS : res;
} }
int int

View file

@ -36,9 +36,9 @@
#define LIBNFC_DEVICECONFDIR LIBNFC_SYSCONFDIR"/devices.d" #define LIBNFC_DEVICECONFDIR LIBNFC_SYSCONFDIR"/devices.d"
static bool static bool
conf_parse_file(const char* filename, void (*conf_keyvalue)(void* data, const char* key, const char* value), void* data) conf_parse_file(const char *filename, void (*conf_keyvalue)(void *data, const char *key, const char *value), void *data)
{ {
FILE *f = fopen (filename, "r"); FILE *f = fopen(filename, "r");
if (!f) { if (!f) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Unable to open file: %s", filename); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Unable to open file: %s", filename);
return false; return false;
@ -46,13 +46,13 @@ conf_parse_file(const char* filename, void (*conf_keyvalue)(void* data, const ch
char line[BUFSIZ]; char line[BUFSIZ];
const char *str_regex = "^[[:space:]]*([[:alnum:]_.]+)[[:space:]]*=[[:space:]]*(\"(.+)\"|([^[:space:]]+))[[:space:]]*$"; const char *str_regex = "^[[:space:]]*([[:alnum:]_.]+)[[:space:]]*=[[:space:]]*(\"(.+)\"|([^[:space:]]+))[[:space:]]*$";
regex_t preg; regex_t preg;
if(regcomp (&preg, str_regex, REG_EXTENDED|REG_NOTEOL) != 0) { if (regcomp(&preg, str_regex, REG_EXTENDED | REG_NOTEOL) != 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Regular expression used for configuration file parsing is not valid."); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Regular expression used for configuration file parsing is not valid.");
return false; return false;
} }
size_t nmatch = preg.re_nsub + 1; size_t nmatch = preg.re_nsub + 1;
regmatch_t *pmatch = malloc (sizeof (*pmatch) * nmatch); regmatch_t *pmatch = malloc(sizeof(*pmatch) * nmatch);
if(!pmatch) { if (!pmatch) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Not enough memory: malloc failed."); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Not enough memory: malloc failed.");
return false; return false;
} }
@ -60,20 +60,22 @@ conf_parse_file(const char* filename, void (*conf_keyvalue)(void* data, const ch
int lineno = 0; int lineno = 0;
while (fgets(line, BUFSIZ, f) != NULL) { while (fgets(line, BUFSIZ, f) != NULL) {
lineno++; lineno++;
switch(line[0]) { switch (line[0]) {
case '#': case '#':
case '\n': case '\n':
break; break;
default: { default: {
int match; int match;
if ((match = regexec (&preg, line, nmatch, pmatch, 0)) == 0) { if ((match = regexec(&preg, line, nmatch, pmatch, 0)) == 0) {
const size_t key_size = pmatch[1].rm_eo - pmatch[1].rm_so; const size_t key_size = pmatch[1].rm_eo - pmatch[1].rm_so;
const off_t value_pmatch = pmatch[3].rm_eo!=-1?3:4; const off_t value_pmatch = pmatch[3].rm_eo != -1 ? 3 : 4;
const size_t value_size = pmatch[value_pmatch].rm_eo - pmatch[value_pmatch].rm_so; const size_t value_size = pmatch[value_pmatch].rm_eo - pmatch[value_pmatch].rm_so;
char key[key_size+1]; char key[key_size + 1];
char value[value_size+1]; char value[value_size + 1];
strncpy(key, line+(pmatch[1].rm_so), key_size); key[key_size]='\0'; strncpy(key, line + (pmatch[1].rm_so), key_size);
strncpy(value, line+(pmatch[value_pmatch].rm_so), value_size); value[value_size]='\0'; key[key_size] = '\0';
strncpy(value, line + (pmatch[value_pmatch].rm_so), value_size);
value[value_size] = '\0';
conf_keyvalue(data, key, value); conf_keyvalue(data, key, value);
} else { } else {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Parse error on line #%d: %s", lineno, line); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Parse error on line #%d: %s", lineno, line);
@ -88,9 +90,9 @@ conf_parse_file(const char* filename, void (*conf_keyvalue)(void* data, const ch
} }
static void static void
conf_keyvalue_context(void *data, const char* key, const char* value) conf_keyvalue_context(void *data, const char *key, const char *value)
{ {
nfc_context *context = (nfc_context*)data; nfc_context *context = (nfc_context *)data;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "key: [%s], value: [%s]", key, value); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "key: [%s], value: [%s]", key, value);
if (strcmp(key, "allow_autoscan") == 0) { if (strcmp(key, "allow_autoscan") == 0) {
string_as_boolean(value, &(context->allow_autoscan)); string_as_boolean(value, &(context->allow_autoscan));
@ -99,30 +101,30 @@ conf_keyvalue_context(void *data, const char* key, const char* value)
} else if (strcmp(key, "log_level") == 0) { } else if (strcmp(key, "log_level") == 0) {
context->log_level = atoi(value); context->log_level = atoi(value);
} else if (strcmp(key, "device.name") == 0) { } else if (strcmp(key, "device.name") == 0) {
if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count-1].name, "") != 0) { if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].name, "") != 0) {
if(context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) { if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices."); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices.");
return; return;
} }
context->user_defined_device_count++; context->user_defined_device_count++;
} }
strcpy(context->user_defined_devices[context->user_defined_device_count-1].name, value); strcpy(context->user_defined_devices[context->user_defined_device_count - 1].name, value);
} else if (strcmp(key, "device.connstring") == 0) { } else if (strcmp(key, "device.connstring") == 0) {
if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count-1].connstring, "") != 0) { if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].connstring, "") != 0) {
if(context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) { if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices."); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices.");
return; return;
} }
context->user_defined_device_count++; context->user_defined_device_count++;
} }
strcpy(context->user_defined_devices[context->user_defined_device_count-1].connstring, value); strcpy(context->user_defined_devices[context->user_defined_device_count - 1].connstring, value);
} else { } else {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Unknown key in config line: %s = %s", key, value); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Unknown key in config line: %s = %s", key, value);
} }
} }
static void static void
conf_keyvalue_device(void *data, const char* key, const char* value) conf_keyvalue_device(void *data, const char *key, const char *value)
{ {
char newkey[BUFSIZ]; char newkey[BUFSIZ];
sprintf(newkey, "device.%s", key); sprintf(newkey, "device.%s", key);
@ -136,22 +138,22 @@ conf_devices_load(const char *dirname, nfc_context *context)
if (!d) { if (!d) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open directory: %s", dirname); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open directory: %s", dirname);
} else { } else {
struct dirent* de; struct dirent *de;
while ((de = readdir(d))) { while ((de = readdir(d))) {
if (de->d_name[0]!='.') { if (de->d_name[0] != '.') {
const size_t filename_len = strlen(de->d_name); const size_t filename_len = strlen(de->d_name);
const size_t extension_len = strlen(".conf"); const size_t extension_len = strlen(".conf");
if ((filename_len > extension_len) && if ((filename_len > extension_len) &&
(strncmp(".conf", de->d_name + (filename_len-extension_len), extension_len) == 0)) { (strncmp(".conf", de->d_name + (filename_len - extension_len), extension_len) == 0)) {
char filename[BUFSIZ] = LIBNFC_DEVICECONFDIR"/"; char filename[BUFSIZ] = LIBNFC_DEVICECONFDIR"/";
strcat (filename, de->d_name); strcat(filename, de->d_name);
struct stat s; struct stat s;
if (stat(filename, &s) == -1) { if (stat(filename, &s) == -1) {
perror("stat"); perror("stat");
continue; continue;
} }
if(S_ISREG(s.st_mode)) { if (S_ISREG(s.st_mode)) {
conf_parse_file (filename, conf_keyvalue_device, context); conf_parse_file(filename, conf_keyvalue_device, context);
} }
} }
} }

View file

@ -572,11 +572,11 @@ uint32_t
htole32(uint32_t u32) htole32(uint32_t u32)
{ {
uint8_t u8[4]; uint8_t u8[4];
for(int i=0; i<4; i++) { for (int i = 0; i < 4; i++) {
u8[i] = (u32 & 0xff); u8[i] = (u32 & 0xff);
u32 >>= 8; u32 >>= 8;
} }
uint32_t *pu32 = (uint32_t*)u8; uint32_t *pu32 = (uint32_t *)u8;
return *pu32; return *pu32;
} }
@ -616,7 +616,7 @@ acr122_usb_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, co
return pnd->last_error; return pnd->last_error;
} }
if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char*)&(DRIVER_DATA(pnd)->tama_frame), res, timeout)) < 0) { if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char *) & (DRIVER_DATA(pnd)->tama_frame), res, timeout)) < 0) {
pnd->last_error = res; pnd->last_error = res;
return pnd->last_error; return pnd->last_error;
} }
@ -657,7 +657,7 @@ read:
uint8_t attempted_response = RDR_to_PC_Escape; // ACR122U attempted response uint8_t attempted_response = RDR_to_PC_Escape; // ACR122U attempted response
size_t len; size_t len;
switch(DRIVER_DATA(pnd)->model) { switch (DRIVER_DATA(pnd)->model) {
case TOUCHATAG: case TOUCHATAG:
attempted_response = RDR_to_PC_DataBlock; attempted_response = RDR_to_PC_DataBlock;
if (res == NFC_ETIMEOUT) { if (res == NFC_ETIMEOUT) {
@ -718,7 +718,7 @@ read:
// XXX In CCID specification, len is a 32-bits (dword), do we need to decode more than 1 byte ? (0-255 bytes for PN532 reply) // XXX In CCID specification, len is a 32-bits (dword), do we need to decode more than 1 byte ? (0-255 bytes for PN532 reply)
len = abtRxBuf[offset++]; len = abtRxBuf[offset++];
if ((abtRxBuf[offset] != 0x00) && (abtRxBuf[offset+1] != 0x00) && (abtRxBuf[offset+2] != 0x00)) { if ((abtRxBuf[offset] != 0x00) && (abtRxBuf[offset + 1] != 0x00) && (abtRxBuf[offset + 2] != 0x00)) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Not implemented: only 1-byte length is supported, please report this bug with a full trace."); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Not implemented: only 1-byte length is supported, please report this bug with a full trace.");
pnd->last_error = NFC_EIO; pnd->last_error = NFC_EIO;
return pnd->last_error; return pnd->last_error;
@ -774,7 +774,7 @@ acr122_usb_ack(nfc_device *pnd)
if ((res = acr122_build_frame_from_tama(pnd, acr122_ack_frame, sizeof(acr122_ack_frame))) < 0) if ((res = acr122_build_frame_from_tama(pnd, acr122_ack_frame, sizeof(acr122_ack_frame))) < 0)
return res; return res;
res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char*)&(DRIVER_DATA(pnd)->tama_frame), res, 1000); res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char *) & (DRIVER_DATA(pnd)->tama_frame), res, 1000);
uint8_t abtRxBuf[255 + sizeof(struct ccid_header)]; uint8_t abtRxBuf[255 + sizeof(struct ccid_header)];
res = acr122_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), 1000); res = acr122_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), 1000);
return res; return res;
@ -787,7 +787,7 @@ acr122_usb_send_apdu(nfc_device *pnd,
{ {
int res; int res;
size_t frame_len = acr122_build_frame_from_apdu(pnd, ins, p1, p2, data, data_len, le); size_t frame_len = acr122_build_frame_from_apdu(pnd, ins, p1, p2, data, data_len, le);
if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char*)&(DRIVER_DATA(pnd)->apdu_frame), frame_len, 1000)) < 0) if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char *) & (DRIVER_DATA(pnd)->apdu_frame), frame_len, 1000)) < 0)
return res; return res;
if ((res = acr122_usb_bulk_read(DRIVER_DATA(pnd), out, out_size, 1000)) < 0) if ((res = acr122_usb_bulk_read(DRIVER_DATA(pnd), out, out_size, 1000)) < 0)
return res; return res;
@ -835,7 +835,7 @@ acr122_usb_init(nfc_device *pnd)
.bMessageSpecific = { 0x01, 0x00, 0x00 }, .bMessageSpecific = { 0x01, 0x00, 0x00 },
}; };
if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char*)&ccid_frame, sizeof(struct ccid_header), 1000)) < 0) if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char *)&ccid_frame, sizeof(struct ccid_header), 1000)) < 0)
return res; return res;
if ((res = acr122_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), 1000)) < 0) if ((res = acr122_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), 1000)) < 0)
return res; return res;

View file

@ -56,8 +56,8 @@ log_put(const uint8_t group, const char *category, const uint8_t priority, const
// printf("log_level = %"PRIu32" group = %"PRIu8" priority = %"PRIu8"\n", log_level, group, priority); // printf("log_level = %"PRIu32" group = %"PRIu8" priority = %"PRIu8"\n", log_level, group, priority);
if (log_level) { // If log is not disabled by log_level=none if (log_level) { // If log is not disabled by log_level=none
if ( ((log_level & 0x00000003) >= priority) || // Global log level if (((log_level & 0x00000003) >= priority) || // Global log level
(((log_level >> (group*2)) & 0x00000003) >= priority) ) { // Group log level (((log_level >> (group * 2)) & 0x00000003) >= priority)) { // Group log level
va_list va; va_list va;
va_start(va, format); va_start(va, format);
fprintf(stderr, "%s\t%s\t", log_priority_to_str(priority), category); fprintf(stderr, "%s\t%s\t", log_priority_to_str(priority), category);

View file

@ -54,10 +54,10 @@ log_priority_to_int(const char* priority)
} }
*/ */
const char* const char *
log_priority_to_str(const int priority) log_priority_to_str(const int priority)
{ {
switch(priority) { switch (priority) {
case NFC_LOG_PRIORITY_ERROR: case NFC_LOG_PRIORITY_ERROR:
return "error"; return "error";
case NFC_LOG_PRIORITY_INFO: case NFC_LOG_PRIORITY_INFO:

View file

@ -50,7 +50,7 @@
*/ */
//int log_priority_to_int(const char* priority); //int log_priority_to_int(const char* priority);
const char* log_priority_to_str(const int priority); const char *log_priority_to_str(const int priority);
#if defined LOG #if defined LOG

View file

@ -34,20 +34,20 @@
#define LOG_CATEGORY "libnfc.general" #define LOG_CATEGORY "libnfc.general"
void void
string_as_boolean(const char* s, bool *value) string_as_boolean(const char *s, bool *value)
{ {
if (s) { if (s) {
if (!(*value)) { if (!(*value)) {
if ( (strcmp(s, "yes") == 0) || if ((strcmp(s, "yes") == 0) ||
(strcmp(s, "true") == 0) || (strcmp(s, "true") == 0) ||
(strcmp(s, "1") == 0) ) { (strcmp(s, "1") == 0)) {
*value = true; *value = true;
return; return;
} }
} else { } else {
if ( (strcmp(s, "no") == 0) || if ((strcmp(s, "no") == 0) ||
(strcmp(s, "false") == 0) || (strcmp(s, "false") == 0) ||
(strcmp(s, "0") == 0) ) { (strcmp(s, "0") == 0)) {
*value = false; *value = false;
return; return;
} }
@ -74,7 +74,7 @@ nfc_context_new(void)
#endif #endif
// Clear user defined devices array // Clear user defined devices array
for (int i=0; i<MAX_USER_DEFINED_DEVICES; i++) { for (int i = 0; i < MAX_USER_DEFINED_DEVICES; i++) {
strcpy(res->user_defined_devices[i].name, ""); strcpy(res->user_defined_devices[i].name, "");
strcpy(res->user_defined_devices[i].connstring, ""); strcpy(res->user_defined_devices[i].connstring, "");
} }
@ -111,11 +111,11 @@ nfc_context_new(void)
#else #else
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "log_level is set to %"PRIu32, res->log_level); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "log_level is set to %"PRIu32, res->log_level);
#endif #endif
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "allow_autoscan is set to %s", (res->allow_autoscan)?"true":"false"); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "allow_autoscan is set to %s", (res->allow_autoscan) ? "true" : "false");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "allow_intrusive_scan is set to %s", (res->allow_intrusive_scan)?"true":"false"); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "allow_intrusive_scan is set to %s", (res->allow_intrusive_scan) ? "true" : "false");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%d device(s) defined by user", res->user_defined_device_count); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%d device(s) defined by user", res->user_defined_device_count);
for(uint32_t i=0; i<res->user_defined_device_count; i++) { for (uint32_t i = 0; i < res->user_defined_device_count; i++) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, " #%d name: \"%s\", connstring: \"%s\"", i, res->user_defined_devices[i].name, res->user_defined_devices[i].connstring); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, " #%d name: \"%s\", connstring: \"%s\"", i, res->user_defined_devices[i].name, res->user_defined_devices[i].connstring);
} }
return res; return res;

View file

@ -207,7 +207,7 @@ struct nfc_device {
nfc_device *nfc_device_new(const nfc_context *context, const nfc_connstring connstring); nfc_device *nfc_device_new(const nfc_context *context, const nfc_connstring connstring);
void nfc_device_free(nfc_device *dev); void nfc_device_free(nfc_device *dev);
void string_as_boolean(const char* s, bool *value); void string_as_boolean(const char *s, bool *value);
void iso14443_cascade_uid(const uint8_t abtUID[], const size_t szUID, uint8_t *pbtCascadedUID, size_t *pszCascadedUID); void iso14443_cascade_uid(const uint8_t abtUID[], const size_t szUID, uint8_t *pbtCascadedUID, size_t *pszCascadedUID);

View file

@ -187,7 +187,7 @@ nfc_open(nfc_context *context, const nfc_connstring connstring)
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open \"%s\".", ncs); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open \"%s\".", ncs);
return pnd; return pnd;
} }
for (uint32_t i=0; i>context->user_defined_device_count; i++) { for (uint32_t i = 0; i > context->user_defined_device_count; i++) {
if (strcmp(ncs, context->user_defined_devices[i].connstring) == 0) { if (strcmp(ncs, context->user_defined_devices[i].connstring) == 0) {
// This is a device sets by user, we use the device name given by user // This is a device sets by user, we use the device name given by user
strcpy(pnd->name, context->user_defined_devices[i].name); strcpy(pnd->name, context->user_defined_devices[i].name);
@ -237,16 +237,16 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
const struct nfc_driver **pndr = nfc_drivers; const struct nfc_driver **pndr = nfc_drivers;
if (!context) { if (!context) {
printf ("NULL context is not supported anymore! Please fix your code.\n"); printf("NULL context is not supported anymore! Please fix your code.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
// Load manually configured devices (from config file and env variables) // Load manually configured devices (from config file and env variables)
// TODO From env var... // TODO From env var...
for (uint32_t i=0; i<context->user_defined_device_count; i++) { for (uint32_t i = 0; i < context->user_defined_device_count; i++) {
strcpy((char*)(connstrings+device_found), context->user_defined_devices[i].connstring); strcpy((char *)(connstrings + device_found), context->user_defined_devices[i].connstring);
device_found++; device_found++;
if(device_found >= connstrings_len) if (device_found >= connstrings_len)
return device_found; return device_found;
} }
@ -254,7 +254,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
if (context->allow_autoscan) { if (context->allow_autoscan) {
while ((ndr = *pndr)) { while ((ndr = *pndr)) {
size_t _device_found = 0; size_t _device_found = 0;
if((ndr->scan_type == NOT_INTRUSIVE) || ((context->allow_intrusive_scan) && (ndr->scan_type == INTRUSIVE))) { if ((ndr->scan_type == NOT_INTRUSIVE) || ((context->allow_intrusive_scan) && (ndr->scan_type == INTRUSIVE))) {
_device_found = ndr->scan(context, connstrings + (device_found), connstrings_len - (device_found)); _device_found = ndr->scan(context, connstrings + (device_found), connstrings_len - (device_found));
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%ld device(s) found using %s driver", (unsigned long) _device_found, ndr->name); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%ld device(s) found using %s driver", (unsigned long) _device_found, ndr->name);
if (_device_found > 0) { if (_device_found > 0) {