General thermodynamics of the diffuse double layer