How can people cancel their membership?
If you are using Drupal, you could set up a webform that allows people to change their membership status. This would not require any custom code, the functionality is all there in the Webform-CiviCRM module. You'd just want to carefully select which membership statuses you want to allow people to give themselves by editing that field and deselecting inappropriate options after adding it to the form.