Beispiel #1
0
int _ortc_disablePresenceRest(char* url, char* applicationKey, char* privateKey, char* channel, char **response){
  char pUrl[256], body[256];
  CURL *curl;
  long httpCode = 0;
  CURLcode res;
  ortc_RestString *s = (ortc_RestString *)malloc(sizeof(ortc_RestString));

  if(s==NULL)
    return -3;


  if(url[strlen(url)-1] == '/'){
    snprintf(pUrl, sizeof pUrl, "%spresence/disable/%s/%s", url, applicationKey, channel);
  } else {
    snprintf(pUrl, sizeof pUrl, "%s/presence/disable/%s/%s", url, applicationKey, channel);
  }

  snprintf(body, sizeof body, "privatekey=%s", privateKey);

  if(_ortc_initRestString(s)<0){
    free(s);
    return -3;
  }

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, pUrl);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _ortc_writeRestString);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, s);
    res = curl_easy_perform(curl);
    if(res == CURLE_OK){
      *response = strdup(s->ptr);
      free(s->ptr);
      free(s);
      curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
      curl_easy_cleanup(curl);
      if(httpCode == 200) {
	return 1;
      } else {
	return 0;
      }
    } else {
      curl_easy_cleanup(curl);
      free(s->ptr);
      free(s);
      return -1;
    }    
  } else {
    free(s);
    return -2;
  }
}
Beispiel #2
0
int _ortc_getBalancer(char* url, char** response){
  CURL *curl;  
  CURLcode res;
  long httpCode;
  char *temp, *cluster;
  ortc_RestString *s = (ortc_RestString *)malloc(sizeof(ortc_RestString));
  
  if(s==NULL){
    *response = strdup("malloc() failed!");
    return -4;
  }

  curl = curl_easy_init();
  if(!curl){
    *response = strdup("Can not init curl!");
    free(s);
    return -1;
  }

  if(_ortc_initRestString(s)<0){
    *response = strdup("malloc() failed!");
    free(s);
    return -4;
  }
  curl_easy_setopt(curl, CURLOPT_URL, url);
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _ortc_writeRestString);
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, s);
  res = curl_easy_perform(curl);  
  if(res != CURLE_OK){
    *response = strdup("Can not connect with balancer!");
    curl_easy_cleanup(curl);
    free(s->ptr);
    free(s);
    return -2;
  }

  curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
  curl_easy_cleanup(curl);
  if(httpCode != 200){
    *response = strdup(s->ptr);
    free(s->ptr);
    free(s);
    return -3;
  }
  temp = _ortc_remove(s->ptr, "var SOCKET_SERVER = \"");
  cluster = _ortc_remove(temp, "\";");
  free(s->ptr);
  free(s);
  free(temp);
  *response = cluster;
  return 0;
}
Beispiel #3
0
int _ortc_getBalancer(char* url, char* appKey, int verifyCA, char** response){
  CURL *curl;  
  CURLcode res;
  long httpCode;
  char *temp, *cluster;
  char uUrl[512];
  ortc_RestString *s = (ortc_RestString *)malloc(sizeof(ortc_RestString));
  
  if(s==NULL){
    *response = strdup("malloc() failed!");
    return -4;
  }

  curl = curl_easy_init();
  if(!curl){
    *response = strdup("Can not init curl!");
    free(s);
    return -1;
  }

  if(_ortc_initRestString(s)<0){
    *response = strdup("malloc() failed!");
    free(s);
    return -4;
  }

  snprintf(uUrl, sizeof uUrl, "%s?appkey=%s", url, appKey);
  

  curl_easy_setopt(curl, CURLOPT_URL, uUrl);
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _ortc_writeRestString);
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, s);
  if(verifyCA==0)
	  curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
  res = curl_easy_perform(curl);  
  if(res != CURLE_OK){
    const char* curlErr = curl_easy_strerror(res);
	*response = (char*)malloc( strlen(curlErr) + strlen("Can not connect with balancer! ") + 1);
	sprintf(*response, "Can not connect with balancer! %s", curlErr);
    curl_easy_cleanup(curl);
    free(s->ptr);
    free(s);
    return -2;
  }

  curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
  curl_easy_cleanup(curl);
  if(httpCode != 200){
    *response = strdup(s->ptr);
    free(s->ptr);
    free(s);
    return -3;
  }
  temp = _ortc_remove(s->ptr, "var SOCKET_SERVER = \"");
  cluster = _ortc_remove(temp, "\";");
  free(s->ptr);
  free(s);
  free(temp);
  *response = cluster;
  return 0;
}
int _ortc_saveAuthRest(char* url, char* authToken, int isPrivate, char* appKey, int ttl, char* prvKey, ortc_channelPermissions *permissions, int sizeOfChannelPermissions, char** response) {
  int i;
  char body[2048], aUrl[128];
  char *temp;
  CURL *curl;
  long httpCode = 0;
  CURLcode res;
  ortc_RestString *s = (ortc_RestString *)malloc(sizeof(ortc_RestString));
  
  if(s==NULL){
    *response = strdup("malloc() failed!");
    return -3;
  }

  snprintf(body, sizeof body, "AT=%s&AK=%s&PK=%s&TTL=%d&PVT=%d&TP=%d",
	   authToken, appKey, prvKey,
	   ttl, isPrivate, sizeOfChannelPermissions);
  for(i=0; i< sizeOfChannelPermissions; i++){
    temp = (char*)malloc (1 + strlen(body));
    if(temp){
      strcpy(temp, body);
      snprintf(body, sizeof body, "%s&%s=%s", temp, permissions[i].channel, permissions[i].permission);	
    } else {
      *response = strdup("malloc failure!");
      free(s);
      return -3;
    }
    free(temp);
  }

  //prepare url (placed in aUrl)
  if(url[strlen(url)-1] == '/'){
    snprintf(aUrl, sizeof aUrl, "%sauthenticate", url);

  } else {
    snprintf(aUrl, sizeof aUrl, "%s/authenticate", url);
  }
  if(_ortc_initRestString(s)<0){
    *response = strdup("malloc() failed!");
    free(s);
    return -4;
  }


  curl = curl_easy_init();
  if(curl) {

    curl_easy_setopt(curl, CURLOPT_URL, aUrl);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _ortc_writeRestString);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, s);
    res = curl_easy_perform(curl);
    if(res == CURLE_OK){
      curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
      curl_easy_cleanup(curl);
      *response = strdup(s->ptr);
      free(s->ptr);
      free(s);
      if(httpCode == 201) {
	return 1;
      } else {
	return 0;
      }
    } else {
      *response = strdup("Can not connect with balancer!");
      free(s->ptr);
      free(s);
      return -1;
    }
    
  }
  *response = strdup("Can not init curl!");
  free(s);
  return -2;
}