-1

Was looking around and found a few answers that suggests that I should use REST. But how would I integrate this in Qt/c++? Could anyone link some examples of this or maybe a few lines of code? Would really appreciate it!

chikuba
  • 4,229
  • 6
  • 43
  • 75
  • http://stackoverflow.com/questions/8471810/accessing-azure-storage-tables-from-c-code/9476451#9476451 – chikuba Feb 28 '12 at 21:50

2 Answers2

2

It took me a lot of time to achieve it. The trickiest thing is that you have to decode your primary key. With the help of this question, I've decided to use OpenSSL and I've made the following code.

QString datastring = "GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:" + date + "\nx-ms-version:2009-09-19\n/myStorage/\ncomp:list";
QByteArray ba = datastring.toUtf8();

unsigned char* signature = reinterpret_cast<unsigned char*>(ba.data());
QByteArray kba = QByteArray::fromBase64("theStorageAccountKey");
unsigned char* key = (unsigned char*) kba.data();
unsigned char result[EVP_MAX_MD_SIZE];
unsigned int result_len;
ENGINE_load_builtin_engines();
ENGINE_register_all_complete();

HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx, key, strlen((const char*)key), EVP_sha256(), NULL);
HMAC_Update(&ctx, signature, strlen((const char*)signature));
HMAC_Final(&ctx, result, &result_len);
HMAC_CTX_cleanup(&ctx);

QByteArray array = QByteArray::fromRawData((char*)result, result_len);
array = array.toBase64();
qDebug() << "signature hash" << array;

QString version = "2009-09-19";

//requesting the list of container to Windows Azure
QNetworkAccessManager* manager = new QNetworkAccessManager();
QNetworkRequest request;
request.setUrl(QUrl("http://myStorage.blob.core.windows.net/?comp=list"));
request.setRawHeader("Authorization","SharedKey myStorage:" + array);
request.setRawHeader("x-ms-date", date.toStdString().c_str());
request.setRawHeader("x-ms-version", version.toStdString().c_str());
QNetworkReply *reply = manager->get(request);
connect(reply, SIGNAL(readyRead()), this, SLOT(manageCloudReply()));

I hope it'll help somebody.

Community
  • 1
  • 1
1

Please check out this question. It covers what you ask and outlines couple of freely available C++ libraries, which you could incorporate to access Azure services.

Community
  • 1
  • 1
astaykov
  • 30,768
  • 3
  • 70
  • 86