/**
  * do the initial handshake
  * @param array params
  */
 public static function handshake($params)
 {
     $auth = isset($params['auth']) ? $params['auth'] : false;
     $user = isset($params['user']) ? $params['user'] : false;
     $time = isset($params['timestamp']) ? $params['timestamp'] : false;
     $now = time();
     if ($now - $time > 10 * 60) {
         echo "<root>\n\t<error code='400'>timestamp is more then 10 minutes old</error>\n</root>";
     }
     if ($auth and $user and $time) {
         $query = OC_DB::prepare("SELECT user_id, user_password_sha256 from *PREFIX*media_users WHERE user_id=?");
         $users = $query->execute(array($user))->fetchAll();
         if (count($users) > 0) {
             $pass = $users[0]['user_password_sha256'];
             $key = hash('sha256', $time . $pass);
             if ($key == $auth) {
                 $token = hash('sha256', 'oc_media_' . $key);
                 OC_MEDIA_COLLECTION::$uid = $users[0]['user_id'];
                 $date = date('c');
                 //todo proper update/add/clean dates
                 $songs = OC_MEDIA_COLLECTION::getSongCount();
                 $artists = OC_MEDIA_COLLECTION::getArtistCount();
                 $albums = OC_MEDIA_COLLECTION::getAlbumCount();
                 $query = OC_DB::prepare("INSERT INTO *PREFIX*media_sessions (`session_id`, `token`, `user_id`, `start`) VALUES (NULL, ?, ?, now());");
                 $query->execute(array($token, $user));
                 $expire = date('c', time() + 600);
                 echo "<root>\n\t<auth>{$token}</auth>\n\t<version>350001</version>\n\t<update>{$date}</update>\n\t<add>{$date}</add>\n\t<clean>{$date}</clean>\n\t<songs>{$songs}</songs>\n\t<artists>{$artists}</artists>\n\t<albums>{$albums}</albums>\\\n\t<session_length>600</session_length>\n\t<session_expire>{$expire}</session_expire>\n\t<tags>0</tags>\n\t<videos>0</videos>\n</root>";
                 return;
             }
         }
         echo "<root>\n\t<error code='400'>Invalid login</error>\n</root>";
     } else {
         echo "<root>\n\t<error code='400'>Missing arguments</error>\n</root>";
     }
 }