Exemple #1
0
void
fdpass_close(struct fdpass *f)
{
	fdpass_peer = NULL;
	file_del(f->file);
	close(f->fd);
	xfree(f);
}
Exemple #2
0
void console_backspace() {

    /* do backspace: */
    if (!cursor_off)
        return;
    file_del(cursor_off-1);
    console_update();
    console_left();
}
Exemple #3
0
void
dev_sio_close(struct dev *d)
{
#ifdef DEBUG
	if (log_level >= 3) {
		dev_log(d);
		log_puts(": closed\n");
	}
#endif
	timo_del(&d->sio.watchdog);
	file_del(d->sio.file);
	sio_close(d->sio.hdl);
}
Exemple #4
0
void file_refresh_info(mdb_conn *conn, int id, char *url, int pid)
{
    file_t *fl;
    int ret;

    ret = file_get_info_by_id(conn, id, url, pid, &fl);
    if (ret != RET_RBTOP_OK) {
        mtc_err("get info failure %d %s %d", id, url, pid);
        return;
    }
    file_refresh_me(fl);
    file_del(fl);
}
Exemple #5
0
int file_get_files(HDF *hdf, mdb_conn *conn, session_t *ses)
{
    PRE_DBOP(hdf, conn);

    int ret, cnt = 0;
    char tok[LEN_MD];
    int count, offset, uin, pid;
    ULIST *gnode;
    gnode_t *node;
    member_t *mb;
    file_t *fl;

    pid = hdf_get_int_value(hdf, PRE_QUERY".pid", 1);

    //sprintf(tok, "pid=%d", pid);
    //mmisc_set_count(hdf, conn, "fileinfo", tok);
    mmisc_get_offset(hdf, &count, &offset);

    if (member_has_login(hdf, conn, ses) != RET_RBTOP_OK) {
        return RET_RBTOP_NOTLOGIN;
    }

    if (!member_has_gmode(ses->member, GROUP_MODE_SENIOR, GROUP_STAT_OK)) {
        mtc_warn("%d attemped to list sys-file", ses->member->uin);
        return RET_RBTOP_LIMITE;
    }

    ret = member_get_group(ses->member, GROUP_MODE_SENIOR, GROUP_STAT_OK, &gnode);
    if (ret != RET_RBTOP_OK) {
        mtc_err("get %d %d failure", ses->member->uin, GROUP_MODE_SENIOR);
        return ret;
    }

    MLIST_ITERATE(gnode, node) {
        ret = file_get_info_by_id(conn, node->gid, NULL, -1, &fl);
        if (ret != RET_RBTOP_OK) {
            mtc_err("get %d info failure", node->gid);
            continue;
        }
        sprintf(tok, "%s.files.%d", PRE_OUTPUT, cnt++);
        file_item2hdf(fl, tok, hdf);
        file_del(fl);
    }
Exemple #6
0
void
listen_close(struct listen *f)
{
	struct listen **pf;

	for (pf = &listen_list; *pf != f; pf = &(*pf)->next) {
#ifdef DEBUG
		if (*pf == NULL) {
			log_puts("listen_close: not on list\n");
			panic();
		}
#endif
	}
	*pf = f->next;

	if (f->path != NULL) {
		unlink(f->path);
		xfree(f->path);
	}
	file_del(f->file);
	close(f->fd);
	xfree(f);
}
Exemple #7
0
int tjt_get_data(HDF *hdf, HASH *dbh, session_t *ses)
{
    char *buf, tbl[LEN_TB];
    size_t datalen;
    file_t *fl;
    ULIST *ul = NULL;
    int count, offset, aid, fid, ret;

    mdb_conn *dbsys, *dbtjt;

    dbsys = (mdb_conn*)hash_lookup(dbh, "Sys");
    dbtjt = (mdb_conn*)hash_lookup(dbh, "Tjt");

    PRE_DBOP(hdf, dbsys);
    PRE_DBOP(hdf, dbtjt);

    aid = ses->file->aid;
    fid = ses->file->id;
    snprintf(tbl, sizeof(tbl), "tjt_%d", aid);

    /* TODO ses->file not null all time? */
    //if (ses->file != NULL)
    lutil_fill_layout_by_file(dbsys, ses->file, hdf);
    if (file_get_info_by_id(dbsys, aid, NULL, -1, &fl) == RET_RBTOP_OK) {
        hdf_set_value(hdf, PRE_OUTPUT".navtitle", fl->remark);
        file_del(fl);
    }
    file_get_nav_by_id(dbsys, aid, PRE_OUTPUT, hdf);

    ret = file_check_user_power(hdf, dbsys, ses, ses->file, LMT_APPEND);
    if (ret == RET_RBTOP_OK) {
        hdf_set_value(hdf, PRE_OUTPUT".appendable", "1");
    }

    lutil_fetch_countf(hdf, dbtjt, tbl, "fid=%d", fid);
    mmisc_get_offset(hdf, &count, &offset);

    buf = mmc_getf(&datalen, 0, PRE_MMC_TJT".%d.%d", fid, offset);
    if (buf == NULL || datalen < sizeof(tjt_t)) {
        LDB_QUERY_RAW(dbtjt, "tjt_%d", TJT_QUERY_COL, "fid=%d ORDER BY uptime "
                      " LIMIT %d OFFSET %d", NULL, aid, fid, count, offset);
        mdb_set_rows(hdf, dbtjt, TJT_QUERY_COL, PRE_OUTPUT".atoms");
        lutil_image_expand(hdf, PRE_OUTPUT".atoms", "img", IMG_PATH, IMG_S, "imgurl");
        lcs_hdf2list(hdf, PRE_OUTPUT".atoms", tjt_hdf2item, &ul);
        ret = list_pack(ul, TJT_LEN, tjt_pack_nalloc, &buf, &datalen);
        if (ret == RET_RBTOP_OK) {
            mmc_storef(MMC_OP_SET, buf, datalen, HALF_HOUR, 0, PRE_MMC_TJT".%d.%d",
                       fid, offset);
        }
    } else {
        list_unpack(buf, tjt_unpack, datalen, &ul);
        ret = lcs_list2hdf(ul, PRE_OUTPUT".atoms", tjt_item2hdf, hdf);
        if (ret != RET_RBTOP_OK) {
            mtc_err("assembly tjt from mmc error");
            return RET_RBTOP_MMCERR;
        }
    }
    uListDestroyFunc(&ul, tjt_del);
    free(buf);

    return ret;
}
Exemple #8
0
/*
 * create a file writer in the ``INIT'' state
 */
struct wav *
wav_new_out(struct fileops *ops, struct dev *dev,
    unsigned int mode, char *name, unsigned int hdr,
    struct aparams *par, unsigned int xrun, int mmc, int join)
{
	int fd;
	struct wav *f;

	if (!wav_autohdr(name, dev, &hdr, &mode))
		return NULL;
	if (strcmp(name, "-") == 0) {
		fd = STDOUT_FILENO;
		if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
			perror(name);
	} else {
		fd = open(name,
		    O_WRONLY | O_TRUNC | O_CREAT | O_NONBLOCK, 0666);
		if (fd < 0) {
			perror(name);
			return NULL;
		}
	}
	f = (struct wav *)pipe_new(ops, fd, name);
	if (f == NULL) {
		close(fd);
		return NULL;
	}
	f->mode = mode;
	f->pstate = WAV_CFG;
	f->endpos = f->startpos = 0;
	f->next = wav_list;
	wav_list = f;
	if (hdr == HDR_WAV) {
		par->le = 1;
		par->sig = (par->bits <= 8) ? 0 : 1;
		par->bps = (par->bits + 7) / 8;
		if (!wav_writehdr(f->pipe.fd, par, &f->startpos, 0)) {
			file_del((struct file *)f);
			return NULL;
		}
		f->wbytes = WAV_DATAMAX;
		f->endpos = f->startpos;
	} else
		f->wbytes = -1;
	f->dev = dev;
	f->mmc = mmc;
	f->join = join;
	f->hpar = *par;
	f->hdr = hdr;
	f->xrun = xrun;
	wwav_new((struct file *)f);
#ifdef DEBUG
	if (debug_level >= 2) {
		dbg_puts(name);
		dbg_puts(":");
		if (f->mode & MODE_RECMASK) {
			dbg_puts(" recording ");
			aparams_dbg(par);
			if (f->mmc)
				dbg_puts(", mmc");
		}
		if (f->mode & MODE_MIDIIN)
			dbg_puts(" midi/in");
		dbg_puts("\n");
	}
#endif
	return f;
}
Exemple #9
0
/*
 * create a file reader in the ``INIT'' state
 */
struct wav *
wav_new_in(struct fileops *ops, struct dev *dev,
    unsigned int mode, char *name, unsigned int hdr,
    struct aparams *par, unsigned int xrun,
    unsigned int volctl, int mmc, int join)
{
	int fd;
	struct wav *f;

	if (!wav_autohdr(name, dev, &hdr, &mode))
		return NULL;
	if (strcmp(name, "-") == 0) {
		fd = STDIN_FILENO;
		if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
			perror(name);
	} else {
		fd = open(name, O_RDONLY | O_NONBLOCK, 0666);
		if (fd < 0) {
			perror(name);
			return NULL;
		}
	}
	f = (struct wav *)pipe_new(ops, fd, name);
	if (f == NULL) {
		close(fd);
		return NULL;
	}
	f->mode = mode;
	f->pstate = WAV_CFG;
	f->endpos = f->startpos = 0;
	f->next = wav_list;
	wav_list = f;
	if (hdr == HDR_WAV) {
		if (!wav_readhdr(f->pipe.fd, par,
			&f->startpos, &f->rbytes, &f->map)) {
			file_del((struct file *)f);
			return NULL;
		}
		f->endpos = f->startpos + f->rbytes;
	} else {
		f->endpos = pipe_endpos(&f->pipe.file);
		if (f->endpos > 0) {
			if (!pipe_seek(&f->pipe.file, 0)) {
				file_del((struct file *)f);
				return NULL;
			}
			f->rbytes = f->endpos;
		} else
			f->rbytes = -1;
		f->map = NULL;
	}
	f->dev = dev;
	f->mmc = mmc;
	f->join = join;
	f->mode = mode;
	f->hpar = *par;
	f->hdr = hdr;
	f->xrun = xrun;
	f->maxweight = MIDI_TO_ADATA(volctl);
	f->slot = -1;
	rwav_new((struct file *)f);
#ifdef DEBUG
	if (debug_level >= 2) {
		dbg_puts(name);
		dbg_puts(":");
		if (f->mode & MODE_PLAY) {
			dbg_puts(" playing ");
			aparams_dbg(par);
			dbg_puts(" ");
			dbg_putu(f->startpos);
			dbg_puts("..");
			dbg_putu(f->endpos);
			if (f->mmc)
				dbg_puts(", mmc");
		}
		if (f->mode & MODE_MIDIOUT)
			dbg_puts(" midi/out");
		dbg_puts("\n");
	}
#endif
	return f;
}
Exemple #10
0
static void corecmd_run(uint cmd, void *udata)
{
	dbglog("%s cmd:%u  udata:%p", __func__, cmd, udata);

	switch ((enum ACTION)cmd) {

	case A_SHOWPCM:
		file_showpcm();
		break;

	case A_DELFILE:
		file_del();
		break;

	case A_PLAY:
		if (gg->curtrk != NULL)
			gg->track->cmd(gg->curtrk->trk, FMED_TRACK_STOP);
		gg->qu->cmd(FMED_QUE_PLAY, (void*)gg->qu->fmed_queue_item(-1, gg->focused));
		break;

	case A_PLAYPAUSE:
		if (gg->curtrk == NULL) {
			gg->qu->cmd(FMED_QUE_PLAY, NULL);
			break;
		}

		if (gg->curtrk->paused) {
			gg->curtrk->paused = 0;
			wmain_status("");
			gg->curtrk->d->snd_output_pause = 0;
			gg->track->cmd(gg->curtrk->trk, FMED_TRACK_UNPAUSE);
			break;
		}

		gg->curtrk->d->snd_output_pause = 1;
		wmain_status("Paused");
		gg->curtrk->paused = 1;
		break;

	case A_STOP:
		gg->track->cmd(NULL, FMED_TRACK_STOPALL);
		break;

	case A_STOP_AFTER:
		gg->qu->cmd(FMED_QUE_STOP_AFTER, NULL);
		break;

	case A_NEXT:
	case A_PREV: {
		if (gg->curtrk != NULL)
			gg->track->cmd(gg->curtrk->trk, FMED_TRACK_STOP);
		uint id = (cmd == A_NEXT) ? FMED_QUE_NEXT2 : FMED_QUE_PREV2;
		gg->qu->cmd(id, (gg->curtrk != NULL) ? gg->curtrk->qent : NULL);
		break;
	}

	case A_SEEK:
	case A_FFWD:
	case A_RWND:
	case A_LEAP_FWD:
	case A_LEAP_BACK:
		gtrk_seek(cmd, (size_t)udata);
		break;
	case A_SETGOPOS:
		if (gg->curtrk != NULL) {
			gg->go_pos = gg->curtrk->time_cur;
			wmain_status("Marker: %u:%02u"
				, gg->go_pos / 60, gg->go_pos % 60);
		}
		break;
	case A_GOPOS:
		if (gg->curtrk != NULL && gg->go_pos != (uint)-1)
			gg->curtrk->time_seek = gg->go_pos;
		break;

	case A_VOL:
		gg->vol = (size_t)udata;
		gtrk_vol(gg->vol);
		break;
	case A_VOLUP:
		gg->vol = ffmin(gg->vol + 5, MAXVOL);
		gtrk_vol(gg->vol);
		break;
	case A_VOLDOWN:
		gg->vol = ffmax((int)gg->vol - 5, 0);
		gtrk_vol(gg->vol);
		break;
	case A_VOLRESET:
		gg->vol = 100;
		gtrk_vol(gg->vol);
		break;

	case A_LIST_SAVE: {
		char *list_fn = udata;
		gg->qu->fmed_queue_save(-1, list_fn);
		ffmem_free(list_fn);
		break;
	}
	case A_LIST_REMOVE:
		list_rmitems();
		break;

	case A_LIST_RMDEAD:
		gg->qu->cmd(FMED_QUE_RMDEAD, NULL);
		break;

	case A_LIST_CLEAR:
		gg->qu->cmd(FMED_QUE_CLEAR | FMED_QUE_NO_ONCHANGE, NULL);
		ffui_post_view_clear(&gg->wmain.vlist);
		break;

	case A_LIST_RANDOM:
		core->props->list_random = !core->props->list_random;
		break;

	case A_ONDROPFILE: {
		ffstr *d = udata;
		ffstr s = *d, ln;
		while (s.len != 0) {
			ffstr_nextval3(&s, &ln, '\n');
			if (!ffs_matchz(ln.ptr, ln.len, "file://"))
				continue;
			ffstr_shift(&ln, FFSLEN("file://"));
			wmain_ent_add(&ln);
		}
		ffstr_free(d);
		ffmem_free(d);
		break;
	}

	case A_URL_ADD: {
		ffstr *s = udata;
		wmain_ent_add(s);
		ffstr_free(s);
		ffmem_free(s);
		break;
	}

	case A_ONCLOSE:
		if (gg->conf.autosave_playlists)
			lists_save();
		core->sig(FMED_STOP);
		break;

	case LOADLISTS:
		lists_load();
		break;

	default:
		FF_ASSERT(0);
	}
}