Exemplo n.º 1
0
/*! \internal
    \brief Subscribes a window to a message type
    \note Obtains ::cs_kmq_types
    */
KHMEXP khm_int32 KHMAPI kmq_subscribe_hwnd(khm_int32 type, HWND hwnd) {
    kmq_msg_subscription * s;

    s = PMALLOC(sizeof(kmq_msg_subscription));
    ZeroMemory(s, sizeof(*s));
    s->magic = KMQ_MSG_SUB_MAGIC;
    LINIT(s);
    s->queue = NULL;
    s->rcpt_type = KMQ_RCPTTYPE_HWND;
    s->recipient.hwnd = hwnd;
    kmqint_msg_type_add_sub(type, s);

    return KHM_ERROR_SUCCESS;
}
Exemplo n.º 2
0
/*! \internal
    \brief Get a message ref object
    \note called with cs_kmq_msg_ref held */
kmq_message_ref * kmqint_get_message_ref(void) {
    kmq_message_ref * r;

    LPOP(&kmq_msg_ref_free, &r);
    if(!r) {
        r = PMALLOC(sizeof(kmq_message_ref));
    }
    ZeroMemory(r, sizeof(kmq_message_ref));

    r->msg = NULL;
    r->recipient = NULL;

    return r;
}
Exemplo n.º 3
0
/* called with cs_identpro held */
static void
identpro_check_and_set_default_provider(void)
{
    wchar_t * p_order = NULL;
    khm_size cb;
    khm_handle csp_kcdb = NULL;
    khm_int32 rv;
    kcdb_identpro_i * p = NULL;
    wchar_t * e;

    if (KHM_SUCCEEDED(khc_open_space(NULL, L"KCDB", KHM_PERM_READ, &csp_kcdb))) {
        rv = khc_read_multi_string(csp_kcdb, L"IdentityProviderOrder", NULL, &cb);
        if (rv == KHM_ERROR_TOO_LONG && cb > sizeof(wchar_t) * 2) {
            p_order = PMALLOC(cb);
            rv = khc_read_multi_string(csp_kcdb, L"IdentityProviderOrder", p_order, &cb);
            if (KHM_FAILED(rv)) {
                PFREE(p_order);
                p_order = NULL;
            }
        }

        khc_close_space(csp_kcdb);
        csp_kcdb = NULL;
    }

    for (e = p_order;
         e && e[0];
         e = multi_string_next(e)) {

        p = identpro_find_by_name(e);
        if (p)
            break;
    }

    if (p != NULL) {
        if (DEFAULT_PROVIDER != p) {
            QDEL(&id_providers, p);
            QPUSH(&id_providers, p);
#ifdef DEBUG
            assert(DEFAULT_PROVIDER == p);
#endif
            kcdbint_identpro_post_message(KCDB_OP_NEW_DEFAULT, DEFAULT_PROVIDER);
        }
    }

    if (p)
        identpro_release(p);
    if (p_order)
        PFREE(p_order);
}
Exemplo n.º 4
0
/*! \internal
    \note Obtains ::cs_kmq_types, ::cs_kmq_global
    */
KHMEXP khm_int32 KHMAPI kmq_subscribe(khm_int32 type, kmq_callback_t cb) {
    kmq_msg_subscription * s;

    s = PMALLOC(sizeof(kmq_msg_subscription));
    ZeroMemory(s, sizeof(*s));
    s->magic = KMQ_MSG_SUB_MAGIC;
    LINIT(s);
    s->queue = kmqint_get_thread_queue();
    s->rcpt_type = KMQ_RCPTTYPE_CB;
    s->recipient.cb = cb;
    kmqint_msg_type_add_sub(type, s);

    return KHM_ERROR_SUCCESS;
}
Exemplo n.º 5
0
KHMEXP khm_int32 KHMAPI kmq_register_type(wchar_t * name,
                                          khm_int32 * new_id)
{
    int i;
    khm_int32 rv = KHM_ERROR_SUCCESS;
    BOOL registered = FALSE;
    int first_free = 0;
    size_t sz;

    if(FAILED(StringCbLength(name, KMQ_MAXCB_TYPE_NAME, &sz)) ||
       sz == 0)
        return KHM_ERROR_INVALID_PARAM;
    sz += sizeof(wchar_t);

    EnterCriticalSection(&cs_kmq_types);
    for(i=KMSGBASE_USER; i <= KMQ_MSG_TYPE_MAX; i++) {
        if(msg_types[i] == NULL) {
            if(first_free == 0)
                first_free = i;
            /* continue searching since we might find that this type
               is already registered. */
        } else {
            if(msg_types[i]->name != NULL &&
               !wcscmp(msg_types[i]->name, name)) {

                registered = TRUE;
                if (new_id)
                    *new_id = i;
                break;
            }
        }
    }

    if(registered) {
        rv = KHM_ERROR_EXISTS;
    } else if(first_free == 0) {
        rv = KHM_ERROR_NO_RESOURCES;
    } else {
        kmqint_msg_type_create(first_free);
        msg_types[first_free]->name = PMALLOC(sz);
        StringCbCopy(msg_types[first_free]->name, sz, name);

        if(new_id != NULL)
            *new_id = first_free;
    }
    LeaveCriticalSection(&cs_kmq_types);

    return rv;
}
Exemplo n.º 6
0
static void
resolve_string(kherr_event * e,
               const wchar_t ** str,
               va_list vl,
               khm_int32 mask,
               khm_int32 free_if,
               khm_int32 or_flag)
{
    wchar_t tbuf[KHERR_MAXCCH_STRING];
    size_t chars;
    size_t bytes;

    if (((e->flags & mask) == 0 ||
         (e->flags & mask) == free_if) &&
        *str != NULL) {

        chars = FormatMessage(FORMAT_MESSAGE_FROM_STRING,
                              (LPCVOID) *str,
                              0,
                              0,
                              tbuf,
                              ARRAYLENGTH(tbuf),
                              &vl);

        if ((e->flags & mask) == free_if) {
            assert(FALSE);
            /* We can't safely free *str here since other threads may
               have references to it.  Threads access event objects
               without locks. */
            PFREE((void *) *str);
        }

        e->flags &= ~mask;

        if (chars == 0) {
            *str = 0;
        } else {
            wchar_t * s;

            bytes = (chars + 1) * sizeof(wchar_t);
            s = PMALLOC(bytes);
            assert(s);
            StringCbCopy(s, bytes, tbuf);
            *str = s;
            e->flags |= or_flag;
        }
    }

}
Exemplo n.º 7
0
/*! \internal
    \brief Get a message object
    \note called with ::cs_kmq_msg held */
kmq_message *
kmqint_get_message(void) {
    kmq_message * m;

    LPOP(&msg_free,&m);
    if(!m) {
        /* allocate one */
        m = PMALLOC(sizeof(kmq_message));
    }
    ZeroMemory((void*)m, sizeof(kmq_message));

    LPUSH(&msg_active, m);

    return m;
}
Exemplo n.º 8
0
static void
resolve_msg_resource(kherr_event * e,
                     const wchar_t ** str,
                     va_list vl,
                     khm_int32 if_flag,
                     khm_int32 or_flag)
{
    wchar_t tbuf[KHERR_MAXCCH_STRING];
    size_t chars = 0;
    size_t bytes = 0;

    if(e->flags & if_flag) {
        if(e->h_module != NULL) {

            chars = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,
                                  (LPCVOID) e->h_module,
                                  (DWORD)(DWORD_PTR) *str,
                                  0,
                                  tbuf,
                                  ARRAYLENGTH(tbuf),
                                  &vl);
        }

        if(e->h_module == NULL || chars == 0) {
            *str = NULL;
        } else {
            wchar_t * s;

            /* MC inserts trailing \r\n to each message unless the
               message is terminated with a %0.  We remove the last
               line break since it is irrelevant to our handling of
               the string in the UI. */
            if (tbuf[chars-1] == L'\n')
                tbuf[--chars] = L'\0';
            if (tbuf[chars-1] == L'\r')
                tbuf[--chars] = L'\0';

            bytes = (chars + 1) * sizeof(wchar_t);
            s = PMALLOC(bytes);
            assert(s);
            StringCbCopy(s, bytes, tbuf);
            *str = s;
            e->flags |= or_flag;
        }
        e->flags &= ~if_flag;
    }
}
Exemplo n.º 9
0
void k5_add_file_cc(k5_ccc_data * d, wchar_t * path) {
    khm_size i;
    khm_size cch;

    if (FAILED(StringCchLength(path, MAX_PATH, &cch)) ||
        cch == 0)
        return;

    /* see if it's there first */
    for (i=0; i < d->n_file_ccs; i++) {
        if(!_wcsicmp(d->file_ccs[i].path, path))
            return;
    }

    if (d->n_file_ccs == d->nc_file_ccs) {
        k5_file_cc * f;

        d->nc_file_ccs = UBOUNDSS(d->n_file_ccs + 1,
                                  K5_FCC_ALLOC_INCR,
                                  K5_FCC_ALLOC_INCR);
#ifdef DEBUG
        assert(d->nc_file_ccs > d->n_file_ccs);
#endif
        f = PMALLOC(sizeof(*f) * d->nc_file_ccs);
        ZeroMemory(f, sizeof(*f) * d->nc_file_ccs);

        if (d->n_file_ccs > 0) {
#ifdef DEBUG
            assert(d->file_ccs != NULL);
#endif
            memcpy(f, d->file_ccs, sizeof(*f) * d->n_file_ccs);
        }
        if (d->file_ccs)
            PFREE(d->file_ccs);
        d->file_ccs = f;
    }

    StringCbCopy(d->file_ccs[d->n_file_ccs].path,
                 sizeof(d->file_ccs[0].path),
                 path);
    if(PathFileExists(path))
        d->file_ccs[d->n_file_ccs].flags = K5_FCC_FLAG_EXISTS;
    else
        d->file_ccs[d->n_file_ccs].flags = 0;

    d->n_file_ccs++;
}
Exemplo n.º 10
0
void
attach_this_thread(void)
{
    kherr_thread * t;

    t = (kherr_thread *) TlsGetValue(tls_error);
    if (t)
        return;

    t = PMALLOC(sizeof(kherr_thread) +
                sizeof(kherr_context *) * THREAD_STACK_SIZE);
    t->nc_ctx = THREAD_STACK_SIZE;
    t->n_ctx = 0;
    t->ctx = (kherr_context **) &t[1];

    TlsSetValue(tls_error, t);
}
Exemplo n.º 11
0
static khui_config_node_i *
cfgui_create_new_node(void) {
    khui_config_node_i * node;

    node = PMALLOC(sizeof(*node));
#ifdef DEBUG
    assert(node);
#endif
    ZeroMemory(node, sizeof(*node));
    node->magic = KHUI_CONFIG_NODE_MAGIC;

    EnterCriticalSection(&cs_cfgui);
    node->id = ++cfgui_node_serial;
    LeaveCriticalSection(&cs_cfgui);

    return node;
}
Exemplo n.º 12
0
static cfg_node_data *
get_node_data(khui_config_node_i * node,
              void * key,
              khm_boolean create) {
    khm_size i;

    for (i=0; i<node->n_data; i++) {
        if (node->data[i].key == key)
            return &(node->data[i]);
    }

    if (!create)
        return NULL;

    if (node->n_data + 1 > node->nc_data) {
        cfg_node_data * newdata;

        node->nc_data = UBOUNDSS((node->n_data + 1),
                                 KHUI_NODEDATA_ALLOC_INCR,
                                 KHUI_NODEDATA_ALLOC_INCR);
#ifdef DEBUG
        assert(node->nc_data >= node->n_data + 1);
#endif
        newdata = PMALLOC(sizeof(*newdata) * node->nc_data);
#ifdef DEBUG
        assert(newdata);
#endif
        ZeroMemory(newdata, sizeof(*newdata) * node->nc_data);

        if (node->data && node->n_data > 0) {
            memcpy(newdata, node->data, node->n_data * sizeof(*newdata));
            PFREE(node->data);
        }
        node->data = newdata;
    }

    node->data[node->n_data].key = key;
    node->data[node->n_data].hwnd = NULL;
    node->data[node->n_data].param = 0;
    node->data[node->n_data].flags = 0;

    node->n_data++;

    return &(node->data[node->n_data - 1]);
}
Exemplo n.º 13
0
static kherr_event *
get_empty_event(void)
{
    kherr_event * e;

    EnterCriticalSection(&cs_error);
    if(evt_free_list) {
        LPOP(&evt_free_list, &e);
    } else {
        e = PMALLOC(sizeof(*e));
    }
    LeaveCriticalSection(&cs_error);
    ZeroMemory(e, sizeof(*e));
    e->severity = KHERR_NONE;
    e->magic = KHERR_EVENT_MAGIC;

    return e;
}
Exemplo n.º 14
0
/*! \internal
    \brief Create a message type
    \note Obtains ::cs_kmq_types
    */
void kmqint_msg_type_create(int t) {
    if(t < 0 || t > KMQ_MSG_TYPE_MAX)
        return;

    EnterCriticalSection(&cs_kmq_types);
    if(!msg_types[t]) {
        kmq_msg_type * mt;
        mt = PMALLOC(sizeof(kmq_msg_type));
        ZeroMemory(mt, sizeof(kmq_msg_type));
        mt->id = t;
        LINIT(mt);
        mt->subs = NULL;
        msg_types[t] = mt;

        LPUSH(&all_msg_types, mt);
    }
    LeaveCriticalSection(&cs_kmq_types);
}
Exemplo n.º 15
0
void k5_pp_begin(khui_property_sheet * s)
{
    PROPSHEETPAGE *p;

    if(s->credtype == credtype_id_krb5 &&
       s->cred) {
        p = PMALLOC(sizeof(*p));
        ZeroMemory(p, sizeof(*p));

        p->dwSize = sizeof(*p);
        p->dwFlags = 0;
        p->hInstance = hResModule;
        p->pszTemplate = MAKEINTRESOURCE(IDD_PP_KRB5C);
        p->pfnDlgProc = krb5_pp_proc;
        p->lParam = (LPARAM) s;
        khui_ps_add_page(s, credtype_id_krb5, 0, p, NULL);
    }
}
Exemplo n.º 16
0
KHMEXP khm_int32 KHMAPI kmq_create_hwnd_subscription(HWND hw,
                                                     khm_handle * result)
{
    kmq_msg_subscription * s;

    s = PMALLOC(sizeof(kmq_msg_subscription));
    ZeroMemory(s, sizeof(*s));
    s->magic = KMQ_MSG_SUB_MAGIC;
    LINIT(s);
    s->queue = NULL;
    s->rcpt_type = KMQ_RCPTTYPE_HWND;
    s->recipient.hwnd = hw;

    EnterCriticalSection(&cs_kmq_global);
    LPUSH(&kmq_adhoc_subs, s);
    LeaveCriticalSection(&cs_kmq_global);

    *result = (khm_handle) s;

    return KHM_ERROR_SUCCESS;
}
Exemplo n.º 17
0
Arquivo: buf.c Projeto: aosm/Kerberos
static void kcdb_buf_assert_size(kcdb_buf * buf, khm_size cbsize)
{
    khm_size new_size;
    void * new_buf;

    /* should be less than or equal to the max signed 32 bit int */
    assert(cbsize <= KHM_INT32_MAX);
    if(cbsize <= buf->cb_buffer)
        return;

    new_size = UBOUNDSS(cbsize, KCDB_BUF_CBBUF_INITIAL, KCDB_BUF_CBBUF_GROWTH);

    assert(new_size > buf->cb_buffer && new_size > 0);

    new_buf = PMALLOC(new_size);
    assert(new_buf != NULL);

    memcpy(new_buf, buf->buffer, buf->cb_used);
    PFREE(buf->buffer);
    buf->buffer = new_buf;
}
Exemplo n.º 18
0
/*! \internal
    \note Obtains ::cs_kmq_global
*/
KHMEXP khm_int32 KHMAPI kmq_create_subscription(kmq_callback_t cb,
                                                khm_handle * result)
{
    kmq_msg_subscription * s;

    s = PMALLOC(sizeof(kmq_msg_subscription));
    ZeroMemory(s, sizeof(*s));
    s->magic = KMQ_MSG_SUB_MAGIC;
    LINIT(s);
    s->queue = kmqint_get_thread_queue();
    s->rcpt_type = KMQ_RCPTTYPE_CB;
    s->recipient.cb = cb;

    EnterCriticalSection(&cs_kmq_global);
    LPUSH(&kmq_adhoc_subs, s);
    LeaveCriticalSection(&cs_kmq_global);

    *result = (khm_handle) s;

    return KHM_ERROR_SUCCESS;
}
Exemplo n.º 19
0
KHMEXP kherr_param
kherr_dup_string(const wchar_t * s)
{
    wchar_t * dest;
    size_t cb_s;

    if (s == NULL)
        return _vnull();

    if (FAILED(StringCbLength(s, KHERR_MAXCB_STRING, &cb_s)))
        cb_s = KHERR_MAXCB_STRING;
    else
        cb_s += sizeof(wchar_t);

    dest = PMALLOC(cb_s);
    assert(dest != NULL);
    dest[0] = L'\0';

    StringCbCopy(dest, cb_s, s);

    return _tstr(dest);
}
Exemplo n.º 20
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");
    }
}
Exemplo n.º 21
0
static void
resolve_string_resource(kherr_event * e,
                        const wchar_t ** str,
                        va_list vl,
                        khm_int32 if_flag,
                        khm_int32 or_flag)
{
    wchar_t tfmt[KHERR_MAXCCH_STRING];
    wchar_t tbuf[KHERR_MAXCCH_STRING];
    size_t chars = 0;
    size_t bytes = 0;

    if(e->flags & if_flag) {
        if(e->h_module != NULL)
            chars = LoadString(e->h_module, (UINT)(INT_PTR) *str,
                               tfmt, ARRAYLENGTH(tbuf));
        if(e->h_module == NULL || chars == 0)
            *str = NULL;
        else {
            wchar_t * s;

            chars = FormatMessage(FORMAT_MESSAGE_FROM_STRING, tfmt,
                                  0, 0, tbuf, ARRAYLENGTH(tbuf), &vl);

            if (chars == 0) {
                *str = NULL;
            } else {
                bytes = (chars + 1) * sizeof(wchar_t);
                s = PMALLOC(bytes);
                assert(s);
                StringCbCopy(s, bytes, tbuf);
                *str = s;
                e->flags |= or_flag;
            }
        }
        e->flags &= ~if_flag;
    }
}
Exemplo n.º 22
0
KHMEXP khm_int32 KHMAPI 
kcdb_credset_create(khm_handle * result)
{
    kcdb_credset * cs;

    cs = PMALLOC(sizeof(kcdb_credset));
    ZeroMemory(cs, sizeof(kcdb_credset));

    cs->magic = KCDB_CREDSET_MAGIC;
    InitializeCriticalSection(&(cs->cs));
    LINIT(cs);
    kcdb_credset_buf_new(cs);
    cs->version = 0;
    cs->seal_count = 0;

    EnterCriticalSection(&cs_credset);
    LPUSH(&kcdb_credsets, cs);
    LeaveCriticalSection(&cs_credset);

    *result = (khm_handle) cs;

    return KHM_ERROR_SUCCESS;
}
Exemplo n.º 23
0
static void
push_context(kherr_context * c)
{
    kherr_thread * t;

    t = (kherr_thread *) TlsGetValue(tls_error);
    if (!t) {
        attach_this_thread();
        t = (kherr_thread *) TlsGetValue(tls_error);
        assert(t);
    }

    if (t->n_ctx == t->nc_ctx) {
        khm_size nc_new;
        khm_size cb_new;
        kherr_thread * nt;

        nc_new = t->nc_ctx + THREAD_STACK_SIZE;
        cb_new = sizeof(kherr_thread) +
            sizeof(kherr_context *) * nc_new;

        nt = PMALLOC(cb_new);
        memcpy(nt, t, sizeof(kherr_thread) +
               sizeof(kherr_context *) * t->n_ctx);
        nt->ctx = (kherr_context **) &nt[1];
        nt->nc_ctx = nc_new;

        PFREE(t);
        t = nt;
        TlsSetValue(tls_error, t);
    }

    assert(t->n_ctx < t->nc_ctx);
    t->ctx[t->n_ctx++] = c;

    kherr_hold_context(c);
}
Exemplo n.º 24
0
KHMEXP khm_int32 KHMAPI
khui_cfg_init_dialog_data(HWND hwnd_dlg,
                          const khui_config_init_data * data,
                          khm_size cb_extra,
                          khui_config_init_data ** new_data,
                          void ** extra) {
    khm_size cb;
    khui_config_init_data * d;

    cb = sizeof(khui_config_init_data) + cb_extra;
    d = PMALLOC(cb);
#ifdef DEBUG
    assert(d);
#endif
    ZeroMemory(d, cb);

    *d = *data;

    if (d->ctx_node)
        khui_cfg_hold(d->ctx_node);
    if (d->this_node)
        khui_cfg_hold(d->this_node);
    if (d->ref_node)
        khui_cfg_hold(d->ref_node);

#pragma warning(push)
#pragma warning(disable: 4244)
    SetWindowLongPtr(hwnd_dlg, DWLP_USER, (LONG_PTR) d);
#pragma warning(pop)

    if (new_data)
        *new_data = d;
    if (extra)
        *extra = (void *) (d + 1);

    return KHM_ERROR_SUCCESS;
}
Exemplo n.º 25
0
KHMEXP khm_int32 KHMAPI 
khui_alert_set_message(khui_alert * alert, const wchar_t * message)
{
    size_t cb = 0;

    assert(alert->magic == KHUI_ALERT_MAGIC);

    if(message) {
        if(FAILED(StringCbLength(message, 
                                 KHUI_MAXCB_MESSAGE, 
                                 &cb))) {
            return KHM_ERROR_INVALID_PARAM;
        }
        cb += sizeof(wchar_t);
    }

    EnterCriticalSection(&cs_alerts);
    if(alert->message && 
       (alert->flags & KHUI_ALERT_FLAG_FREE_MESSAGE)) {

        PFREE(alert->message);
        alert->flags &= ~KHUI_ALERT_FLAG_FREE_MESSAGE;
    }

    alert->message = NULL;

    if(message) {
        alert->message = PMALLOC(cb);
        StringCbCopy(alert->message, cb, message);
        alert->flags |= KHUI_ALERT_FLAG_FREE_MESSAGE;
    }
    alert->flags |= KHUI_ALERT_FLAG_MODIFIED;
    LeaveCriticalSection(&cs_alerts);

    return KHM_ERROR_SUCCESS;
}
Exemplo n.º 26
0
static kherr_context *
get_empty_context(void)
{
    kherr_context * c;

    EnterCriticalSection(&cs_error);
    if(ctx_free_list) {
        LPOP(&ctx_free_list, &c);
    } else {
        c = PMALLOC(sizeof(kherr_context));
    }

    ZeroMemory(c,sizeof(*c));
    c->severity = KHERR_NONE;
    c->flags = KHERR_CF_UNBOUND;
    c->magic = KHERR_CONTEXT_MAGIC;
    c->serial = ++ctx_serial;

    LPUSH(&ctx_root_list, c);

    LeaveCriticalSection(&cs_error);

    return c;
}
Exemplo n.º 27
0
void 
khui_statusbar_set_parts(HWND parent) {
    int i;
    int fillerwidth;
    int staticwidth;
    int lastx;
    int width;
    RECT r;
    INT * parts;

    GetClientRect(parent, &r);
    width = r.right - r.left;

    /* calculate fillerwidth and staticwidth */
    staticwidth = 0;
    for(i=0;i<khm_n_statusbar_parts;i++) {
        if(khm_statusbar_parts[i].wtype == KHUI_SB_WTYPE_ABSOLUTE) {
            staticwidth += khm_statusbar_parts[i].width;
        } else if(khm_statusbar_parts[i].wtype == KHUI_SB_WTYPE_RELATIVE) {
            staticwidth += (khm_statusbar_parts[i].width * width) / 100;
        }
    }

    fillerwidth = width - staticwidth;

    parts = PMALLOC(sizeof(INT) * khm_n_statusbar_parts);

    lastx = 0;
    for(i=0;i<khm_n_statusbar_parts;i++) {
        int w = 0;
        switch(khm_statusbar_parts[i].wtype) {
        case KHUI_SB_WTYPE_ABSOLUTE:
            w = khm_statusbar_parts[i].width;
            break;

        case KHUI_SB_WTYPE_RELATIVE:
            w = (khm_statusbar_parts[i].width * width) / 100;
            break;

        case KHUI_SB_WTYPE_FILLER:
            w = fillerwidth;
            break;

        default:
            w = 0;
#ifdef DEBUG
            assert(FALSE);
#endif
        }
        lastx += w;

        if(i==khm_n_statusbar_parts - 1)
            parts[i] = -1;
        else
            parts[i] = lastx;
    }

    SendMessage(
        khm_hwnd_statusbar,
        SB_SETPARTS,
        khm_n_statusbar_parts,
        (LPARAM) parts);

    PFREE(parts);
}
int
oss_als3xx_attach (oss_device_t * osdev)
{
  unsigned char pci_irq_line, pci_revision;
  unsigned short pci_command, vendor, device;
  unsigned int pci_ioaddr;
  int err;
  als300_devc *devc;

  DDB (cmn_err (CE_WARN, "Entered ALS ALS300 probe routine\n"));


  pci_read_config_word (osdev, PCI_VENDOR_ID, &vendor);
  pci_read_config_byte (osdev, PCI_REVISION_ID, &pci_revision);
  pci_read_config_word (osdev, PCI_COMMAND, &pci_command);
  pci_read_config_word (osdev, PCI_DEVICE_ID, &device);
  pci_read_config_irq (osdev, PCI_INTERRUPT_LINE, &pci_irq_line);
  pci_read_config_dword (osdev, PCI_BASE_ADDRESS_0, &pci_ioaddr);

  if (vendor != ALS_VENDOR_ID || (device != ALS_300 && device != ALS_300P))
    return 0;

  DDB (cmn_err (CE_WARN, "rev %x I/O base %04x\n", pci_revision, pci_ioaddr));

  if (pci_ioaddr == 0)
    {
      cmn_err (CE_WARN, "I/O address not assigned by BIOS.\n");
      return 0;
    }

  if (pci_irq_line == 0)
    {
      cmn_err (CE_WARN, "IRQ not assigned by BIOS (%d).\n", pci_irq_line);
      return 0;
    }

  if ((devc = PMALLOC (osdev, sizeof (*devc))) == NULL)
    {
      cmn_err (CE_WARN, "Out of memory\n");
      return 0;
    }

  devc->osdev = osdev;
  osdev->devc = devc;
  devc->open_mode = 0;

  devc->base = MAP_PCI_IOADDR (devc->osdev, 0, pci_ioaddr);
  /* Remove I/O space marker in bit 0. */
  devc->base &= ~3;

  devc->irq = pci_irq_line;
  devc->mpu_base = als300_mpu_base;

  pci_command |= PCI_COMMAND_MASTER | PCI_COMMAND_IO;
  pci_write_config_word (osdev, PCI_COMMAND, pci_command);


  switch (device)
    {
    case ALS_300:
      devc->model = MDL_ALS300;
      devc->chip_name = "Avance Logic ALS300";
      devc->chip_rev = pci_revision;
      break;

    case ALS_300P:
      devc->model = MDL_ALS300PLUS;
      devc->chip_name = "Avance Logic ALS300+";
      devc->chip_rev = pci_revision;
      break;
    }

  MUTEX_INIT (devc->osdev, devc->mutex, MH_DRV);
  MUTEX_INIT (devc->osdev, devc->low_mutex, MH_DRV + 1);

  oss_register_device (osdev, devc->chip_name);

  if ((err = oss_register_interrupts (devc->osdev, 0, als300intr, NULL)) < 0)
    {
      cmn_err (CE_WARN, "Can't allocate IRQ%d, err=%d\n", pci_irq_line, err);
      return 0;
    }

  return init_als300 (devc);	/* Detected */
}
Exemplo n.º 29
0
/* not threadsafe.  should only be called from the plugin thread */
khm_int32
afs_add_extension(afs_msg_announce * ann) {
    size_t cbname = 0;
    size_t cbtashort = 0;
    size_t cbtalong = 0;
    afs_extension * ext;
    wchar_t * tmp;

    if (ann->cbsize != sizeof(afs_msg_announce) ||
        FAILED(StringCbLength(ann->name, KHUI_MAXCB_NAME, &cbname)) ||
        ann->sub == NULL ||
        (ann->provide_token_acq &&
         ((FAILED(StringCbLength(ann->token_acq.short_desc,
                                 KHUI_MAXCB_SHORT_DESC,
                                 &cbtashort))) ||
          (ann->token_acq.long_desc &&
           FAILED(StringCbLength(ann->token_acq.long_desc,
                                 KHUI_MAXCB_LONG_DESC,
                                 &cbtalong))))) ||
        ann->version < AFS_PLUGIN_VERSION_MIN ||
        ann->version > AFS_PLUGIN_VERSION_MAX)

        return KHM_ERROR_INVALID_PARAM;

    if (n_extensions == MAX_EXTENSIONS)
        return KHM_ERROR_NO_RESOURCES;

    cbname += sizeof(wchar_t);
    cbtashort += sizeof(wchar_t);
    cbtalong += sizeof(wchar_t);

    ext = &extensions[n_extensions];

    *ext = *ann;

    tmp = PMALLOC(cbname);
#ifdef DEBUG
    assert(tmp);
#endif
    StringCbCopy(tmp, cbname, ann->name);
    ext->name = tmp;

    if (ann->provide_token_acq) {
        tmp = PMALLOC(cbtashort);
#ifdef DEBUG
        assert(tmp);
#endif
        StringCbCopy(tmp, cbtashort, ann->token_acq.short_desc);
        ext->token_acq.short_desc = tmp;

        if (ann->token_acq.long_desc) {
            tmp = PMALLOC(cbtalong);
#ifdef DEBUG
            assert(tmp);
#endif
            StringCbCopy(tmp, cbtalong,
                         ann->token_acq.long_desc);
            ext->token_acq.long_desc = tmp;
        } else {
            ext->token_acq.long_desc = NULL;
        }

        ann->token_acq.method_id = next_method_id++;
        ext->token_acq.method_id = ann->token_acq.method_id;
    } else {
        ZeroMemory(&ext->token_acq, sizeof(ext->token_acq));
    }

    n_extensions++;

    return KHM_ERROR_SUCCESS;
}
Exemplo n.º 30
0
/* Dialog procedure for IDD_IDSEL

   runs in UI thread */
static INT_PTR CALLBACK
idspec_dlg_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg) {
    case WM_INITDIALOG:
        {
            struct idsel_dlg_data * d;

            d = PMALLOC(sizeof(*d));
            ZeroMemory(d, sizeof(*d));
            d->magic = IDSEL_DLG_DATA_MAGIC;
            d->identity = NULL;

#pragma warning(push)
#pragma warning(disable: 4244)
            SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) d);
#pragma warning(pop)

            /* TODO: Initialize controls etc. */

        }

        CheckRadioButton(hwnd, IDC_REGISTRY, IDC_FILE, IDC_REGISTRY);
        EnableWindow(GetDlgItem(hwnd, IDC_PATH), FALSE);
        EnableWindow(GetDlgItem(hwnd, IDC_BROWSE), FALSE);

        SendDlgItemMessage(hwnd, IDC_NAME, EM_SETLIMITTEXT, KCDB_MAXCCH_NAME, 0);
        SendDlgItemMessage(hwnd, IDC_DESCRIPTION, EM_SETLIMITTEXT, KCDB_MAXCCH_SHORT_DESC, 0);
        SendDlgItemMessage(hwnd, IDC_PATH, EM_SETLIMITTEXT, MAX_PATH, 0);

        {
            wchar_t cuebanner[KCDB_MAXCCH_NAME];
            LoadString(hResModule, IDS_CUE_NAME, cuebanner, ARRAYLENGTH(cuebanner));
            SendDlgItemMessage(hwnd, IDC_NAME, EM_SETCUEBANNER, 0, (LPARAM)cuebanner);
            LoadString(hResModule, IDS_CUE_DESC, cuebanner, ARRAYLENGTH(cuebanner));
            SendDlgItemMessage(hwnd, IDC_DESCRIPTION, EM_SETCUEBANNER, 0, (LPARAM)cuebanner);
        }

        /* We return FALSE here because this is an embedded modeless
           dialog and we don't want to steal focus from the
           container. */
        return FALSE;

    case WM_DESTROY:
        {
            struct idsel_dlg_data * d;

            d = (struct idsel_dlg_data *)(LONG_PTR)
                GetWindowLongPtr(hwnd, DWLP_USER);

#ifdef DEBUG
            assert(d != NULL);
            assert(d->magic == IDSEL_DLG_DATA_MAGIC);
#endif
            if (d && d->magic == IDSEL_DLG_DATA_MAGIC) {
                if (d->identity) {
                    kcdb_identity_release(d->identity);
                    d->identity = NULL;
                }

                d->magic = 0;
                PFREE(d);
            }
#pragma warning(push)
#pragma warning(disable: 4244)
            SetWindowLongPtr(hwnd, DWLP_USER, 0);
#pragma warning(pop)
        }
        return TRUE;

    case WM_COMMAND:
        {
            switch (wParam) {
            case MAKEWPARAM(IDC_REGISTRY, BN_CLICKED):
                EnableWindow(GetDlgItem(hwnd, IDC_PATH), FALSE);
                EnableWindow(GetDlgItem(hwnd, IDC_BROWSE), FALSE);
                return TRUE;

            case MAKEWPARAM(IDC_FILE, BN_CLICKED):
                EnableWindow(GetDlgItem(hwnd, IDC_PATH), TRUE);
                EnableWindow(GetDlgItem(hwnd, IDC_BROWSE), TRUE);
                return TRUE;

            case MAKEWPARAM(IDC_BROWSE, BN_CLICKED):
                return on_browse(hwnd);
            }
        }
        break;

    case KHUI_WM_NC_NOTIFY:
        {
            struct idsel_dlg_data * d;
            khm_handle * ph;

            d = (struct idsel_dlg_data *)(LONG_PTR)
                GetWindowLongPtr(hwnd, DWLP_USER);

            switch (HIWORD(wParam)) {
            case WMNC_IDSEL_GET_IDENT:
                ph = (khm_handle *) lParam;

                on_get_ident(hwnd, d, ph);
                break;
            }
        }
        return TRUE;
    }
    return FALSE;
}