Example #1
0
/* tell FIFO client what happened via reply pipe */
void fifo_reply( char *reply_fifo, char *reply_fmt, ... )
{
	FILE *file_handle;
	int r;
	va_list ap;

	file_handle=open_reply_pipe(reply_fifo);
	if (file_handle==0) {
		LOG(L_ERR, "ERROR: fifo_reply: no reply pipe %s\n",
			reply_fifo);
		return;
	}
retry:
	va_start(ap, reply_fmt);
	r=vfprintf(file_handle, reply_fmt, ap);
	va_end(ap);
	if (r<=0) {
		LOG(L_ERR, "ERROR: fifo_error: write error (%s): %s\n",
			fifo, strerror(errno));
		if ((errno==EINTR)||(errno==EAGAIN)||(errno==EWOULDBLOCK)) {
			goto retry;
		}
	}
	fclose(file_handle);
}
Example #2
0
/*
 * Send a reply, either positive or negative, to the client
 */
static int rpc_send(rpc_ctx_t* ctx) 
{
	struct iovec v[MAX_MSG_CHUNKS];
	int f;
	int n;
	int ret;
	/* Send the reply only once */
	if (ctx->reply_sent) return 1;
	else ctx->reply_sent = 1;
	
	if ((n=build_iovec(ctx, v, MAX_MSG_CHUNKS))<0)
		goto error;
	if (ctx->send_h->type==S_FIFO){
	/* Open the reply file */
		f = open_reply_pipe(ctx->reply_file);
		if (f == -1) {
			ERR("No reply pipe %s\n", ctx->reply_file);
			return -1;
		}
		ret=tsend_dgram_ev(f, v, n, FIFO_TX_TIMEOUT);
		close(f);
	}else{
		ret=sock_send_v(ctx->send_h, v, n);
	}
	return (ret>=0)?0:-1;
error:
	ERR("rpc_send fifo error\n");
	return -1;
}
Example #3
0
int static ul_dump(FILE* pipe, char* response_file)
{
	FILE* reply_file;

	reply_file=open_reply_pipe(response_file);
	if (reply_file==0) {
		LOG(L_ERR, "ERROR: ul_dump: file not opened\n");
		return -1;
	}
	fputs( "200 ok\n", reply_file);
	print_all_udomains(reply_file);
	fclose(reply_file);
	return 1;
}
Example #4
0
/*
 * Fifo function to print gws from current gw table
 */
static int lcr_dump ( FILE* pipe, char* response_file )
{
    FILE *reply_file;

    reply_file=open_reply_pipe(response_file);
    if (reply_file==0) {
        LOG(L_ERR, "lcr_dump(): Opening of response file failed\n");
        return -1;
    }
    fputs( "200 OK\n", reply_file );
    print_gws(reply_file );
    fclose(reply_file);
    return 1;
}
Example #5
0
/* print accumulated distribution of the hash table */
int fifo_hash( FILE *stream, char *response_file )
{
	FILE *reply_file;
	unsigned int i;

	reply_file=open_reply_pipe(response_file);
	if (reply_file==0) {
		LOG(L_ERR, "ERROR: fifo_hash: file '%s' not opened\n", 
			response_file);
		return -1;
	}
	fputs( "200 ok\n\tcurrent\ttotal\n", reply_file);
	for (i=0; i<TABLE_ENTRIES; i++) {
		fprintf(reply_file, "%d.\t%lu\t%lu\n", 
			i, tm_table->entrys[i].cur_entries ,
			tm_table->entrys[i].acc_entries );
	}
	fclose(reply_file);
	return 1;
}
Example #6
0
int static fifo_stats( FILE *pipe, char *response_file )
{
	FILE *file;

	if (response_file==0 || *response_file==0 ) {
		LOG(L_ERR, "ERROR: fifo_stats: null file\n");
		return -1;
	}

	file=open_reply_pipe(response_file );
	if (file==NULL) {
		LOG(L_ERR, "ERROR: fifo_stats: file %s bad: %s\n",
			response_file, strerror(errno) );
		return -1;
	}
	fputs( "200 ok\n", file);
	print_stats( file );
	fclose(file);
	
	return 1;

}
Example #7
0
static int arg_cmd( FILE *stream, char *response_file )
{
	FILE *reply_pipe;
	int p;

	if (response_file==0 || *response_file==0 ) {
		 LOG(L_ERR, "ERROR: ps_fifo_cmd: null file\n");
		return -1;
	}
	reply_pipe=open_reply_pipe(response_file);
	if (reply_pipe==NULL) {
		LOG(L_ERR, "ERROR: ps_fifo_cmd: opening reply pipe (%s) failed\n",
			response_file );
		return -1;
	}

	fputs( "200 ok\n", reply_pipe);
	for (p=0; p<my_argc;p++) 
			fprintf( reply_pipe, "%s\n", my_argv[p] );
			
	fclose(reply_pipe);
	return 1;
}
Example #8
0
static int ps_fifo_cmd(FILE *stream, char *response_file )
{
	FILE *reply_pipe;
	int p;

	if (response_file==0 || *response_file==0 ) {
		 LOG(L_ERR, "ERROR: ps_fifo_cmd: null file\n");
		return -1;
	}
	reply_pipe=open_reply_pipe(response_file);
	if (reply_pipe==NULL) {
		LOG(L_ERR, "ERROR: ps_fifo_cmd: opening reply pipe (%s) failed\n",
			response_file );
		return -1;
	}

	fputs( "200 ok\n", reply_pipe);
	for (p=0; p<process_count();p++) 
		fprintf( reply_pipe, "%d\t%d\t%s\n",
			p, pt[p].pid, pt[p].desc );

	fclose(reply_pipe);
	return 1;
}
Example #9
0
static int which_fifo_cmd(FILE *stream, char *response_file )
{
	FILE *reply_pipe;
	struct fifo_command *c;

	if (response_file==0 || *response_file==0 ) {
		 LOG(L_ERR, "ERROR: which_fifo_cmd: null file\n");
		return -1;
	}

	reply_pipe=open_reply_pipe(response_file);
	if (reply_pipe==NULL) {
		LOG(L_ERR, "ERROR: which_fifo_cmd: opening reply pipe (%s) failed\n",
			response_file );
		return -1;
	}
	fputs( "200 ok\n", reply_pipe);
	for(c=cmd_list; c; c=c->next) {
		fprintf( reply_pipe, "%s\n", c->name );
	}

	fclose(reply_pipe);
	return 1;
}
Example #10
0
static inline int ul_show_contact(FILE* pipe, char* response_file)
{
	char table[MAX_TABLE];
	char user[MAX_USER];
	FILE* reply_file;
	udomain_t* d;
	urecord_t* r;
	int res;
	str t, aor;
	char* at;

	if (!read_line(table, MAX_TABLE, pipe, &t.len) || t.len ==0) {
		fifo_reply(response_file, 
			   "400 ul_show_contact: table name expected\n");
		LOG(L_ERR, "ERROR: ul_show_contact: table name expected\n");
		return 1;
	}
	if (!read_line(user, MAX_USER, pipe, &aor.len) || aor.len==0) {
		fifo_reply(response_file, 
			   "400 ul_show_contact: user name expected\n");
		LOG(L_ERR, "ERROR: ul_show_contact: user name expected\n");
		return 1;
	}
	
	at = memchr(user, '@', aor.len);

	if (use_domain) {
		if (!at) {
			fifo_reply(response_file,
				   "400 ul_show_contact: user@domain expected\n");
			LOG(L_ERR, "ERROR: ul_show_contact: Domain missing\n");
			return 1;
		}
	} else {
		if (at) {
			aor.len = at - user;
		}
	}

	aor.s = user;
	strlower(&aor);

	t.s = table;
	
	fifo_find_domain(&t, &d);

	if (d) {
		lock_udomain(d);	

		res = get_urecord(d, &aor, &r);
		if (res < 0) {
			fifo_reply(response_file, "500 Error while looking for username %s in table %s\n", user, table);
			LOG(L_ERR, "ERROR: ul_show_contact: Error while looking for username %s in table %s\n", user, table);
			unlock_udomain(d);
			return 1;
		}
		
		if (res > 0) {
			fifo_reply(response_file, "404 Username %s in table %s not found\n", user, table);
			unlock_udomain(d);
			return 1;
		}
		
		get_act_time();

		reply_file=open_reply_pipe(response_file);
		if (reply_file==0) {
			LOG(L_ERR, "ERROR: ul_show_contact: file not opened\n");
			unlock_udomain(d);
			return 1;
		}

		if (!print_contacts(reply_file, r->contacts)) {
			unlock_udomain(d);
			fprintf(reply_file, "404 No registered contacts found\n");
			fclose(reply_file);
			return 1;
		}

		fclose(reply_file);
		unlock_udomain(d);
		return 1;
	} else {
		fifo_reply(response_file, "400 table (%s) not found\n", table);
		return 1;
	}
}