// Path: src/main/java/org/kontalk/misc/Callback.java
// public final class Callback<V> {
//     private static final Logger LOGGER = Logger.getLogger(Callback.class.getName());
// 
//     public final V value;
//     public final Optional<Exception> exception;
// 
//     public Callback() {
//         this.value = null;
//         this.exception = Optional.empty();
//     }
// 
//     public Callback(V response) {
//         this.value = response;
//         this.exception = Optional.empty();
//     }
// 
//     public Callback(Exception ex) {
//         this.value = null;
//         this.exception = Optional.of(ex);
//     }
// 
//     public interface Handler<V> {
//         void handle(Callback<V> callback);
//     }
// 
//     public static class Synchronizer {
//         private final CountDownLatch mLatch = new CountDownLatch(1);
// 
//         public void sync() {
//             mLatch.countDown();
//         }
// 
//         public void waitForSync() {
//             boolean succ = false;
//             try {
//                 succ = mLatch.await(5, TimeUnit.SECONDS);
//             } catch (InterruptedException ex) {
//                 LOGGER.log(Level.WARNING, "interrupted", ex);
//             }
//             if (!succ) {
//                 LOGGER.warning("await failed, timeout reached");
//             }
//         }
//     }
// }


import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.kontalk.misc.Callback;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.SuccessCallback;
import org.jivesoftware.smackx.iqregister.packet.Registration;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;
/*
 *  Kontalk Java client
 *  Copyright (C) 2016 Kontalk Devteam <devteam@kontalk.org>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.kontalk.client;



/**
 * Send request and listen to response for private data over
 * 'jabber:iq:register' namespace.
 *
 * Temporary server connection is established when requesting key.
 *
 * TODO not used
 *
 * @author Alexander Bikadorov {@literal <bikaejkb@mail.tu-berlin.de>}
 */
public final class PrivateKeyReceiver implements SuccessCallback<IQ> {
    private static final Logger LOGGER = Logger.getLogger(PrivateKeyReceiver.class.getName());

    private static final String FORM_TYPE_VALUE = "http://kontalk.org/protocol/register#privatekey";
    private static final String FORM_TOKEN_VAR = "token";

// Path: src/main/java/org/kontalk/misc/Callback.java
// public final class Callback<V> {
//     private static final Logger LOGGER = Logger.getLogger(Callback.class.getName());
// 
//     public final V value;
//     public final Optional<Exception> exception;
// 
//     public Callback() {
//         this.value = null;
//         this.exception = Optional.empty();
//     }
// 
//     public Callback(V response) {
//         this.value = response;
//         this.exception = Optional.empty();
//     }
// 
//     public Callback(Exception ex) {
//         this.value = null;
//         this.exception = Optional.of(ex);
//     }
// 
//     public interface Handler<V> {
//         void handle(Callback<V> callback);
//     }
// 
//     public static class Synchronizer {
//         private final CountDownLatch mLatch = new CountDownLatch(1);
// 
//         public void sync() {
//             mLatch.countDown();
//         }
// 
//         public void waitForSync() {
//             boolean succ = false;
//             try {
//                 succ = mLatch.await(5, TimeUnit.SECONDS);
//             } catch (InterruptedException ex) {
//                 LOGGER.log(Level.WARNING, "interrupted", ex);
//             }
//             if (!succ) {
//                 LOGGER.warning("await failed, timeout reached");
//             }
//         }
//     }
// }


// Path: src/main/java/org/kontalk/client/PrivateKeyReceiver.java
import org.jivesoftware.smackx.xdata.packet.DataForm;
import org.kontalk.misc.Callback;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.SuccessCallback;
import org.jivesoftware.smackx.iqregister.packet.Registration;
import org.jivesoftware.smackx.xdata.Form;
import org.jivesoftware.smackx.xdata.FormField;

/*
 *  Kontalk Java client
 *  Copyright (C) 2016 Kontalk Devteam <devteam@kontalk.org>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.kontalk.client;



/**
 * Send request and listen to response for private data over
 * 'jabber:iq:register' namespace.
 *
 * Temporary server connection is established when requesting key.
 *
 * TODO not used
 *
 * @author Alexander Bikadorov {@literal <bikaejkb@mail.tu-berlin.de>}
 */
public final class PrivateKeyReceiver implements SuccessCallback<IQ> {
    private static final Logger LOGGER = Logger.getLogger(PrivateKeyReceiver.class.getName());

    private static final String FORM_TYPE_VALUE = "http://kontalk.org/protocol/register#privatekey";
    private static final String FORM_TOKEN_VAR = "token";

    private final Callback.Handler<String> mHandler;