Ejemplo n.º 1
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    user_id = ht.get_required(query, 'user_id')
    to_user_key = ht.get_optional(query, 'to_user_key')
    from_user = ht.get_optional(query, 'from_user')
    from_user_key = ht.get_optional(query, 'from_user_key')
    start_time = ht.convert_int(ht.get_optional(query, 'start_time'), 'start_time')
    end_time = ht.convert_int(ht.get_optional(query, 'end_time'), 'end_time')
    max_records = ht.convert_int(ht.get_optional(query, 'max_records'), 'max_records')
    order = ht.get_optional(query, 'order')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        message_list = db.read_message_list(c, timestamp, node_name, user_id,
                                            to_user_key, from_user, from_user_key,
                                            start_time, end_time, max_records, order,
                                            public_key_hash, signature)

        raise ht.ok_json({'status' : 'ok', 'message_list' : message_list})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 2
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    start_time = ht.convert_int(ht.get_optional(query, 'start_time'), 'start_time')
    end_time = ht.convert_int(ht.get_optional(query, 'end_time'), 'end_time')
    max_records = ht.convert_int(ht.get_optional(query, 'max_records'), 'max_records')
    order = ht.get_optional(query, 'order')
    read_signature = ht.get_optional(query, 'read_signature')
    proof_of_work = ht.get_optional(query, 'proof_of_work')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        post_list = db.read_post_list(
                c, timestamp, node_name, group_id, owner_id,
                start_time, end_time, max_records,
                order, read_signature, proof_of_work)

        raise ht.ok_json({'status' : 'ok', 'post_list' : post_list})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 3
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    new_size = ht.convert_int(ht.get_optional(query, 'new_size'), 'new_size')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        
        db.change_max_post_size(c,
                timestamp, node_name, group_id, owner_id, new_size,
                public_key_hash, signature)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 4
0
def get_handler(environ):

    query = ht.parse_get_request(environ)
    cookies = ht.parse_cookies(environ)

    user_id = ht.get_required_cookie(cookies, 'user_id')
    session_id = ht.get_required_cookie(cookies, 'session_id')

    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    start_time = ht.convert_int(ht.get_optional(query, 'start_time'), 'start_time')
    end_time = ht.convert_int(ht.get_optional(query, 'end_time'), 'end_time')
    max_records = ht.convert_int(ht.get_optional(query, 'max_records'), 'max_records')
    order = ht.get_optional(query, 'order')
    passphrase = ht.get_optional(query, 'passphrase')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        resp = db.read_post_list(c, user_id, session_id,
                                 node_name, group_id, owner_id,
                                 start_time, end_time, max_records, order, passphrase)

        raise ht.ok_json({'status' : 'ok', 'resp' : resp})
        
    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 5
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, "timestamp"), "timestamp")
    node_name = ht.get_required(query, "node_name")
    group_id = ht.get_required(query, "group_id")
    owner_id = ht.get_required(query, "owner_id")
    new_size = ht.convert_int(ht.get_required(query, "new_size"), "new_size")
    when_space_exhausted = ht.get_required(query, "when_space_exhausted")

    public_key_hash = ht.get_required(query, "public_key_hash")
    signature = ht.get_required(query, "signature")

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.change_group_quota(
            c, timestamp, node_name, group_id, owner_id, new_size, when_space_exhausted, public_key_hash, signature
        )
        db.commit(conn)

        raise ht.ok_json({"status": "ok"})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 6
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    user_id = ht.get_required(query, 'user_id')
    new_size = ht.convert_int(ht.get_required(query, 'new_size'), 'new_size')
    when_space_exhausted = ht.get_required(query, 'when_space_exhausted')

    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.change_message_quota(c,
                timestamp, node_name, user_id, new_size, when_space_exhausted,
                public_key_hash, signature)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 7
0
def delete_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    post_id = ht.get_required(query, 'post_id')
    delete_signature = ht.get_optional(query, 'delete_signature')
    proof_of_work = ht.get_optional(query, 'proof_of_work')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.delete_post(c, timestamp, node_name, group_id, owner_id, post_id, proof_of_work, delete_signature)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 8
0
def post_handler(environ):

    query = ht.parse_post_request(environ)
    cookies = ht.parse_cookies(environ)

    user_id = ht.get_required_cookie(cookies, 'user_id')
    session_id = ht.get_required_cookie(cookies, 'session_id')

    public_key_hash  = ht.get_required(query, 'public_key_hash')
    passphrase = ht.get_required(query, 'passphrase')
    expire_time = ht.convert_int(ht.get_optional(query, 'expire_time'), 'expire_time')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.cache_passphrase(c, user_id, session_id, public_key_hash, passphrase, expire_time)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 9
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, "timestamp"), "timestamp")
    node_name = ht.get_required(query, "node_name")
    group_id = ht.get_required(query, "group_id")
    owner_id = ht.get_required(query, "owner_id")
    key_use = ht.get_required(query, "key_use")
    key_type = ht.get_optional(query, "key_type")
    pub_key = ht.get_optional(query, "pub_key")
    public_key_hash = ht.get_required(query, "public_key_hash")
    signature = ht.get_required(query, "signature")

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.change_group_key(
            c, timestamp, node_name, group_id, owner_id, key_use, key_type, pub_key, public_key_hash, signature
        )
        db.commit(conn)

        raise ht.ok_json({"status": "ok"})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 10
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, "timestamp"), "timestamp")
    node_name = ht.get_required(query, "node_name")
    to_user = ht.get_required(query, "to_user")
    from_user = ht.get_optional(query, "from_user")
    from_user_key_hash = ht.get_optional(query, "from_user_key_hash")
    from_user_key_sig = ht.get_optional(query, "from_user_key_sig")

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        max_message_size = db.read_max_message_size(
            c, timestamp, node_name, to_user, from_user, from_user_key_hash, from_user_key_sig
        )

        raise ht.ok_json({"status": "ok", "max_message_size": max_message_size})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 11
0
def post_handler(environ):

    query = ht.parse_post_request(environ)
    cookies = ht.parse_cookies(environ)

    user_id = ht.get_required_cookie(cookies, 'user_id')
    session_id = ht.get_required_cookie(cookies, 'session_id')

    node_name = ht.get_required(query, 'node_name')
    new_size = ht.convert_int(ht.get_required(query, 'new_size'), 'new_size')
    when_space_exhausted = ht.get_required(query, 'when_space_exhausted')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    passphrase = ht.get_optional(query, 'passphrase')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        resp = db.change_message_quota(c, user_id, session_id,
                                       node_name, new_size, when_space_exhausted,
                                       public_key_hash, passphrase)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok', 'resp' : resp})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 12
0
def delete_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    user_id = ht.get_required(query, 'user_id')
    from_user_key_hash = ht.get_required(query, 'from_user_key_hash')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')
    
    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.delete_message_access(c,
                timestamp, node_name, user_id, from_user_key_hash, public_key_hash, signature)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 13
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    post_access = ht.get_required(query, 'post_access')
    read_access = ht.get_required(query, 'read_access')
    delete_access = ht.get_required(query, 'delete_access')
    posting_key_type = ht.get_optional(query, 'posting_key_type')
    posting_pub_key = ht.get_optional(query, 'posting_pub_key')
    reading_key_type = ht.get_optional(query, 'reading_key_type')
    reading_pub_key = ht.get_optional(query, 'reading_pub_key')
    delete_key_type = ht.get_optional(query, 'delete_key_type')
    delete_pub_key = ht.get_optional(query, 'delete_pub_key')
    quota_allocated = ht.convert_int(ht.get_required(query, 'quota_allocated'), 'quota_allocated')
    when_space_exhausted = ht.get_required(query, 'when_space_exhausted')
    max_post_size = ht.convert_int(ht.get_optional(query, 'max_post_size'), 'max_post_size')

    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        row = (timestamp, group_id, owner_id,
               post_access, read_access, delete_access,
               posting_key_type, posting_pub_key,
               reading_key_type, reading_pub_key,
               delete_key_type, delete_pub_key,
               quota_allocated, when_space_exhausted,
               max_post_size)
        db.create_group(c, row, node_name, public_key_hash, signature)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 14
0
def post_handler(environ):

    query = ht.parse_post_request(environ)
    cookies = ht.parse_cookies(environ)

    user_id = ht.get_required_cookie(cookies, 'user_id')
    session_id = ht.get_required_cookie(cookies, 'session_id')

    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    post_access = ht.get_required(query, 'post_access')
    read_access = ht.get_required(query, 'read_access')
    delete_access = ht.get_required(query, 'delete_access')
    posting_key_hash = ht.get_optional(query, 'posting_key_hash')
    reading_key_hash = ht.get_optional(query, 'reading_key_hash')
    delete_key_hash = ht.get_optional(query, 'delete_key_hash')
    quota_allocated = ht.convert_int(ht.get_required(query, 'quota_allocated'), 'quota_allocated')
    when_space_exhausted = ht.get_required(query, 'when_space_exhausted')
    max_post_size = ht.convert_int(ht.get_optional(query, 'max_post_size'), 'max_post_size')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    passphrase = ht.get_optional(query, 'passphrase')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        resp = db.create_group(c, user_id, session_id,
                               node_name, group_id,
                               post_access, read_access, delete_access,
                               posting_key_hash, reading_key_hash, delete_key_hash,
                               quota_allocated, when_space_exhausted,
                               max_post_size,
                               public_key_hash, passphrase)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok', 'resp' : resp})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 15
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    node_name = ht.get_required(query, 'node_name')
    user_id = ht.get_required(query, 'user_id')
    key_type = ht.get_required(query, 'key_type')
    public_key = ht.get_required(query, 'public_key')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    revoke_date = ht.convert_int(ht.get_optional(query, 'revoke_date'), 'revoke_date')
    default_message_access = ht.get_required(query, 'default_message_access')
    when_mail_exhausted = ht.get_required(query, 'when_mail_exhausted')
    quota_size = ht.convert_int(ht.get_required(query, 'quota_size'), 'quota_size')
    mail_quota_size = ht.convert_int(ht.get_required(query, 'mail_quota_size'), 'mail_quota_size')
    max_message_size = ht.convert_int(ht.get_optional(query, 'max_message_size'), 'max_message_size')

    # TODO: figure these out
    user_class = ht.get_optional(query, 'user_class')
    auth_token = ht.get_optional(query, 'auth_token')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.create_user(c, node_name,
                       user_id, key_type, public_key, public_key_hash, revoke_date,
                       default_message_access, when_mail_exhausted,
                       db.root_quota_id, quota_size, mail_quota_size,
                       max_message_size)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 16
0
def post_handler(environ):

    query = ht.parse_post_request(environ)
    cookies = ht.parse_cookies(environ)

    user_id = ht.get_required_cookie(cookies, 'user_id')
    session_id = ht.get_required_cookie(cookies, 'session_id')

    node_name = ht.get_required(query, 'node_name')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    default_message_access = ht.get_required(query, 'default_message_access')
    when_mail_exhausted = ht.get_required(query, 'when_mail_exhausted')
    quota_size = ht.convert_int(ht.get_required(query, 'quota_size'), 'quota_size')
    mail_quota_size = ht.convert_int(ht.get_required(query, 'mail_quota_size'), 'mail_quota_size')
    max_message_size = ht.convert_int(ht.get_optional(query, 'max_message_size'), 'max_message_size')
    user_class = ht.get_optional(query, 'user_class')
    auth_token = ht.get_optional(query, 'auth_token')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        resp = db.create_user(c, user_id, session_id,
                              node_name, public_key_hash,
                              default_message_access, when_mail_exhausted,
                              quota_size, mail_quota_size,
                              max_message_size,
                              user_class, auth_token)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok', 'resp' : resp})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 17
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, "timestamp"), "timestamp")
    node_name = ht.get_required(query, "node_name")
    user_id = ht.get_required(query, "user_id")
    new_size = ht.convert_int(ht.get_optional(query, "new_size"), "new_size")
    public_key_hash = ht.get_required(query, "public_key_hash")
    signature = ht.get_required(query, "signature")

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.change_max_message_size(c, timestamp, node_name, user_id, new_size, public_key_hash, signature)
        db.commit(conn)

        raise ht.ok_json({"status": "ok"})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 18
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    user_id = ht.get_required(query, 'user_id')
    public_key_hash = ht.get_required(query, 'public_key_hash')
    signature = ht.get_required(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        quota_obj = db.read_user_quota(c, timestamp, node_name, user_id, public_key_hash, signature)

        raise ht.ok_json({'status' : 'ok', 'user_quota' : quota_obj})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 19
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    post_signature = ht.get_required(query, 'post_signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        max_post_size = db.read_max_post_size(c,
                timestamp, node_name, group_id, owner_id, post_signature)

        raise ht.ok_json({'status' : 'ok', 'max_post_size' : max_post_size})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 20
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    use = ht.get_required(query, 'use')
    signature = ht.get_optional(query, 'signature')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        access = db.read_group_access(c, timestamp, node_name, group_id, owner_id, use, signature)

        raise ht.ok_json({'status' : 'ok', 'access' : access})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 21
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    group_id = ht.get_required(query, 'group_id')
    owner_id = ht.get_required(query, 'owner_id')
    read_signature = ht.get_optional(query, 'read_signature')
    proof_of_work = ht.get_optional(query, 'proof_of_work')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        last_post_time = db.read_last_post_time(c, timestamp, node_name, group_id, owner_id, read_signature, proof_of_work)

        raise ht.ok_json({'status' : 'ok', 'last_post_time' : last_post_time})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 22
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, "timestamp"), "timestamp")
    node_name = ht.get_required(query, "node_name")
    group_id = ht.get_required(query, "group_id")
    owner_id = ht.get_required(query, "owner_id")
    read_signature = ht.get_optional(query, "read_signature")
    proof_of_work = ht.get_optional(query, "proof_of_work")

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        group_quota = db.read_group_quota(c, timestamp, node_name, group_id, owner_id, read_signature, proof_of_work)

        raise ht.ok_json({"status": "ok", "group_quota": group_quota})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 23
0
def post_handler(environ):

    query = ht.parse_post_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    to_user = ht.get_required(query, 'to_user')
    to_user_key_hash = ht.get_optional(query, 'to_user_key_hash')
    from_user = ht.get_optional(query, 'from_user')
    from_user_key_hash = ht.get_optional(query, 'from_user_key_hash')
    message_hash = ht.get_required(query, 'message_hash')

    message = ht.get_required(query, 'message')
    message_id = ht.get_required(query, 'message_id')

    from_signature = ht.get_optional(query, 'from_signature')
    proof_of_work = ht.get_optional(query, 'proof_of_work')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        db.add_message(c,
                       (message_id, timestamp, 
                        to_user, to_user_key_hash,
                        from_user, from_user_key_hash,
                        message, message_hash,
                        from_signature, proof_of_work, None),
                       node_name)
        db.commit(conn)

        raise ht.ok_json({'status' : 'ok'})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)
Ejemplo n.º 24
0
def get_handler(environ):

    query = ht.parse_get_request(environ)

    timestamp = ht.convert_int(ht.get_required(query, 'timestamp'), 'timestamp')
    node_name = ht.get_required(query, 'node_name')
    to_user = ht.get_required(query, 'to_user')
    from_user = ht.get_required(query, 'from_user')
    from_user_key_hash = ht.get_optional(query, 'from_user_key_hash')
    from_user_key_sig = ht.get_optional(query, 'from_user_key_sig')

    conn = db.connect(config.db_path)
    try:
        c = db.cursor(conn)
        message_access = db.query_message_access(c,
                timestamp, node_name, to_user, from_user, from_user_key_hash, from_user_key_sig)

        raise ht.ok_json({'status' : 'ok', 'message_access' : message_access})

    except ex.SqueakException as e:
        raise ht.convert_squeak_exception(e)

    finally:
        db.close(conn)