Пример #1
0
void IMSelectorGetCands(IMSelector* imselector)
{
    FcitxInstance* instance = imselector->owner;
    FcitxInputState *input = FcitxInstanceGetInputState(instance);
    FcitxIM* pim;
    UT_array* imes = FcitxInstanceGetIMEs(instance);
    FcitxInstanceCleanInputWindow(instance);
    FcitxCandidateWordSetPageSize(FcitxInputStateGetCandidateList(input), 10);
    FcitxCandidateWordSetChoose(FcitxInputStateGetCandidateList(input), DIGIT_STR_CHOOSE);
    FcitxInputStateSetShowCursor(input, false);

    FcitxInputContext* ic = FcitxInstanceGetCurrentIC(instance);
    FcitxInputContext2* ic2 = (FcitxInputContext2*) ic;
    if (!ic)
        return;

    FcitxMessagesAddMessageStringsAtLast(FcitxInputStateGetAuxUp(input),
                                         MSG_TIPS, imselector->global ?
                                         _("Select global input method: ") :
                                         _("Select local input method: "));
    if (ic2->imname) {
        int idx = FcitxInstanceGetIMIndexByName(instance, ic2->imname);
        FcitxIM* im = (FcitxIM*) utarray_eltptr(imes, idx);
        if (im) {
            FcitxMessagesAddMessageAtLast(FcitxInputStateGetAuxUp(input), MSG_TIPS, _("Current local input method is %s"), im->strName);
        }
    }
    else {
        FcitxMessagesAddMessageStringsAtLast(FcitxInputStateGetAuxUp(input),
                                             MSG_TIPS,
                                             _("No local input method"));
    }
    for (pim = (FcitxIM *) utarray_front(imes);
            pim != NULL;
            pim = (FcitxIM *) utarray_next(imes, pim)) {
        FcitxCandidateWord candWord;
        candWord.callback = IMSelectorGetCand;
        candWord.owner = imselector;
        candWord.strExtra = NULL;
        if (ic2->imname && strcmp(ic2->imname, pim->uniqueName) == 0) {
            candWord.priv = NULL;
            candWord.strWord = strdup(_("Clear local input method"));
        }
        else {
            candWord.priv = strdup(pim->uniqueName);
            candWord.strWord = strdup(pim->strName);
        }
        candWord.wordType = MSG_OTHER;
        FcitxCandidateWordAppend(FcitxInputStateGetCandidateList(input), &candWord);
    }
}
Пример #2
0
void hook_add(char *group, char *event, char *pattern, char *expr, int id)
{
  log_msg("HOOK", "ADD");
  log_msg("HOOK", "<%s> %s `%s`", event, pattern, expr);

  EventHandler *evh = get_event(event_idx(event));
  if (!evh)
    return;

  expr = strip_quotes(expr);

  Pattern *pat = NULL;
  if (pattern)
    pat = regex_pat_new(pattern);

  Hook hook = { id, HK_CMD, NULL, NULL, NULL, pat, .data.cmd = expr };
  augroup_insert(group, &hook);
  utarray_push_back(evh->hooks, &hook);
}

static void hook_delete(EventHandler *evh, Augroup *aug)
{
  for (int i = 0; i < utarray_len(evh->hooks); i++) {
    Hook *it = (Hook*)utarray_eltptr(evh->hooks, i);
    if (it->type == HK_CMD && it->aug == aug) {
      free(it->data.cmd);
      utarray_erase(evh->hooks, i, 1);
    }
  }
}

void hook_remove(char *group, char *event, char *pattern)
{
  log_msg("HOOK", "REMOVE");
  log_msg("HOOK", "<%s> %s `%s`", event, pattern, group);

  Augroup *aug = NULL;
  if (group)
    HASH_FIND_STR(aug_tbl, group, aug);

  if (event) {
    EventHandler *evh = get_event(event_idx(event));
    if (!evh)
      return;
    return hook_delete(evh, aug);
  }

  EventHandler *it;
  for (it = default_events; it != NULL; it = it->hh.next)
    hook_delete(it, aug);
}
Пример #3
0
FCITX_EXPORT_API
void FcitxInstanceGetWindowPosition(FcitxInstance* instance, FcitxInputContext* ic, int* x, int* y)
{
    if (ic == NULL)
        return;

    UT_array* frontends = &instance->frontends;
    FcitxAddon** pfrontend = (FcitxAddon**) utarray_eltptr(frontends, ic->frontendid);
    if (pfrontend == NULL)
        return;
    FcitxFrontend* frontend = (*pfrontend)->frontend;
    if (frontend->GetWindowPosition)
        frontend->GetWindowPosition((*pfrontend)->addonInstance, ic, x, y);
}
Пример #4
0
/* Add a sub-category to an existing or new category
 * IN: parent_name, name of the parent category
 * IN: child_name, name of the child category
 */
int MPIR_T_cat_add_subcat(const char *parent_name, const char *child_name)
{
    int mpi_errno = MPI_SUCCESS;
    int parent_index, child_index;
    name2index_hash_t *hash_entry;
    cat_table_entry_t *parent;

    /* NULL or empty string are allowed */
    if (parent_name == NULL || *parent_name == '\0' ||
        child_name == NULL || *child_name == '\0')
    {
        goto fn_exit;
    }

    /* Find or create parent */
    HASH_FIND_STR(cat_hash, parent_name, hash_entry);
    if (hash_entry != NULL) {
        /* Found parent in cat_table */
        parent_index = hash_entry->idx;
    } else {
        /* parent is a new category */
        MPIR_T_cat_create(parent_name);
        parent_index = utarray_len(cat_table) - 1;
    }

    /* Find or create child */
    HASH_FIND_STR(cat_hash, child_name, hash_entry);
    if (hash_entry != NULL) {
        /* Found child in cat_table */
        child_index = hash_entry->idx;
    } else {
        /* child is a new category */
        MPIR_T_cat_create(child_name);
        child_index = utarray_len(cat_table) - 1;
    }

    /* Connect parent and child */
    parent = (cat_table_entry_t *)utarray_eltptr(cat_table, parent_index);
    utarray_push_back(parent->subcat_indices, &child_index);

    /* Notify categories have been changed */
    cat_stamp++;

fn_exit:
    return mpi_errno;

fn_fail:
    goto fn_exit;
}
Пример #5
0
void hook_clear_host(int id)
{
  log_msg("HOOK", "CLEAR HOST");
  EventHandler *evh;
  for (evh = default_events; evh != NULL; evh = evh->hh.next) {
    for (int i = 0; i < utarray_len(evh->hooks); i++) {
      Hook *it = (Hook*)utarray_eltptr(evh->hooks, i);
      if (it->bufno == id) {
        if (it->type == HK_CMD)
          free(it->data.cmd);
        utarray_erase(evh->hooks, i, 1);
      }
    }
  }
}
Пример #6
0
void device_consistency_signature_list_free(device_consistency_signature_list *list)
{
    unsigned int size;
    unsigned int i;
    device_consistency_signature **p;
    if(list) {
        size = utarray_len(list->values);
        for (i = 0; i < size; i++) {
            p = (device_consistency_signature **)utarray_eltptr(list->values, i);
            SIGNAL_UNREF(*p);
        }
        utarray_free(list->values);
        free(list);
    }
}
Пример #7
0
void LoadSkinDirectory(FcitxClassicUI* classicui)
{
    UT_array* skinBuf = &classicui->skinBuf;
    utarray_clear(skinBuf);
    int i ;
    DIR *dir;
    struct dirent *drt;
    struct stat fileStat;
    size_t len;
    char *pathBuf;
    char **skinPath = FcitxXDGGetPathWithPrefix(&len, "skin");
    for (i = 0; i < len; i++) {
        dir = opendir(skinPath[i]);
        if (dir == NULL)
            continue;

        while ((drt = readdir(dir)) != NULL) {
            if (strcmp(drt->d_name , ".") == 0 || strcmp(drt->d_name, "..") == 0)
                continue;
            asprintf(&pathBuf, "%s/%s", skinPath[i], drt->d_name);

            int statresult = stat(pathBuf, &fileStat);
            free(pathBuf);
            if (statresult == -1) {
                continue;
            }
            if (fileStat.st_mode & S_IFDIR) {
                /* check duplicate name */
                int j = 0;
                for (; j < skinBuf->i; j++) {
                    char **name = (char**) utarray_eltptr(skinBuf, j);
                    if (strcmp(*name, drt->d_name) == 0)
                        break;
                }
                if (j == skinBuf->i) {
                    char *temp = drt->d_name;
                    utarray_push_back(skinBuf, &temp);
                }
            }
        }

        closedir(dir);
    }

    FcitxXDGFreePath(skinPath);

    return;
}
Пример #8
0
END_TEST

START_TEST (test_ports)
    {
        const zcr_port_t test_data[] = {
                {PROTO_TCP, ACCESS_ALLOW, htons(21), 1},
                {PROTO_TCP, ACCESS_ALLOW, htons(22), 1},
                {PROTO_UDP, ACCESS_ALLOW, htons(23), 1},
                {PROTO_UDP, ACCESS_ALLOW, htons(24), 1},
                {PROTO_TCP, ACCESS_DENY, htons(25), 1},
                {PROTO_TCP, ACCESS_DENY, htons(26), 1},
                {PROTO_UDP, ACCESS_DENY, htons(27), 1},
                {PROTO_UDP, ACCESS_DENY, htons(28), 1},
                {PROTO_TCP, ACCESS_ALLOW, htons(29), 0},
                {PROTO_TCP, ACCESS_ALLOW, htons(30), 0},
                {PROTO_UDP, ACCESS_ALLOW, htons(31), 0},
                {PROTO_UDP, ACCESS_ALLOW, htons(32), 0},
                {PROTO_TCP, ACCESS_DENY, htons(33), 0},
                {PROTO_TCP, ACCESS_DENY, htons(34), 0},
                {PROTO_UDP, ACCESS_DENY, htons(35), 0},
                {PROTO_UDP, ACCESS_DENY, htons(36), 0},
        };

        zclient_rule_parser_t *parser = zclient_rule_parser_new();
        zclient_rules_t rules;
        zclient_rules_init(&rules);

        fail_if(!zclient_rule_parse(parser, &rules, "ports.allow.tcp.21.22"));
        fail_if(!zclient_rule_parse(parser, &rules, "ports.allow.udp.23.24"));
        fail_if(!zclient_rule_parse(parser, &rules, "ports.deny.tcp.25.26"));
        fail_if(!zclient_rule_parse(parser, &rules, "ports.deny.udp.27.28"));
        fail_if(!zclient_rule_parse(parser, &rules, "rmports.allow.tcp.29.30"));
        fail_if(!zclient_rule_parse(parser, &rules, "rmports.allow.udp.31.32"));
        fail_if(!zclient_rule_parse(parser, &rules, "rmports.deny.tcp.33.34"));
        fail_if(!zclient_rule_parse(parser, &rules, "rmports.deny.udp.35.36"));
        fail_if(!rules.have.port_rules);
        fail_if(ARRAYSIZE(test_data) != utarray_len(&rules.port_rules));

        for (size_t i = 0; i < ARRAYSIZE(test_data); i++) {
            zcr_port_t *rule = *(zcr_port_t **) utarray_eltptr(&rules.port_rules, i);
            fail_if(test_data[i].add != rule->add, "ports idx=%u add flag fail", i);
            fail_if(test_data[i].proto != rule->proto, "ports idx=%u proto fail", i);
            fail_if(test_data[i].policy != rule->policy, "ports idx=%u policy fail", i);
            fail_if(test_data[i].port != rule->port, "ports idx=%u port fail", i);
        }

        zclient_rules_destroy(&rules);
    }
Пример #9
0
Файл: Array.c Проект: awm/atp
int ATP_arrayGetArray(const ATP_Array *p_array, unsigned int p_index, ATP_Array **p_value)
{
    Value *l_entry = (Value *) utarray_eltptr(CCAST(p_array), p_index);
    if (l_entry == NULL)
    {
        ERR("Index out of bounds\n");
        return 0;
    }

    if (l_entry->m_type == e_ATP_ValueType_array)
    {
        *p_value = &l_entry->m_value.m_array;
        return 1;
    }
    return 0;
}
Пример #10
0
FCITX_EXPORT_API
FcitxInputContext* FcitxInstanceFindIC(FcitxInstance* instance, int frontendid, void *filter)
{
    UT_array* frontends = &instance->frontends;
    FcitxAddon** pfrontend = (FcitxAddon**) utarray_eltptr(frontends, frontendid);
    if (pfrontend == NULL)
        return NULL;
    FcitxFrontend* frontend = (*pfrontend)->frontend;
    FcitxInputContext *rec = instance->ic_list;
    while (rec != NULL) {
        if (rec->frontendid == frontendid && frontend->CheckIC((*pfrontend)->addonInstance, rec, filter))
            return rec;
        rec = rec->next;
    }
    return NULL;
}
Пример #11
0
Файл: Array.c Проект: awm/atp
int ATP_arrayGetString(const ATP_Array *p_array, unsigned int p_index, const char **p_value)
{
    Value *l_entry = (Value *) utarray_eltptr(CCAST(p_array), p_index);
    if (l_entry == NULL)
    {
        ERR("Index out of bounds\n");
        return 0;
    }

    if (l_entry->m_type == e_ATP_ValueType_string)
    {
        *p_value = utstring_body(&l_entry->m_value.m_string);
        return 1;
    }
    return 0;
}
Пример #12
0
END_TEST

START_TEST (test_ports)
    {
        const struct zrule_port test_data[] = {
                {PROTO_TCP, PORT_ALLOW, htons(21), 1},
                {PROTO_TCP, PORT_ALLOW, htons(22), 1},
                {PROTO_UDP, PORT_ALLOW, htons(23), 1},
                {PROTO_UDP, PORT_ALLOW, htons(24), 1},
                {PROTO_TCP, PORT_DENY, htons(25), 1},
                {PROTO_TCP, PORT_DENY, htons(26), 1},
                {PROTO_UDP, PORT_DENY, htons(27), 1},
                {PROTO_UDP, PORT_DENY, htons(28), 1},
                {PROTO_TCP, PORT_ALLOW, htons(29), 0},
                {PROTO_TCP, PORT_ALLOW, htons(30), 0},
                {PROTO_UDP, PORT_ALLOW, htons(31), 0},
                {PROTO_UDP, PORT_ALLOW, htons(32), 0},
                {PROTO_TCP, PORT_DENY, htons(33), 0},
                {PROTO_TCP, PORT_DENY, htons(34), 0},
                {PROTO_UDP, PORT_DENY, htons(35), 0},
                {PROTO_UDP, PORT_DENY, htons(36), 0},
        };

        struct zcrules rules;
        crules_init(&rules);

        fail_if(0 != crules_parse(&rules, "ports.allow.tcp.21.22"), "ports parse fail");
        fail_if(0 != crules_parse(&rules, "ports.allow.udp.23.24"), "ports parse fail");
        fail_if(0 != crules_parse(&rules, "ports.deny.tcp.25.26"), "ports parse fail");
        fail_if(0 != crules_parse(&rules, "ports.deny.udp.27.28"), "ports parse fail");
        fail_if(0 != crules_parse(&rules, "rmports.allow.tcp.29.30"), "ports parse fail");
        fail_if(0 != crules_parse(&rules, "rmports.allow.udp.31.32"), "ports parse fail");
        fail_if(0 != crules_parse(&rules, "rmports.deny.tcp.33.34"), "ports parse fail");
        fail_if(0 != crules_parse(&rules, "rmports.deny.udp.35.36"), "ports parse fail");
        fail_if(!rules.have.port_rules, "ports have fail");
        fail_if(sizeof(test_data) / sizeof(test_data[0]) != utarray_len(&rules.port_rules), "ports count fail");

        for (size_t i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) {
            struct zrule_port *rule = *(struct zrule_port **) utarray_eltptr(&rules.port_rules, i);
            fail_if(test_data[i].add != rule->add, "ports idx=%u add flag fail", i);
            fail_if(test_data[i].proto != rule->proto, "ports idx=%u proto fail", i);
            fail_if(test_data[i].type != rule->type, "ports idx=%u type fail", i);
            fail_if(test_data[i].port != rule->port, "ports idx=%u port fail", i);
        }

        crules_free(&rules);
    }
Пример #13
0
FCITX_EXPORT_API
void FcitxInstanceUpdateClientSideUI(FcitxInstance* instance, FcitxInputContext* ic)
{
    if (ic == NULL)
        return;

    if (!(ic->contextCaps & CAPACITY_CLIENT_SIDE_UI))
        return;

    UT_array* frontends = &instance->frontends;

    FcitxAddon** pfrontend = (FcitxAddon**) utarray_eltptr(frontends, ic->frontendid);
    if (pfrontend == NULL)
        return;
    FcitxFrontend* frontend = (*pfrontend)->frontend;
    if (frontend->UpdateClientSideUI)
        frontend->UpdateClientSideUI((*pfrontend)->addonInstance, ic);
}
Пример #14
0
void LoadSkinDirectory(FcitxClassicUI* classicui)
{
    UT_array* skinBuf = &classicui->skinBuf;
    utarray_clear(skinBuf);
    int i ;
    DIR *dir;
    struct dirent *drt;
    size_t len;
    char **skinPath = FcitxXDGGetPathWithPrefix(&len, "skin");
    for (i = 0; i < len; i++) {
        dir = opendir(skinPath[i]);
        if (dir == NULL)
            continue;

        while ((drt = readdir(dir)) != NULL) {
            if (strcmp(drt->d_name , ".") == 0 ||
                strcmp(drt->d_name, "..") == 0)
                continue;
            char *pathBuf;
            fcitx_utils_alloc_cat_str(pathBuf, skinPath[i], "/", drt->d_name, "/fcitx_skin.conf");
            boolean result = fcitx_utils_isreg(pathBuf);
            free(pathBuf);
            if (result) {
                /* check duplicate name */
                int j = 0;
                for (; j < skinBuf->i; j++) {
                    char **name = (char**) utarray_eltptr(skinBuf, j);
                    if (strcmp(*name, drt->d_name) == 0)
                        break;
                }
                if (j == skinBuf->i) {
                    char *temp = drt->d_name;
                    utarray_push_back(skinBuf, &temp);
                }
            }
        }

        closedir(dir);
    }

    FcitxXDGFreePath(skinPath);

    return;
}
Пример #15
0
FCITX_EXPORT_API
void FcitxInstanceSetICStateFromSameApplication(FcitxInstance* instance, int frontendid, FcitxInputContext *ic)
{
    UT_array* frontends = &instance->frontends;
    FcitxAddon** pfrontend = (FcitxAddon**) utarray_eltptr(frontends, frontendid);
    if (pfrontend == NULL)
        return;
    FcitxFrontend* frontend = (*pfrontend)->frontend;
    if (!frontend->CheckICFromSameApplication)
        return;
    FcitxInputContext *rec = instance->ic_list;
    while (rec != NULL) {
        if (rec->frontendid == frontendid && frontend->CheckICFromSameApplication((*pfrontend)->addonInstance, rec, ic)) {
            ic->state = rec->state;
            break;
        }
        rec = rec->next;
    }
}
Пример #16
0
FCITX_EXPORT_API
void FcitxInstanceUpdatePreedit(FcitxInstance* instance, FcitxInputContext* ic)
{
    if (!instance->profile->bUsePreedit)
        return;

    if (ic == NULL)
        return;

    if (!(ic->contextCaps & CAPACITY_PREEDIT))
        return;

    UT_array* frontends = &instance->frontends;

    FcitxAddon** pfrontend = (FcitxAddon**) utarray_eltptr(frontends, ic->frontendid);
    if (pfrontend == NULL)
        return;
    FcitxFrontend* frontend = (*pfrontend)->frontend;
    frontend->UpdatePreedit((*pfrontend)->addonInstance, ic);
}
Пример #17
0
int MPII_Genutil_sched_sink(MPII_Genutil_sched_t * sched)
{
    MPL_DBG_MSG_FMT(MPIR_DBG_COLL, VERBOSE,
                    (MPL_DBG_FDEST, "Gentran: sched [sink] total=%d", sched->total_vtcs));

    vtx_t *vtxp;
    int i, n_in_vtcs = 0, vtx_id;
    int *in_vtcs;
    int mpi_errno = MPI_SUCCESS;

    MPIR_CHKLMEM_DECL(1);

    /* assign a new vertex */
    vtx_id = MPII_Genutil_vtx_create(sched, &vtxp);

    vtxp->vtx_kind = MPII_GENUTIL_VTX_KIND__SINK;

    MPIR_CHKLMEM_MALLOC(in_vtcs, int *, sizeof(int) * vtx_id,
                        mpi_errno, "in_vtcs buffer", MPL_MEM_COLL);
    /* record incoming vertices */
    for (i = vtx_id - 1; i >= 0; i--) {
        vtx_t *sched_fence = (vtx_t *) utarray_eltptr(sched->vtcs, i);
        MPIR_Assert(sched_fence != NULL);
        if (sched_fence->vtx_kind == MPII_GENUTIL_VTX_KIND__FENCE)
            /* no need to record this and any vertex before fence.
             * Dependency on the last fence call will be added by
             * the subsequent call to MPIC_Genutil_vtx_add_dependencies function */
            break;
        else {
            in_vtcs[vtx_id - 1 - i] = i;
            n_in_vtcs++;
        }
    }

    MPII_Genutil_vtx_add_dependencies(sched, vtx_id, n_in_vtcs, in_vtcs);
  fn_exit:
    MPIR_CHKLMEM_FREEALL();
    return vtx_id;
  fn_fail:
    goto fn_exit;
}
Пример #18
0
END_TEST

START_TEST (test_fwd)
    {
        const zcr_forward_t test_data[] = {
                {PROTO_TCP, htons(53), 0x04030201, 0, 1},
                {PROTO_UDP, htons(53), 0x08070605, 0, 1},
                {PROTO_TCP, htons(80), 0x0C0B0A09, htons(83), 1},
                {PROTO_UDP, htons(80), 0x100F0E0D, htons(83), 1},
                {PROTO_TCP, htons(53), 0, 0, 0},
                {PROTO_UDP, htons(53), 0, 0, 0},
                {PROTO_TCP, htons(80), 0, 0, 0},
                {PROTO_UDP, htons(80), 0, 0, 0},
        };

        zclient_rule_parser_t *parser = zclient_rule_parser_new();
        zclient_rules_t rules;
        zclient_rules_init(&rules);

        fail_if(!zclient_rule_parse(parser, &rules, "fwd.tcp.53.1.2.3.4"));
        fail_if(!zclient_rule_parse(parser, &rules, "fwd.udp.53.5.6.7.8"));
        fail_if(!zclient_rule_parse(parser, &rules, "fwd.tcp.80.9.10.11.12:83"));
        fail_if(!zclient_rule_parse(parser, &rules, "fwd.udp.80.13.14.15.16:83"));
        fail_if(!zclient_rule_parse(parser, &rules, "rmfwd.tcp.53"));
        fail_if(!zclient_rule_parse(parser, &rules, "rmfwd.udp.53"));
        fail_if(!zclient_rule_parse(parser, &rules, "rmfwd.tcp.80"));
        fail_if(!zclient_rule_parse(parser, &rules, "rmfwd.udp.80"));
        fail_if(!rules.have.fwd_rules, "fwd have fail");
        fail_if(ARRAYSIZE(test_data) != utarray_len(&rules.fwd_rules));

        for (size_t i = 0; i < ARRAYSIZE(test_data); i++) {
            zcr_forward_t *rule = *(zcr_forward_t **) utarray_eltptr(&rules.fwd_rules, i);
            fail_if(test_data[i].add != rule->add, "fwd idx=%u add flag fail", i);
            fail_if(test_data[i].proto != rule->proto, "fwd idx=%u proto fail", i);
            fail_if(test_data[i].port != rule->port, "fwd idx=%u port fail", i);
            fail_if(test_data[i].fwd_ip != rule->fwd_ip, "fwd idx=%u fwd_ip fail (0x%X)", i, rule->fwd_ip);
            fail_if(test_data[i].fwd_port != rule->fwd_port, "fwd idx=%u fwd_port fail", i);
        }

        zclient_rules_destroy(&rules);
    }
Пример #19
0
Файл: Array.c Проект: awm/atp
static Value *findOrCreateEntry(ATP_Array *p_array, unsigned int p_index)
{
    Value *l_entry;
    unsigned int l_length = utarray_len(CAST(p_array));
    if (p_index > l_length)
    {
        ERR("Index out of bounds\n");
        return NULL;
    }
    else if (p_index == l_length)
    {
        utarray_extend_back(CAST(p_array));
        l_entry = (Value *) utarray_back(CAST(p_array));
    }
    else
    {
        l_entry = (Value *) utarray_eltptr(CAST(p_array), p_index);
    }

    return l_entry;
}
Пример #20
0
void call_hooks(EventHandler *evh, Plugin *host, Plugin *caller, HookArg *hka)
{
  if (!evh)
    return;

  int count = utarray_len(evh->hooks);
  for (int i = 0; i < count; i++) {
    Hook *it = (Hook*)utarray_eltptr(evh->hooks, i);

    if (it->type == HK_CMD) {
      int id = id_from_plugin(host);
      if (it->bufno == -1 || (host && id == it->bufno))
        call_cmd_hook(it, hka);
      continue;
    }
    if (it->host != host && it->type != HK_TMP)
      continue;

    call_intl_hook(it, host, caller, hka);
  }
}
Пример #21
0
END_TEST

START_TEST (test_fwd)
    {
        const struct zrule_fwd test_data[] = {
                {PROTO_TCP, htons(53), 0x04030201, 0, 1},
                {PROTO_UDP, htons(53), 0x08070605, 0, 1},
                {PROTO_TCP, htons(80), 0x0C0B0A09, htons(83), 1},
                {PROTO_UDP, htons(80), 0x100F0E0D, htons(83), 1},
                {PROTO_TCP, htons(53), 0, 0, 0},
                {PROTO_UDP, htons(53), 0, 0, 0},
                {PROTO_TCP, htons(80), 0, 0, 0},
                {PROTO_UDP, htons(80), 0, 0, 0},
        };

        struct zcrules rules;
        crules_init(&rules);

        fail_if(0 != crules_parse(&rules, "fwd.tcp.53.1.2.3.4"), "fwd parse fail");
        fail_if(0 != crules_parse(&rules, "fwd.udp.53.5.6.7.8"), "fwd parse fail");
        fail_if(0 != crules_parse(&rules, "fwd.tcp.80.9.10.11.12:83"), "fwd parse fail");
        fail_if(0 != crules_parse(&rules, "fwd.udp.80.13.14.15.16:83"), "fwd parse fail");
        fail_if(0 != crules_parse(&rules, "rmfwd.tcp.53"), "fwd parse fail");
        fail_if(0 != crules_parse(&rules, "rmfwd.udp.53"), "fwd parse fail");
        fail_if(0 != crules_parse(&rules, "rmfwd.tcp.80"), "fwd parse fail");
        fail_if(0 != crules_parse(&rules, "rmfwd.udp.80"), "fwd parse fail");
        fail_if(!rules.have.fwd_rules, "fwd have fail");
        fail_if(sizeof(test_data) / sizeof(test_data[0]) != utarray_len(&rules.fwd_rules), "fwd count fail");

        for (size_t i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) {
            struct zrule_fwd *rule = *(struct zrule_fwd **) utarray_eltptr(&rules.fwd_rules, i);
            fail_if(test_data[i].add != rule->add, "fwd idx=%u add flag fail", i);
            fail_if(test_data[i].proto != rule->proto, "fwd idx=%u proto fail", i);
            fail_if(test_data[i].port != rule->port, "fwd idx=%u port fail", i);
            fail_if(test_data[i].fwd_ip != rule->fwd_ip, "fwd idx=%u fwd_ip fail (0x%X)", i, rule->fwd_ip);
            fail_if(test_data[i].fwd_port != rule->fwd_port, "fwd idx=%u fwd_port fail", i);
        }

        crules_free(&rules);
    }
Пример #22
0
FCITX_EXPORT_API
FcitxInputContext* FcitxInstanceCreateIC(FcitxInstance* instance, int frontendid, void * priv)
{
    UT_array* frontends = &instance->frontends;
    FcitxAddon** pfrontend = (FcitxAddon**) utarray_eltptr(frontends, frontendid);
    if (pfrontend == NULL)
        return NULL;
    FcitxFrontend* frontend = (*pfrontend)->frontend;

    FcitxInputContext *rec;
    if (instance->free_list != NULL) {
        rec = instance->free_list;
        instance->free_list = instance->free_list->next;
    } else
        rec = malloc(sizeof(FcitxInputContext));

    memset(rec, 0, sizeof(FcitxInputContext));
    rec->frontendid = frontendid;
    rec->offset_x = -1;
    rec->offset_y = -1;
    switch (instance->config->shareState) {
    case ShareState_All:
        rec->state = instance->globalState;
        break;
    case ShareState_None:
    case ShareState_PerProgram:
        rec->state = instance->config->defaultIMState;
        break;
    default:
        break;
    }

    frontend->CreateIC((*pfrontend)->addonInstance, rec, priv);

    rec->next = instance->ic_list;
    instance->ic_list = rec;
    return rec;
}
Пример #23
0
void scan_spool(int do_unlink) {
  int i;
  glob_t g;
  struct stat sb;
  UT_array *files;
  UT_array *xtras;
  utarray_new(files,&ut_str_icd);
  utarray_new(xtras,&xtra_icd);
  char **f, *file;
  file_xtra x, *xp;

  if (chdir(dir) == -1) exit(-1);
  glob(wild, 0, NULL, &g);
  for(i=0; i < g.gl_pathc; i++) {
    utarray_push_back(files, &g.gl_pathv[i]);
  }
  utarray_sort(files, strsort);

  f=NULL;
  while ( (f=(char**)utarray_next(files,f))) {
    file = *f;
    stat(file,&sb);
    if (do_unlink) unlink(file);
    x.file_idx = utarray_eltidx(files,f);
    x.file_len = sb.st_size;
    utarray_push_back(xtras, &x);
  }
  utarray_sort(xtras, xtrasort);
  xp=NULL;
  while ( (xp=(file_xtra*)utarray_next(xtras,xp))) {
    f = (char**)utarray_eltptr(files,xp->file_idx);
    file = *f;
    printf("file %s, len %d\n", blot(file),xp->file_len);
  }
  globfree(&g);
  utarray_free(files);
  utarray_free(xtras);
}
Пример #24
0
device_consistency_signature_list *device_consistency_signature_list_copy(const device_consistency_signature_list *list)
{
    int result = 0;
    device_consistency_signature_list *result_list = 0;
    unsigned int size;
    unsigned int i;
    device_consistency_signature **p;

    result_list = device_consistency_signature_list_alloc();
    if(!result_list) {
        result = SG_ERR_NOMEM;
        goto complete;
    }

    size = utarray_len(list->values);

    utarray_reserve(result_list->values, size);

    for (i = 0; i < size; i++) {
        p = (device_consistency_signature **)utarray_eltptr(list->values, i);
        result = device_consistency_signature_list_push_back(result_list, *p);
        if(result < 0) {
            goto complete;
        }
    }

complete:
    if(result < 0) {
        if(result_list) {
            device_consistency_signature_list_free(result_list);
        }
        return 0;
    }
    else {
        return result_list;
    }
}
Пример #25
0
FCITX_EXPORT_API
void FcitxInstanceCommitString(FcitxInstance* instance, FcitxInputContext* ic, char* str)
{
    if (str == NULL)
        return ;

    if (ic == NULL)
        return;

    UT_array* frontends = &instance->frontends;

    char *pstr = FcitxInstanceProcessCommitFilter(instance, str);
    if (pstr != NULL)
        str = pstr;

    FcitxAddon** pfrontend = (FcitxAddon**) utarray_eltptr(frontends, ic->frontendid);
    if (pfrontend == NULL)
        return;
    FcitxFrontend* frontend = (*pfrontend)->frontend;
    frontend->CommitString((*pfrontend)->addonInstance, ic, str);

    if (pstr)
        free(pstr);
}
Пример #26
0
FCITX_EXPORT_API
void FcitxInstanceEnd(FcitxInstance* instance)
{
    /* avoid duplicate destroy */
    if (instance->destroy)
        return;

    if (!instance->initialized) {
        if (!instance->loadingFatalError) {
            if (!instance->quietQuit)
                FcitxLog(ERROR, "Exiting.");
            instance->loadingFatalError = true;
            sem_post(instance->sem);
        }
        return;
    }

    instance->destroy = true;

    FcitxProfileSave(instance->profile);
    FcitxInstanceSaveAllIM(instance);

    if (instance->uinormal && instance->uinormal->ui->Destroy)
        instance->uinormal->ui->Destroy(instance->uinormal->addonInstance);

    if (instance->uifallback && instance->uifallback->ui->Destroy)
        instance->uifallback->ui->Destroy(instance->uifallback->addonInstance);

    instance->uifallback = NULL;
    instance->ui = NULL;
    instance->uinormal = NULL;

    /* handle exit */
    FcitxAddon** pimclass;
    FcitxAddon** pfrontend;
    FcitxFrontend* frontend;
    FcitxInputContext* rec = NULL;

    for (pimclass = (FcitxAddon**) utarray_front(&instance->imeclasses);
            pimclass != NULL;
            pimclass = (FcitxAddon**) utarray_next(&instance->imeclasses, pimclass)
        ) {
        if ((*pimclass)->imclass->Destroy)
            (*pimclass)->imclass->Destroy((*pimclass)->addonInstance);
    }

    for (rec = instance->ic_list; rec != NULL; rec = rec->next) {
        pfrontend = (FcitxAddon**) utarray_eltptr(&instance->frontends, rec->frontendid);
        frontend = (*pfrontend)->frontend;
        frontend->CloseIM((*pfrontend)->addonInstance, rec);
    }

    for (rec = instance->ic_list; rec != NULL; rec = rec->next) {
        pfrontend = (FcitxAddon**) utarray_eltptr(&instance->frontends, rec->frontendid);
        frontend = (*pfrontend)->frontend;
        frontend->DestroyIC((*pfrontend)->addonInstance, rec);
    }

    for (pfrontend = (FcitxAddon**) utarray_front(&instance->frontends);
            pfrontend != NULL;
            pfrontend = (FcitxAddon**) utarray_next(&instance->frontends, pfrontend)
        ) {
        if (pfrontend == NULL)
            continue;
        FcitxFrontend* frontend = (*pfrontend)->frontend;
        frontend->Destroy((*pfrontend)->addonInstance);
    }

    FcitxAddon** pmodule;
    for (pmodule = (FcitxAddon**) utarray_front(&instance->modules);
            pmodule != NULL;
            pmodule = (FcitxAddon**) utarray_next(&instance->modules, pmodule)
        ) {
        if (pmodule == NULL)
            return;
        FcitxModule* module = (*pmodule)->module;
        if (module->Destroy)
            module->Destroy((*pmodule)->addonInstance);
    }

    sem_post(instance->sem);

    /* don't return to main loop, wait for exit */
    int countDown = 5;
    while(countDown--) {
        sleep(1000);
    }
    exit(0);
}
Пример #27
0
void* RunInstance(void* arg)
{
    FcitxInstance* instance = (FcitxInstance*) arg;
    instance->initialized = true;
    int64_t curtime = 0;
    while (1) {
        FcitxAddon** pmodule;
        uint8_t signo = 0;
        while (read(instance->fd, &signo, sizeof(char)) > 0) {
            if (signo == SIGINT || signo == SIGTERM || signo == SIGQUIT)
                FcitxInstanceEnd(instance);
            else if (signo == SIGHUP)
                fcitx_utils_launch_restart();
            else if (signo == SIGUSR1)
                FcitxInstanceReloadConfig(instance);
        }
        do {
            instance->uiflag = UI_NONE;
            for (pmodule = (FcitxAddon**) utarray_front(&instance->eventmodules);
                    pmodule != NULL;
                    pmodule = (FcitxAddon**) utarray_next(&instance->eventmodules, pmodule)) {
                FcitxModule* module = (*pmodule)->module;
                module->ProcessEvent((*pmodule)->addonInstance);
            }
            struct timeval current_time;
            gettimeofday(&current_time, NULL);
            curtime = (current_time.tv_sec * 1000LL) + (current_time.tv_usec / 1000LL);

            int idx = 0;
            while(idx < utarray_len(&instance->timeout))
            {
                TimeoutItem* ti = (TimeoutItem*) utarray_eltptr(&instance->timeout, idx);
                uint64_t id = ti->idx;
                if (ti->time + ti->milli <= curtime) {
                    ti->callback(ti->arg);
                    ti = (TimeoutItem*) utarray_eltptr(&instance->timeout, idx);
                    /* faster remove */
                    if (ti && ti->idx == id)
                        utarray_remove_quick(&instance->timeout, idx);
                    else {
                        FcitxInstanceRemoveTimeoutById(instance, id);
                        idx = 0;
                    }
                }
                else {
                    idx++;
                }
            }

            if (instance->uiflag & UI_MOVE)
                FcitxUIMoveInputWindowReal(instance);

            if (instance->uiflag & UI_UPDATE)
                FcitxUIUpdateInputWindowReal(instance);
        } while (instance->uiflag != UI_NONE);

        FD_ZERO(&instance->rfds);
        FD_ZERO(&instance->wfds);
        FD_ZERO(&instance->efds);

        instance->maxfd = 0;
        if (instance->fd > 0) {
            instance->maxfd = instance->fd;
            FD_SET(instance->fd, &instance->rfds);
        }
        for (pmodule = (FcitxAddon**) utarray_front(&instance->eventmodules);
                pmodule != NULL;
                pmodule = (FcitxAddon**) utarray_next(&instance->eventmodules, pmodule)) {
            FcitxModule* module = (*pmodule)->module;
            module->SetFD((*pmodule)->addonInstance);
        }
        if (instance->maxfd == 0)
            break;
        struct timeval tval;
        struct timeval* ptval = NULL;
        if (utarray_len(&instance->timeout) != 0) {
            long int min_time = LONG_MAX;
            TimeoutItem* ti;
            for (ti = (TimeoutItem*) utarray_front(&instance->timeout);
                 ti != NULL;
                 ti = (TimeoutItem*) utarray_next(&instance->timeout, ti))
            {
                if (ti->time + ti->milli - curtime < min_time) {
                    min_time = ti->time + ti->milli - curtime;
                }
            }
            tval.tv_usec = (min_time % 1000) * 1000;
            tval.tv_sec = min_time / 1000;
            ptval = &tval;
        }
        select(instance->maxfd + 1, &instance->rfds, &instance->wfds, &instance->efds, ptval);
    }
    return NULL;
}
Пример #28
0
/*@
MPI_T_pvar_get_info - Get the inforamtion about a performance variable

Input/Output Parameters:
+ name_len - length of the string and/or buffer for name (integer)
- desc_len - length of the string and/or buffer for desc (integer)

Input Parameters:
. pvar_index - index of the performance variable to be queried between 0 and num_pvar-1 (integer)

Output Parameters:
+ name - buffer to return the string containing the name of the performance variable (string)
. verbosity - verbosity level of this variable (integer)
. var_class - class of performance variable (integer)
. datatype - MPI type of the information stored in the performance variable (handle)
. enumtype - optional descriptor for enumeration information (handle)
. desc - buffer to return the string containing a description of the performance variable (string)
. binding - type of MPI object to which this variable must be bound (integer)
. readonly - flag indicating whether the variable can be written/reset (integer)
. continuous - flag indicating whether the variable can be started and stopped or is continuously active (integer)
- atomic - flag indicating whether the variable can be atomically read and reset (integer)

.N ThreadSafe

.N Errors
.N MPI_SUCCESS
.N MPI_T_ERR_NOT_INITIALIZED
.N MPI_T_ERR_INVALID_INDEX
@*/
int MPI_T_pvar_get_info(int pvar_index, char *name, int *name_len, int *verbosity,
    int *var_class, MPI_Datatype *datatype, MPI_T_enum *enumtype, char *desc,
    int *desc_len, int *binding, int *readonly, int *continuous, int *atomic)
{
    int mpi_errno = MPI_SUCCESS;
    const pvar_table_entry_t *entry;
    const pvar_table_entry_t *info;

    MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_PVAR_GET_INFO);
    MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
    MPIR_T_THREAD_CS_ENTER();
    MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_PVAR_GET_INFO);

    /* Validate parameters */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS
        {
            MPIR_ERRTEST_PVAR_INDEX(pvar_index, mpi_errno);
            /* Do not do _TEST_ARGNULL for other arguments, since this is
             * allowed or will be allowed by MPI_T standard.
             */
        }
        MPID_END_ERROR_CHECKS
    }
#   endif /* HAVE_ERROR_CHECKING */

    /* ... body of routine ...  */

    entry = (pvar_table_entry_t *) utarray_eltptr(pvar_table, pvar_index);
    if (!entry->active) {
        mpi_errno = MPI_T_ERR_INVALID_INDEX;
        goto fn_fail;
    }

    info = (pvar_table_entry_t *) utarray_eltptr(pvar_table, pvar_index);

    MPIR_T_strncpy(name, info->name, name_len);
    MPIR_T_strncpy(desc, info->desc, desc_len);

    if (verbosity != NULL)
        *verbosity = info->verbosity;

    if (var_class != NULL)
        *var_class = info->varclass;

    if (datatype != NULL)
        *datatype = info->datatype;

    if (enumtype != NULL)
        *enumtype = info->enumtype;

    if (binding != NULL)
        *binding = info->bind;

    if (readonly != NULL)
        *readonly = info->flags & MPIR_T_PVAR_FLAG_READONLY;

    if (continuous != NULL)
        *continuous = info->flags & MPIR_T_PVAR_FLAG_CONTINUOUS;

    if (atomic != NULL)
        *atomic = info->flags & MPIR_T_PVAR_FLAG_ATOMIC;

    /* ... end of body of routine ... */

fn_exit:
    MPID_MPI_FUNC_EXIT(MPID_STATE_MPI_T_PVAR_GET_INFO);
    MPIR_T_THREAD_CS_EXIT();
    return mpi_errno;

fn_fail:
    /* --BEGIN ERROR HANDLING-- */
#   ifdef HAVE_ERROR_CHECKING
    {
        mpi_errno = MPIR_Err_create_code(
            mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER,
            "**mpi_t_pvar_get_info", "**mpi_t_pvar_get_info %d %p %p %p %p %p %p %p %p %p %p %p %p",
            pvar_index, name, name_len, verbosity, var_class, datatype, enumtype, desc, desc_len,
            binding, readonly, continuous, atomic);
    }
#   endif
    mpi_errno = MPIR_Err_return_comm(NULL, FCNAME, mpi_errno);
    goto fn_exit;
    /* --END ERROR HANDLING-- */
}
Пример #29
0
int MPIR_T_pvar_handle_alloc_impl(MPI_T_pvar_session session, int pvar_index,
                                  void *obj_handle, MPI_T_pvar_handle *handle,int *count)
{
    int mpi_errno = MPI_SUCCESS;
    int cnt, extra, bytes;
    int is_sum, is_watermark;
    const pvar_table_entry_t *info;
    MPIR_T_pvar_handle_t *hnd;

    MPIR_CHKPMEM_DECL(1);

    info = (pvar_table_entry_t *) utarray_eltptr(pvar_table, pvar_index);

    if (info->get_count == NULL) {
        cnt = info->count;
    } else {
        info->get_count(info->addr, obj_handle, &cnt);
    }

    bytes = MPID_Datatype_get_basic_size(info->datatype);
    is_sum = FALSE;
    is_watermark = FALSE;
    extra = 0;

    if (info->varclass == MPI_T_PVAR_CLASS_COUNTER ||
            info->varclass == MPI_T_PVAR_CLASS_AGGREGATE ||
            info->varclass == MPI_T_PVAR_CLASS_TIMER)
    {
        /* Extra memory for accum, offset, current */
        is_sum = TRUE;
        extra = bytes * cnt * 3;
    } else if (info->varclass == MPI_T_PVAR_CLASS_HIGHWATERMARK ||
               info->varclass == MPI_T_PVAR_CLASS_LOWWATERMARK)
    {
        is_watermark = TRUE;
    }

    /* Allocate memory and bzero it */
    MPIR_CHKPMEM_CALLOC(hnd, MPIR_T_pvar_handle_t*, sizeof(*hnd) + extra,
                        mpi_errno, "performance variable handle");
#ifdef HAVE_ERROR_CHECKING
    hnd->kind = MPIR_T_PVAR_HANDLE;
#endif

    /* Setup the common fields */
    if (is_sum)
        hnd->flags |= MPIR_T_PVAR_FLAG_SUM;
    else if (is_watermark)
        hnd->flags |= MPIR_T_PVAR_FLAG_WATERMARK;

    hnd->addr = info->addr;
    hnd->datatype = info->datatype;
    hnd->count = cnt;
    hnd->varclass = info->varclass;
    hnd->flags = info->flags;
    hnd->session = session;
    hnd->info = info;
    hnd->obj_handle = obj_handle;
    hnd->get_value = info->get_value;
    hnd->bytes = bytes;
    hnd->count = cnt;

    /* Init pointers to cache buffers for a SUM */
    if (MPIR_T_pvar_is_sum(hnd)) {
        hnd->accum = (char*)(hnd) + sizeof(*hnd);
        hnd->offset = (char*)(hnd) + sizeof(*hnd) + bytes*cnt;
        hnd->current = (char*)(hnd) + sizeof(*hnd) + bytes*cnt*2;
    }

    if (MPIR_T_pvar_is_continuous(hnd))
        MPIR_T_pvar_set_started(hnd);

    /* Set starting value of a continuous SUM */
    if (MPIR_T_pvar_is_continuous(hnd) && MPIR_T_pvar_is_sum(hnd)) {
        /* Cache current value of a SUM in offset.
         * accum is zero since we called CALLOC before.
         */
        if (hnd->get_value == NULL)
            MPIR_Memcpy(hnd->offset, hnd->addr, bytes*cnt);
        else
            hnd->get_value(hnd->addr, hnd->obj_handle, hnd->count, hnd->offset);
    }

    /* Link a WATERMARK handle to its pvar & set starting value if continuous */
    if (MPIR_T_pvar_is_watermark(hnd)) {
        MPIR_T_pvar_watermark_t *mark = (MPIR_T_pvar_watermark_t *)hnd->addr;
        if (!mark->first_used) {
            /* Use the special handle slot for optimization if available */
            mark->first_used = TRUE;
            MPIR_T_pvar_set_first(hnd);

            /* Set starting value */
            if (MPIR_T_pvar_is_continuous(hnd)) {
                mark->first_started = TRUE;
                mark->watermark = mark->current;
            } else {
                mark->first_started = FALSE;
            }
        } else {
            /* If the special handle slot is unavailable, link it to hlist */
            if (mark->hlist == NULL) {
                hnd->prev2 = hnd;
                mark->hlist = hnd;
            } else {
                hnd->prev2 = hnd;
                hnd->next2 = mark->hlist;
                mark->hlist->prev2 = hnd;
                mark->hlist = hnd;
            }

            /* Set starting value */
            if (MPIR_T_pvar_is_continuous(hnd))
                hnd->watermark = mark->current;
        }
    }

    /* Link the handle in its session and return it */
    MPL_DL_APPEND(session->hlist, hnd);
    *handle = hnd;
    *count = cnt;

    MPIR_CHKPMEM_COMMIT();
fn_exit:
    return mpi_errno;
fn_fail:
    MPIR_CHKPMEM_REAP();
    goto fn_exit;
}
Пример #30
0
compl_item* compl_idx_match(fn_compl *cmpl, int idx)
{
  return (compl_item*)utarray_eltptr(cmpl->matches, idx);
}