Esempio n. 1
0
int ms_append_test(void)
{
  wchar_t wbuf[512];
  size_t cbbuf;
  khm_int32 code;
  int i;

  for(i=0; i<n_strings; i++) {
    cbbuf = sizeof(wbuf);
    csv_to_multi_string(wbuf, &cbbuf, strings[i].csv);

    log(KHERR_DEBUG_1, "MS[");
    print_ms(wbuf);
    log(KHERR_DEBUG_1, "] + [foo]=[");

    cbbuf = sizeof(wbuf);
    code = multi_string_append(wbuf, &cbbuf, L"foo");

    if(code) {
      log(KHERR_DEBUG_1, " returned %d\n", code);
      return code;
    }

    print_ms(wbuf);
    log(KHERR_DEBUG_1, "]\n");

    log(KHERR_DEBUG_1, "  byte length: %d\n", cbbuf);
  }
  return code;
}
Esempio n. 2
0
void k5_write_file_cc_data(k5_ccc_data * d) {
    wchar_t * ms;
    khm_size cb;
    khm_size cbt;
    khm_int32 t;
    khm_size i;

#ifdef DEBUG
    assert(csp_params);
#endif
    if (KHM_FAILED(khc_read_int32(csp_params, L"MsLsaList", &t)) ||
        !!t != !!d->inc_mslsa) {
        khc_write_int32(csp_params, L"MsLsaList", !!d->inc_mslsa);
    }

    if (d->n_file_ccs > 0) {
        cb = d->n_file_ccs * MAX_PATH * sizeof(wchar_t);
        ms = PMALLOC(cb);
#ifdef DEBUG
        assert(ms);
#endif
        multi_string_init(ms, cb);

        for(i=0; i<d->n_file_ccs; i++) {
            cbt = cb;
            multi_string_append(ms, &cbt, d->file_ccs[i].path);
        }

        khc_write_multi_string(csp_params, L"FileCCList", ms);

        PFREE(ms);
    } else {
        if (khc_read_multi_string(csp_params, L"FileCCList", NULL, &cb)
            != KHM_ERROR_TOO_LONG ||
            cb != sizeof(wchar_t) * 2)

            khc_write_multi_string(csp_params, L"FileCCList", L"\0\0");
    }
}
Esempio n. 3
0
KHMEXP khm_int32   KHMAPI
kmm_register_plugin(kmm_plugin_reg * plugin, khm_int32 config_flags)
{
    khm_int32 rv = KHM_ERROR_SUCCESS;
    khm_handle csp_plugin = NULL;
    khm_handle csp_module = NULL;
    size_t cch;

    /* avoid accidently creating the module key if it doesn't exist */
    config_flags &= ~KHM_FLAG_CREATE;

    if((plugin == NULL) ||
       (plugin->dependencies &&
        KHM_FAILED(multi_string_length_cch(plugin->dependencies,
                                           KMM_MAXCCH_DEPS, &cch))) ||
       FAILED(StringCchLength(plugin->module, KMM_MAXCCH_NAME, &cch)) ||
       (plugin->description &&
        FAILED(StringCchLength(plugin->description,
                               KMM_MAXCCH_DESC, &cch))) ||
       FAILED(StringCchLength(plugin->name, KMM_MAXCCH_NAME, &cch)))
    {
        return KHM_ERROR_INVALID_PARAM;
    }

    /* note that we are retaining the length of the plugin name in
       chars in cch */
    cch ++;

#define CKRV if(KHM_FAILED(rv)) goto _exit

    rv = kmm_get_plugin_config(plugin->name,
                               config_flags | KHM_FLAG_CREATE, &csp_plugin);
    CKRV;

    /* should fail if the module key doesn't exist */
    rv = kmm_get_module_config(plugin->module, config_flags, &csp_module);
    CKRV;

    /*TODO: Make sure that the module registration is in the same
      config store as the one in which the plugin is going to be
      registered */

    rv = khc_write_string(csp_plugin, L"Module", plugin->module);
    CKRV;
    if(plugin->description) {
        rv = khc_write_string(csp_plugin, L"Description", plugin->description);
        CKRV;
    }

    if(plugin->dependencies) {
        rv = khc_write_multi_string(csp_plugin, L"Dependencies",
                                    plugin->dependencies);
        CKRV;
    }

    rv = khc_write_int32(csp_plugin, L"Type", plugin->type);
    CKRV;
    rv = khc_write_int32(csp_plugin, L"Disabled",
                         !!(plugin->flags & KMM_PLUGIN_FLAG_DISABLED));
    CKRV;

    {
        khm_size cb = 0;
        wchar_t * pl = NULL;
        size_t scb = 0;

        rv = khc_read_multi_string(csp_module, L"PluginList", NULL, &cb);
        if(rv != KHM_ERROR_TOO_LONG) {
            if (rv == KHM_ERROR_NOT_FOUND) {

                scb = cb = (cch + 1) * sizeof(wchar_t);
                pl = PMALLOC(cb);
                multi_string_init(pl, cb);
                rv = KHM_ERROR_SUCCESS;

                goto add_plugin_to_list;

            } else {
                goto _exit;
            }
        }

        cb += cch * sizeof(wchar_t);
        scb = cb;

        pl = PMALLOC(cb);

        rv = khc_read_multi_string(csp_module, L"PluginList", pl, &cb);
        if(KHM_FAILED(rv)) {
            if(pl)
                PFREE(pl);
            goto _exit;
        }

    add_plugin_to_list:

        if(!multi_string_find(pl, plugin->name, 0)) {
            multi_string_append(pl, &scb, plugin->name);
            rv = khc_write_multi_string(csp_module, L"PluginList", pl);
        }

        PFREE(pl);
        CKRV;
    }

#undef CKRV

_exit:
    if(csp_plugin)
        khc_close_space(csp_plugin);
    if(csp_module)
        khc_close_space(csp_module);

    return rv;
}