Пример #1
0
QString Toxme::createAddress(ExecCode &code, QString server, ToxId id, QString address,
                             bool keepPrivate, QString bio)
{
    int privacy = keepPrivate ? 0 : 2;
    // JSON injection ?
    bio.replace('\\',"\\\\");
    bio.replace('"',"\"");

    address.replace('\\',"\\\\");
    address.replace('"',"\"");

    bio = bio.trimmed();
    address = address.trimmed();
    server = server.trimmed();
    if (!server.contains("://"))
        server = "https://" + server;

    const QString payload{"{\"tox_id\":\""+id.toString()+"\","
                          "\"name\":\""+address+"\","
                          "\"privacy\":"+QString().setNum(privacy)+","
                          "\"bio\":\""+bio+"\","
                          "\"timestamp\":"+QString().setNum(time(0))+"}"};

    QString pubkeyUrl = server + "/pk";
    QString apiUrl =  server + "/api";
    QNetworkReply::NetworkError error = QNetworkReply::NoError;
    QByteArray encrypted = prepareEncryptedJson(pubkeyUrl, 1, payload);
    QByteArray response = makeJsonRequest(apiUrl, encrypted, error);

    code = extractError(response);
    if ((code != Ok && code != Updated) || error != QNetworkReply::NoError)
        return QString();

    return getPass(response, code);
}
Пример #2
0
int checkReturnCode(char* title, SQLRETURN rc, SQLHANDLE handle, SQLSMALLINT type) {
  if (rc == SQL_SUCCESS) {
    if (DEBUGINFO == 1) printf("%s ... true\n", title);
    return 1;
  }

  printf("%s ... ", title);
  if (rc == SQL_SUCCESS_WITH_INFO) {
    printf("true (Warning!)\n");
    extractError(handle, type);
    return 1;
  }
  else {
    printf("false\n^\n");
    extractError(handle, type);
    printf("\n");
    return 0;
  }
}
Пример #3
0
/*
 * Class:     org_jboss_odbc_OdbcClient
 * Method:    execute
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_org_jboss_odbc_OdbcClient_execute(JNIEnv *jnienv, jobject obj, jstring query) {
    SQLRETURN ret;
    char error[10240];
    jbyte *str;
    int h = getStaticHandle(jnienv, obj);

    str = (*jnienv)->GetStringUTFChars(jnienv, query, NULL);
    
    ret = SQLAllocHandle(SQL_HANDLE_STMT, dbc[h], &(stmt[h]));
    if (!SQL_SUCCEEDED(ret)) {
        extractError(dbc[h], SQL_HANDLE_DBC, error, sizeof(error));        
        throwIOException(jnienv, "SQLAllocHandle failed with return value %d:\n%s", ret, error);        
    }
    
    ret = SQLExecDirect(stmt[h], str, SQL_NTS);
    (*jnienv)->ReleaseStringUTFChars(jnienv, query, str);    

    if (!SQL_SUCCEEDED(ret)) {
        extractError(stmt[h], SQL_HANDLE_STMT, error, sizeof(error));        
        throwIOException(jnienv, "SQLExecDirect failed with return value %d:\n%s", ret, error);        
    }
    
}
Пример #4
0
int Toxme::deleteAddress(QString server, ToxId id)
{
    const QString payload{"{\"public_key\":\""+id.toString().left(64)+"\","
                          "\"timestamp\":"+QString().setNum(time(0))+"}"};

    server = server.trimmed();
    if (!server.contains("://"))
        server = "https://" + server;

    QString pubkeyUrl = server + "/pk";
    QString apiUrl = server + "/api";
    QNetworkReply::NetworkError error = QNetworkReply::NoError;
    QByteArray response = makeJsonRequest(apiUrl, prepareEncryptedJson(pubkeyUrl, 2, payload), error);

    return extractError(response);
}
Пример #5
0
/*
 * Class:     org_jboss_odbc_OdbcClient
 * Method:    getColData
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_org_jboss_odbc_OdbcClient_getColData(JNIEnv *jnienv, jobject obj, jint col) {
    int h = getStaticHandle(jnienv, obj);
    SQLINTEGER indicator;
    SQLRETURN ret;
    char buf[5120];
    char error[10240];
       
    ret = SQLGetData(stmt[h], (SQLUSMALLINT) col, SQL_C_CHAR, buf, sizeof(buf), &indicator);
    
    if (SQL_SUCCEEDED(ret)) {
        if (indicator == SQL_NULL_DATA) strcpy(buf, "NULL");
    } else {
        extractError(stmt[h], SQL_HANDLE_STMT, error, sizeof(error));        
        throwIOException(jnienv, "SQLGetData failed with return value %d:\n%s", ret, error);
    }
        
    return (*jnienv)->NewStringUTF(jnienv, buf);
}
Пример #6
0
/*
 * Class:     org_jboss_odbc_OdbcClient
 * Method:    connect
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_org_jboss_odbc_OdbcClient_connect(JNIEnv *jnienv, jobject obj, jstring conn) {
    SQLRETURN ret;
    jbyte *str;
    int h = getStaticHandle(jnienv, obj);  
    char error[10240];  

    jclass cls = (*jnienv)->GetObjectClass(jnienv, obj);

    str = (*jnienv)->GetStringUTFChars(jnienv, conn, NULL);
    
    SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &(env[h]));
    SQLSetEnvAttr(env[h], SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
    SQLAllocHandle(SQL_HANDLE_DBC, env[h], &(dbc[h]));
    ret = SQLDriverConnect(dbc[h], NULL, str, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_COMPLETE);

    if (!SQL_SUCCEEDED(ret)) {
        extractError(dbc[h], SQL_HANDLE_DBC, error, sizeof(error));        
        throwIOException(jnienv, "SQLDriverConnect failed with return value %d:\n%s", ret, error);
    }
    
    (*jnienv)->ReleaseStringUTFChars(jnienv, conn, str);
}