/* helper call for armature_bone_rename */
static void constraint_bone_name_fix(Object *ob, ListBase *conlist, const char *oldname, const char *newname)
{
	bConstraint *curcon;
	bConstraintTarget *ct;
	
	for (curcon = conlist->first; curcon; curcon = curcon->next) {
		bConstraintTypeInfo *cti = BKE_constraint_get_typeinfo(curcon);
		ListBase targets = {NULL, NULL};
		
		/* constraint targets */
		if (cti && cti->get_constraint_targets) {
			cti->get_constraint_targets(curcon, &targets);
			
			for (ct = targets.first; ct; ct = ct->next) {
				if (ct->tar == ob) {
					if (STREQ(ct->subtarget, oldname)) {
						BLI_strncpy(ct->subtarget, newname, MAXBONENAME);
					}
				}
			}
			
			if (cti->flush_constraint_targets)
				cti->flush_constraint_targets(curcon, &targets, 0);
		}
		
		/* action constraints */
		if (curcon->type == CONSTRAINT_TYPE_ACTION) {
			bActionConstraint *actcon = (bActionConstraint *)curcon->data;
			BKE_action_fix_paths_rename(&ob->id, actcon->act, "pose.bones", oldname, newname, 0, 0, 1);
		}
	}
}
static void joined_armature_fix_links_constraints(
        Object *tarArm, Object *srcArm, bPoseChannel *pchan, EditBone *curbone,
        ListBase *lb)
{
	bConstraint *con;

	for (con = lb->first; con; con = con->next) {
		bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
		ListBase targets = {NULL, NULL};
		bConstraintTarget *ct;

		/* constraint targets */
		if (cti && cti->get_constraint_targets) {
			cti->get_constraint_targets(con, &targets);

			for (ct = targets.first; ct; ct = ct->next) {
				if (ct->tar == srcArm) {
					if (ct->subtarget[0] == '\0') {
						ct->tar = tarArm;
					}
					else if (STREQ(ct->subtarget, pchan->name)) {
						ct->tar = tarArm;
						BLI_strncpy(ct->subtarget, curbone->name, sizeof(ct->subtarget));
					}
				}
			}

			if (cti->flush_constraint_targets)
				cti->flush_constraint_targets(con, &targets, 0);
		}

		/* action constraint? (pose constraints only) */
		if (con->type == CONSTRAINT_TYPE_ACTION) {
			bActionConstraint *data = con->data;

			if (data->act) {
				BKE_action_fix_paths_rename(&tarArm->id, data->act, "pose.bones[", 
				                            pchan->name, curbone->name, 0, 0, false);
			}
		}

	}
}