ext/RemoveUser.c in rubyfb-0.5.5 vs ext/RemoveUser.c in rubyfb-0.5.6

- old
+ new

@@ -27,11 +27,11 @@ #include "RemoveUser.h" #include "ibase.h" #include "ServiceManager.h" /* Function prototypes. */ -static VALUE initializeRemoveUser(VALUE , VALUE); +static VALUE initializeRemoveUser(VALUE, VALUE); static VALUE getUserName(VALUE); static VALUE setUserName(VALUE, VALUE); static void createRemoveUserBuffer(VALUE, char **, short *); @@ -47,30 +47,28 @@ * user to be removed. * * @return A reference to the newly initialized RemoveUser object. * */ -VALUE initializeRemoveUser(VALUE self, VALUE username) -{ - VALUE actual = rb_funcall(username, rb_intern("to_s"), 0), - value = Qnil; - int length = 0; - - /* Check that the parameters are valid. */ - value = rb_funcall(actual, rb_intern("length"), 0); - length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value); - if(length < 1 || length > 31) - { - rb_fireruby_raise(NULL, - "Invalid user name specified. A user name must not be "\ - "blank and may have no more than 31 characters."); - } +VALUE initializeRemoveUser(VALUE self, VALUE username) { + VALUE actual = rb_funcall(username, rb_intern("to_s"), 0), + value = Qnil; + int length = 0; - /* Assign class values. */ - rb_iv_set(self, "@user_name", actual); - - return(self); + /* Check that the parameters are valid. */ + value = rb_funcall(actual, rb_intern("length"), 0); + length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value); + if(length < 1 || length > 31) { + rb_fireruby_raise(NULL, + "Invalid user name specified. A user name must not be " \ + "blank and may have no more than 31 characters."); + } + + /* Assign class values. */ + rb_iv_set(self, "@user_name", actual); + + return(self); } /** * This function provides the user_name attribute accessor for the RemoveUser @@ -79,13 +77,12 @@ * @param self A reference to the RemoveUser object to make the call on. * * @return A reference to the attribute value for the object. * */ -VALUE getUserName(VALUE self) -{ - return(rb_iv_get(self, "@user_name")); +VALUE getUserName(VALUE self) { + return(rb_iv_get(self, "@user_name")); } /** * This function provides the user_name attribute mutator for the RemoveUser @@ -95,26 +92,24 @@ * @param setting The new value for the attribute. * * @return A reference to the newly update RemoveUser object. * */ -VALUE setUserName(VALUE self, VALUE setting) -{ - VALUE actual = rb_funcall(setting, rb_intern("to_s"), 0), - value = rb_funcall(actual, rb_intern("length"), 0); - int length = 0; - - length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value); - if(length < 1 || length > 31) - { - rb_fireruby_raise(NULL, - "Invalid user name specified. A user name must not be "\ - "blank and may have no more than 31 characters."); - } - rb_iv_set(self, "@user_name", actual); - - return(self); +VALUE setUserName(VALUE self, VALUE setting) { + VALUE actual = rb_funcall(setting, rb_intern("to_s"), 0), + value = rb_funcall(actual, rb_intern("length"), 0); + int length = 0; + + length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value); + if(length < 1 || length > 31) { + rb_fireruby_raise(NULL, + "Invalid user name specified. A user name must not be " \ + "blank and may have no more than 31 characters."); + } + rb_iv_set(self, "@user_name", actual); + + return(self); } /** @@ -125,36 +120,33 @@ * execute the task. * * @return A reference to the RemoveUser object executed. * */ -VALUE executeRemoveUser(VALUE self, VALUE manager) -{ - ManagerHandle *handle = NULL; - char *buffer = NULL; - short length = 0; - ISC_STATUS status[20]; +VALUE executeRemoveUser(VALUE self, VALUE manager) { + ManagerHandle *handle = NULL; + char *buffer = NULL; + short length = 0; + ISC_STATUS status[ISC_STATUS_LENGTH]; - /* Check that the service manager is connected. */ - Data_Get_Struct(manager, ManagerHandle, handle); - if(handle->handle == 0) - { - rb_fireruby_raise(NULL, - "Remove user error. Service manager not connected."); - } + /* Check that the service manager is connected. */ + Data_Get_Struct(manager, ManagerHandle, handle); + if(handle->handle == 0) { + rb_fireruby_raise(NULL, + "Remove user error. Service manager not connected."); + } - createRemoveUserBuffer(self, &buffer, &length); + createRemoveUserBuffer(self, &buffer, &length); - /* Start the service request. */ - if(isc_service_start(status, &handle->handle, NULL, length, buffer)) - { - free(buffer); - rb_fireruby_raise(status, "Error removing user."); - } - free(buffer); + /* Start the service request. */ + if(isc_service_start(status, &handle->handle, NULL, length, buffer)) { + free(buffer); + rb_fireruby_raise(status, "Error removing user."); + } + free(buffer); - return(self); + return(self); } /** * This function provides the execute method for the RemoveUser class. @@ -164,51 +156,48 @@ * buffer contents. * @param length A pointer to a short integer that will be assigned the length * of the buffer. * */ -void createRemoveUserBuffer(VALUE self, char **buffer, short *length) -{ - VALUE value = Qnil, - tmp_str = Qnil; - char *offset = NULL; - int number = 0; - - /* Calculate the required buffer length. */ - *length = 1; - tmp_str = rb_iv_get(self, "@user_name"); - *length += strlen(StringValuePtr(tmp_str)) + 3; - - /* Create and populate the buffer. */ - offset = *buffer = ALLOC_N(char, *length); - if(*buffer == NULL) - { - rb_raise(rb_eNoMemError, - "Memory allocation error preparing to remove user."); - } - memset(*buffer, 0, *length); +void createRemoveUserBuffer(VALUE self, char **buffer, short *length) { + VALUE value = Qnil, + tmp_str = Qnil; + char *offset = NULL; + int number = 0; - *offset++ = isc_action_svc_delete_user; - - *offset++ = isc_spb_sec_username; - value = rb_iv_get(self, "@user_name"); - number = strlen(StringValuePtr(value)); - ADD_SPB_LENGTH(offset, number); - memcpy(offset, StringValuePtr(value), number); - offset += number; + /* Calculate the required buffer length. */ + *length = 1; + tmp_str = rb_iv_get(self, "@user_name"); + *length += strlen(StringValuePtr(tmp_str)) + 3; + + /* Create and populate the buffer. */ + offset = *buffer = ALLOC_N(char, *length); + if(*buffer == NULL) { + rb_raise(rb_eNoMemError, + "Memory allocation error preparing to remove user."); + } + memset(*buffer, 0, *length); + + *offset++ = isc_action_svc_delete_user; + + *offset++ = isc_spb_sec_username; + value = rb_iv_get(self, "@user_name"); + number = strlen(StringValuePtr(value)); + ADD_SPB_LENGTH(offset, number); + memcpy(offset, StringValuePtr(value), number); + offset += number; } /** * This function initialize the RemoveUser class in the Ruby environment. * * @param module The module to create the new class definition under. * */ -void Init_RemoveUser(VALUE module) -{ - cRemoveUser = rb_define_class_under(module, "RemoveUser", rb_cObject); - rb_define_method(cRemoveUser, "initialize", initializeRemoveUser, 1); - rb_define_method(cRemoveUser, "user_name", getUserName, 0); - rb_define_method(cRemoveUser, "user_name=", setUserName, 1); - rb_define_method(cRemoveUser, "execute", executeRemoveUser, 1); +void Init_RemoveUser(VALUE module) { + cRemoveUser = rb_define_class_under(module, "RemoveUser", rb_cObject); + rb_define_method(cRemoveUser, "initialize", initializeRemoveUser, 1); + rb_define_method(cRemoveUser, "user_name", getUserName, 0); + rb_define_method(cRemoveUser, "user_name=", setUserName, 1); + rb_define_method(cRemoveUser, "execute", executeRemoveUser, 1); }