From: Andre Noll <maan@tuebingen.mpg.de>
Date: Sun, 25 Oct 2015 15:06:43 +0000 (+0100)
Subject: Merge branch 'refs/heads/t/command_handler_cleanups'
X-Git-Tag: v0.5.6~94
X-Git-Url: https://git.tue.mpg.de/?a=commitdiff_plain;h=0f4910b50116416fefb09ca67a615679067ef359;p=paraslash.git

Merge branch 'refs/heads/t/command_handler_cleanups'

Cooking for about two months.

* refs/heads/t/command_handler_cleanups: (39 commits)
  com_addatt(): Return negative on errors
  com_rm(): In force mode, don't complain if no paths matched.
  aft: Unify handling of hash and path duplicates.
  afs: Provide pbout para_buffer for each callback.
  afs: Make afs callbacks more flexible.
  afs: Rename callback_function to afs_callback.
  com_check(): Add attribute checking.
  Let afs_event() return int.
  playlist_check_callback(): Return negative on errors
  mood_check_callback(): Return negative on errors
  com_mvblob(): Return negative on errors
  com_addblob(): Return negative on errors
  com_rmblob(): Return negative on errors, cleanup
  com_catblob(): Return negative on errors
  com_lsblob(): Return negative on errors
  rmatt: Cleanup callback.
  com_rmatt(): Return negative on errors
  com_mvatt(): Return negative on errors
  com_lsatt(): Return negative on errors
  com_init(): Return negative on errors
  ...
---

0f4910b50116416fefb09ca67a615679067ef359
diff --cc NEWS
index f1940d3d,834b61fc..7faa0ddd
--- a/NEWS
+++ b/NEWS
@@@ -1,19 -1,9 +1,24 @@@
  NEWS
  ====
  
 ------------------------------------------
 -current master branch "magnetic momentum"
 ------------------------------------------
 +------------------------------------------
 +current master branch "cascading gradient"
 +------------------------------------------
 +
 +	- para_afh learned to modify meta tags of mp3 wma ogg spx
 +	  opus flac aac files.
++	- afs commands propagate error codes to the client.
++	- The check command now also checks the attribute table for
++	  inconsistencies.
++	- New -v flag for the version command (print verbose version string)
++
 +
 +--------------------------------------
 +0.5.5 (2015-09-20) "magnetic momentum"
 +--------------------------------------
 +
 +Many new features and a lot of other improvements.
 +
  	- On Linux systems, local sockets are now created in the
  	  abstract name space by default. This allows to get rid of
  	  the socket specials in /var/paraslash.
diff --cc aft.c
index f2c1edab,a5da1a92..8a8e5282
--- a/aft.c
+++ b/aft.c
@@@ -1800,17 -1723,16 +1722,16 @@@ static int com_add_callback(struct afs_
  			&objs[AFTCOL_CHUNKS]));
  		if (ret < 0)
  			goto out;
- 		afs_event(AFHI_CHANGE, &msg, row);
- 		goto out;
- 	}
- 	/* new entry, use default afsi */
- 	if (flags & ADD_FLAG_VERBOSE) {
- 		ret = para_printf(&msg, "new file\n");
+ 		ret = afs_event(AFHI_CHANGE, &aca->pbout, row);
  		if (ret < 0)
  			goto out;
+ 		goto out;
  	}
+ 	/* new entry, use default afsi */
+ 	if (flags & ADD_FLAG_VERBOSE)
+ 		para_printf(&aca->pbout, "new file\n");
  	default_afsi.last_played = time(NULL) - 365 * 24 * 60 * 60;
 -	default_afsi.audio_format_id = read_u8(buf + CAB_AUDIO_FORMAT_OFFSET);
 +	default_afsi.audio_format_id = read_u8(buf + CAB_AUDIO_FORMAT_ID_OFFSET);
  
  	objs[AFTCOL_AFSI].data = &afsi_buf;
  	objs[AFTCOL_AFSI].size = AFSI_SIZE;
@@@ -2560,9 -2415,8 +2414,9 @@@ static int com_setatt_callback(struct a
  	if (!cad.add_mask && !cad.del_mask)
  		goto out;
  	pmd.patterns.data = p;
- 	if (p >= (char *)query->data + query->size)
 -	assert(p < (char *)aca->query.data + aca->query.size);
++	if (p >= (char *)aca->query.data + aca->query.size)
 +		goto out;
- 	pmd.patterns.size = (char *)query->data + query->size - p;
+ 	pmd.patterns.size = (char *)aca->query.data + aca->query.size - p;
  	ret = for_each_matching_row(&pmd);
  	if (ret < 0)
  		goto out;
diff --cc attribute.c
index d74ec928,e3bd40b5..f3f8ea7a
--- a/attribute.c
+++ b/attribute.c
@@@ -135,49 -129,45 +129,45 @@@ static int print_attribute(struct osl_t
  	struct osl_object bitnum_obj;
  	int ret;
  
- 	if (!(laad->flags & LSATT_FLAG_LONG))
- 		return para_printf(&laad->pb, "%s\n", name);
+ 	if (!(flags & LSATT_FLAG_LONG)) {
+ 		para_printf(&aca->pbout, "%s\n", name);
+ 		return 1;
+ 	}
  	ret = osl(osl_get_object(table, row, ATTCOL_BITNUM, &bitnum_obj));
  	if (ret < 0) {
- 		para_printf(&laad->pb, "%s: %s\n", name, para_strerror(-ret));
+ 		para_printf(&aca->pbout, "%s: %s\n", name, para_strerror(-ret));
  		return ret;
  	}
- 	return para_printf(&laad->pb, "%u\t%s\n", *(unsigned char*)bitnum_obj.data,
+ 	para_printf(&aca->pbout, "%u\t%s\n", *(unsigned char*)bitnum_obj.data,
  		name);
+ 	return 1;
  }
  
- static void com_lsatt_callback(int fd, const struct osl_object *query)
+ static int com_lsatt_callback(struct afs_callback_arg *aca)
  {
- 	struct lsatt_action_data laad = {
- 		.flags = *(unsigned *) query->data,
- 		.pb = {
- 			.max_size = shm_get_shmmax(),
- 			.private_data = &(struct afs_max_size_handler_data) {
- 				.fd = fd,
- 				.band = SBD_OUTPUT
- 			},
- 			.max_size_handler = afs_max_size_handler
- 		}
- 
- 	};
+ 	unsigned flags = *(unsigned *)aca->query.data;
+ 	int ret;
  	struct pattern_match_data pmd = {
  		.table = attribute_table,
 -		.loop_col_num = ATTCOL_BITNUM,
 +		.loop_col_num = ATTCOL_NAME,
  		.match_col_num = ATTCOL_NAME,
- 		.patterns = {.data = (char *)query->data + sizeof(laad.flags),
- 			.size = query->size - sizeof(laad.flags)},
+ 		.patterns = {.data = (char *)aca->query.data + sizeof(flags),
+ 			.size = aca->query.size - sizeof(flags)},
  		.pm_flags = PM_NO_PATTERN_MATCHES_EVERYTHING,
- 		.data = &laad,
+ 		.data = aca,
  		.action = print_attribute
  	};
- 	if (laad.flags & LSATT_FLAG_SORT_BY_ID)
+ 	if (flags & LSATT_FLAG_SORT_BY_ID)
 -		pmd.loop_col_num = ATTCOL_NAME;
 +		pmd.loop_col_num = ATTCOL_BITNUM;
- 	if (laad.flags & LSATT_FLAG_REVERSE)
+ 	if (flags & LSATT_FLAG_REVERSE)
  		pmd.pm_flags |= PM_REVERSE_LOOP;
- 	for_each_matching_row(&pmd);
- 	if (laad.pb.offset)
- 		pass_buffer_as_shm(fd, SBD_OUTPUT, laad.pb.buf, laad.pb.offset);
- 	free(laad.pb.buf);
+ 	ret = for_each_matching_row(&pmd);
+ 	if (ret < 0)
+ 		goto out;
+ 	if (pmd.num_matches == 0)
+ 		ret = -E_NO_MATCH;
+ out:
+ 	return ret;
  }
  
  int com_lsatt(struct command_context *cc)
diff --cc blob.c
index adfdb1a9,1a411823..2e0a4762
--- a/blob.c
+++ b/blob.c
@@@ -286,24 -257,20 +257,20 @@@ static int com_rmblob_callback(struct o
  		.action = remove_blob
  	};
  	ret = for_each_matching_row(&pmd);
- 	if (ret < 0) {
- 		ret2 = para_printf(&rmbd.pb, "%s\n", para_strerror(-ret));
- 		if (ret2 < 0)
- 			goto out;
- 	}
+ 	if (ret < 0)
+ 		goto out;
  	if (pmd.num_matches == 0)
- 		ret2 = para_printf(&rmbd.pb, "no matches, nothing removed\n");
+ 		ret = -E_NO_MATCH;
  	else {
- 		ret2 = para_printf(&rmbd.pb, "removed %d blobs\n", pmd.num_matches);
- 		afs_event(BLOB_REMOVE, NULL, table);
+ 		para_printf(&aca->pbout, "removed %d blob(s)\n",
+ 			pmd.num_matches);
 -		ret = afs_event(BLOB_RENAME, NULL, table);
++		ret = afs_event(BLOB_REMOVE, NULL, table);
  	}
  out:
- 	if (ret2 >= 0 && rmbd.pb.offset)
- 		pass_buffer_as_shm(fd, SBD_OUTPUT, rmbd.pb.buf, rmbd.pb.offset);
- 	free(rmbd.pb.buf);
+ 	return ret;
  }
  
- static int com_rmblob(callback_function *f, struct command_context *cc)
+ static int com_rmblob(afs_callback *f, struct command_context *cc)
  {
  	if (cc->argc < 2)
  		return -E_MOOD_SYNTAX;