Exemple #1
0
static int pwd_cmd( FILE *stream, char *response_file )
{
	char *cwd_buf;
	int max_len;

	if (!response_file) {
		LOG(L_ERR, "ERROR: no file for %s\n", "pwd_cmd" );
		return 1;
	}

	max_len=pathmax();
	cwd_buf=pkg_malloc(max_len);
	if (!cwd_buf) {
		LOG(L_ERR, "ERROR: pwd_cmd: no cwd pkg mem\n");
		fifo_reply(response_file, "500 no memory\n");
		return 1;
	}

	if (getcwd(cwd_buf, max_len)) {
		fifo_reply(response_file, "200 ok\n%s\n", cwd_buf );
	} else {
		fifo_reply(response_file, "500 getcwd failed\n" );
	}

	pkg_free(cwd_buf);
	return 1;
}
Exemple #2
0
static int pwd_cmd(str* msg)
{
	char *cwd_buf;
	int max_len, ret;

	max_len = pathmax();
	cwd_buf = pkg_malloc(max_len);
	ret = 0;
	if (!cwd_buf) {
		LOG(L_ERR, "pwd_cmd: No memory left\n");
		unixsock_reply_asciiz("500 No Memory Left\n");
		ret = -1;
	}

	if (getcwd(cwd_buf, max_len)) {
		if (unixsock_reply_printf("200 OK\n%s\n", cwd_buf) < 0) {
			unixsock_reply_reset();
			unixsock_reply_asciiz("500 Error while sending reply\n");
			ret = -1;
		}
	} else {
		unixsock_reply_asciiz("500 getcwd Failed\n");
		ret = -1;
	}

	pkg_free(cwd_buf);
	if (unixsock_reply_send() < 0) {
		ret = -1;
	}
	return ret;
}
Exemple #3
0
/* returns a pkg_malloc'ed file name */
static char* get_name(struct flat_id* id)
{
	char* buf;
	int buf_len;
	char* num, *ptr;
	int num_len;
	int total_len;

	buf_len=pathmax();
	if (!id) {
		LM_ERR("invalid parameter value\n");
		return 0;
	}
	total_len=id->dir.len+1 /* / */+id->table.len+1 /* _ */+
				FILE_SUFFIX_LEN+1 /* \0 */; /* without pid*/
	if (buf_len<total_len){
		LM_ERR("the path is too long (%d and PATHMAX is %d)\n",
					total_len, buf_len);
		return 0;
	}
	
	buf=pkg_malloc(buf_len);
	if (buf==0){
		LM_ERR("pkg memory allocation failure\n");
		return 0;
	}

	ptr = buf;

	memcpy(ptr, id->dir.s, id->dir.len);
	ptr += id->dir.len;
	*ptr++ = '/';

	memcpy(ptr, id->table.s, id->table.len);
	ptr += id->table.len;

	*ptr++ = '_';
	
	num = int2str(km_flat_pid, &num_len);
	if (buf_len<(total_len+num_len)){
		LM_ERR("the path is too long (%d and PATHMAX is"
				" %d)\n", total_len+num_len, buf_len);
		pkg_free(buf);
		return 0;
	}
	memcpy(ptr, num, num_len);
	ptr += num_len;

	memcpy(ptr, FILE_SUFFIX, FILE_SUFFIX_LEN);
	ptr += FILE_SUFFIX_LEN;

	*ptr = '\0';
	return buf;
}
Exemple #4
0
static void core_pwd(rpc_t* rpc, void* c)
{
        char *cwd_buf;
        int max_len;

        max_len = pathmax();
        cwd_buf = pkg_malloc(max_len);
        if (!cwd_buf) {
                ERR("core_pwd: No memory left\n");
                rpc->fault(c, 500, "Server Ran Out of Memory");
		return;
        }

        if (getcwd(cwd_buf, max_len)) {
		rpc->add(c, "s", cwd_buf);
        } else {
		rpc->fault(c, 500, "getcwd Failed");
        }
        pkg_free(cwd_buf);
}
Exemple #5
0
static struct mi_root *mi_pwd(struct mi_root *cmd, void *param)
{
	int max_len = 0;
	char *cwd_buf = 0;
	struct mi_root *rpl_tree;
	struct mi_node *rpl;
	struct mi_node *node;

	max_len = pathmax();
	cwd_buf = pkg_malloc(max_len);
	if (cwd_buf==NULL) {
		LM_ERR("no more pkg mem\n");
		return NULL;
	}

	if (getcwd(cwd_buf, max_len)==0) {
		LM_ERR("getcwd failed = %s\n",strerror(errno));
		pkg_free(cwd_buf);
		return NULL;
	}

	rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK));
	if (rpl_tree==0) {
		pkg_free(cwd_buf);
		return NULL;
	}
	rpl = &rpl_tree->node;

	node = add_mi_node_child( rpl, MI_FREE_VALUE, MI_SSTR("WD"), cwd_buf,strlen(cwd_buf));
	if (node==0) {
		LM_ERR("failed to add node\n");
		pkg_free(cwd_buf);
		free_mi_tree(rpl_tree);
		return NULL;
	}

	return rpl_tree;
}
static struct mi_root *mi_pwd(struct mi_root *cmd, void *param)
{
	static int max_len = 0;
	static char *cwd_buf = 0;
	struct mi_root *rpl_tree;
	struct mi_node *rpl;
	struct mi_node *node;

	if (cwd_buf==NULL) {
		max_len = pathmax();
		cwd_buf = pkg_malloc(max_len);
		if (cwd_buf==NULL) {
			LM_ERR("no more pkg mem\n");
			return 0;
		}
	}

	rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK));
	if (rpl_tree==0)
		return 0;
	rpl = &rpl_tree->node;

	if (getcwd(cwd_buf, max_len)==0) {
		LM_ERR("getcwd failed = %s\n",strerror(errno));
		goto error;
	}

	node = add_mi_node_child( rpl, 0, MI_SSTR("WD"), cwd_buf,strlen(cwd_buf));
	if (node==0) {
		LM_ERR("failed to add node\n");
		goto error;
	}

	return rpl_tree;
error:
	free_mi_tree(rpl_tree);
	return 0;
}
Exemple #7
0
	bool filterlower()
	{
		int i,j,w,z;

 //fprintf(stderr, "AllDiffBounds::filterlower()\n");
		for (i=1; i<=nb+1; i++) {
			d[i] = bounds[i] - bounds[t[i]=h[i]=i-1];
			bucket[i] = -1; // this could perhaps be avoided
		}
		for (i=0; i<sz; i++) { // visit intervals in increasing max order
			int minrank = iv[maxsorted[i]].minrank;
			int maxrank = iv[maxsorted[i]].maxrank;
 //fprintf(stderr, "var %d [%d, %d)\n", maxsorted[i], bounds[minrank], bounds[maxrank]);
			j = t[z = pathmax(t, minrank+1)];
			iv[maxsorted[i]].next = bucket[z];
			bucket[z] = maxsorted[i];
			if (--d[z] == 0)
				t[z = pathmax(t, t[z]=z+1)] = j;
			pathset(t, minrank+1, z, z); // path compression
			//if (d[z] < bounds[z]-bounds[maxrank]) return false; // no solution
			if (h[minrank] > minrank) {
				Clause* r = NULL;
				int hall_max = bounds[w = pathmax(h, h[minrank])];
				if (so.lazy) {
					int hall_min = bounds[minrank];
					// here both k and hall_min are decreasing, stop when k catches up
					for (int k = w; bounds[k] > hall_min; --k)
						for (int l = bucket[k]; l >= 0; l = iv[l].next)
							hall_min = std::min(hall_min, iv[l].min);
 //fprintf(stderr, "  in hall [%d, %d):\n", hall_min, hall_max);
					r = Reason_new(2 + (hall_max - hall_min) * 2);
					(*r)[1] = ~x[maxsorted[i]].getLit(hall_min, 2);
					int m = 2;
					for (int k = w; bounds[k] > hall_min; --k)
						for (int l = bucket[k]; l >= 0; l = iv[l].next) {
 //fprintf(stderr, "    var %d [%d, %d)\n", l, iv[l].min, iv[l].max);
							(*r)[m++] = ~x[l].getLit(hall_min, 2);
							(*r)[m++] = ~x[l].getLit(hall_max - 1, 3);
					}
					assert(m == 2 + (hall_max - hall_min) * 2);
				}
				if (!x[maxsorted[i]].setMin(hall_max, r)) {
 //fprintf(stderr, "  failure\n");
					return false;
				}
				iv[maxsorted[i]].min = hall_max;
				if (x[maxsorted[i]].getMin() > hall_max) {
 //fprintf(stderr, "  hole, var %d [%d, %d)\n", maxsorted[i], static_cast<int>(x[maxsorted[i]].getMin()), iv[maxsorted[i]].max);
					pushInQueue(); // hole in domain
				}
				pathset(h, minrank, w, w); // path compression

			}
			if (d[z] == bounds[z]-bounds[maxrank]) {
 //fprintf(stderr, "  new hall [%d, %d)\n", bounds[j], bounds[maxrank]);
				pathset(h, h[maxrank], j-1, maxrank); // mark hall interval
				h[maxrank] = j-1;
			}
		}
		return true;
	}
Exemple #8
0
/* returns a pkg_malloc'ed file name */
static char* get_name(struct flat_id* id)
{
	char* buf;
	int buf_len;
	char* num, *ptr;
	int num_len;
	int total_len;
	str prefix, suffix;

	static struct sip_msg flat_dummy_msg;

	buf_len=pathmax();
	if (!id) {
		LM_ERR("invalid parameter value\n");
		return 0;
	}
	if (flat_suffix) {
		if (fixup_get_svalue(&flat_dummy_msg, flat_suffix, &suffix) < 0) {
			LM_ERR("bad suffix - using default \"%s\"\n", FILE_SUFFIX);
			suffix.s = FILE_SUFFIX;
			suffix.len = FILE_SUFFIX_LEN;
		}
	} else {
		suffix.s = 0;
		suffix.len = 0;
	}
	if (flat_prefix) {
		if (fixup_get_svalue(&flat_dummy_msg, flat_prefix, &prefix) < 0) {
			LM_ERR("bad prefix - discarding\n");
			prefix.s = 0;
			prefix.len = 0;
		}
	} else {
		prefix.s = 0;
		prefix.len = 0;
	}


	total_len = id->dir.len + 1 /* / */ +
		prefix.len /* table prefix */ +
		id->table.len /* table name */ +
		suffix.len /* table suffix */ +
		flat_single_file ? 2 : 1 /* _ needed? + '\0' */;
				/* without pid */
	if (buf_len<total_len){
		LM_ERR("the path is too long (%d and PATHMAX is %d)\n",
					total_len, buf_len);
		return 0;
	}

	buf=pkg_malloc(buf_len);
	if (buf==0){
		LM_ERR("pkg memory allocation failure\n");
		return 0;
	}

	ptr = buf;

	memcpy(ptr, id->dir.s, id->dir.len);
	ptr += id->dir.len;
	*ptr++ = '/';

	memcpy(ptr, prefix.s, prefix.len);
	ptr += prefix.len;

	memcpy(ptr, id->table.s, id->table.len);
	ptr += id->table.len;

	if (!flat_single_file) {
		*ptr++ = '_';

		num = int2str(flat_pid, &num_len);
		if (buf_len<(total_len+num_len)){
			LM_ERR("the path is too long (%d and PATHMAX is"
					" %d)\n", total_len+num_len, buf_len);
			pkg_free(buf);
			return 0;
		}
		memcpy(ptr, num, num_len);
		ptr += num_len;
	}

	memcpy(ptr, suffix.s, suffix.len);
	ptr += suffix.len;

	*ptr = '\0';
	return buf;
}