test/src/util/test_util.cc
author Krista Bennett <krista@pep-project.org>
Fri, 28 Sep 2018 10:07:05 +0200
branchsync_and_key_reset
changeset 2956 e82181973f21
parent 2955 3b2500a15709
child 3001 8c1aafb3ad57
permissions -rw-r--r--
ENGINE-398: Merge now compiles and tests pass.
roker@1656
     1
#include "pEpEngine_test.h"
krista@1812
     2
#include "pEpEngine.h"
krista@2444
     3
#include "pEp_internal.h"
krista@1812
     4
#include "message_api.h"
krista@2917
     5
#include "test_util.h"
krista@2703
     6
roker@1656
     7
#include <fstream>
roker@1656
     8
#include <sstream>
roker@1656
     9
#include <stdexcept>
krista@2703
    10
#include <stdlib.h>
krista@2703
    11
#include <sys/stat.h>
krista@2703
    12
#include <errno.h>
krista@2703
    13
#include <stdlib.h>
krista@2703
    14
#include <unistd.h>
krista@2703
    15
#include <ftw.h>
roker@1656
    16
krista@2917
    17
PEP_STATUS read_file_and_import_key(PEP_SESSION session, const char* fname) {
krista@2917
    18
    const std::string key = slurp(fname);
krista@2917
    19
    PEP_STATUS status = (key.empty() ? PEP_KEY_NOT_FOUND : PEP_STATUS_OK);
krista@2917
    20
    if (status == PEP_STATUS_OK)
krista@2917
    21
        status = import_key(session, key.c_str(), key.size(), NULL);
krista@2917
    22
    return status;    
krista@2917
    23
}
krista@2917
    24
krista@2917
    25
PEP_STATUS set_up_ident_from_scratch(PEP_SESSION session,
krista@2917
    26
                                     const char* key_fname,
krista@2917
    27
                                     const char* address,
krista@2917
    28
                                     const char* fpr,
krista@2917
    29
                                     const char* user_id,
krista@2917
    30
                                     const char* username,
krista@2917
    31
                                     pEp_identity** ret_ident,
krista@2917
    32
                                     bool is_priv) {
krista@2917
    33
    PEP_STATUS status = read_file_and_import_key(session,key_fname);
krista@2917
    34
    if (status != PEP_STATUS_OK)
krista@2917
    35
        return status;
krista@2917
    36
    
krista@2917
    37
    pEp_identity* ident = new_identity(address, fpr, user_id, username);
krista@2917
    38
    if (is_priv && fpr) {
krista@2917
    39
        status = set_own_key(session, ident, fpr);
krista@2917
    40
        if (status == PEP_STATUS_OK)
krista@2917
    41
            status = myself(session, ident);
krista@2917
    42
    }
krista@2917
    43
    else    
krista@2917
    44
        status = update_identity(session, ident);
krista@2917
    45
krista@2917
    46
    if (status != PEP_STATUS_OK)
krista@2917
    47
        goto pep_free;
krista@2917
    48
        
krista@2917
    49
    if (!ident || !ident->fpr) {
krista@2917
    50
        status = PEP_CANNOT_FIND_IDENTITY;
krista@2917
    51
        goto pep_free;
krista@2917
    52
    }
krista@2917
    53
    
krista@2917
    54
    if (ret_ident)
krista@2917
    55
        *ret_ident = ident;
krista@2917
    56
        
krista@2917
    57
pep_free:
krista@2917
    58
    if (!ret_ident)
krista@2917
    59
        free_identity(ident);
krista@2956
    60
    return status;    
krista@2917
    61
}
krista@2917
    62
krista@2917
    63
krista@2798
    64
bool file_exists(std::string filename) {
krista@2798
    65
    struct stat buffer;
krista@2798
    66
    return (stat(filename.c_str(), &buffer) == 0);
krista@2798
    67
}
krista@2798
    68
krista@2533
    69
char* str_to_lower(const char* str) {
krista@2533
    70
    if (!str)
krista@2533
    71
        return NULL;
krista@2533
    72
    int str_len = strlen(str);
krista@2533
    73
    if (str_len == 0)
krista@2533
    74
        return strdup("");
krista@2533
    75
    int i;
krista@2533
    76
    
krista@2533
    77
    char* retval = (char*) calloc(1, str_len + 1);
krista@2533
    78
    for (i = 0; i < str_len; i++) {
krista@2533
    79
        retval[i] = tolower(str[i]);
krista@2533
    80
    }    
krista@2533
    81
    return retval;
krista@2533
    82
}
krista@2533
    83
krista@2533
    84
// Because annoyed
krista@2533
    85
bool _streq(const char* str1, const char* str2) {
krista@2533
    86
    if (!str1) {
krista@2533
    87
        if (str2)
krista@2533
    88
            return false;
krista@2533
    89
        return true;
krista@2533
    90
    }
krista@2533
    91
    if (!str2)
krista@2533
    92
        return false;
krista@2533
    93
        
krista@2533
    94
    return (strcmp(str1, str2) == 0);
krista@2533
    95
}
krista@2533
    96
krista@2533
    97
bool _strceq(const char* str1, const char* str2) {
krista@2533
    98
    char* str1_dup = str_to_lower(str1);
krista@2533
    99
    char* str2_dup = str_to_lower(str2);
krista@2533
   100
krista@2533
   101
    bool retval = _streq(str_to_lower(str1_dup), str_to_lower(str2_dup));
krista@2533
   102
    free(str1_dup);
krista@2533
   103
    free(str2_dup);
krista@2533
   104
    return retval;
krista@2533
   105
}
krista@2477
   106
krista@2477
   107
void test_init() {
krista@2477
   108
    unlink ("../test_home/.pEp_management.db");
krista@2477
   109
    unlink ("../test_home/.pEp_management.db-shm");
krista@2477
   110
    unlink ("../test_home/.pEp_management.db-wal");
krista@2477
   111
}
krista@2477
   112
roker@1656
   113
std::string slurp(const std::string& filename)
roker@1656
   114
{
roker@1656
   115
	std::ifstream input(filename.c_str());
roker@1656
   116
	if(!input)
roker@1656
   117
	{
roker@1656
   118
		throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
roker@1656
   119
	}
roker@1656
   120
	
roker@1656
   121
	std::stringstream sstr;
roker@1656
   122
	sstr << input.rdbuf();
roker@1656
   123
	return sstr.str();
roker@1656
   124
}
krista@1812
   125
krista@2282
   126
void dump_out(const char* filename, const char* outdata)
krista@2282
   127
{
krista@2282
   128
	std::ofstream outfile(filename);
krista@2282
   129
	if(!outfile)
krista@2282
   130
	{
krista@2282
   131
		throw std::runtime_error("Cannot open output file!");
krista@2282
   132
	}
krista@2282
   133
	
krista@2282
   134
	outfile << outdata;
krista@2282
   135
    outfile.close();
krista@2282
   136
}
krista@2282
   137
krista@2444
   138
char* get_new_uuid() {
krista@2444
   139
    char* new_uuid = (char*)calloc(37, 1);
krista@2444
   140
    pEpUUID uuid;
krista@2444
   141
    uuid_generate_random(uuid);
krista@2444
   142
    uuid_unparse_upper(uuid, new_uuid);
krista@2444
   143
    return new_uuid;
krista@2444
   144
}
krista@2282
   145
krista@1812
   146
const char* tl_status_string(PEP_STATUS status) {
krista@1812
   147
    switch (status) {
krista@1812
   148
        case PEP_STATUS_OK:
krista@1812
   149
            return "PEP_STATUS_OK";
krista@1812
   150
        case PEP_INIT_CANNOT_LOAD_GPGME:
krista@1812
   151
            return "PEP_INIT_CANNOT_LOAD_GPGME";
krista@1812
   152
        case PEP_INIT_GPGME_INIT_FAILED:
krista@1812
   153
            return "PEP_INIT_GPGME_INIT_FAILED";
krista@1812
   154
        case PEP_INIT_NO_GPG_HOME:
krista@1812
   155
            return "PEP_INIT_NO_GPG_HOME";
krista@1812
   156
        case PEP_INIT_NETPGP_INIT_FAILED:
krista@1812
   157
            return "PEP_INIT_NETPGP_INIT_FAILED";
krista@1812
   158
        case PEP_INIT_SQLITE3_WITHOUT_MUTEX:
krista@1812
   159
            return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
krista@1812
   160
        case PEP_INIT_CANNOT_OPEN_DB:
krista@1812
   161
            return "PEP_INIT_CANNOT_OPEN_DB";
krista@1812
   162
        case PEP_INIT_CANNOT_OPEN_SYSTEM_DB:
krista@1812
   163
            return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
krista@1812
   164
        case PEP_KEY_NOT_FOUND:
krista@1812
   165
            return "PEP_KEY_NOT_FOUND";
krista@1812
   166
        case PEP_KEY_HAS_AMBIG_NAME:
krista@1812
   167
            return "PEP_KEY_HAS_AMBIG_NAME";
krista@1812
   168
        case PEP_GET_KEY_FAILED:
krista@1812
   169
            return "PEP_GET_KEY_FAILED";
krista@1812
   170
        case PEP_CANNOT_EXPORT_KEY:
krista@1812
   171
            return "PEP_CANNOT_EXPORT_KEY";
krista@1812
   172
        case PEP_CANNOT_EDIT_KEY:
krista@1812
   173
            return "PEP_CANNOT_EDIT_KEY";
krista@1812
   174
        case PEP_CANNOT_FIND_IDENTITY:
krista@1812
   175
            return "PEP_CANNOT_FIND_IDENTITY";
krista@1812
   176
        case PEP_CANNOT_SET_PERSON:
krista@1812
   177
            return "PEP_CANNOT_SET_PERSON";
krista@1812
   178
        case PEP_CANNOT_SET_PGP_KEYPAIR:
krista@1812
   179
            return "PEP_CANNOT_SET_PGP_KEYPAIR";
krista@1812
   180
        case PEP_CANNOT_SET_IDENTITY:
krista@1812
   181
            return "PEP_CANNOT_SET_IDENTITY";
krista@1812
   182
        case PEP_CANNOT_SET_TRUST:
krista@1812
   183
            return "PEP_CANNOT_SET_TRUST";
krista@1812
   184
        case PEP_KEY_BLACKLISTED:
krista@1812
   185
            return "PEP_KEY_BLACKLISTED";
krista@1812
   186
        case PEP_UNENCRYPTED:
krista@1812
   187
            return "PEP_UNENCRYPTED";
krista@1812
   188
        case PEP_VERIFIED:
krista@1812
   189
            return "PEP_VERIFIED";
krista@1812
   190
        case PEP_DECRYPTED:
krista@1812
   191
            return "PEP_DECRYPTED";
krista@1812
   192
        case PEP_DECRYPTED_AND_VERIFIED:
krista@1812
   193
            return "PEP_DECRYPTED_AND_VERIFIED";
krista@1812
   194
        case PEP_DECRYPT_WRONG_FORMAT:
krista@1812
   195
            return "PEP_DECRYPT_WRONG_FORMAT";
krista@1812
   196
        case PEP_DECRYPT_NO_KEY:
krista@1812
   197
            return "PEP_DECRYPT_NO_KEY";
krista@1812
   198
        case PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH:
krista@1812
   199
            return "PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH";
krista@2703
   200
//        case PEP_DECRYPTED_BUT_UNSIGNED:
krista@2703
   201
//            return "PEP_DECRYPTED_BUT_UNSIGNED";
krista@2703
   202
//        case PEP_DECRYPT_MODIFICATION_DETECTED:
krista@2703
   203
//            return "PEP_DECRYPT_MODIFICATION_DETECTED";
krista@2703
   204
//        case PEP_DECRYPT_NO_KEY_FOR_SIGNER:
krista@2703
   205
//            return "PEP_DECRYPT_NO_KEY_FOR_SIGNER";
krista@1812
   206
        case PEP_VERIFY_NO_KEY:
krista@1812
   207
            return "PEP_VERIFY_NO_KEY";
krista@1812
   208
        case PEP_VERIFIED_AND_TRUSTED:
krista@1812
   209
            return "PEP_VERIFIED_AND_TRUSTED";
krista@1812
   210
        case PEP_CANNOT_DECRYPT_UNKNOWN:
krista@1812
   211
            return "PEP_CANNOT_DECRYPT_UNKNOWN";
krista@1812
   212
        case PEP_TRUSTWORD_NOT_FOUND:
krista@1812
   213
            return "PEP_TRUSTWORD_NOT_FOUND";
krista@1812
   214
        case PEP_TRUSTWORDS_FPR_WRONG_LENGTH:
krista@1812
   215
            return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
krista@1812
   216
        case PEP_CANNOT_CREATE_KEY:
krista@1812
   217
            return "PEP_CANNOT_CREATE_KEY";
krista@1812
   218
        case PEP_CANNOT_SEND_KEY:
krista@1812
   219
            return "PEP_CANNOT_SEND_KEY";
krista@1812
   220
        case PEP_PHRASE_NOT_FOUND:
krista@1812
   221
            return "PEP_PHRASE_NOT_FOUND";
krista@1812
   222
        case PEP_SEND_FUNCTION_NOT_REGISTERED:
krista@1812
   223
            return "PEP_SEND_FUNCTION_NOT_REGISTERED";
krista@1812
   224
        case PEP_CONTRAINTS_VIOLATED:
krista@1812
   225
            return "PEP_CONTRAINTS_VIOLATED";
krista@1812
   226
        case PEP_CANNOT_ENCODE:
krista@1812
   227
            return "PEP_CANNOT_ENCODE";
krista@1812
   228
        case PEP_SYNC_NO_NOTIFY_CALLBACK:
krista@1812
   229
            return "PEP_SYNC_NO_NOTIFY_CALLBACK";
krista@1812
   230
        case PEP_SYNC_ILLEGAL_MESSAGE:
krista@1812
   231
            return "PEP_SYNC_ILLEGAL_MESSAGE";
krista@1812
   232
        case PEP_SYNC_NO_INJECT_CALLBACK:
krista@1812
   233
            return "PEP_SYNC_NO_INJECT_CALLBACK";
krista@1812
   234
        case PEP_CANNOT_INCREASE_SEQUENCE:
krista@1812
   235
            return "PEP_CANNOT_INCREASE_SEQUENCE";
vb@2847
   236
        case PEP_STATEMACHINE_ERROR:
vb@2847
   237
            return "PEP_STATEMACHINE_ERROR";
vb@2847
   238
        case PEP_NO_TRUST:
vb@2847
   239
            return "PEP_NO_TRUST";
krista@1812
   240
        case PEP_STATEMACHINE_INVALID_STATE:
krista@1812
   241
            return "PEP_STATEMACHINE_INVALID_STATE";
krista@1812
   242
        case PEP_STATEMACHINE_INVALID_EVENT:
krista@1812
   243
            return "PEP_STATEMACHINE_INVALID_EVENT";
krista@1812
   244
        case PEP_STATEMACHINE_INVALID_CONDITION:
krista@1812
   245
            return "PEP_STATEMACHINE_INVALID_CONDITION";
krista@1812
   246
        case PEP_STATEMACHINE_INVALID_ACTION:
krista@1812
   247
            return "PEP_STATEMACHINE_INVALID_ACTION";
krista@1812
   248
        case PEP_STATEMACHINE_INHIBITED_EVENT:
krista@1812
   249
            return "PEP_STATEMACHINE_INHIBITED_EVENT";
krista@1812
   250
        case PEP_COMMIT_FAILED:
krista@1812
   251
            return "PEP_COMMIT_FAILED";
krista@1812
   252
        case PEP_MESSAGE_CONSUME:
krista@1812
   253
            return "PEP_MESSAGE_CONSUME";
krista@1812
   254
        case PEP_MESSAGE_IGNORE:
krista@1812
   255
            return "PEP_MESSAGE_IGNORE";
krista@1812
   256
        case PEP_RECORD_NOT_FOUND:
krista@1812
   257
            return "PEP_RECORD_NOT_FOUND";
krista@1812
   258
        case PEP_CANNOT_CREATE_TEMP_FILE:
krista@1812
   259
            return "PEP_CANNOT_CREATE_TEMP_FILE";
krista@1812
   260
        case PEP_ILLEGAL_VALUE:
krista@1812
   261
            return "PEP_ILLEGAL_VALUE";
krista@1812
   262
        case PEP_BUFFER_TOO_SMALL:
krista@1812
   263
            return "PEP_BUFFER_TOO_SMALL";
krista@1812
   264
        case PEP_OUT_OF_MEMORY:
krista@1812
   265
            return "PEP_OUT_OF_MEMORY";
krista@1812
   266
        case PEP_UNKNOWN_ERROR:
krista@2703
   267
            return "PEP_UNKNOWN_ERROR";    
krista@1812
   268
        default:
krista@2630
   269
 
krista@1812
   270
            return "PEP_STATUS_OMGWTFBBQ - This means you're using a status the test lib doesn't know about!";
krista@1812
   271
    }
krista@1812
   272
}
krista@1812
   273
const char* tl_rating_string(PEP_rating rating) {
krista@1812
   274
    switch (rating) {
krista@1812
   275
        case PEP_rating_undefined:
krista@1812
   276
            return "PEP_rating_undefined";
krista@1812
   277
        case PEP_rating_cannot_decrypt:
krista@1812
   278
            return "PEP_rating_cannot_decrypt";
krista@1812
   279
        case PEP_rating_have_no_key:
krista@1812
   280
            return "PEP_rating_have_no_key";
krista@1812
   281
        case PEP_rating_unencrypted:
krista@1812
   282
            return "PEP_rating_unencrypted";
krista@1812
   283
        case PEP_rating_unencrypted_for_some:
krista@1812
   284
            return "PEP_rating_unencrypted_for_some";
krista@1812
   285
        case PEP_rating_unreliable:
krista@1812
   286
            return "PEP_rating_unreliable";
krista@1812
   287
        case PEP_rating_reliable:
krista@1812
   288
            return "PEP_rating_reliable";
krista@1812
   289
        case PEP_rating_trusted:
krista@1812
   290
            return "PEP_rating_trusted";
krista@1812
   291
        case PEP_rating_trusted_and_anonymized:
krista@1812
   292
            return "PEP_rating_trusted_and_anonymized";
krista@1812
   293
        case PEP_rating_fully_anonymous:
krista@1812
   294
            return "PEP_rating_fully_anonymous";
krista@1812
   295
        case PEP_rating_mistrust:
krista@1812
   296
            return "PEP_rating_mistrust";
krista@1812
   297
        case PEP_rating_b0rken:
krista@1812
   298
            return "PEP_rating_b0rken";
krista@1812
   299
        case PEP_rating_under_attack:
krista@1812
   300
            return "PEP_rating_under_attack";
krista@1812
   301
        default:
krista@1812
   302
            return "PEP_rating_OMGWTFBBQ - in other words, INVALID RATING VALUE!!!\n\nSomething bad is going on here, or a new rating value has been added to the enum and not the test function.";
krista@1812
   303
    }
krista@1812
   304
}
krista@1812
   305
krista@1812
   306
const char* tl_ct_string(PEP_comm_type ct) {
krista@1812
   307
    switch (ct) {
krista@1812
   308
        case PEP_ct_unknown:
krista@1812
   309
            return "PEP_ct_unknown";
krista@1812
   310
        case PEP_ct_no_encryption:
krista@1812
   311
            return "PEP_ct_no_encryption";
krista@1812
   312
        case PEP_ct_no_encrypted_channel:
krista@1812
   313
            return "PEP_ct_no_encrypted_channel";
krista@1812
   314
        case PEP_ct_key_not_found:
krista@1812
   315
            return "PEP_ct_key_not_found";
krista@1812
   316
        case PEP_ct_key_expired:
krista@1812
   317
            return "PEP_ct_key_expired";
krista@1812
   318
        case PEP_ct_key_revoked:
krista@1812
   319
            return "PEP_ct_key_revoked";
krista@1812
   320
        case PEP_ct_key_b0rken:
krista@1812
   321
            return "PEP_ct_key_b0rken";
krista@1812
   322
        case PEP_ct_my_key_not_included:
krista@1812
   323
            return "PEP_ct_my_key_not_included";
krista@1812
   324
        case PEP_ct_security_by_obscurity:
krista@1812
   325
            return "PEP_ct_security_by_obscurity";
krista@1812
   326
        case PEP_ct_b0rken_crypto:
krista@1812
   327
            return "PEP_ct_b0rken_crypto";
krista@1812
   328
        case PEP_ct_key_too_short:
krista@1812
   329
            return "PEP_ct_key_too_short";
krista@2593
   330
        case PEP_ct_compromised:
krista@2593
   331
            return "PEP_ct_compromised";
krista@1812
   332
        case PEP_ct_mistrusted:
krista@1812
   333
            return "PEP_ct_mistrusted";
krista@1812
   334
        case PEP_ct_unconfirmed_encryption:
krista@1812
   335
            return "PEP_ct_unconfirmed_encryption";
krista@1812
   336
        case PEP_ct_OpenPGP_weak_unconfirmed:
krista@1812
   337
            return "PEP_ct_OpenPGP_weak_unconfirmed";
krista@1812
   338
        case PEP_ct_to_be_checked:
krista@1812
   339
            return "PEP_ct_to_be_checked";
krista@1812
   340
        case PEP_ct_SMIME_unconfirmed:
krista@1812
   341
            return "PEP_ct_SMIME_unconfirmed";
krista@1812
   342
        case PEP_ct_CMS_unconfirmed:
krista@1812
   343
            return "PEP_ct_CMS_unconfirmed";
krista@1812
   344
        case PEP_ct_strong_but_unconfirmed:
krista@1812
   345
            return "PEP_ct_strong_but_unconfirmed";
krista@1812
   346
        case PEP_ct_OpenPGP_unconfirmed:
krista@1812
   347
            return "PEP_ct_OpenPGP_unconfirmed";
krista@1812
   348
        case PEP_ct_OTR_unconfirmed:
krista@1812
   349
            return "PEP_ct_OTR_unconfirmed";
krista@1812
   350
        case PEP_ct_unconfirmed_enc_anon:
krista@1812
   351
            return "PEP_ct_unconfirmed_enc_anon";
krista@1812
   352
        case PEP_ct_pEp_unconfirmed:
krista@1812
   353
            return "PEP_ct_pEp_unconfirmed";
krista@1812
   354
        case PEP_ct_confirmed:
krista@1812
   355
            return "PEP_ct_pEp_confirmed";
krista@1812
   356
        case PEP_ct_confirmed_encryption:
krista@1812
   357
            return "PEP_ct_confirmed_encryption";
krista@1812
   358
        case PEP_ct_OpenPGP_weak:
krista@1812
   359
            return "PEP_ct_OpenPGP_weak";
krista@1812
   360
        case PEP_ct_to_be_checked_confirmed:
krista@1812
   361
            return "PEP_ct_to_be_checked_confirmed";
krista@1812
   362
        case PEP_ct_SMIME:
krista@1812
   363
            return "PEP_ct_SMIME";
krista@1812
   364
        case PEP_ct_CMS:
krista@1812
   365
            return "PEP_ct_CMS";
krista@1812
   366
        case PEP_ct_strong_encryption:
krista@1812
   367
            return "PEP_ct_strong_encryption";
krista@1812
   368
        case PEP_ct_OpenPGP:
krista@1812
   369
            return "PEP_ct_OpenPGP";
krista@1812
   370
        case PEP_ct_OTR:
krista@1812
   371
            return "PEP_ct_OTR";
krista@1812
   372
        case PEP_ct_confirmed_enc_anon:
krista@1812
   373
            return "PEP_ct_confirmed_enc_anon";
krista@1812
   374
        case PEP_ct_pEp:
krista@1812
   375
            return "PEP_ct_pEp";
krista@1812
   376
        default:
krista@1812
   377
            return "PEP_ct_OMGWTFBBQ\n\nIn other words, comm type is invalid. Either something's corrupt or a new ct value has been added to the enum but not to the test function.";
krista@1812
   378
    }
krista@1812
   379
}
krista@2703
   380
krista@2703
   381
bool slurp_message_and_import_key(PEP_SESSION session, const char* message_fname, std::string& message, const char* key_filename) {
krista@2703
   382
    message = slurp(message_fname);
krista@2703
   383
    if (key_filename) {
krista@2703
   384
        std::string keyfile = slurp(key_filename);
krista@2703
   385
        if (import_key(session, keyfile.c_str(), keyfile.size(), NULL) != PEP_STATUS_OK)
krista@2703
   386
            return false;
krista@2703
   387
    }
krista@2703
   388
    return true;
krista@2703
   389
}
krista@2703
   390
krista@2703
   391
krista@2703
   392
krista@2703
   393
int util_delete_filepath(const char *filepath, 
krista@2703
   394
                         const struct stat *file_stat, 
krista@2703
   395
                         int ftw_info, 
krista@2703
   396
                         struct FTW * ftw_struct) {
krista@2703
   397
    int retval = 0;
krista@2703
   398
    switch (ftw_info) {
krista@2703
   399
        case FTW_DP:
krista@2703
   400
            retval = rmdir(filepath);
krista@2703
   401
            break;
krista@2703
   402
        case FTW_F:
krista@2703
   403
        case FTW_SLN:
krista@2703
   404
            retval = unlink(filepath);
krista@2703
   405
            break;    
krista@2703
   406
        default:
krista@2703
   407
            retval = -1;
krista@2703
   408
    }
krista@2703
   409
    
krista@2703
   410
    return retval;
krista@2703
   411
}
krista@2703
   412