Skip to content

Prepare/restructure for stable RC #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

yurii-scanbot
Copy link
Collaborator

No description provided.

@yurii-scanbot yurii-scanbot changed the title Prepare for stable RC Prepare/restructure for stable RC Aug 18, 2025

cleanup:
scanbotsdk_license_info_free(info);
scanbotsdk_deregister_device();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deregistration is the most important part about floating license. We should add here comments that describe why should it be called and what are the consequences of not calling

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated with description for both calls

if (ec != SCANBOTSDK_OK) { fprintf(stderr, "get_license_info (before wait): %d: %s\n", ec, error_message(ec)); goto cleanup; }

// Wait for the online license check to complete
ec = scanbotsdk_wait_for_online_license_check_completion(15000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic constant

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced with constant

cleanup:
scanbotsdk_license_info_free(info);
scanbotsdk_deregister_device();
scanbotsdk_wait_for_device_deregistration_completion(15000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic constant

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced with constant

if (ec != SCANBOTSDK_OK) { fprintf(stderr, "wait_for_online_license_check_completion: %d: %s\n", ec, error_message(ec)); goto cleanup; }

// Query license info AFTER waiting for online check
ec = scanbotsdk_get_license_info(&info);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The info obtained above is leaked here as you no longer have a pointer to it. As we discussed, let's have to variables info_before_initialization and info_after_initialization and free both of them in the cleanup

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separated as proposed into info_before_initialization and info_after_initialization

ec = scanbotsdk_get_license_info(&info);
if (ec != SCANBOTSDK_OK) { fprintf(stderr, "get_license_info (before wait): %d: %s\n", ec, error_message(ec)); goto cleanup; }

// Wait for the online license check to complete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should explain why this wait is needed - because initialize is a non-blocking operation which asynchrnously performs online license check

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description on top was added

if (ec != SCANBOTSDK_OK) { fprintf(stderr, "get_detection_result: %d: %s\n", ec, error_message(ec)); goto cleanup; }

scanbotsdk_document_detection_result_get_status(detect_result, &status);
printf("Document Detection Status = %d\n", (int)status);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is int representation of the status useful for the user?

return ec;
}

printf("Detection Status = %d\n", (int)status);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we print the status twice? And is int representation of the status useful fot the user?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed previous condition and print


cleanup:
if (blocks) free(blocks);
if (lines) free(lines);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double free for lines and words can occur

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored

if (ec != SCANBOTSDK_OK) { fprintf(stderr, "classifier_run: %d: %s\n", ec, error_message(ec)); goto cleanup; }

ec = scanbotsdk_document_classifier_result_get_status(result, &status);
printf("Classifier Status: %d\n", (int)status);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are int statuses here and below meaningful for the user?

scanbotsdk_document_classifier_configuration_t *config = NULL;
scanbotsdk_document_classifier_result_t *result = NULL;
scanbotsdk_document_classifier_t *classifier = NULL;
scanbotsdk_document_scanning_result_t *scanning_result = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need scanning result here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, no need

if (ec != SCANBOTSDK_OK) { fprintf(stderr, "get_check: %d\n", ec); return ec; }

scanbotsdk_credit_card_scanning_result_get_detection_status(result, &status);
printf("Document Detection Status = %d\n", (int)status);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Int status doesn't provide user with any useful information

printf("Fields count: %zu\n", fields_count);

scanbotsdk_field_t **fields = calloc(fields_count, sizeof(*fields));
if (!fields) { fprintf(stderr, "alloc fields failed\n"); return SCANBOTSDK_ERROR_UNKNOWN_ERROR; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When calloc returns 0, you sometimes return OUT_OF_MEMORY, sometimes UNKNOWN ERROR. Better to return the same status in all the places

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goto cleanup

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced with SCANBOTSDK_ERROR_OUT_OF_MEMORY

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added goto cleanup

const char *text = NULL;
double confidence = 0.0;
scanbotsdk_ocr_result_get_text(ocr, &text);
scanbotsdk_ocr_result_get_confidence(ocr, &confidence);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid printing confidence. For non-ocred docuemnts it usually zero

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed confidence getter

const char *type_name = NULL;
scanbotsdk_field_type_get_name(field_type, &type_name);

scanbotsdk_ocr_result_t *ocr = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not call the variable ocr as this info doesn't always come from ocr

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced with ocr_result

printf("Field[%zu]: type=%s, value=\"%s\", confidence=%f\n",
i, type_name, text ? text : "", confidence);
} else {
printf("Field[%zu]: type=%s, value=(n/a)\n", i, type_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better "text value n/a", this will usually be the case from such filds as photo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated text


// TODO Add your Scanbot SDK trial license key here.
// The SDK and a trial license are available on request via [email protected]
char *scanbot_license_key = "<SCANBOTSDK-LICENSE>";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's read license from console

scanbotsdk_error_code_t ec = scanbotsdk_initialize(&params);
if (ec != SCANBOTSDK_OK) { fprintf(stderr, "initialize: %d: %s\n", ec, error_message(ec)); return 1; }

ec = scanbotsdk_wait_for_online_license_check_completion(15000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic constant

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced with constant


cleanup:
scanbotsdk_deregister_device();
scanbotsdk_wait_for_device_deregistration_completion(15000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic constant

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced with constant

if (ec != SCANBOTSDK_OK) { fprintf(stderr, "license_wait: %d: %s\n", ec, error_message(ec)); goto cleanup; }

if (strcmp(category, "scan") == 0) {
if (!file_path) { print_usage(argv[0]); return 1; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No deregistration occurs in case of early outs. Should be goto cleanup. And image should also be freed there. Same for all ealy outs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored every place with goto cleanup

else if (strcmp(category, "classify") == 0) {
if (!file_path) { print_usage(argv[0]); return 1; }

scanbotsdk_image_t *image = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image is not freed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored with
scanbotsdk_image_free(image);
at the end of condition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants