1 /* 2 Copyright 2011-2020, Dirk Krause. All rights reserved. 3 SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 /* 7 WARNING: This file was generated by dkct. 8 Changes you make here will be lost if dkct is run again! 9 You should modify the original source and run dkct on it. 10 Original source: dkt.ctr 11 */ 12 13 /* 14 Copyright (C) 2011-2020, Dirk Krause 15 16 Redistribution and use in source and binary forms, with or without 17 modification, are permitted provided that the following conditions are met: 18 19 * Redistributions of source code must retain the above copyright notice, 20 this list of conditions and the following disclaimer. 21 * Redistributions in binary form must reproduce the above opyright notice, 22 this list of conditions and the following disclaimer in the documentation 23 and/or other materials provided with the distribution. 24 * Neither the name of the author nor the names of contributors may be used 25 to endorse or promote products derived from this software without specific 26 prior written permission. 27 28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 29 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 30 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 31 ARE DISCLAIMED. 32 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY 33 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 35 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 38 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 */ 40 41 /** @file dkt.h Header file for the dkt module. 42 */ 43 44 #ifndef DKT_H_INCLUDED 45 /** Avoid multiple inclusions. */ 46 #define DKT_H_INCLUDED 1 47 48 49 #line 10 "dkt.ctr" 50 51 #ifndef DK3_CONF_H_INCLUDED 52 #include "dk3conf.h" 53 #endif 54 55 #if DK3_HAVE_OPENSSL_RAND_H 56 #include <openssl/rand.h> 57 #endif 58 59 60 61 /** Handler function to process one configuration line. 62 @param o Object to modify during processing. 63 @param k Key found in the line. 64 @param v Value found in the line or NULL if no value was found. 65 @return 1 on success, 0 on error (can continue), -1 on error (abort). 66 */ 67 typedef int dkt_conf_fct_t(void *o, dkChar const *k, dkChar const *v); 68 69 70 71 #ifdef __cplusplus 72 extern "C" { 73 #endif 74 75 /** Print current working directory. 76 @param app Application structure. 77 @param sn Section name for configuration file. 78 @param msg Messages. 79 @param kwnl Keywords, not localized. 80 @return 0 on success or other exit code on errors. 81 */ 82 int 83 dkt_cwd( 84 dk3_app_t *app, 85 dkChar const *sn, 86 dkChar const * const *msg, 87 dkChar const * const *kwnl 88 ); 89 90 /** Sort texts line by line. 91 @param app Application structure. 92 @param sn Section name for configuration file. 93 @param msg Messages. 94 @param kwnl Keywords, not localized. 95 @return 0 on success or other exit code on errors. 96 */ 97 int 98 dkt_sort( 99 dk3_app_t *app, 100 dkChar const *sn, 101 dkChar const * const *msg, 102 dkChar const * const *kwnl 103 ); 104 105 /** List specified files. 106 @param app Application structure. 107 @param sn Section name for configuration file. 108 @param msg Message texts. 109 @param kwnl Keywords, not localized. 110 @return Exit status code. 111 */ 112 int 113 dkt_ls( 114 dk3_app_t *app, 115 dkChar const *sn, 116 dkChar const * const *msg, 117 dkChar const * const *kwnl 118 ); 119 120 /** Read configuration file section. 121 @param app Application structure. 122 @param sn Section name. 123 @param obj Object to store information. 124 @param fct Function to process key/value pair. 125 */ 126 void 127 dkt_tool_read_conf( 128 dk3_app_t *app, dkChar const *sn, void *obj, dkt_conf_fct_t *fct 129 ); 130 131 /** Find encoding. 132 @param app Application structure. 133 @param enc Pointer to encoding variable. 134 @param val Text containing encoding. 135 @param de Default encoding. 136 @return 1 on success, 0 on error. 137 */ 138 int 139 dkt_tool_set_encoding( 140 dk3_app_t *app, 141 int *enc, 142 dkChar const *val, 143 int de 144 ); 145 146 /** Perform checksum or checksize command. 147 @param app Application structure. 148 @param sn Section name for configuration file. 149 @param msg Localized messages. 150 @param kwnl Keywords, not localized. 151 @param what Flag: Run for checksum (0) or checksize (1). 152 @return Exit status code. 153 */ 154 int 155 dkt_check( 156 dk3_app_t *app, 157 dkChar const *sn, 158 dkChar const * const *msg, 159 dkChar const * const *kwnl, 160 int what 161 ); 162 163 /** Run the "uid" sub-command. 164 @param app Application structure for diagnostics. 165 @param sn Section name for configuration file. 166 @param msg Localized messages. 167 @param kwnl Keywords, not localized. 168 @return Exit status code. 169 */ 170 int 171 dkt_uid( 172 dk3_app_t *app, 173 dkChar const *sn, 174 dkChar const * const *msg, 175 dkChar const * const *kwnl 176 ); 177 178 /** Run the "tape" sub-command. 179 @param app Application structure for diagnostics. 180 @param sn Section name for configuration file. 181 @param msg Localized messages. 182 @param kwnl Keywords, not localized. 183 @return Exit status code. 184 */ 185 int 186 dkt_tape( 187 dk3_app_t *app, 188 dkChar const *sn, 189 dkChar const * const *msg, 190 dkChar const * const *kwnl 191 ); 192 193 /** Run the "tape-report" sub-command. 194 @param app Application structure for diagnostics. 195 @param sn Section name for configuration file. 196 @param msg Localized messages. 197 @param kwnl Keywords, not localized. 198 @return Exit status code. 199 */ 200 int 201 dkt_tapereport( 202 dk3_app_t *app, 203 dkChar const *sn, 204 dkChar const * const *msg, 205 dkChar const * const *kwnl 206 ); 207 208 /** Run the "tapeset" sub-command. 209 @param app Application structure for diagnostics. 210 @param sn Section name for configuration file. 211 @param msg Localized messages. 212 @param kwnl Keywords, not localized. 213 @return Exit status code. 214 */ 215 int 216 dkt_tapeset( 217 dk3_app_t *app, 218 dkChar const *sn, 219 dkChar const * const *msg, 220 dkChar const * const *kwnl 221 ); 222 223 /** Run the "dkt blocksize" sub-command. 224 @param app Application structure for diagnostics. 225 @param sn Section name for configuration file. 226 @param msg Localized messages. 227 @param kwnl Keywords, not localized. 228 @return Exit status code. 229 */ 230 int 231 dkt_blocksize( 232 dk3_app_t *app, 233 dkChar const *sn, 234 dkChar const * const *msg, 235 dkChar const * const *kwnl 236 ); 237 238 /** Run the "dkt hex" sub-command. 239 @param app Application structure for diagnostics. 240 @param sn Section name for configuration file. 241 @param msg Localized messages. 242 @param kwnoloc Not localized keywords. 243 @param f_oct Flag: Show contents octal. 244 @return Exit status code. 245 */ 246 int 247 dkt_hex( 248 dk3_app_t *app, 249 dkChar const *sn, 250 dkChar const * const *msg, 251 dkChar const * const *kwnoloc, 252 int f_oct 253 ); 254 255 /** Create password suggestions. 256 @param app Application structure. 257 @param sn Section name for configuration file. 258 @param msg Localized messages. 259 @param kwnoloc Keywords, not localized. 260 @return Exit status code. 261 */ 262 int 263 dkt_create_password( 264 dk3_app_t *app, 265 dkChar const *sn, 266 dkChar const * const *msg, 267 dkChar const * const *kwnoloc 268 ); 269 270 /** Convert standard input, file or cmd argument to LaTeX. 271 @param app Application structure. 272 @param sn Section name for configuration file. 273 @param msg Localized messages. 274 @param kwnoloc Keywords, not localized. 275 @return Exit status code. 276 */ 277 int 278 dkt_lat( 279 dk3_app_t *app, 280 dkChar const *sn, 281 dkChar const * const *msg, 282 dkChar const * const *kwnoloc 283 ); 284 285 /** Conversion to HTML (dkt html). 286 @param app Application structure. 287 @param sn Section name for configuration file. 288 @param msg Localized texts. 289 @param kwnl Keywords, not localized. 290 */ 291 int 292 dkt_html( 293 dk3_app_t *app, 294 dkChar const *sn, 295 dkChar const * const *msg, 296 dkChar const * const *kwnl 297 ); 298 299 /** Cat file(s). 300 @param app Application structure. 301 @param sn Configuration file section name. 302 @param msg Localized texts. 303 @param kwnl Keywords, not localized. 304 */ 305 int 306 dkt_cat( 307 dk3_app_t *app, 308 dkChar const *sn, 309 dkChar const * const *msg, 310 dkChar const * const *kwnl 311 ); 312 313 /** Create password. 314 @param app Application structure. 315 @param sn Configuration file section name. 316 @param msg Localized texts. 317 @param kwnl Keywords, not localized. 318 */ 319 int 320 dkt_crp( 321 dk3_app_t *app, 322 dkChar const *sn, 323 dkChar const * const *msg, 324 dkChar const * const *kwnl 325 ); 326 327 /** Show help text file(s). 328 @param app Application structure. 329 @param sn Configuration file section name. 330 @param msg Localized texts. 331 @param kwnl Keywords, not localized. 332 @param htp Help topic index. 333 */ 334 int 335 dkt_help( 336 dk3_app_t *app, 337 dkChar const *sn, 338 dkChar const * const *msg, 339 dkChar const * const *kwnl, 340 int htp 341 ); 342 343 /** Find message digest type and digest encoding. 344 @param jmdt Pointer to result variable for digest type. 345 @param jmde Pointer to result variable for digest encoding. 346 @param exval Pointer to exit status code variable. 347 @param txt Text to inspect. 348 @param app Application structure for diagnostics. 349 @param msg Message array for diagnostics. 350 @param verb Flag: Verbose. 351 @return 1 on success, 0 on error. 352 */ 353 int 354 dkt_tool_set_md_type( 355 int *jmdt, 356 int *jmde, 357 int *exval, 358 dkChar const *txt, 359 dk3_app_t *app, 360 dkChar const * const *msg, 361 int verb 362 ); 363 364 /** Set size_t value from string. 365 @param rp Pointer to result variable. 366 @param src String containing the value. 367 @param msg Localized text messages for diagnostics. 368 @param kwnl Non-localized keywords for diagnostics. 369 @param app Application structure for diagnostics. 370 @param exc Pointer to exit code variable. 371 @return 1 on success, 0 on error. 372 */ 373 int 374 dkt_tool_set_size( 375 size_t *rp, 376 dkChar const *src, 377 dkChar const * const *msg, 378 dkChar const * const *kwnl, 379 dk3_app_t *app, 380 int *exc 381 ); 382 383 /** Run the "dkt erase-disk" sub-command. 384 @param app Application structure for diagnostics. 385 @param sn Section name for configuration file. 386 @param msg Localized messages. 387 @param kwnl Not localized keywords. 388 @return Exit status code. 389 */ 390 int 391 dkt_ed( 392 dk3_app_t *app, 393 dkChar const *sn, 394 dkChar const * const *msg, 395 dkChar const * const *kwnl 396 ); 397 398 /** Run the "dkt random" sub-command. 399 @param app Application structure for diagnostics. 400 @param sn Section name for configuration file. 401 @param msg Localized messages. 402 @param kwnl Not localized keywords. 403 @return Exit status code. 404 */ 405 int 406 dkt_rnd( 407 dk3_app_t *app, 408 dkChar const *sn, 409 dkChar const * const *msg, 410 dkChar const * const *kwnl 411 ); 412 413 #ifdef __cplusplus 414 } 415 #endif 416 417 418 419 /** @defgroup dktresult Exit codes for dkt. */ 420 /**@{*/ 421 /** Result: No error occured. 422 */ 423 #define DKT_RESULT_OK 0 424 425 /** Error: Unspecific error. 426 */ 427 #define DKT_RESULT_ERR_UNSPECIFIC 1 428 429 /** Error: Aborted by signal. 430 */ 431 #define DKT_RESULT_ERR_SIGNAL 2 432 433 /** Error: Illegal/unknown option or problem in configuration file. 434 */ 435 #define DKT_RESULT_ERR_OPTION 3 436 437 /** Error: getcwd() failed. 438 */ 439 #define DKT_RESULT_ERR_GETCWD 4 440 441 /** Error: Memory allocation failed. 442 */ 443 #define DKT_RESULT_ERR_MEMORY 5 444 445 /** Error: Failed to open one of the input files. 446 */ 447 #define DKT_RESULT_ERR_FOPEN 6 448 449 /** Error: No such file. 450 */ 451 #define DKT_RESULT_ERR_FILENAME 7 452 453 /** Error: Checksum or size mismatch. 454 */ 455 #define DKT_RESULT_ERR_MISMATCH 8 456 457 /** Error: Failed to create or write output. 458 */ 459 #define DKT_RESULT_ERR_OUTPUT 9 460 461 /** Error: The PRNG was unable to deliver enough bytes. 462 */ 463 #define DKT_RESULT_ERR_PRNG 10 464 465 /** Error: Invalid input (Input can't be processed). 466 */ 467 #define DKT_RESULT_ERR_INPUT 11 468 469 /** Error: Mathematical overflow. 470 */ 471 #define DKT_RESULT_ERR_MATH_OVERFLOW 12 472 473 /** Error: Failed to open directory. 474 */ 475 #define DKT_RESULT_ERR_OPENDIR 13 476 477 /** Error: Functionality not supported on this system. 478 */ 479 #define DKT_RESULT_ERR_UNSUPPORTED 14 480 481 /** Error: Status code from command execution indicates error. 482 */ 483 #define DKT_RESULT_ERR_SYSEXEC 15 484 /**@}*/ 485 486 487 488 /** @defgroup dktsortcrit Sort criteria for "dkt sort". */ 489 /**@{*/ 490 /** Sort criteria: Normal text search. 491 */ 492 #define DKT_SORT_NORMAL 0 493 494 /** Sort criteria: Sort by leading integer. 495 */ 496 #define DKT_SORT_INTEGER 1 497 498 /** Sort criteria: Sort by leading unsigned integer. 499 */ 500 #define DKT_SORT_UNSIGNED 2 501 502 /** Sort criteria: Sort by leading double. 503 */ 504 #define DKT_SORT_DOUBLE 3 505 506 /** Sort criteria mask. 507 */ 508 #define DKT_SORT_CRITERIA_MASK 7 509 510 /** Normalize strings before comparison. 511 */ 512 #define DKT_SORT_NORMALIZE 8 513 514 /** Ignore leading whitespaces. 515 */ 516 #define DKT_SORT_IGNORE_LWHS 16 517 518 /** Do exact comparison. 519 */ 520 #define DKT_SORT_EXACT 32 521 522 /** Merge equal strings. 523 */ 524 #define DKT_SORT_MERGE 64 525 526 /** Invert search order. 527 */ 528 #define DKT_SORT_INVERT 128 529 530 /** Case insensitve comparisons. 531 */ 532 #define DKT_SORT_CASEINS 256 533 534 /** Show lines without value before lines with value. 535 */ 536 #define DKT_SORT_NOVALUE_FIRST 512 537 538 /**@}*/ 539 540 541 542 /** @defgroup dktsortmerge Merge criteria for "dkt sort". */ 543 /**@{*/ 544 /** No line merging. 545 */ 546 #define DKT_SORT_MERGE_NONE 0 547 548 /** Merge lines evaluating equally. 549 */ 550 #define DKT_SORT_MERGE_EQUAL 1 551 552 /** Merge lines exactly equally. 553 */ 554 #define DKT_SORT_MERGE_EXACT 2 555 /**@}*/ 556 557 /** @defgroup pwclasses Password classes. */ 558 /**@{*/ 559 560 /** Simple password. 561 */ 562 #define DKT_PWCLASS_SIMPLE 0 563 564 /** Hexadecimal characters. 565 */ 566 #define DKT_PWCLASS_HEX 1 567 568 /** ASCII-85 set password. 569 */ 570 #define DKT_PWCLASS_A85 2 571 /**@}*/ 572 573 /** Default line size for the sort component. 574 */ 575 #define DKT_SORT_LINE_SIZE ((size_t)4096U) 576 577 /** Size of builtin buffer for dkt blocksize. 578 */ 579 #define DKT_BLOCKSIZE_OUTPUT_SIZE ((size_t)4096) 580 581 /** Size of builtin buffer for dkt latex. 582 */ 583 #define DKT_LATEX_LINE_SIZE ((size_t)4096U) 584 585 /** Line size for dkt html. 586 */ 587 #define DKT_HTML_LINE_SIZE ((size_t)4096U) 588 589 /** Size for long options 590 */ 591 #define DKT_LONGOPT_LINE_SIZE ((size_t)256) 592 593 /** Maximum length for password. 594 */ 595 #define DKT_PASSWORD_MAXLENGTH 4096 596 597 /** Line size for dkt tapeset. 598 */ 599 #define DKT_TS_LINE_SIZE 1024 600 601 /** Buffer size for dkt ed. 602 */ 603 #define DKT_ED_BUFFER_SIZE ((size_t)16384U) 604 605 /** Buffer size for dkt random. 606 */ 607 #define DKT_RND_BUFFER_SIZE ((size_t)16384U) 608 609 /** For allocation of string pointer arrays. 610 */ 611 typedef dkChar const *DKT_PDKCHAR; 612 613 614 615 616 #endif 617