static int setMcastInfo( McastInfo** const mcastInfo, const feedtypet feedtype) { ServiceAddr* mcastServAddr; int status = sa_new(&mcastServAddr, "224.0.0.1", 38800); if (status) { LOG_ADD0("Couldn't create multicast service address object"); } else { ServiceAddr* ucastServAddr; status = sa_new(&ucastServAddr, LOCAL_HOST, 0); if (status) { LOG_ADD0("Couldn't create unicast service address object"); } else { status = mi_new(mcastInfo, feedtype, mcastServAddr, ucastServAddr); if (status) { LOG_ADD0("Couldn't create multicast information object"); } else { sa_free(ucastServAddr); sa_free(mcastServAddr); } } } return status; }
static void init() { ServiceAddr* groupAddr = sa_new(GROUP_ADDR, GROUP_PORT); OP_ASSERT_TRUE(groupAddr != NULL); ServiceAddr* serverAddr = sa_new(SERVER_ADDR, SERVER_PORT); OP_ASSERT_TRUE(serverAddr != NULL); mcastInfo = mi_new(feedtype, groupAddr, serverAddr); OP_ASSERT_TRUE(mcastInfo != NULL); sa_free(groupAddr); sa_free(serverAddr); prodQ = (void*)2; }
/* * Loads a playlist from the provided filename. The files within the playlist * are compared against the given meta-information-database to see if they * exist there. If they do, the corresponding entry in the playlist structure * built is simply a pointer to the existing entry. Otherwise, that file's * meta information is set to NULL and the file is copied (allocated) in the * playlist structure. * * A newly allocated playlist is returned. */ playlist * playlist_load(const char *filename, meta_info **db, int ndb) { meta_info *mi, **mit; FILE *fin; char *period; char entry[PATH_MAX + 1]; /* open file */ if ((fin = fopen(filename, "r")) == NULL) err(1, "playlist_load: failed to open playlist '%s'", filename); /* create playlist and setup */ playlist *p = playlist_new(); p->filename = strdup(filename); p->name = strdup(basename(filename)); if (p->filename == NULL || p->name == NULL) err(1, "playlist_load: failed to allocate info for playlist '%s'", filename); /* hack to remove '.playlist' from name */ period = strrchr(p->name, '.'); *period = '\0'; /* read each line from the file and copy into playlist object */ while (fgets(entry, PATH_MAX, fin) != NULL) { /* sanitize */ entry[strcspn(entry, "\n")] = '\0'; /* check if file exists in the meta info. db */ mit = bsearch(entry, db, ndb, sizeof(meta_info *), cmp_fn_mi); mi = *mit; if (mi != NULL) /* file DOES exist in DB */ playlist_files_append(p, &mi, 1, false); else { /* file does NOT exist in DB */ /* create empty meta-info object with just the file name */ mi = mi_new(); mi->filename = strdup(entry); if (mi->filename == NULL) err(1, "playlist_load: failed to strdup filename"); /* add new record to the db and link it to the playlist */ playlist_files_append(p, &mi, 1, false); warnx("playlist \"%s\", file \"%s\" is NOT in media database (added for now)", p->name, entry); } } fclose(fin); return p; }
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; }