static int sender_start( const feedtypet feedtype) { // The following ensures that the first product-index will be 0 int status = pim_delete(NULL, feedtype); if (status) { LOG_ADD1("Couldn't delete product-index map for feedtype %#lx", feedtype); } else { status = createEmptyProductQueue(UP7_PQ_PATHNAME); if (status) { LOG_ADD1("Couldn't create empty product queue \"%s\"", UP7_PQ_PATHNAME); } else { // Thread-safe because 2 threads: upstream LDM-7 & product insertion. status = pq_open(getQueuePath(), PQ_READONLY | PQ_THREADSAFE, &pq); if (status) { LOG_ADD1("Couldn't open product-queue \"%s\"", getQueuePath()); } else { McastInfo* mcastInfo; status = setMcastInfo(&mcastInfo, feedtype); if (status) { LOG_ADD0("Couldn't set multicast information"); } else { status = mlsm_clear(); status = mlsm_addPotentialSender(mcastInfo, 2, LOCAL_HOST, UP7_PQ_PATHNAME); if (status) { LOG_ADD0("mlsm_addPotentialSender() failure"); } else { // Starts the sender on a new thread status = sender_spawn(); if (status) { LOG_ADD0("Couldn't spawn sender"); } else { done = 0; } } mi_free(mcastInfo); } // `mcastInfo` allocated if (status) (void)pq_close(pq); } // Product-queue open if (status) (void)deleteProductQueue(UP7_PQ_PATHNAME); } // empty product-queue created } // product-index map deleted return status; }
static int config_module(void) { struct module_info mi; int ret; memset(&mi, 0, sizeof(mi)); ret = csv_load("modules.csv", &mi, mi_field, mi_row_end); mi_free(&mi); return ret; }
static int mi_row_end(void *p, unsigned row) { struct module_info *mi = p; struct module *mod; assert(mi != NULL); if (!row) /* ignore first row */ return 0; if (!mi->module || !mi->dll_path) return -1; mod = mo_load(mi->module, mi->dll_path, mi->args); if (!mod) return -1; mi_free(mi); return 0; }
int ecmd_addurl(int argc, char *argv[]) { meta_info *m; bool found; int found_idx; char input[255]; int field, i; if (argc != 2) errx(1, "usage: -e %s filename|URL", argv[0]); /* start new record, set filename */ m = mi_new(); m->is_url = true; if ((m->filename = strdup(argv[1])) == NULL) err(1, "%s: strdup failed (filename)", argv[0]); /* get fields from user */ for (field = 0; field < MI_NUM_CINFO; field++) { printf("%10.10s: ", MI_CINFO_NAMES[field]); if (fgets(input, sizeof(input), stdin) == NULL) { warnx("Operation canceled. Database unchanged."); mi_free(m); return 0; } if (input[strlen(input) - 1] == '\n') input[strlen(input) - 1] = '\0'; if ((m->cinfo[field] = strdup(input)) == NULL) err(1, "%s: strdup failed (field)", argv[0]); } /* load existing database and see if file/URL already exists */ medialib_load(db_file, playlist_dir); /* does the URL already exist in the database? */ found = false; found_idx = -1; for (i = 0; i < mdb.library->nfiles && !found; i++) { if (strcmp(m->filename, mdb.library->files[i]->filename) == 0) { found = true; found_idx = i; } } if (found) { printf("Warning: file/URL '%s' already in the database.\n", argv[0]); printf("Do you want to replace the existing record? [y/n] "); if (fgets(input, sizeof(input), stdin) == NULL || (strcasecmp(input, "yes\n") != 0 && strcasecmp(input, "y\n") != 0)) { warnx("Operation Canceled. Database unchanged."); mi_free(m); medialib_destroy(); return 0; } mi_sanitize(m); playlist_file_replace(mdb.library, found_idx, m); } else { mi_sanitize(m); playlist_files_append(mdb.library, &m, 1, false); } medialib_db_save(db_file); medialib_destroy(); return 0; }
/* Dispose of workspace */ void wsfree() { if(_gws.m) free(_gws.m); if(_gws.s) free(_gws.s); if(_gws.mi) mi_free(_gws.mi); if(_gws.si) si_free(_gws.si); }