예제 #1
0
static vhsm_rv send_message_raw_data_response(VhsmMessage const & message,
                                              VhsmResponse & response,
                                              unsigned char * buf,
                                              unsigned int buf_sz) {
  if (!send_message(message, response)) {
    return VHSM_RV_ERR;
  }
  
  switch (response.type()) {
    case VhsmResponse::ERROR : return convert_error_code(response.error_code());
    case VhsmResponse::RAW_DATA : {
      if (!response.has_raw_data()) {
        return VHSM_RV_ERR;
      }
      
      if (response.raw_data().data().size() > buf_sz) {
        return VHSM_RV_BAD_BUFFER_SIZE;
      }
      
      unsigned char const * data = (unsigned char const *) response.raw_data().data().data();
      std::copy(data, data + response.raw_data().data().size(), buf);
      
      return VHSM_RV_OK;
    }
    default : return VHSM_RV_ERR;
  }
}
static gboolean mkdg_config_file_key_file_open(MkdgConfigFile *configFile, MkdgError **error){
    MkdgError * cfgErr=NULL, *cfgErr_prep=NULL;
    if (g_access(configFile->path,R_OK)==0){
	GKeyFile *keyFile=g_key_file_new();
	configFile->fileObj= (gpointer) keyFile;
	g_key_file_load_from_file(keyFile, configFile->path, G_KEY_FILE_NONE, &cfgErr_prep);
	if (cfgErr_prep){
	    if (cfgErr->code==G_KEY_FILE_ERROR_PARSE){
		/* Possibly empty file */
		g_warning("Error parse on file %s, but it can also mean an empty file.", configFile->path);
		mkdg_error_handle(cfgErr_prep,error);
	    }else{
		cfgErr=convert_error_code(cfgErr_prep, configFile->path,
			"config_file_key_file_open(): g_key_file_load_from_file");
		mkdg_error_handle(cfgErr,error);
		if (keyFile){
		    g_key_file_free(keyFile);
		}
		return FALSE;
	    }
	}else{
	    /* No error */
	    configFile->flags |= MKDG_CONFIG_FILE_FLAG_HAS_CONTENT;
	}
	return TRUE;
    }
    cfgErr=mkdg_error_new(MKDG_ERROR_CONFIG_CANT_READ, "File %s cannot be read!", configFile->path);
    mkdg_error_handle(cfgErr,error);
    return FALSE;
}
예제 #3
0
static vhsm_rv send_message_key_info_response(const VhsmMessage &message,
                                              VhsmResponse &response,
                                              vhsm_key_info *keys_info,
                                              unsigned int keys_count) {
    if(!send_message(message, response)) return VHSM_RV_ERR;

    switch(response.type()) {
    case VhsmResponse::ERROR: return convert_error_code(response.error_code());
    case VhsmResponse::KEY_INFO_LIST: {
        if(!response.has_key_info()) return VHSM_RV_ERR;
        const KeyInfoList &info_list = response.key_info();
        if(info_list.keys_size() > keys_count) return VHSM_RV_BAD_BUFFER_SIZE;
        for (int i = 0; i != info_list.keys_size(); ++i) {
            const KeyInfo &ki = info_list.keys(i);
            if(ki.id().id().size() + 1 > sizeof(vhsm_key_id::id)) {
                //this means vhsm's key_id length is greater than the length in this API.
                return VHSM_RV_ERR;
            }

            vhsm_key_info *cki = keys_info + i;
            cki->length = ki.length();
            cki->purpose = ki.purpose();
            cki->import_date = ki.time();
            std::copy(ki.id().id().begin(), ki.id().id().end(), cki->key_id.id);
            cki->key_id.id[ki.id().id().size()] = 0;
        }
        return VHSM_RV_OK;
    }
    default:
        return VHSM_RV_ERR;
    }
}
예제 #4
0
static vhsm_rv send_message_ok_response(VhsmMessage const & message, VhsmResponse & response) {
  if (!send_message(message, response)) {
    return VHSM_RV_ERR;
  }
  
  switch (response.type()) {
    case VhsmResponse::ERROR : return convert_error_code(response.error_code());
    case VhsmResponse::OK : return VHSM_RV_OK;
    default : return VHSM_RV_ERR;
  }
}
static MkdgValue *mkdg_config_file_key_file_get_value(MkdgConfigFile *configFile, const gchar *pageName, const gchar *key,
       	MkdgType valueType, const gchar *parseOption, MkdgError **error){
    MkdgError *cfgErr_prep=NULL;
    gchar *str=g_key_file_get_string(configFile->fileObj, pageName, key, &cfgErr_prep);
    if (cfgErr_prep!=NULL){
	MkdgError *cfgErr=convert_error_code(cfgErr_prep, configFile->path, "config_file_key_file_get_value()");
	mkdg_error_handle(cfgErr,error);
	return NULL;
    }
    MkdgValue *mValue=mkdg_value_new(valueType,NULL);
    MkdgValue *ret=mkdg_value_from_string(mValue, str, parseOption);
    g_free(str);
    return ret;
}
예제 #6
0
static vhsm_rv send_message_unsigned_int_response(VhsmMessage const & message,
                                                  VhsmResponse & response,
                                                  unsigned int * r) {
  if (!send_message(message, response)) {
    return VHSM_RV_ERR;
  }
  
  switch (response.type()) {
    case VhsmResponse::ERROR : return convert_error_code(response.error_code());
    case VhsmResponse::UNSIGNED_INT : {
      if (!response.has_unsigned_int()) {
        return VHSM_RV_ERR;
      }
      *r = response.unsigned_int();
      return VHSM_RV_OK;
    }
    default : return VHSM_RV_ERR;
  }
}
예제 #7
0
vhsm_rv vhsm_tr_start_session(vhsm_session * session_ptr) {
  VhsmMessage message = create_session_message(VhsmSessionMessage::START, *session_ptr);
  VhsmResponse response;
  
  if (!send_message(message, response)) {
    return VHSM_RV_ERR;
  }
  
  switch (response.type()) {
    case VhsmResponse::ERROR : return convert_error_code(response.error_code());
    case VhsmResponse::SESSION : {
      if (!response.has_session()) {
        return VHSM_RV_ERR;
      }
      session_ptr->sid = response.session().sid();
      return VHSM_RV_OK;
    }
    default : return VHSM_RV_ERR;
  }
}
예제 #8
0
static vhsm_rv send_message_key_ids_response(VhsmMessage const & message,
                                             VhsmResponse & response,
                                             vhsm_key_id * key_ids,
                                             unsigned int ids_max) {
  if (!send_message(message, response)) {
    return VHSM_RV_ERR;
  }
  
  switch (response.type()) {
    case VhsmResponse::ERROR : return convert_error_code(response.error_code());
    case VhsmResponse::KEY_ID_LIST : {
      if (!response.has_key_ids()) {
        return VHSM_RV_ERR;
      }
      
      KeyIdList const & fetched_ids_list = response.key_ids();
      
      if (fetched_ids_list.ids_size() > ids_max) {
        return VHSM_RV_BAD_BUFFER_SIZE;
      }
      
      for (int i = 0; i != fetched_ids_list.ids_size(); ++i) {
        VhsmKeyId const & kid = fetched_ids_list.ids(i);
        
        if (kid.id().size() + 1 > sizeof(vhsm_key_id::id)) {
          //this means vhsm's key_id length is greater than the length in this API.
          return VHSM_RV_ERR;
        }
        
        std::copy(kid.id().begin(), kid.id().end(), (key_ids + i)->id);
        (key_ids + i)->id[kid.id().size()] = 0;
      }
      
      return VHSM_RV_OK;
    }
    default : return VHSM_RV_ERR;
  }
}