00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00037 #include <string.h>
00038 #include <dirent.h>
00039 #include <errno.h>
00040
00041 #include <ltdl.h>
00042
00043 #ifdef __WIN32__
00044 #include <direct.h>
00045 #endif
00046
00047 #include "splt.h"
00048 #include "plugins.h"
00049
00050 int splt_p_append_plugin_scan_dir(splt_state *state, const char *dir)
00051 {
00052 if (dir == NULL)
00053 {
00054 return SPLT_OK;
00055 }
00056
00057 splt_plugins *pl = state->plug;
00058
00059 if (pl->plugins_scan_dirs == NULL)
00060 {
00061 pl->plugins_scan_dirs = malloc(sizeof(char *));
00062 }
00063 else
00064 {
00065 pl->plugins_scan_dirs = realloc(pl->plugins_scan_dirs,
00066 sizeof(char *) * (pl->number_of_dirs_to_scan + 1));
00067 }
00068 if (pl->plugins_scan_dirs == NULL)
00069 {
00070 return SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00071 }
00072
00073 size_t dir_size = strlen(dir) + 1;
00074
00075 pl->plugins_scan_dirs[pl->number_of_dirs_to_scan] = malloc(sizeof(char) * dir_size);
00076 if (pl->plugins_scan_dirs[pl->number_of_dirs_to_scan] == NULL)
00077 {
00078 return SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00079 }
00080
00081 snprintf(pl->plugins_scan_dirs[pl->number_of_dirs_to_scan], dir_size, "%s", dir);
00082 pl->number_of_dirs_to_scan++;
00083
00084 return SPLT_OK;
00085 }
00086
00087 #ifdef __WIN32__
00088 static int splt_p_filter_plugin_files(const struct _wdirent *de)
00089 {
00090 wchar_t *file = (wchar_t *) de->d_name;
00091 const wchar_t *p_end = NULL;
00092 const wchar_t *p_start = NULL;
00093
00094 if (!file)
00095 {
00096 return 0;
00097 }
00098
00099 if (wcslen(file) < 8)
00100 {
00101 return 0;
00102 }
00103
00104 if (wcsncmp(file, L"libsplt_", 8) != 0)
00105 {
00106 return 0;
00107 }
00108
00109 splt_d_print_debug(NULL, "Looking at the file _%s_\n", splt_w32_utf16_to_utf8(file));
00110
00111 p_start = wcschr(file,'.');
00112 p_end = wcsrchr(file,'.');
00113 if ((p_end != NULL) && (p_start == p_end))
00114 {
00115 if (wcscmp(p_end, L".dll") == 0)
00116 {
00117 return 1;
00118 }
00119 }
00120
00121 return 0;
00122 }
00123 #else
00124 static int splt_p_filter_plugin_files(const struct dirent *de)
00125 {
00126 char *file = (char *) de->d_name;
00127 const char *p_end = NULL;
00128 const char *p_start = NULL;
00129
00130 if (!file)
00131 {
00132 return 0;
00133 }
00134
00135 if (strlen(file) < 8)
00136 {
00137 return 0;
00138 }
00139
00140 if (strncmp(file,"libsplt_", 8) != 0)
00141 {
00142 return 0;
00143 }
00144
00145 splt_d_print_debug(NULL, "Looking at the file _%s_\n", file);
00146
00147 p_start = strchr(file,'.');
00148
00149 #ifndef __WIN32__
00150
00151 p_end = strstr(file, ".so.0");
00152 if (p_end != NULL && (p_start == p_end) && (*(p_end+5) == '\0'))
00153 {
00154 return 1;
00155 }
00156 #endif
00157
00158 p_end = strrchr(file,'.');
00159 if ((p_end != NULL) && (p_start == p_end))
00160 {
00161
00162 #ifdef __WIN32__
00163 if (strcmp(p_end,".dll") == 0)
00164 {
00165 return 1;
00166 }
00167 #else
00168
00169 if ((strcmp(p_end,".sl") == 0) || (strcmp(p_end,".dylib") == 0))
00170 {
00171 return 1;
00172 }
00173 #endif
00174 }
00175
00176 return 0;
00177 }
00178 #endif
00179
00180 static int splt_p_alloc_init_new_plugin(splt_plugins *pl)
00181 {
00182 int return_value = SPLT_OK;
00183
00184 if (pl->data == NULL)
00185 {
00186 pl->data = malloc(sizeof(splt_plugin_data) * (pl->number_of_plugins_found+1));
00187 if (pl->data == NULL)
00188 {
00189 return_value = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00190 return return_value;
00191 }
00192 }
00193 else
00194 {
00195 pl->data = realloc(pl->data,sizeof(splt_plugin_data) *
00196 (pl->number_of_plugins_found+1));
00197 if (pl->data == NULL)
00198 {
00199 return_value = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00200 return return_value;
00201 }
00202 }
00203
00204 pl->data[pl->number_of_plugins_found].func = NULL;
00205 pl->data[pl->number_of_plugins_found].plugin_handle = NULL;
00206 pl->data[pl->number_of_plugins_found].info.version = 0;
00207 pl->data[pl->number_of_plugins_found].info.name = NULL;
00208 pl->data[pl->number_of_plugins_found].info.extension = NULL;
00209 pl->data[pl->number_of_plugins_found].info.upper_extension = NULL;
00210 pl->data[pl->number_of_plugins_found].plugin_filename = NULL;
00211
00212 return return_value;
00213 }
00214
00219 static int splt_p_scan_dir_for_plugins(splt_state *state, splt_plugins *pl, const char *directory)
00220 {
00221 int return_value = SPLT_OK;
00222
00223 #ifdef __WIN32__
00224 struct _wdirent **files = NULL;
00225 #else
00226 struct dirent **files = NULL;
00227 #endif
00228
00229 int number_of_files = 0;
00230 errno = 0;
00231 #ifdef __WIN32__
00232 number_of_files = wscandir(directory, &files, splt_p_filter_plugin_files, walphasort);
00233 #else
00234 number_of_files = scandir(directory, &files, splt_p_filter_plugin_files, alphasort);
00235 #endif
00236 int new_number_of_files = number_of_files;
00237
00238 if (number_of_files == -1)
00239 {
00240 if (errno == ENOMEM)
00241 {
00242 return SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00243 }
00244 }
00245 else if (new_number_of_files >= 0)
00246 {
00247 char *dir_and_fname = NULL;
00248
00249
00250
00251 while (new_number_of_files--)
00252 {
00253 #ifdef __WIN32__
00254 char *fname = splt_w32_utf16_to_utf8(files[new_number_of_files]->d_name);
00255 #else
00256 char *fname = files[new_number_of_files]->d_name;
00257 #endif
00258
00259 #ifdef __WIN32__
00260 splt_su_copy(fname, &dir_and_fname);
00261 #else
00262 splt_su_copy(directory, &dir_and_fname);
00263 splt_su_append_str(&dir_and_fname, SPLT_DIRSTR, fname, NULL);
00264 #endif
00265
00266 int i = 0;
00267 int err = SPLT_OK;
00268 for (i = 0;i < pl->number_of_plugins_found;i++)
00269 {
00270 if (splt_check_is_the_same_file(state, dir_and_fname, pl->data[i].plugin_filename, &err))
00271 {
00272 goto loop_end;
00273 }
00274
00275 if (err != SPLT_OK)
00276 {
00277 return_value = err;
00278 goto end;
00279 }
00280 }
00281
00282 int alloc_err = splt_p_alloc_init_new_plugin(pl);
00283 if (alloc_err < 0)
00284 {
00285 return_value = alloc_err;
00286 goto end;
00287 }
00288
00289 pl->data[pl->number_of_plugins_found].func = malloc(sizeof(splt_plugin_func));
00290 if (pl->data[pl->number_of_plugins_found].func == NULL)
00291 {
00292 return_value = SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00293 goto end;
00294 }
00295 memset(pl->data[pl->number_of_plugins_found].func, 0, sizeof(splt_plugin_func));
00296
00297 splt_su_copy(dir_and_fname,
00298 &pl->data[pl->number_of_plugins_found].plugin_filename);
00299
00300 pl->number_of_plugins_found++;
00301
00302 loop_end:
00303 ;
00304 }
00305
00306 end:
00307 ;
00308
00309 if (dir_and_fname)
00310 {
00311 free(dir_and_fname);
00312 dir_and_fname = NULL;
00313 }
00314
00315 if (files)
00316 {
00317 while (number_of_files--)
00318 {
00319 if (files[number_of_files])
00320 {
00321 free(files[number_of_files]);
00322 files[number_of_files] = NULL;
00323 }
00324 }
00325 free(files);
00326 files = NULL;
00327 }
00328 }
00329
00330 return return_value;
00331 }
00332
00333
00334
00335
00336 static int splt_p_find_plugins(splt_state *state)
00337 {
00338 int return_value = SPLT_OK;
00339
00340 splt_plugins *pl = state->plug;
00341
00342
00343
00344 int i = 0;
00345
00346 char current_dir[3] = { '\0' };
00347 snprintf(current_dir,3,".%c",SPLT_DIRCHAR);
00348
00349 for (i = 0;i < pl->number_of_dirs_to_scan;i++)
00350 {
00351 if (pl->plugins_scan_dirs[i] != NULL)
00352 {
00353 splt_d_print_debug(state,"Scanning plugins in the directory _%s_\n",
00354 pl->plugins_scan_dirs[i]);
00355
00356
00357
00358 if (((strlen(pl->plugins_scan_dirs[i]) >= 2) &&
00359 strncmp(pl->plugins_scan_dirs[i], current_dir,2) == 0) ||
00360 splt_io_check_if_directory(pl->plugins_scan_dirs[i]))
00361 {
00362 return_value = splt_p_scan_dir_for_plugins(state, pl, pl->plugins_scan_dirs[i]);
00363 if (return_value != SPLT_OK)
00364 {
00365 return return_value;
00366 }
00367 }
00368 }
00369 }
00370
00371 return return_value;
00372 }
00373
00375 static void splt_p_free_plugin_data_info(splt_plugin_data *pl_data)
00376 {
00377 if (pl_data->info.name)
00378 {
00379 free(pl_data->info.name);
00380 pl_data->info.name = NULL;
00381 }
00382 if (pl_data->info.extension)
00383 {
00384 free(pl_data->info.extension);
00385 pl_data->info.extension = NULL;
00386 }
00387 if (pl_data->info.upper_extension)
00388 {
00389 free(pl_data->info.upper_extension);
00390 pl_data->info.upper_extension = NULL;
00391 }
00392 }
00393
00394 static void splt_p_free_plugin_data(splt_plugin_data *pl_data)
00395 {
00396 splt_p_free_plugin_data_info(pl_data);
00397 if (pl_data->plugin_filename)
00398 {
00399 free(pl_data->plugin_filename);
00400 pl_data->plugin_filename = NULL;
00401 }
00402 if (pl_data->plugin_handle)
00403 {
00404 lt_dlclose(pl_data->plugin_handle);
00405 pl_data->plugin_handle = NULL;
00406 }
00407 if (pl_data->func)
00408 {
00409 free(pl_data->func);
00410 pl_data->func = NULL;
00411 }
00412 }
00413
00414 int splt_p_move_replace_plugin_data(splt_state *state, int old, int new)
00415 {
00416 splt_plugins *pl = state->plug;
00417
00418 splt_p_free_plugin_data(&pl->data[new]);
00419
00420 pl->data[new].func = malloc(sizeof(splt_plugin_func));
00421 if (pl->data[new].func == NULL)
00422 {
00423 return SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00424 }
00425 memset(pl->data[new].func,0,sizeof(splt_plugin_func));
00426
00427 int plugin_fname_len = strlen(pl->data[old].plugin_filename) + 1;
00428 pl->data[new].plugin_filename = malloc(sizeof(char) * plugin_fname_len);
00429 if (pl->data[new].plugin_filename == NULL)
00430 {
00431 return SPLT_ERROR_CANNOT_ALLOCATE_MEMORY;
00432 }
00433 snprintf(pl->data[new].plugin_filename, plugin_fname_len, "%s",
00434 pl->data[old].plugin_filename);
00435
00436 splt_p_free_plugin_data(&pl->data[old]);
00437
00438 return SPLT_OK;
00439 }
00440
00441
00442 static int splt_p_shift_left_plugins_data(splt_state *state, int index)
00443 {
00444 int i = 0;
00445 splt_plugins *pl = state->plug;
00446
00447 for (i = index+1;i < pl->number_of_plugins_found;i++)
00448 {
00449 int err = splt_p_move_replace_plugin_data(state, i, i - 1);
00450 if (err != SPLT_OK)
00451 {
00452 return err;
00453 }
00454 }
00455
00456 return SPLT_OK;
00457 }
00458
00459
00460 static int splt_p_open_get_valid_plugins(splt_state *state)
00461 {
00462 splt_plugins *pl = state->plug;
00463
00464 int *plugin_index_to_remove = NULL;
00465 int number_of_plugins_to_remove = 0;
00466
00467 int error = SPLT_OK;
00468
00469 int i = 0;
00470 for (i = 0;i < pl->number_of_plugins_found;i++)
00471 {
00472 splt_d_print_debug(state,"\nTrying to open the plugin _%s_ ...\n",
00473 pl->data[i].plugin_filename);
00474
00475
00476 pl->data[i].plugin_handle = lt_dlopen(pl->data[i].plugin_filename);
00477
00478 if (! pl->data[i].plugin_handle)
00479 {
00480 splt_d_print_debug(state,"Error loading the plugin _%s_\n", pl->data[i].plugin_filename);
00481 splt_d_print_debug(state," - error message from libltdl: _%s_\n", lt_dlerror());
00482
00483
00484
00485 if (! plugin_index_to_remove)
00486 {
00487 plugin_index_to_remove = malloc(sizeof(int));
00488 }
00489 else
00490 {
00491 plugin_index_to_remove = realloc(plugin_index_to_remove, sizeof(int) * (number_of_plugins_to_remove + 1));
00492 }
00493 plugin_index_to_remove[number_of_plugins_to_remove] = i;
00494 number_of_plugins_to_remove++;
00495 }
00496 else
00497 {
00498 splt_d_print_debug(state," - success !\n");
00499
00500 pl->data[i].func->set_plugin_info =
00501 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_set_plugin_info");
00502 if (pl->data[i].func->set_plugin_info != NULL)
00503 {
00504 pl->data[i].func->set_plugin_info(&pl->data[i].info,&error);
00505 }
00506
00507
00508 int j = 0;
00509 splt_p_set_current_plugin(state, i);
00510 const char *current_plugin_name = splt_p_get_name(state, &error);
00511 for (j = 0;j < i;j++)
00512 {
00513 if (pl->data[j].plugin_handle)
00514 {
00515 splt_p_set_current_plugin(state, j);
00516 const char *plugin_name = splt_p_get_name(state, &error);
00517
00518 if (strcmp(plugin_name,current_plugin_name) == 0)
00519 {
00520
00521 int unique = SPLT_TRUE;
00522 int k = 0;
00523 for (k = 0;k < number_of_plugins_to_remove;k++)
00524 {
00525 if (i == plugin_index_to_remove[k])
00526 {
00527 unique = SPLT_FALSE;
00528 break;
00529 }
00530 }
00531 if (unique)
00532 {
00533 if (! plugin_index_to_remove)
00534 {
00535 plugin_index_to_remove = malloc(sizeof(int));
00536 }
00537 else
00538 {
00539 plugin_index_to_remove = realloc(plugin_index_to_remove,
00540 sizeof(int) * (number_of_plugins_to_remove + 1));
00541 }
00542 plugin_index_to_remove[number_of_plugins_to_remove] = i;
00543 number_of_plugins_to_remove++;
00544 }
00545 }
00546 }
00547 }
00548 }
00549 }
00550
00551
00552
00553 int left_shift = 0;
00554
00555
00556 for (i = 0;i < number_of_plugins_to_remove;i++)
00557 {
00558 int index_to_remove = plugin_index_to_remove[i] - left_shift;
00559
00560 splt_d_print_debug(state,"Removing the plugin _%s_ at index %d\n",
00561 pl->data[index_to_remove].plugin_filename, index_to_remove);
00562
00563 error = splt_p_shift_left_plugins_data(state, index_to_remove);
00564 if (error < SPLT_OK) { break; }
00565
00566 pl->number_of_plugins_found--;
00567 left_shift++;
00568 }
00569
00570
00571 if (plugin_index_to_remove)
00572 {
00573 free(plugin_index_to_remove);
00574 plugin_index_to_remove = NULL;
00575 }
00576 number_of_plugins_to_remove = 0;
00577
00578 return error;
00579 }
00580
00581
00582
00583
00584 int splt_p_find_get_plugins_data(splt_state *state)
00585 {
00586 int return_value = SPLT_OK;
00587
00588 splt_d_print_debug(state,"\nSearching for plugins ...\n");
00589
00590
00591 return_value = splt_p_find_plugins(state);
00592
00593 if (return_value != SPLT_OK)
00594 {
00595 return return_value;
00596 }
00597 else
00598 {
00599
00600 return_value = splt_p_open_get_valid_plugins(state);
00601 }
00602
00603 if (return_value >= 0)
00604 {
00605 splt_plugins *pl = state->plug;
00606 splt_d_print_debug(state,"\nNumber of plugins found: _%d_\n", pl->number_of_plugins_found);
00607 int i = 0;
00608 int err = 0;
00609 for (i = 0;i < pl->number_of_plugins_found;i++)
00610 {
00611 pl->data[i].plugin_handle = lt_dlopen(pl->data[i].plugin_filename);
00612
00613 pl->data[i].func->check_plugin_is_for_file =
00614 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_check_plugin_is_for_file");
00615 pl->data[i].func->search_syncerrors =
00616 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_search_syncerrors");
00617 pl->data[i].func->dewrap =
00618 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_dewrap");
00619 pl->data[i].func->simple_split =
00620 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_simple_split");
00621 pl->data[i].func->split =
00622 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_split");
00623 pl->data[i].func->init =
00624 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_init");
00625 pl->data[i].func->end =
00626 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_end");
00627 pl->data[i].func->scan_silence =
00628 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_scan_silence");
00629 pl->data[i].func->scan_trim_silence =
00630 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_scan_trim_silence");
00631 pl->data[i].func->set_original_tags =
00632 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_set_original_tags");
00633 pl->data[i].func->clear_original_tags =
00634 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_clear_original_tags");
00635 pl->data[i].func->set_plugin_info =
00636 lt_dlsym(pl->data[i].plugin_handle, "splt_pl_set_plugin_info");
00637 if (pl->data[i].func->set_plugin_info != NULL)
00638 {
00639 splt_p_free_plugin_data_info(&pl->data[i]);
00640 pl->data[i].func->set_plugin_info(&pl->data[i].info,&err);
00641 }
00642
00643 splt_p_set_current_plugin(state, i);
00644 if (pl->data[i].plugin_filename != NULL)
00645 {
00646 splt_d_print_debug(state,"plugin filename = _%s_\n", pl->data[i].plugin_filename);
00647 }
00648
00649 const char *temp = splt_p_get_name(state, &err);
00650 splt_d_print_debug(state,"plugin name = _%s_\n", temp);
00651
00652 float version = splt_p_get_version(state, &err);
00653 splt_d_print_debug(state,"plugin version = _%lf_\n", version);
00654
00655 temp = splt_p_get_extension(state,&err);
00656 splt_d_print_debug(state,"extension = _%s_\n\n", temp);
00657 }
00658 }
00659 splt_p_set_current_plugin(state, -1);
00660
00661 return return_value;
00662 }
00663
00664
00665
00666 float splt_p_get_version(splt_state *state, int *error)
00667 {
00668 splt_plugins *pl = state->plug;
00669 int current_plugin = splt_p_get_current_plugin(state);
00670 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00671 {
00672 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00673 return 0;
00674 }
00675 else
00676 {
00677 return pl->data[current_plugin].info.version;
00678 }
00679 }
00680
00681 const char *splt_p_get_name(splt_state *state, int *error)
00682 {
00683 splt_plugins *pl = state->plug;
00684 int current_plugin = splt_p_get_current_plugin(state);
00685 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00686 {
00687 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00688 return NULL;
00689 }
00690 else
00691 {
00692 return pl->data[current_plugin].info.name;
00693 }
00694 }
00695
00696 const char *splt_p_get_extension(splt_state *state, int *error)
00697 {
00698 splt_plugins *pl = state->plug;
00699 int current_plugin = splt_p_get_current_plugin(state);
00700 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00701 {
00702 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00703 return NULL;
00704 }
00705 else
00706 {
00707 return pl->data[current_plugin].info.extension;
00708 }
00709 }
00710
00711 const char *splt_p_get_upper_extension(splt_state *state, int *error)
00712 {
00713 splt_plugins *pl = state->plug;
00714 int current_plugin = splt_p_get_current_plugin(state);
00715 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00716 {
00717 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00718 return NULL;
00719 }
00720 else
00721 {
00722 return pl->data[current_plugin].info.upper_extension;
00723 }
00724 }
00725
00726
00727
00728 int splt_p_check_plugin_is_for_file(splt_state *state, int *error)
00729 {
00730 splt_plugins *pl = state->plug;
00731 int current_plugin = splt_p_get_current_plugin(state);
00732 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00733 {
00734 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00735 return SPLT_FALSE;
00736 }
00737 else
00738 {
00739 if (pl->data[current_plugin].func->check_plugin_is_for_file != NULL)
00740 {
00741 return pl->data[current_plugin].func->check_plugin_is_for_file(state, error);
00742 }
00743 else
00744 {
00745 *error = SPLT_PLUGIN_ERROR_UNSUPPORTED_FEATURE;
00746 return SPLT_FALSE;
00747 }
00748 }
00749 }
00750
00751 void splt_p_search_syncerrors(splt_state *state, int *error)
00752 {
00753 splt_plugins *pl = state->plug;
00754 int current_plugin = splt_p_get_current_plugin(state);
00755 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00756 {
00757 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00758 return;
00759 }
00760 else
00761 {
00762 if (pl->data[current_plugin].func->search_syncerrors != NULL)
00763 {
00764 splt_se_serrors_free(state);
00765 pl->data[current_plugin].func->search_syncerrors(state, error);
00766 }
00767 else
00768 {
00769 *error = SPLT_PLUGIN_ERROR_UNSUPPORTED_FEATURE;
00770 }
00771 }
00772 }
00773
00774 void splt_p_dewrap(splt_state *state, int listonly, const char *dir, int *error)
00775 {
00776 splt_plugins *pl = state->plug;
00777 int current_plugin = splt_p_get_current_plugin(state);
00778 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00779 {
00780 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00781 return;
00782 }
00783 else
00784 {
00785 if (pl->data[current_plugin].func->dewrap != NULL)
00786 {
00787 pl->data[current_plugin].func->dewrap(state, listonly, dir, error);
00788 }
00789 else
00790 {
00791 *error = SPLT_PLUGIN_ERROR_UNSUPPORTED_FEATURE;
00792 }
00793 }
00794 }
00795
00796 double splt_p_split(splt_state *state, const char *final_fname, double begin_point,
00797 double end_point, int *error, int save_end_point)
00798 {
00799 splt_plugins *pl = state->plug;
00800 int current_plugin = splt_p_get_current_plugin(state);
00801 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00802 {
00803 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00804 return end_point;
00805 }
00806 else
00807 {
00808 int err = SPLT_OK;
00809
00810 splt_d_print_debug(state, "split creating directories of final fname ... _%s_\n", final_fname);
00811
00812 splt_io_create_output_dirs_if_necessary(state, final_fname, &err);
00813 if (err < 0) { *error = err; return end_point; }
00814
00815 if (pl->data[current_plugin].func->split != NULL)
00816 {
00817 double new_end_point = pl->data[current_plugin].func->split(state, final_fname,
00818 begin_point, end_point, error, save_end_point);
00819
00820 splt_d_print_debug(state, "New end point after split = _%lf_\n", new_end_point);
00821
00822 return new_end_point;
00823 }
00824 else
00825 {
00826 *error = SPLT_PLUGIN_ERROR_UNSUPPORTED_FEATURE;
00827 }
00828 }
00829
00830 return end_point;
00831 }
00832
00833 void splt_p_init(splt_state *state, int *error)
00834 {
00835 splt_plugins *pl = state->plug;
00836 int current_plugin = splt_p_get_current_plugin(state);
00837 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00838 {
00839 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00840 return;
00841 }
00842 else
00843 {
00844 if (pl->data[current_plugin].func->init != NULL)
00845 {
00846 pl->data[current_plugin].func->init(state, error);
00847 }
00848 else
00849 {
00850 *error = SPLT_PLUGIN_ERROR_UNSUPPORTED_FEATURE;
00851 }
00852 }
00853 }
00854
00855 void splt_p_end(splt_state *state, int *error)
00856 {
00857 splt_plugins *pl = state->plug;
00858 int current_plugin = splt_p_get_current_plugin(state);
00859 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00860 {
00861 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00862 return;
00863 }
00864 else
00865 {
00866 if (pl->data[current_plugin].func->end != NULL)
00867 {
00868 pl->data[current_plugin].func->end(state, error);
00869 }
00870 else
00871 {
00872 *error = SPLT_PLUGIN_ERROR_UNSUPPORTED_FEATURE;
00873 }
00874 }
00875 }
00876
00877 int splt_p_simple_split(splt_state *state, const char *output_fname, off_t begin,
00878 off_t end)
00879 {
00880 splt_plugins *pl = state->plug;
00881 int current_plugin = splt_p_get_current_plugin(state);
00882 int error = SPLT_OK;
00883 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00884 {
00885 error = SPLT_ERROR_NO_PLUGIN_FOUND;
00886 return error;
00887 }
00888 else
00889 {
00890 if (pl->data[current_plugin].func->simple_split != NULL)
00891 {
00892 error = pl->data[current_plugin].func->simple_split(state, output_fname, begin, end);
00893 }
00894 else
00895 {
00896 error = SPLT_PLUGIN_ERROR_UNSUPPORTED_FEATURE;
00897 }
00898 }
00899
00900 return error;
00901 }
00902
00903 int splt_p_scan_silence(splt_state *state, int *error)
00904 {
00905 splt_plugins *pl = state->plug;
00906 int current_plugin = splt_p_get_current_plugin(state);
00907 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00908 {
00909 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00910 return 0;
00911 }
00912 else
00913 {
00914 if (pl->data[current_plugin].func->scan_silence != NULL)
00915 {
00916 return pl->data[current_plugin].func->scan_silence(state, error);
00917 }
00918 else
00919 {
00920 *error = SPLT_PLUGIN_ERROR_UNSUPPORTED_FEATURE;
00921 }
00922 }
00923
00924 return 0;
00925 }
00926
00927 int splt_p_scan_trim_silence(splt_state *state, int *error)
00928 {
00929 splt_plugins *pl = state->plug;
00930 int current_plugin = splt_p_get_current_plugin(state);
00931 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00932 {
00933 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00934 return 0;
00935 }
00936 else
00937 {
00938 if (pl->data[current_plugin].func->scan_trim_silence != NULL)
00939 {
00940 return pl->data[current_plugin].func->scan_trim_silence(state, error);
00941 }
00942 else
00943 {
00944 *error = SPLT_PLUGIN_ERROR_UNSUPPORTED_FEATURE;
00945 }
00946 }
00947
00948 return 0;
00949 }
00950
00951 void splt_p_set_original_tags(splt_state *state, int *error)
00952 {
00953 splt_plugins *pl = state->plug;
00954 int current_plugin = splt_p_get_current_plugin(state);
00955 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00956 {
00957 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00958 return;
00959 }
00960 else
00961 {
00962 if (pl->data[current_plugin].func->set_original_tags != NULL)
00963 {
00964 pl->data[current_plugin].func->set_original_tags(state, error);
00965 }
00966 }
00967 }
00968
00969 void splt_p_clear_original_tags(splt_state *state, int *error)
00970 {
00971 splt_plugins *pl = state->plug;
00972 int current_plugin = splt_p_get_current_plugin(state);
00973 if ((current_plugin < 0) || (current_plugin >= pl->number_of_plugins_found))
00974 {
00975 *error = SPLT_ERROR_NO_PLUGIN_FOUND;
00976 return;
00977 }
00978 else
00979 {
00980 if (pl->data[current_plugin].func->clear_original_tags != NULL)
00981 {
00982 pl->data[current_plugin].func->clear_original_tags(&state->original_tags);
00983 }
00984 }
00985 }
00986
00987 static int splt_p_set_default_plugins_scan_dirs(splt_state *state)
00988 {
00989 int err = SPLT_OK;
00990 char *dir = NULL;
00991
00992 #ifndef __WIN32__
00993 err = splt_p_append_plugin_scan_dir(state, SPLT_PLUGINS_DIR);
00994 if (err < 0) { return err; }
00995 #endif
00996
00997 err = splt_su_append_str(&dir, getenv("HOME"), SPLT_DIRSTR, ".libmp3splt", NULL);
00998 if (err < 0) { goto end; }
00999 err = splt_p_append_plugin_scan_dir(state, dir);
01000 free(dir);
01001 dir = NULL;
01002
01003 err = splt_su_append_str(&dir, ".", SPLT_DIRSTR, NULL);
01004 if (err < 0) { goto end; }
01005 err = splt_p_append_plugin_scan_dir(state, dir);
01006
01007 end:
01008 if (dir)
01009 {
01010 free(dir);
01011 dir = NULL;
01012 }
01013
01014 return err;
01015 }
01016
01017 int splt_p_set_default_values(splt_state *state)
01018 {
01019 state->plug->plugins_scan_dirs = NULL;
01020 state->plug->number_of_plugins_found = 0;
01021 state->plug->data = NULL;
01022 state->plug->number_of_dirs_to_scan = 0;
01023
01024 return splt_p_set_default_plugins_scan_dirs(state);
01025 }
01026
01027 void splt_p_free_plugins(splt_state *state)
01028 {
01029 splt_plugins *pl = state->plug;
01030 int i = 0;
01031
01032 if (pl->plugins_scan_dirs)
01033 {
01034 for (i = 0;i < pl->number_of_dirs_to_scan;i++)
01035 {
01036 if (pl->plugins_scan_dirs[i])
01037 {
01038 free(pl->plugins_scan_dirs[i]);
01039 pl->plugins_scan_dirs[i] = NULL;
01040 }
01041 }
01042 free(pl->plugins_scan_dirs);
01043 pl->plugins_scan_dirs = NULL;
01044 pl->number_of_dirs_to_scan = 0;
01045 }
01046 if (pl->data)
01047 {
01048 for (i = 0;i < pl->number_of_plugins_found;i++)
01049 {
01050 splt_p_free_plugin_data(&pl->data[i]);
01051 }
01052 free(pl->data);
01053 pl->data = NULL;
01054 pl->number_of_plugins_found = 0;
01055 }
01056 }
01057
01058 void splt_p_set_current_plugin(splt_state *state, int current_plugin)
01059 {
01060
01061 if (current_plugin >= -1)
01062 {
01063 state->current_plugin = current_plugin;
01064 }
01065 else
01066 {
01067 splt_e_error(SPLT_IERROR_INT,__func__, current_plugin, NULL);
01068 }
01069 }
01070
01071 int splt_p_get_current_plugin(splt_state *state)
01072 {
01073 return state->current_plugin;
01074 }
01075
01076 int splt_p_file_is_supported_by_plugins(splt_state *state, const char *fname)
01077 {
01078 splt_plugins *pl = state->plug;
01079
01080 int fname_length = strlen(fname);
01081 if (fname_length > 3)
01082 {
01083 char *ptr_to_compare = strrchr(fname, '.');
01084 if (ptr_to_compare)
01085 {
01086 int i = 0;
01087 for (i = 0;i < pl->number_of_plugins_found;i++)
01088 {
01089 char *pl_extension = pl->data[i].info.extension;
01090 char *pl_upper_extension = pl->data[i].info.upper_extension;
01091
01092 if ((strcmp(ptr_to_compare, pl_extension) == 0) ||
01093 (strcmp(ptr_to_compare, pl_upper_extension) == 0))
01094 {
01095 return SPLT_TRUE;
01096 }
01097 }
01098 }
01099 }
01100
01101 return SPLT_FALSE;
01102 }
01103