Esempio n. 1
0
/**
 * Fetches handlers registered for the given suite.
 *
 * @param suiteId requested suite ID.
 * @param result the buffer for Content Handlers result array. 
 *  <br>Use @link jsr211_fillHandlerArray function to fill this structure.
 * @return status of the operation
 */
jsr211_result jsr211_find_for_suite(SuiteIdType suiteId, 
                        /*OUT*/ JSR211_RESULT_CHARRAY* result) {
  int found_num;
  JSR211_CH *res_buffer;
  JSR211_CH *current_result, *last;

  if (open_table_file(0) != JSR211_OK) {
    return JSR211_FAILED;
  }

  res_buffer = alloc_CH_buffer(JSR211_MAX_RESULT_SET);
  if (res_buffer == NULL) {
    close_table_file();
    return JSR211_FAILED;
  }

  for (current_result = res_buffer, last = res_buffer + JSR211_MAX_RESULT_SET;
       current_result < last;
       current_result++) {
    if (-1 == find_next_by_suite(suiteId)) {
      break;
    }
    load_current_handler(current_result);
    goto_next_record();
  }

  if ((found_num = (int)(current_result - res_buffer))) {
    jsr211_fillHandlerArray(res_buffer, found_num, result);
  }
  free_CH_buffer(res_buffer, found_num);
  close_table_file();
  return JSR211_OK;
}
Esempio n. 2
0
/**
 * Loads the handler's data field. Allowed fields are: <UL>
 *  <LI> JSR211_FIELD_TYPES, <LI> JSR211_FIELD_SUFFIXES, 
 *  <LI> JSR211_FIELD_ACTIONS, <LI> JSR211_FIELD_LOCALES, 
 *  <LI> JSR211_FIELD_ACTION_MAP, <LI> and JSR211_FIELD_ACCESSES. </UL>
 *
 * @param id requested handler ID.
 * @param field_id requested field.
 * @param result output structure where requested array is placed to.
 *  <br>Use @link jsr211_fillStringArray function to fill this structure.
 * @return status of the operation
 */
jsr211_result jsr211_get_handler_field(const pcsl_string* id, 
                                    jsr211_field field_id, 
                                    /*OUT*/ JSR211_RESULT_STRARRAY* result) {
  int result_len = 0;
  pcsl_string* buf = NULL;

  if (record_struct[CHR_INDEX((int)(field_id))] != field_array) {
    return JSR211_FAILED;
  }

  if (open_table_file(0) != JSR211_OK) {
    return JSR211_FAILED;
  }

  if (find_next_by_field(NULL, JSR211_FIELD_ID, id, JSR211_TRUE, find_exact) 
                                                                        == -1) {
    close_table_file();
    return JSR211_FAILED;
  }

  /* reading field */
  position_field(CHR_INDEX((int)(field_id)));
  read_string_array(&result_len, &buf);
  if (result_len > 0) {
    jsr211_fillStringArray(buf, result_len, result);
    free_pcsl_string_list(buf, result_len);
  }

  close_table_file();
  return JSR211_OK;
}
Esempio n. 3
0
/**
 * Store content handler information into a registry.
 *
 * @param handler description of a registering handler. Implementation MUST NOT 
 * retain pointed object
 * @return JSR211_OK if content handler registered successfully
 */
jsr211_result jsr211_register_handler(const JSR211_content_handler* handler) {
  long current_position;
  unsigned int record_size = sizeof(int);

  if (open_table_file(1) != JSR211_OK) {
    return JSR211_FAILED;
  }
  storagePosition(&io_error_message, table_file, 
                                storageSizeOf(&io_error_message, table_file));
  current_position = storageRelativePosition(&io_error_message, table_file, 0);
  storageWrite(&io_error_message, table_file, (char *)&record_size, 
                        sizeof(record_size)); /* Placeholder for record size */

  record_size += write_string(&(handler->id));
  record_size += write_int(handler->flag);
  record_size += write_int(handler->suite_id);
  record_size += write_string(&(handler->class_name));
  record_size += write_string_array(handler->type_num, handler->types);
  record_size += write_string_array(handler->suff_num, handler->suffixes);
  record_size += write_string_array(handler->act_num, handler->actions);
  record_size += write_string_array(handler->locale_num, handler->locales);
  record_size += write_string_array(handler->locale_num * handler->act_num, 
                                                           handler->action_map);
  record_size += write_string_array(handler->access_num, handler->accesses);

  storagePosition(&io_error_message, table_file, current_position);
  storageWrite(&io_error_message, table_file, (char *)&record_size, 
                                                           sizeof(record_size));
  storageRelativePosition(&io_error_message, table_file, record_size - 
                                                                   sizeof(int));
  
  close_table_file();
  return JSR211_OK;
}
Esempio n. 4
0
void WriteTableInit( char *table,
                     ListNode *reserved,
                     ListNode *structs,
                     ListNode *unions)
{  /* DJS  Generate a <table>_init.h  header file so that the C file
           can be compiled separately.
           The header file contains the necessary includes and the
           prototype for <table>_InitTable().
   */
    FILE *initfile = open_table_file( table, INIT_FILE, EXT_C );

    fprintf( initfile, "\n"
"                 /*  %s cmodes definition module  */\n\n",
                      table );
    fprintf( initfile, "#include \"%s%s%s.%s\"\n\n",
                       table, FILENAME_SEPERATOR, INIT_FILE, EXT_H);

    fprintf( initfile, "extern Table *%s_InitTable()\n{", table);

    fprintf( initfile,
                  "  Table *%s_table = CreateTable( \"%s\", %s_%s, %s_%s );\n",
                       table, table, table, STRUCT_QTY_FRMT, table,
                       UNION_QTY_FRMT);

    WriteElements( initfile, table, reserved, structs);
    WriteUnionSorts( initfile, table, unions);
    fprintf( initfile, "\n   return( %s_table);\n}\n", table);
    fclose(initfile);
}
Esempio n. 5
0
void WriteTokens( char *signature,
                  char *table,
                  ListNode *reserved,
                  ListNode *structs,
                  ListNode *unions,
                  ListNode *vec_secs,
                  ListNode *macros,
                  ListNode *primitives )
{   FILE *outfile = open_table_file( table, INIT_FILE, EXT_H );

    fprintf( outfile, "\n"
"                 /* Header file for %s cmodes definition module */\n",
                      table );
    sprintf( buffer, "_%s%s%s_%s",
                     table, FILENAME_SEPERATOR, INIT_FILE, EXT_H );
    fprintf( outfile, "\n#ifndef %s\n#define %s\n\n#include \"cmodes.h\"\n\n",
                      buffer, buffer );

    if( signature != NULL )
    {  WriteSignature( outfile, table, signature);
    }
    WriteReservedTokens( outfile, reserved);
    WriteStructTokens( outfile, table, structs);
    WriteUnionTokens( outfile, table, unions);
    WriteVec_SecTokens( outfile, table, reserved, vec_secs);
    WriteAccessMacros( outfile, macros );
    WritePrimitiveSorts( outfile, primitives );
    WriteExterns( outfile, table);

    fprintf( outfile, "#endif\n\n" );
    fclose(outfile);
}
Esempio n. 6
0
/**
 * Searches content handler using specified key and value.
 *
 * @param caller_id calling application identifier
 * @param key search field id. Valid keys are: <ul> 
 *   <li>JSR211_FIELD_TYPES, <li>JSR211_FIELD_SUFFIXES, 
 *   <li>JSR211_FIELD_ACTIONS. </ul>
 * @param value search value
 * @param result the buffer for Content Handlers result array. 
 *  <br>Use @link jsr211_fillHandlerArray function to fill this structure.
 * @return status of the operation
 */
jsr211_result jsr211_find_handler(const pcsl_string* caller_id,
                        jsr211_field key, const pcsl_string* value,
                        /*OUT*/ JSR211_RESULT_CHARRAY* result) {
  int found_num;
  JSR211_CH *res_buffer;
  JSR211_CH *current_result, *last;
  jsr211_boolean case_sens;
  find_condition cond = find_exact;

  if (open_table_file(0) != JSR211_OK) {
    return JSR211_FAILED;
  }

  switch (key) {
    case JSR211_FIELD_TYPES:
    case JSR211_FIELD_SUFFIXES:
        case_sens = JSR211_FALSE;
        break;
    case JSR211_FIELD_ID:
        cond = find_test;
    case JSR211_FIELD_ACTIONS:
        case_sens = JSR211_TRUE;
        break;
    default:
        close_table_file();
        return JSR211_FAILED;
  }

  res_buffer = alloc_CH_buffer(JSR211_MAX_RESULT_SET);
  if (res_buffer == NULL) {
    close_table_file();
    return JSR211_FAILED;
  }

  for (current_result = res_buffer, last = res_buffer + JSR211_MAX_RESULT_SET;
       current_result < last;
       current_result++) {
    if (-1 == find_next_by_field(caller_id, key, value, case_sens, cond)) {
      break;
    }

    load_current_handler(current_result);
    goto_next_record();
  }

  if ((found_num = (int)(current_result - res_buffer))) {
    jsr211_fillHandlerArray(res_buffer, found_num, result);
  }
  free_CH_buffer(res_buffer, found_num);
  close_table_file();
  return JSR211_OK;
}
Esempio n. 7
0
/**
 * Gets the registered content handler for the ID.
 * The query can be for an exact match or for the handler
 * matching the prefix of the requested ID.
 *  <BR>Only a content handler which is visible to and accessible to the 
 * given @link caller_id should be returned.
 *
 * @param caller_id calling application identifier.
 * @param id handler ID.
 * @param mode flag indicating whether exact, prefixed or test search should be 
 * performed according to @link JSR211_SEARCH_MODE constants.
 * @param handler output value - requested handler.
 *  <br>Use @link jsr211_fillHandler function to fill this structure.
 * @return status of the operation
 */
jsr211_result jsr211_get_handler(const pcsl_string* caller_id, 
                        const pcsl_string* id, jsr211_search_flag mode,
                        /*OUT*/ JSR211_RESULT_CH* handler) {
  JSR211_CH ch;
  find_condition cond = mode == JSR211_SEARCH_PREFIX?   find_first:
                                                        find_exact; 

  if (open_table_file(0) != JSR211_OK) {
    return JSR211_FAILED;
  }

  if (find_next_by_field(caller_id, JSR211_FIELD_ID, id, JSR211_TRUE, cond) != -1) {
    load_current_handler(&ch);
    jsr211_fillHandler(&ch, handler);
    free_CH(&ch);
  }

  close_table_file();
  return JSR211_OK;
}
Esempio n. 8
0
/**
 * Deletes content handler information from a registry.
 *
 * @param handler_id content handler ID
 * @return JSR211_OK if content handler unregistered successfully
 */
jsr211_result jsr211_unregister_handler(const pcsl_string* handler_id) {
  long current_position, file_size, buffer_size;
  int record_size;
  char *buffer;

  if (open_table_file(1) != JSR211_OK) {
    return JSR211_FAILED;
  }
  if (find_next_by_field(NULL, JSR211_FIELD_ID, handler_id, JSR211_TRUE,
                                                            find_exact) == -1) {
    close_table_file();
    return JSR211_FAILED;
  }
  
  storageRead(&io_error_message, table_file, (char *)&record_size, sizeof(int));
  current_position = storageRelativePosition(&io_error_message, table_file, 
                                                            -(long)sizeof(int));
  file_size = storageSizeOf(&io_error_message, table_file);
  goto_next_record();
  
  if (!(buffer = JSR211_MALLOC((buffer_size = file_size - current_position - 
                                                            record_size)))) {
    close_table_file();
    return JSR211_FAILED;
  }
  
  storageRead(&io_error_message, table_file, buffer, buffer_size);
  storagePosition(&io_error_message, table_file, current_position);
  storageWrite(&io_error_message, table_file, buffer, buffer_size);
  JSR211_FREE(buffer);
  storageTruncate(&io_error_message, table_file, current_position + 
                                                                   buffer_size);
  
  close_table_file();
  return JSR211_OK;
}
Esempio n. 9
0
/**
 * Returns all found values for specified field. Tha allowed fields are: <ul>
 *    <li> JSR211_FIELD_ID, <li> JSR211_FIELD_TYPES, <li> JSR211_FIELD_SUFFIXES,
 *    <li> and JSR211_FIELD_ACTIONS. </ul>
 * Values should be selected only from handlers accessible for given caller_id.
 *
 * @param caller_id calling application identifier.
 * @param field search field id
 * @param result output structure where result is placed to.
 *  <br>Use @link jsr211_fillStringArray function to fill this structure.
 * @return status of the operation
 */
jsr211_result jsr211_get_all(const pcsl_string* caller_id, jsr211_field field,
                        /*OUT*/ JSR211_RESULT_STRARRAY* result) {
  long current_position;
  int found_num, access, current_size;
  pcsl_string *res_buffer = NULL;
  pcsl_string *current_result, *last;
  int chr = CHR_INDEX((int)(field));
  int isString;

  switch (record_struct[chr]) {
    case field_string:
      isString = 1;
      break;
    case field_array:
      isString = 0;
      break;
    default:
      return JSR211_FAILED;
  }

  if (open_table_file(0) != JSR211_OK) {
    return JSR211_FAILED;
  }
  res_buffer = alloc_pcsl_string_list(JSR211_MAX_RESULT_SET);
  if (res_buffer == NULL) {
    close_table_file();
    return JSR211_FAILED;
  }

  current_position = 0;
  for (current_result = res_buffer, last = res_buffer + JSR211_MAX_RESULT_SET;
       current_result < last;) {
    
    access = check_access(caller_id, current_position, &current_size);
    if (access == -1) {
      break;
    }
    
    if (access && position_field(chr) > 0) {
      if (isString) {
        read_string(current_result);
        if (!findStringInArray(res_buffer, current_result - res_buffer, 
                                                            current_result)) {
          current_result++;
        }
      }
      else {
        pcsl_string *array_res = NULL, *results, *last_res;
        int array_length = 0;

        read_string_array(&array_length, &array_res);
        if (array_length > 0) {
            for (results = array_res, last_res = array_res + array_length;
                 results < last_res && current_result < last;
                 results++) {
              if (!findStringInArray(res_buffer, current_result - res_buffer, 
                                                                    results)) {
                *(current_result++) = *results;
                *results = PCSL_STRING_NULL;
              }
            }
            free_pcsl_string_list(array_res, array_length);
        }
      }
    }
    
    storagePosition(&io_error_message, table_file, current_position);
    current_position += current_size;
    goto_next_record();
  }
  
  if ((found_num = (int)(current_result - res_buffer))) {
    jsr211_fillStringArray(res_buffer, found_num, result);
  }

  free_pcsl_string_list(res_buffer, JSR211_MAX_RESULT_SET);
  close_table_file();
  return JSR211_OK;
}