A party shall have an unrestricted right to agree with an attorney as to compensation for services, and the measure and mode thereof; but certain sums may be allowed to the prevailing party for expenses in an action, which are termed costs.