Project

General

Profile

relpath.2.diff

Yoann VANDOORSELAERE, 10/03/2008 04:58 PM

Download (9.14 KB)

View differences:

src/prelude-client-profile.c
82 82
extern char *_prelude_prefix;
83 83
static char *user_prefix = NULL;
84 84
static const char *relocated_prefix;
85
static const char *relative_spool_dir;
86
static const char *relative_config_default_dir;
87
static const char *relative_profile_dir;
88

  
85
static const char *relative_spool_dir = NULL;
86
static const char *relative_config_default_dir = NULL;
87
static const char *relative_profile_dir = NULL;
89 88

  
90 89
gl_lock_t lock = gl_lock_initializer;
91 90
gl_once_define(static, relocate_once);
92 91

  
93 92

  
93

  
94
static const char *get_relpath(const char *path)
95
{
96
        return ( strstr(path, INSTALLPREFIX) ) ? path + sizeof(INSTALLPREFIX) : NULL;
97
}
98

  
99

  
100

  
94 101
static void _get_dir_once(void)
95 102
{
96 103
        relocated_prefix = (_prelude_prefix) ? _prelude_prefix : relocate(INSTALLPREFIX);
97
        relative_spool_dir = PRELUDE_SPOOL_DIR + sizeof(INSTALLPREFIX);
98
        relative_profile_dir = PRELUDE_PROFILE_DIR + sizeof(INSTALLPREFIX);
99
        relative_config_default_dir = PRELUDE_CONFIG_DEFAULT_DIR + sizeof(INSTALLPREFIX);
104

  
105
        relative_spool_dir = get_relpath(PRELUDE_SPOOL_DIR);
106
        relative_profile_dir = get_relpath(PRELUDE_PROFILE_DIR);
107
        relative_config_default_dir = get_relpath(PRELUDE_CONFIG_DEFAULT_DIR);
100 108

  
101 109
        prelude_log_debug(2, "install   prefix=%s", INSTALLPREFIX);
102 110
        prelude_log_debug(2, "relocated prefix=%s\n", relocated_prefix);
103
        prelude_log_debug(2, "relative   spool=%s\n", relative_spool_dir);
104
        prelude_log_debug(2, "relative  config=%s\n", relative_config_default_dir);
105
        prelude_log_debug(2, "relative profile=%s\n", relative_profile_dir);
111
        prelude_log_debug(2, "relative   spool=%s\n", relative_spool_dir ? relative_spool_dir : PRELUDE_SPOOL_DIR);
112
        prelude_log_debug(2, "relative  config=%s\n", relative_config_default_dir ? relative_config_default_dir : PRELUDE_CONFIG_DEFAULT_DIR);
113
        prelude_log_debug(2, "relative profile=%s\n", relative_profile_dir ? relative_profile_dir : PRELUDE_PROFILE_DIR);
106 114
}
107 115

  
108 116

  
109
static const char *get_prefix(void)
117
static const char *init_once_and_get_prefix(void)
110 118
{
111 119
        gl_once(relocate_once, _get_dir_once);
112 120
        return (user_prefix) ? user_prefix : relocated_prefix;
......
194 202

  
195 203
        gl_lock_lock(lock);
196 204

  
197
        prefix = get_prefix();
205
        prefix = init_once_and_get_prefix();
198 206
        snprintf(buf, size, "%s", prefix);
199 207

  
200 208
        gl_lock_unlock(lock);
......
218 226

  
219 227
        gl_lock_lock(lock);
220 228

  
221
        prefix = get_prefix();
222
        snprintf(buf, size, "%s/%s", prefix, relative_config_default_dir);
229
        prefix = init_once_and_get_prefix();
230
        if ( ! relative_config_default_dir )
231
                snprintf(buf, size, "%s", PRELUDE_CONFIG_DEFAULT_DIR);
232
        else
233
                snprintf(buf, size, "%s/%s", prefix, relative_config_default_dir);
223 234

  
224 235
        gl_lock_unlock(lock);
225 236
}
......
243 254

  
244 255
        gl_lock_lock(lock);
245 256

  
246
        prefix = get_prefix();
247
        snprintf(buf, size, "%s/%s/%s/analyzerid", prefix, relative_profile_dir, cp->name);
257
        prefix = init_once_and_get_prefix();
258
        if ( ! relative_profile_dir )
259
                snprintf(buf, size, "%s/%s/analyzerid", PRELUDE_PROFILE_DIR, cp->name);
260
        else
261
                snprintf(buf, size, "%s/%s/%s/analyzerid", prefix, relative_profile_dir, cp->name);
248 262

  
249 263
        gl_lock_unlock(lock);
250 264
}
......
268 282

  
269 283
        gl_lock_lock(lock);
270 284

  
271
        prefix = get_prefix();
272
        snprintf(buf, size, "%s/%s/%s/config", prefix, relative_profile_dir, cp->name);
285
        prefix = init_once_and_get_prefix();
286
        if ( ! relative_profile_dir )
287
                snprintf(buf, size, "%s/%s/config", PRELUDE_PROFILE_DIR, cp->name);
288
        else
289
                snprintf(buf, size, "%s/%s/%s/config", prefix, relative_profile_dir, cp->name);
273 290

  
274 291
        gl_lock_unlock(lock);
275 292
}
276 293

  
277 294

  
278

  
279 295
/**
280 296
 * prelude_client_profile_get_tls_key_filename:
281 297
 * @cp: pointer on a #prelude_client_profile_t object.
......
293 309

  
294 310
        gl_lock_lock(lock);
295 311

  
296
        prefix = get_prefix();
297
        snprintf(buf, size, "%s/%s/%s/key", prefix, relative_profile_dir, cp->name);
312
        prefix = init_once_and_get_prefix();
313
        if ( ! relative_profile_dir )
314
                snprintf(buf, size, "%s/%s/key", PRELUDE_PROFILE_DIR, cp->name);
315
        else
316
                snprintf(buf, size, "%s/%s/%s/key", prefix, relative_profile_dir, cp->name);
298 317

  
299 318
        gl_lock_unlock(lock);
300 319
}
......
319 338

  
320 339
        gl_lock_lock(lock);
321 340

  
322
        prefix = get_prefix();
323
        snprintf(buf, size, "%s/%s/%s/server.ca", prefix, relative_profile_dir, cp->name);
341
        prefix = init_once_and_get_prefix();
342
        if ( ! relative_profile_dir )
343
                snprintf(buf, size, "%s/%s/server.ca", PRELUDE_PROFILE_DIR, cp->name);
344
        else
345
                snprintf(buf, size, "%s/%s/%s/server.ca", prefix, relative_profile_dir, cp->name);
324 346

  
325 347
        gl_lock_unlock(lock);
326 348
}
......
345 367

  
346 368
        gl_lock_lock(lock);
347 369

  
348
        prefix = get_prefix();
349
        snprintf(buf, size, "%s/%s/%s/server.keycrt", prefix, relative_profile_dir, cp->name);
370
        prefix = init_once_and_get_prefix();
371
        if ( ! relative_profile_dir )
372
                snprintf(buf, size, "%s/%s/server.keycrt", PRELUDE_PROFILE_DIR, cp->name);
373
        else
374
                snprintf(buf, size, "%s/%s/%s/server.keycrt", prefix, relative_profile_dir, cp->name);
350 375

  
351 376
        gl_lock_unlock(lock);
352 377
}
......
371 396

  
372 397
        gl_lock_lock(lock);
373 398

  
374
        prefix = get_prefix();
375
        snprintf(buf, size, "%s/%s/%s/server.crl", prefix, relative_profile_dir, cp->name);
399
        prefix = init_once_and_get_prefix();
400
        if ( ! relative_profile_dir )
401
                snprintf(buf, size, "%s/%s/server.crl", PRELUDE_PROFILE_DIR, cp->name);
402
        else
403
                snprintf(buf, size, "%s/%s/%s/server.crl", prefix, relative_profile_dir, cp->name);
376 404

  
377 405
        gl_lock_unlock(lock);
378 406
}
......
397 425

  
398 426
        gl_lock_lock(lock);
399 427

  
400
        prefix = get_prefix();
401
        snprintf(buf, size, "%s/%s/%s/client.trusted", prefix, relative_profile_dir, cp->name);
428
        prefix = init_once_and_get_prefix();
429
        if ( ! relative_profile_dir )
430
                snprintf(buf, size, "%s/%s/client.trusted", PRELUDE_PROFILE_DIR, cp->name);
431
        else
432
                snprintf(buf, size, "%s/%s/%s/client.trusted", prefix, relative_profile_dir, cp->name);
402 433

  
403 434
        gl_lock_unlock(lock);
404 435
}
......
424 455

  
425 456
        gl_lock_lock(lock);
426 457

  
427
        prefix = get_prefix();
428
        snprintf(buf, size, "%s/%s/%s/client.keycrt", prefix, relative_profile_dir, cp->name);
458
        prefix = init_once_and_get_prefix();
459
        if ( ! relative_profile_dir )
460
                snprintf(buf, size, "%s/%s/client.keycrt", PRELUDE_PROFILE_DIR, cp->name);
461
        else
462
                snprintf(buf, size, "%s/%s/%s/client.keycrt", prefix, relative_profile_dir, cp->name);
429 463

  
430 464
        gl_lock_unlock(lock);
431 465
}
......
450 484

  
451 485
        gl_lock_lock(lock);
452 486

  
453
        prefix = get_prefix();
454
        snprintf(buf, size, "%s/%s/%s", prefix, relative_spool_dir, cp->name);
487
        prefix = init_once_and_get_prefix();
488
        if ( ! relative_spool_dir )
489
                snprintf(buf, size, "%s/%s", PRELUDE_SPOOL_DIR, cp->name);
490
        else
491
                snprintf(buf, size, "%s/%s/%s", prefix, relative_spool_dir, cp->name);
455 492

  
456 493
        gl_lock_unlock(lock);
457 494
}
......
474 511
        prelude_return_if_fail(buf);
475 512

  
476 513
        gl_lock_lock(lock);
477
        prefix = get_prefix();
478 514

  
479
        if ( cp && cp->name )
480
                snprintf(buf, size, "%s/%s/%s", prefix, relative_profile_dir, cp->name);
515
        prefix = init_once_and_get_prefix();
516
        if ( ! relative_profile_dir )
517
                snprintf(buf, size, "%s/%s%s", PRELUDE_PROFILE_DIR, (cp->name) ? "/" : "", (cp->name) ? cp->name : "");
481 518
        else
482
                snprintf(buf, size, "%s/%s", prefix, relative_profile_dir);
519
                snprintf(buf, size, "%s/%s%s%s", prefix, relative_profile_dir, (cp->name) ? "/" : "", (cp->name) ? cp->name : "");
483 520

  
484 521
        gl_lock_unlock(lock);
485 522
}