Privacy-Preserving Distributed Optimization via Subspace Perturbation: A General Framework