code
stringlengths
31
2.05k
label_name
stringclasses
5 values
label
int64
0
4
roleId: new ObjectId(input.roleId) } } ); await updateSessionUser(ctx, `${membership.userId}`); publishEvent(ctx, `${ctx.auth.workspaceId}`, { action: "update", data: { id: input.id, userId: `${membership.userId}`, roleId: `${role._id}`, role: { id: `${role._id}`, name: role.name, permissions: role.permissions, description: role.description } } }); }),
Base
1
roleId: new ObjectId(input.roleId) } } ); await updateSessionUser(ctx, `${membership.userId}`); publishEvent(ctx, `${ctx.auth.workspaceId}`, { action: "update", data: { id: input.id, userId: `${membership.userId}`, roleId: `${role._id}`, role: { id: `${role._id}`, name: role.name, permissions: role.permissions, description: role.description } } }); }),
Base
1
wrappers: (workspaceSettings.wrappers || []).map((item, index) => { if (index === sameKeyWrapperIndex) { return { ...item, ...input, ...(extensionId && { extension: item.extension || true }) }; } return item; }) } } ); } else {
Class
2
wrappers: (workspaceSettings.wrappers || []).map((item, index) => { if (index === sameKeyWrapperIndex) { return { ...item, ...input, ...(extensionId && { extension: item.extension || true }) }; } return item; }) } } ); } else {
Base
1
wrappers: (workspaceSettings.wrappers || []).map((item, index) => { if (index === sameKeyWrapperIndex) { return { ...item, ...input, ...(extensionId && { extension: item.extension || true }) }; } return item; }) } } ); } else {
Base
1
...(extensionId && { extension: item.extension || true }) }; } return item; })
Class
2
...(extensionId && { extension: item.extension || true }) }; } return item; })
Base
1
...(extensionId && { extension: item.extension || true }) }; } return item; })
Base
1
schema: zodToJsonSchema(envSchema.extend(envSchemaExtension || {})) })
Class
2
schema: zodToJsonSchema(envSchema.extend(envSchemaExtension || {})) })
Base
1
schema: zodToJsonSchema(envSchema.extend(envSchemaExtension || {})) })
Base
1
renderHTML({ node, HTMLAttributes }) { return [ "pre", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), [ "code", { class: node.attrs.lang ? `language-${node.attrs.lang}` : null }, 0 ] ]; },
Class
2
renderHTML({ node, HTMLAttributes }) { return [ "pre", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), [ "code", { class: node.attrs.lang ? `language-${node.attrs.lang}` : null }, 0 ] ]; },
Base
1
renderHTML({ node, HTMLAttributes }) { return [ "pre", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), [ "code", { class: node.attrs.lang ? `language-${node.attrs.lang}` : null }, 0 ] ]; },
Base
1
void context.ready.then(async () => { const file = context.model; const workspace = file.toJSON() as unknown as Workspace.IWorkspace; const path = context.path; const id = workspace.metadata.id; // Save the file contents as a workspace. await this._workspaces.save(id, workspace); // Save last save location for the save command. await this._state.save(LAST_SAVE_ID, path); // Navigate to new workspace. const url = URLExt.join(this._application, 'workspaces', id); if (this._router) { this._router.navigate(url, { hard: true }); } else { document.location.href = url; } });
Class
2
void context.ready.then(async () => { const file = context.model; const workspace = file.toJSON() as unknown as Workspace.IWorkspace; const path = context.path; const id = workspace.metadata.id; // Save the file contents as a workspace. await this._workspaces.save(id, workspace); // Save last save location for the save command. await this._state.save(LAST_SAVE_ID, path); // Navigate to new workspace. const url = URLExt.join(this._application, 'workspaces', id); if (this._router) { this._router.navigate(url, { hard: true }); } else { document.location.href = url; } });
Base
1
export function getSessionUrl(baseUrl: string, id: string): string { return URLExt.join(baseUrl, SESSION_SERVICE_URL, id); }
Class
2
export function getSessionUrl(baseUrl: string, id: string): string { return URLExt.join(baseUrl, SESSION_SERVICE_URL, id); }
Base
1
export async function requestTranslationsAPI<T>( translationsUrl: string = '', locale = '', init: RequestInit = {}, serverSettings: ServerConnection.ISettings | undefined = undefined ): Promise<T> { // Make request to Jupyter API const settings = serverSettings ?? ServerConnection.makeSettings(); translationsUrl = translationsUrl || `${settings.appUrl}/${TRANSLATIONS_SETTINGS_URL}`; const requestUrl = URLExt.join(settings.baseUrl, translationsUrl, locale); let response: Response; try { response = await ServerConnection.makeRequest(requestUrl, init, settings); } catch (error) { throw new ServerConnection.NetworkError(error); } let data: any = await response.text(); if (data.length > 0) { try { data = JSON.parse(data); } catch (error) { console.error('Not a JSON response body.', response); } } if (!response.ok) { throw new ServerConnection.ResponseError(response, data.message || data); } return data; }
Class
2
export async function requestTranslationsAPI<T>( translationsUrl: string = '', locale = '', init: RequestInit = {}, serverSettings: ServerConnection.ISettings | undefined = undefined ): Promise<T> { // Make request to Jupyter API const settings = serverSettings ?? ServerConnection.makeSettings(); translationsUrl = translationsUrl || `${settings.appUrl}/${TRANSLATIONS_SETTINGS_URL}`; const requestUrl = URLExt.join(settings.baseUrl, translationsUrl, locale); let response: Response; try { response = await ServerConnection.makeRequest(requestUrl, init, settings); } catch (error) { throw new ServerConnection.NetworkError(error); } let data: any = await response.text(); if (data.length > 0) { try { data = JSON.parse(data); } catch (error) { console.error('Not a JSON response body.', response); } } if (!response.ok) { throw new ServerConnection.ResponseError(response, data.message || data); } return data; }
Base
1
headers: baseHeaders(), }) .then((res) => res.json()) .then((res) => res) .catch((e) => { console.error(e); return { filename: null, error: e.message }; }); },
Class
2
exportImport: () => { return "/settings/export-import"; },
Class
2
exports: () => { return `${API_BASE.replace("/api", "")}/system/data-exports`; },
Class
2
get url() { return `http://${this[incomingKey].headers.host}${this[incomingKey].url}` },
Base
1
msg_puts_printf(char_u *str, int maxlen) { char_u *s = str; char_u *buf = NULL; char_u *p = s; #ifdef MSWIN if (!(silent_mode && p_verbose == 0)) mch_settmode(TMODE_COOK); // handle CR and NL correctly #endif while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) { if (!(silent_mode && p_verbose == 0)) { // NL --> CR NL translation (for Unix, not for "--version") if (*s == NL) { int n = (int)(s - p); buf = alloc(n + 3); if (buf != NULL) { memcpy(buf, p, n); if (!info_message) buf[n++] = CAR; buf[n++] = NL; buf[n++] = NUL; if (info_message) // informative message, not an error mch_msg((char *)buf); else mch_errmsg((char *)buf); vim_free(buf); } p = s + 1; } } // primitive way to compute the current column #ifdef FEAT_RIGHTLEFT if (cmdmsg_rl) { if (*s == CAR || *s == NL) msg_col = Columns - 1; else --msg_col; } else #endif { if (*s == CAR || *s == NL) msg_col = 0; else ++msg_col; } ++s; } if (*p != NUL && !(silent_mode && p_verbose == 0)) { char_u *tofree = NULL; if (maxlen > 0 && STRLEN(p) > (size_t)maxlen) { tofree = vim_strnsave(p, (size_t)maxlen); p = tofree; } if (p != NULL) { if (info_message) mch_msg((char *)p); else mch_errmsg((char *)p); vim_free(tofree); } } msg_didout = TRUE; // assume that line is not empty #ifdef MSWIN if (!(silent_mode && p_verbose == 0)) mch_settmode(TMODE_RAW); #endif }
Variant
0
get_register( int name, int copy) // make a copy, if FALSE make register empty. { yankreg_T *reg; int i; #ifdef FEAT_CLIPBOARD // When Visual area changed, may have to update selection. Obtain the // selection too. if (name == '*' && clip_star.available) { if (clip_isautosel_star()) clip_update_selection(&clip_star); may_get_selection(name); } if (name == '+' && clip_plus.available) { if (clip_isautosel_plus()) clip_update_selection(&clip_plus); may_get_selection(name); } #endif get_yank_register(name, 0); reg = ALLOC_ONE(yankreg_T); if (reg == NULL) return (void *)NULL; *reg = *y_current; if (copy) { // If we run out of memory some or all of the lines are empty. if (reg->y_size == 0) reg->y_array = NULL; else reg->y_array = ALLOC_MULT(char_u *, reg->y_size); if (reg->y_array != NULL) { for (i = 0; i < reg->y_size; ++i) reg->y_array[i] = vim_strsave(y_current->y_array[i]); } } else y_current->y_array = NULL; return (void *)reg; }
Base
1
regtilde(char_u *source, int magic) { char_u *newsub = source; char_u *tmpsub; char_u *p; int len; int prevlen; for (p = newsub; *p; ++p) { if ((*p == '~' && magic) || (*p == '\\' && *(p + 1) == '~' && !magic)) { if (reg_prev_sub != NULL) { // length = len(newsub) - 1 + len(prev_sub) + 1 prevlen = (int)STRLEN(reg_prev_sub); tmpsub = alloc(STRLEN(newsub) + prevlen); if (tmpsub != NULL) { // copy prefix len = (int)(p - newsub); // not including ~ mch_memmove(tmpsub, newsub, (size_t)len); // interpret tilde mch_memmove(tmpsub + len, reg_prev_sub, (size_t)prevlen); // copy postfix if (!magic) ++p; // back off backslash STRCPY(tmpsub + len + prevlen, p + 1); if (newsub != source) // already allocated newsub vim_free(newsub); newsub = tmpsub; p = newsub + len + prevlen; } } else if (magic) STRMOVE(p, p + 1); // remove '~' else STRMOVE(p, p + 2); // remove '\~' --p; } else { if (*p == '\\' && p[1]) // skip escaped characters ++p; if (has_mbyte) p += (*mb_ptr2len)(p) - 1; } } // Store a copy of newsub in reg_prev_sub. It is always allocated, // because recursive calls may make the returned string invalid. vim_free(reg_prev_sub); reg_prev_sub = vim_strsave(newsub); return newsub; }
Base
1
is_qf_win(win_T *win, qf_info_T *qi) { // A window displaying the quickfix buffer will have the w_llist_ref field // set to NULL. // A window displaying a location list buffer will have the w_llist_ref // pointing to the location list. if (bt_quickfix(win->w_buffer)) if ((IS_QF_STACK(qi) && win->w_llist_ref == NULL) || (IS_LL_STACK(qi) && win->w_llist_ref == qi)) return TRUE; return FALSE; }
Variant
0
ex_history(exarg_T *eap) { histentry_T *hist; int histype1 = HIST_CMD; int histype2 = HIST_CMD; int hisidx1 = 1; int hisidx2 = -1; int idx; int i, j, k; char_u *end; char_u *arg = eap->arg; if (hislen == 0) { msg(_("'history' option is zero")); return; } if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) { end = arg; while (ASCII_ISALPHA(*end) || vim_strchr((char_u *)":=@>/?", *end) != NULL) end++; i = *end; *end = NUL; histype1 = get_histtype(arg); if (histype1 == -1) { if (STRNICMP(arg, "all", STRLEN(arg)) == 0) { histype1 = 0; histype2 = HIST_COUNT-1; } else { *end = i; semsg(_(e_trailing_characters_str), arg); return; } } else histype2 = histype1; *end = i; } else end = arg; if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) { semsg(_(e_trailing_characters_str), end); return; } for (; !got_int && histype1 <= histype2; ++histype1) { STRCPY(IObuff, "\n # "); STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); msg_puts_title((char *)IObuff); idx = hisidx[histype1]; hist = history[histype1]; j = hisidx1; k = hisidx2; if (j < 0) j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; if (k < 0) k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; if (idx >= 0 && j <= k) for (i = idx + 1; !got_int; ++i) { if (i == hislen) i = 0; if (hist[i].hisstr != NULL && hist[i].hisnum >= j && hist[i].hisnum <= k) { msg_putchar('\n'); sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', hist[i].hisnum); if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); else STRCAT(IObuff, hist[i].hisstr); msg_outtrans(IObuff); out_flush(); } if (i == idx) break; } } }
Base
1
ex_history(exarg_T *eap) { histentry_T *hist; int histype1 = HIST_CMD; int histype2 = HIST_CMD; int hisidx1 = 1; int hisidx2 = -1; int idx; int i, j, k; char_u *end; char_u *arg = eap->arg; if (hislen == 0) { msg(_("'history' option is zero")); return; } if (!(VIM_ISDIGIT(*arg) || *arg == '-' || *arg == ',')) { end = arg; while (ASCII_ISALPHA(*end) || vim_strchr((char_u *)":=@>/?", *end) != NULL) end++; i = *end; *end = NUL; histype1 = get_histtype(arg); if (histype1 == -1) { if (STRNICMP(arg, "all", STRLEN(arg)) == 0) { histype1 = 0; histype2 = HIST_COUNT-1; } else { *end = i; semsg(_(e_trailing_characters_str), arg); return; } } else histype2 = histype1; *end = i; } else end = arg; if (!get_list_range(&end, &hisidx1, &hisidx2) || *end != NUL) { semsg(_(e_trailing_characters_str), end); return; } for (; !got_int && histype1 <= histype2; ++histype1) { STRCPY(IObuff, "\n # "); STRCAT(STRCAT(IObuff, history_names[histype1]), " history"); msg_puts_title((char *)IObuff); idx = hisidx[histype1]; hist = history[histype1]; j = hisidx1; k = hisidx2; if (j < 0) j = (-j > hislen) ? 0 : hist[(hislen+j+idx+1) % hislen].hisnum; if (k < 0) k = (-k > hislen) ? 0 : hist[(hislen+k+idx+1) % hislen].hisnum; if (idx >= 0 && j <= k) for (i = idx + 1; !got_int; ++i) { if (i == hislen) i = 0; if (hist[i].hisstr != NULL && hist[i].hisnum >= j && hist[i].hisnum <= k) { msg_putchar('\n'); sprintf((char *)IObuff, "%c%6d ", i == idx ? '>' : ' ', hist[i].hisnum); if (vim_strsize(hist[i].hisstr) > (int)Columns - 10) trunc_string(hist[i].hisstr, IObuff + STRLEN(IObuff), (int)Columns - 10, IOSIZE - (int)STRLEN(IObuff)); else STRCAT(IObuff, hist[i].hisstr); msg_outtrans(IObuff); out_flush(); } if (i == idx) break; } } }
Variant
0
get_list_range(char_u **str, int *num1, int *num2) { int len; int first = FALSE; varnumber_T num; *str = skipwhite(*str); if (**str == '-' || vim_isdigit(**str)) // parse "from" part of range { vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE, NULL); *str += len; *num1 = (int)num; first = TRUE; } *str = skipwhite(*str); if (**str == ',') // parse "to" part of range { *str = skipwhite(*str + 1); vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE, NULL); if (len > 0) { *num2 = (int)num; *str = skipwhite(*str + len); } else if (!first) // no number given at all return FAIL; } else if (first) // only one number given *num2 = *num1; return OK; }
Base
1
get_list_range(char_u **str, int *num1, int *num2) { int len; int first = FALSE; varnumber_T num; *str = skipwhite(*str); if (**str == '-' || vim_isdigit(**str)) // parse "from" part of range { vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE, NULL); *str += len; *num1 = (int)num; first = TRUE; } *str = skipwhite(*str); if (**str == ',') // parse "to" part of range { *str = skipwhite(*str + 1); vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE, NULL); if (len > 0) { *num2 = (int)num; *str = skipwhite(*str + len); } else if (!first) // no number given at all return FAIL; } else if (first) // only one number given *num2 = *num1; return OK; }
Variant
0
shift_line( int left, int round, int amount, int call_changed_bytes) // call changed_bytes() { int count; int i, j; int sw_val = (int)get_sw_value_indent(curbuf); count = get_indent(); // get current indent if (round) // round off indent { i = count / sw_val; // number of 'shiftwidth' rounded down j = count % sw_val; // extra spaces if (j && left) // first remove extra spaces --amount; if (left) { i -= amount; if (i < 0) i = 0; } else i += amount; count = i * sw_val; } else // original vi indent { if (left) { count -= sw_val * amount; if (count < 0) count = 0; } else count += sw_val * amount; } // Set new indent if (State & VREPLACE_FLAG) change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes); else (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0); }
Base
1
static bool meta_set(RAnal *a, RAnalMetaType type, int subtype, ut64 from, ut64 to, const char *str) { if (to < from) { return false; } RSpace *space = r_spaces_current (&a->meta_spaces); RIntervalNode *node = find_node_at (a, type, space, from); RAnalMetaItem *item = node ? node->data : R_NEW0 (RAnalMetaItem); if (!item) { return false; } item->type = type; item->subtype = subtype; item->space = space; free (item->str); item->str = str ? strdup (str) : NULL; if (str && !item->str) { if (!node) { // If we just created this free (item); } return false; } R_DIRTY (a); if (!node) { r_interval_tree_insert (&a->meta, from, to, item); } else if (node->end != to) { r_interval_tree_resize (&a->meta, node, from, to); } return true; }
Class
2
R_API size_t r_str_ansi_strip(char *str) { size_t i = 0; while (str[i]) { size_t chlen = __str_ansi_length (str + i); if (chlen > 1) { r_str_cpy (str + i + 1, str + i + chlen); } i++; } return i; }
Class
2
static RList *patch_relocs(RBin *b) { r_return_val_if_fail (b && b->iob.io && b->iob.io->desc, NULL); RBinObject *bo = r_bin_cur_object (b); RIO *io = b->iob.io; if (!bo || !bo->bin_obj) { return NULL; } struct r_bin_coff_obj *bin = (struct r_bin_coff_obj*)bo->bin_obj; if (bin->hdr.f_flags & COFF_FLAGS_TI_F_EXEC) { return NULL; } if (!(io->cached & R_PERM_W)) { eprintf ( "Warning: please run r2 with -e io.cache=true to patch " "relocations\n"); return NULL; } size_t nimports = 0; int i; for (i = 0; i < bin->hdr.f_nsyms; i++) { if (is_imported_symbol (&bin->symbols[i])) { nimports++; } i += bin->symbols[i].n_numaux; } ut64 m_vaddr = UT64_MAX; if (nimports) { ut64 offset = 0; RIOBank *bank = b->iob.bank_get (io, io->bank); RListIter *iter; RIOMapRef *mapref; r_list_foreach (bank->maprefs, iter, mapref) { RIOMap *map = b->iob.map_get (io, mapref->id); if (r_io_map_end (map) > offset) { offset = r_io_map_end (map); } } m_vaddr = R_ROUND (offset, 16); ut64 size = nimports * BYTES_PER_IMP_RELOC; char *muri = r_str_newf ("malloc://%" PFMT64u, size); RIODesc *desc = b->iob.open_at (io, muri, R_PERM_R, 0664, m_vaddr); free (muri); if (!desc) { return NULL; } RIOMap *map = b->iob.map_get_at (io, m_vaddr); if (!map) { return NULL; } map->name = strdup (".imports.r2"); } return _relocs_list (b, bin, true, m_vaddr); }
Class
2
static int getid(char ch) { const char *keys = "[]<>+-,."; const char *cidx = strchr (keys, ch); return cidx? cidx - keys + 1: 0; }
Base
1
static void process_constructors(RKernelCacheObj *obj, struct MACH0_(obj_t) *mach0, RList *ret, ut64 paddr, bool is_first, int mode, const char *prefix) { const RVector *sections = MACH0_(load_sections) (mach0); if (!sections) { return; } int type; struct section_t *section; r_vector_foreach (sections, section) { if (section->size == 0) { continue; } if (strstr (section->name, "_mod_fini_func") || strstr (section->name, "_mod_term_func")) { type = R_BIN_ENTRY_TYPE_FINI; } else if (strstr (section->name, "_mod_init_func")) { type = is_first ? 0 : R_BIN_ENTRY_TYPE_INIT; is_first = false; } else { continue; } ut8 *buf = calloc (section->size, 1); if (!buf) { break; } if (r_buf_read_at (obj->cache_buf, section->paddr + paddr, buf, section->size) < section->size) { free (buf); break; } int j; int count = 0; for (j = 0; j < section->size; j += 8) { ut64 addr64 = K_RPTR (buf + j); ut64 paddr64 = section->paddr + paddr + j; if (mode == R_K_CONSTRUCTOR_TO_ENTRY) { RBinAddr *ba = newEntry (paddr64, addr64, type); r_list_append (ret, ba); } else if (mode == R_K_CONSTRUCTOR_TO_SYMBOL) { RBinSymbol *sym = R_NEW0 (RBinSymbol); if (!sym) { break; } sym->name = r_str_newf ("%s.%s.%d", prefix, (type == R_BIN_ENTRY_TYPE_INIT) ? "init" : "fini", count++); sym->vaddr = addr64; sym->paddr = paddr64; sym->size = 0; sym->forwarder = "NONE"; sym->bind = "GLOBAL"; sym->type = "FUNC"; r_list_append (ret, sym); } } free (buf); } }
Base
1
Bool gf_sg_proto_field_is_sftime_offset(GF_Node *node, GF_FieldInfo *field) { u32 i; GF_Route *r; GF_ProtoInstance *inst; GF_FieldInfo inf; if (node->sgprivate->tag != TAG_ProtoNode) return 0; if (field->fieldType != GF_SG_VRML_SFTIME) return 0; inst = (GF_ProtoInstance *) node; /*check in interface if this is ISed */ i=0; while ((r = (GF_Route*)gf_list_enum(inst->proto_interface->sub_graph->Routes, &i))) { if (!r->IS_route) continue; /*only check eventIn/field/exposedField*/ if (r->FromNode || (r->FromField.fieldIndex != field->fieldIndex)) continue; gf_node_get_field(r->ToNode, r->ToField.fieldIndex, &inf); /*IS to another proto*/ if (r->ToNode->sgprivate->tag == TAG_ProtoNode) return gf_sg_proto_field_is_sftime_offset(r->ToNode, &inf); /*IS to a startTime/stopTime field*/ if (!stricmp(inf.name, "startTime") || !stricmp(inf.name, "stopTime")) return 1; } return 0; }
Variant
0
static s32 svc_parse_slice(GF_BitStream *bs, AVCState *avc, AVCSliceInfo *si) { s32 pps_id; /*s->current_picture.reference= h->nal_ref_idc != 0;*/ gf_bs_read_ue_log(bs, "first_mb_in_slice"); si->slice_type = gf_bs_read_ue_log(bs, "slice_type"); if (si->slice_type > 9) return -1; pps_id = gf_bs_read_ue_log(bs, "pps_id"); if ((pps_id<0) || (pps_id > 255)) return -1; si->pps = &avc->pps[pps_id]; si->pps->id = pps_id; if (!si->pps->slice_group_count) return -2; si->sps = &avc->sps[si->pps->sps_id + GF_SVC_SSPS_ID_SHIFT]; if (!si->sps->log2_max_frame_num) return -2; si->frame_num = gf_bs_read_int_log(bs, si->sps->log2_max_frame_num, "frame_num"); si->field_pic_flag = 0; if (si->sps->frame_mbs_only_flag) { /*s->picture_structure= PICT_FRAME;*/ } else { si->field_pic_flag = gf_bs_read_int_log(bs, 1, "field_pic_flag"); if (si->field_pic_flag) si->bottom_field_flag = gf_bs_read_int_log(bs, 1, "bottom_field_flag"); } if (si->nal_unit_type == GF_AVC_NALU_IDR_SLICE || si->svc_nalhdr.idr_pic_flag) si->idr_pic_id = gf_bs_read_ue_log(bs, "idr_pic_id"); if (si->sps->poc_type == 0) { si->poc_lsb = gf_bs_read_int_log(bs, si->sps->log2_max_poc_lsb, "poc_lsb"); if (si->pps->pic_order_present && !si->field_pic_flag) { si->delta_poc_bottom = gf_bs_read_se_log(bs, "delta_poc_bottom"); } } else if ((si->sps->poc_type == 1) && !si->sps->delta_pic_order_always_zero_flag) { si->delta_poc[0] = gf_bs_read_se_log(bs, "delta_poc0"); if ((si->pps->pic_order_present == 1) && !si->field_pic_flag) si->delta_poc[1] = gf_bs_read_se_log(bs, "delta_poc1"); } if (si->pps->redundant_pic_cnt_present) { si->redundant_pic_cnt = gf_bs_read_ue_log(bs, "redundant_pic_cnt"); } return 0; }
Base
1
GF_Err Q_DecCoordOnUnitSphere(GF_BifsDecoder *codec, GF_BitStream *bs, u32 NbBits, u32 NbComp, Fixed *m_ft) { u32 i, orient, sign; s32 value; Fixed tang[4], delta; s32 dir; if (NbComp != 2 && NbComp != 3) return GF_BAD_PARAM; //only 2 or 3 comp in the quantized version dir = 1; if(NbComp == 2) dir -= 2 * gf_bs_read_int(bs, 1); orient = gf_bs_read_int(bs, 2); if ((orient==3) && (NbComp==2)) return GF_NON_COMPLIANT_BITSTREAM; for(i=0; i<NbComp; i++) { value = gf_bs_read_int(bs, NbBits) - (1 << (NbBits-1) ); sign = (value >= 0) ? 1 : -1; m_ft[i] = sign * Q_InverseQuantize(0, 1, NbBits-1, sign*value); } delta = 1; for (i=0; i<NbComp; i++) { tang[i] = gf_tan(gf_mulfix(GF_PI/4, m_ft[i]) ); delta += gf_mulfix(tang[i], tang[i]); } delta = gf_divfix(INT2FIX(dir), gf_sqrt(delta) ); m_ft[orient] = delta; for (i=0; i<NbComp; i++) { m_ft[ (orient + i+1) % (NbComp+1) ] = gf_mulfix(tang[i], delta); } return GF_OK; }
Base
1
GF_Err dac3_box_write(GF_Box *s, GF_BitStream *bs) { GF_Err e; GF_AC3ConfigBox *ptr = (GF_AC3ConfigBox *)s; if (ptr->cfg.is_ec3) s->type = GF_ISOM_BOX_TYPE_DEC3; e = gf_isom_box_write_header(s, bs); if (ptr->cfg.is_ec3) s->type = GF_ISOM_BOX_TYPE_DAC3; if (e) return e; e = gf_odf_ac3_cfg_write_bs(&ptr->cfg, bs); if (e) return e; if (ptr->cfg.atmos_ec3_ext || ptr->cfg.complexity_index_type) { gf_bs_write_int(bs, 0, 7); gf_bs_write_int(bs, ptr->cfg.atmos_ec3_ext, 1); gf_bs_write_u8(bs, ptr->cfg.complexity_index_type); } return GF_OK; }
Variant
0
GF_Err video_sample_entry_box_size(GF_Box *s) { GF_Box *b; u32 pos=0; GF_MPEGVisualSampleEntryBox *ptr = (GF_MPEGVisualSampleEntryBox *)s; gf_isom_video_sample_entry_size((GF_VisualSampleEntryBox *)s); /*make sure we write the config box first, we don't care about the rest*/ /*mp4v*/ gf_isom_check_position(s, (GF_Box *)ptr->esd, &pos); gf_isom_check_position(s, (GF_Box *)ptr->cfg_3gpp, &pos); /*avc / SVC + MVC*/ gf_isom_check_position(s, (GF_Box *)ptr->avc_config, &pos); gf_isom_check_position(s, (GF_Box *)ptr->svc_config, &pos); if (ptr->mvc_config) { gf_isom_check_position(s, gf_isom_box_find_child(s->child_boxes, GF_ISOM_BOX_TYPE_VWID), &pos); gf_isom_check_position(s, (GF_Box *)ptr->mvc_config, &pos); } /*HEVC*/ gf_isom_check_position(s, (GF_Box *)ptr->hevc_config, &pos); gf_isom_check_position(s, (GF_Box *)ptr->lhvc_config, &pos); /*VVC*/ gf_isom_check_position(s, (GF_Box *)ptr->vvc_config, &pos); /*AV1*/ gf_isom_check_position(s, (GF_Box *)ptr->av1_config, &pos); /*VPx*/ gf_isom_check_position(s, (GF_Box *)ptr->vp_config, &pos); /*JP2H*/ gf_isom_check_position(s, (GF_Box *)ptr->jp2h, &pos); /*DolbyVision*/ gf_isom_check_position(s, (GF_Box *)ptr->dovi_config, &pos); b = gf_isom_box_find_child(ptr->child_boxes, GF_ISOM_BOX_TYPE_ST3D); if (b) gf_isom_check_position(s, b, &pos); b = gf_isom_box_find_child(ptr->child_boxes, GF_ISOM_BOX_TYPE_SV3D); if (b) gf_isom_check_position(s, b, &pos); return GF_OK; }
Variant
0
void gf_isom_check_position(GF_Box *s, GF_Box *child, u32 *pos) { if (!s || !s->child_boxes || !child || !pos) return; if (s->internal_flags & GF_ISOM_ORDER_FREEZE) return; s32 cur_pos = gf_list_find(s->child_boxes, child); //happens when partially cloning boxes if (cur_pos < 0) return; if (cur_pos != (s32) *pos) { gf_list_del_item(s->child_boxes, child); gf_list_insert(s->child_boxes, child, *pos); } (*pos)++;
Variant
0
GF_EXPORT GF_Err gf_isom_box_write(GF_Box *a, GF_BitStream *bs) { GF_Err e; u64 pos = gf_bs_get_position(bs); if (!a) return GF_BAD_PARAM; //box has been disabled, do not write if (!a->size) return GF_OK; if (a->registry->disabled) { GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("[iso file] Box %s disabled registry, skip write\n", gf_4cc_to_str(a->type))); return GF_OK; } GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("[iso file] Box %s size %d write\n", gf_4cc_to_str(a->type), a->size)); e = gf_isom_box_write_listing(a, bs); if (e) return e; if (a->child_boxes) { e = gf_isom_box_array_write(a, a->child_boxes, bs); } pos = gf_bs_get_position(bs) - pos; if (pos != a->size) { if (a->type != GF_ISOM_BOX_TYPE_MDAT) { GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("[iso file] Box %s wrote "LLU" bytes but size is "LLU"\n", gf_4cc_to_str(a->type), pos, a->size )); } } return e;
Variant
0
const u32 *gf_isom_get_track_switch_parameter(GF_ISOFile *movie, u32 trackNumber, u32 group_index, u32 *switchGroupID, u32 *criteriaListSize) { GF_TrackBox *trak; GF_UserDataMap *map; GF_TrackSelectionBox *tsel; trak = gf_isom_get_track_from_file(movie, trackNumber); if (!group_index || !trak || !trak->udta) return NULL; map = udta_getEntry(trak->udta, GF_ISOM_BOX_TYPE_TSEL, NULL); if (!map) return NULL; tsel = (GF_TrackSelectionBox*)gf_list_get(map->boxes, group_index-1); if (!tsel) return NULL; *switchGroupID = tsel->switchGroup; *criteriaListSize = tsel->attributeListCount; return (const u32 *) tsel->attributeList; }
Variant
0
char *gf_text_get_utf8_line(char *szLine, u32 lineSize, FILE *txt_in, s32 unicode_type) { u32 i, j, len; char *sOK; char szLineConv[2048]; unsigned short *sptr; memset(szLine, 0, sizeof(char)*lineSize); sOK = gf_fgets(szLine, lineSize, txt_in); if (!sOK) return NULL; if (unicode_type<=1) { j=0; len = (u32) strlen(szLine); for (i=0; i<len; i++) { if (!unicode_type && (szLine[i] & 0x80)) { /*non UTF8 (likely some win-CP)*/ if ((szLine[i+1] & 0xc0) != 0x80) { szLineConv[j] = 0xc0 | ( (szLine[i] >> 6) & 0x3 ); j++; szLine[i] &= 0xbf; } /*UTF8 2 bytes char*/ else if ( (szLine[i] & 0xe0) == 0xc0) { szLineConv[j] = szLine[i]; i++; j++; } /*UTF8 3 bytes char*/ else if ( (szLine[i] & 0xf0) == 0xe0) { szLineConv[j] = szLine[i]; i++; j++; szLineConv[j] = szLine[i]; i++; j++; } /*UTF8 4 bytes char*/ else if ( (szLine[i] & 0xf8) == 0xf0) { szLineConv[j] = szLine[i]; i++; j++; szLineConv[j] = szLine[i]; i++; j++; szLineConv[j] = szLine[i]; i++; j++; } else { i+=1; continue; } } szLineConv[j] = szLine[i]; j++; if (j >= GF_ARRAY_LENGTH(szLineConv) - 1) { GF_LOG(GF_LOG_DEBUG, GF_LOG_PARSER, ("[TXTIn] Line too long to convert to utf8 (len: %d)\n", len)); break; } } szLineConv[j] = 0; strcpy(szLine, szLineConv); return sOK; } #ifdef GPAC_BIG_ENDIAN if (unicode_type==3) #else if (unicode_type==2) #endif { i=0; while (1) { char c; if (!szLine[i] && !szLine[i+1]) break; c = szLine[i+1]; szLine[i+1] = szLine[i]; szLine[i] = c; i+=2; } } sptr = (u16 *)szLine; i = gf_utf8_wcstombs(szLineConv, 2048, (const unsigned short **) &sptr); if (i == GF_UTF8_FAIL) i = 0; szLineConv[i] = 0; strcpy(szLine, szLineConv); /*this is ugly indeed: since input is UTF16-LE, there are many chances the gf_fgets never reads the \0 after a \n*/ if (unicode_type==3) gf_fgetc(txt_in); return sOK;
Base
1
void gf_filter_pid_inst_del(GF_FilterPidInst *pidinst) { assert(pidinst); gf_filter_pid_inst_reset(pidinst); gf_fq_del(pidinst->packets, (gf_destruct_fun) pcki_del); gf_mx_del(pidinst->pck_mx); gf_list_del(pidinst->pck_reassembly); if (pidinst->props) { assert(pidinst->props->reference_count); if (safe_int_dec(&pidinst->props->reference_count) == 0) { //see \ref gf_filter_pid_merge_properties_internal for mutex gf_mx_p(pidinst->pid->filter->tasks_mx); gf_list_del_item(pidinst->pid->properties, pidinst->props); gf_mx_v(pidinst->pid->filter->tasks_mx); gf_props_del(pidinst->props); } } gf_free(pidinst); }
Class
2
static GF_Err xml_sax_append_string(GF_SAXParser *parser, char *string) { u32 size = parser->line_size; u32 nl_size = (u32) strlen(string); if (!nl_size) return GF_OK; if ( (parser->alloc_size < size+nl_size+1) /* || (parser->alloc_size / 2 ) > size+nl_size+1 */ ) { parser->alloc_size = size+nl_size+1; parser->alloc_size = 3 * parser->alloc_size / 2; parser->buffer = (char*)gf_realloc(parser->buffer, sizeof(char) * parser->alloc_size); if (!parser->buffer ) return GF_OUT_OF_MEM; } memcpy(parser->buffer+size, string, sizeof(char)*nl_size); parser->buffer[size+nl_size] = 0; parser->line_size = size+nl_size; return GF_OK; }
Base
1
int AVI_read_audio(avi_t *AVI, u8 *audbuf, int bytes, int *continuous) { int nr, todo; s64 pos; if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; } if(!AVI->track[AVI->aptr].audio_index) { AVI_errno = AVI_ERR_NO_IDX; return -1; } nr = 0; /* total number of bytes read */ if (bytes==0) { AVI->track[AVI->aptr].audio_posc++; AVI->track[AVI->aptr].audio_posb = 0; } *continuous = 1; while(bytes>0) { s64 ret; int left = (int) (AVI->track[AVI->aptr].audio_index[AVI->track[AVI->aptr].audio_posc].len - AVI->track[AVI->aptr].audio_posb); if(left==0) { if(AVI->track[AVI->aptr].audio_posc>=AVI->track[AVI->aptr].audio_chunks-1) return nr; AVI->track[AVI->aptr].audio_posc++; AVI->track[AVI->aptr].audio_posb = 0; *continuous = 0; continue; } if(bytes<left) todo = bytes; else todo = left; pos = AVI->track[AVI->aptr].audio_index[AVI->track[AVI->aptr].audio_posc].pos + AVI->track[AVI->aptr].audio_posb; gf_fseek(AVI->fdes, pos, SEEK_SET); if ( (ret = avi_read(AVI->fdes,audbuf+nr,todo)) != todo) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[avilib] XXX pos = %"LLD", ret = %"LLD", todo = %ld\n", pos, ret, todo)); AVI_errno = AVI_ERR_READ; return -1; } bytes -= todo; nr += todo; AVI->track[AVI->aptr].audio_posb += todo; } return nr; }
Variant
0
int AVI_read_frame(avi_t *AVI, u8 *vidbuf, int *keyframe) { int n; if(AVI->mode==AVI_MODE_WRITE) { AVI_errno = AVI_ERR_NOT_PERM; return -1; } if(!AVI->video_index) { AVI_errno = AVI_ERR_NO_IDX; return -1; } if(AVI->video_pos < 0 || AVI->video_pos >= AVI->video_frames) return -1; n = (u32) AVI->video_index[AVI->video_pos].len; *keyframe = (AVI->video_index[AVI->video_pos].key==0x10) ? 1:0; if (vidbuf == NULL) { AVI->video_pos++; return n; } gf_fseek(AVI->fdes, AVI->video_index[AVI->video_pos].pos, SEEK_SET); if (avi_read(AVI->fdes,vidbuf,n) != (u32) n) { AVI_errno = AVI_ERR_READ; return -1; } AVI->video_pos++; return n; }
Variant
0
static void get_info_for_all_streams (mpeg2ps_t *ps) { u8 stream_ix, max_ix, av; mpeg2ps_stream_t *sptr; u8 *buffer; u32 buflen; file_seek_to(ps->fd, 0); // av will be 0 for video streams, 1 for audio streams // av is just so I don't have to dup a lot of code that does the // same thing. for (av = 0; av < 2; av++) { if (av == 0) max_ix = ps->video_cnt; else max_ix = ps->audio_cnt; for (stream_ix = 0; stream_ix < max_ix; stream_ix++) { if (av == 0) sptr = ps->video_streams[stream_ix]; else sptr = ps->audio_streams[stream_ix]; // we don't open a separate file descriptor yet (only when they // start reading or seeking). Use the one from the ps. sptr->m_fd = ps->fd; // for now clear_stream_buffer(sptr); if (mpeg2ps_stream_read_frame(sptr, &buffer, &buflen, 0) == 0) { sptr->m_stream_id = 0; sptr->m_fd = FDNULL; continue; } get_info_from_frame(sptr, buffer, buflen); // here - if (sptr->first_pes_has_dts == 0) should be processed if (sptr->first_pes_has_dts == 0) { u32 frames_from_beg = 0; Bool have_frame; do { advance_frame(sptr); have_frame = mpeg2ps_stream_read_frame(sptr, &buffer, &buflen, 0); frames_from_beg++; } while (have_frame && sptr->frame_ts.have_dts == 0 && sptr->frame_ts.have_pts == 0 && frames_from_beg < 1000); if (have_frame == 0 || (sptr->frame_ts.have_dts == 0 && sptr->frame_ts.have_pts == 0)) { } else { sptr->start_dts = sptr->frame_ts.have_dts ? sptr->frame_ts.dts : sptr->frame_ts.pts; if (sptr->is_video) { sptr->start_dts -= frames_from_beg * sptr->ticks_per_frame; } else { u64 conv; conv = sptr->samples_per_frame * 90000; conv /= (u64)sptr->freq; sptr->start_dts -= conv; } } } clear_stream_buffer(sptr); sptr->m_fd = FDNULL; } } }
Base
1
static u32 swf_get_32(SWFReader *read) { u32 val, res; val = swf_read_int(read, 32); res = (val&0xFF); res <<=8; res |= ((val>>8)&0xFF); res<<=8; res |= ((val>>16)&0xFF); res<<=8; res|= ((val>>24)&0xFF); return res; }
Variant
0
static s16 swf_get_s16(SWFReader *read) { s16 val; u8 v1; v1 = swf_read_int(read, 8); val = swf_read_sint(read, 8); val = (val<<8)&0xFF00; val |= (v1&0xFF); return val; }
Variant
0
static u16 swf_get_16(SWFReader *read) { u16 val, res; val = swf_read_int(read, 16); res = (val&0xFF); res <<=8; res |= ((val>>8)&0xFF); return res; }
Variant
0
char *gf_bt_get_next(GF_BTParser *parser, Bool point_break) { u32 has_quote; Bool go = 1; s32 i; gf_bt_check_line(parser); i=0; has_quote = 0; while (go) { if (parser->line_buffer[parser->line_pos + i] == '\"') { if (!has_quote) has_quote = 1; else has_quote = 0; parser->line_pos += 1; if (parser->line_pos+i==parser->line_size) break; continue; } if (!has_quote) { switch (parser->line_buffer[parser->line_pos + i]) { case 0: case ' ': case '\t': case '\r': case '\n': case '{': case '}': case ']': case '[': case ',': go = 0; break; case '.': if (point_break) go = 0; break; } if (!go) break; } parser->cur_buffer[i] = parser->line_buffer[parser->line_pos + i]; i++; if (parser->line_pos+i==parser->line_size) break; } parser->cur_buffer[i] = 0; parser->line_pos += i; return parser->cur_buffer; }
Base
1
GF_Err chnl_box_size(GF_Box *s) { GF_ChannelLayoutBox *ptr = (GF_ChannelLayoutBox *) s; s->size += 1; if (ptr->layout.stream_structure & 1) { s->size += 1; if (ptr->layout.definedLayout==0) { u32 i; for (i=0; i<ptr->layout.channels_count; i++) { s->size+=1; if (ptr->layout.layouts[i].position==126) s->size+=3; } } else { s->size += 8; } } if (ptr->layout.stream_structure & 2) { s->size += 1; } return GF_OK; }
Base
1
GF_Err chnl_box_read(GF_Box *s,GF_BitStream *bs) { GF_ChannelLayoutBox *ptr = (GF_ChannelLayoutBox *) s; ISOM_DECREASE_SIZE(s, 1) ptr->layout.stream_structure = gf_bs_read_u8(bs); if (ptr->layout.stream_structure & 1) { ISOM_DECREASE_SIZE(s, 1) ptr->layout.definedLayout = gf_bs_read_u8(bs); if (ptr->layout.definedLayout==0) { u32 remain = (u32) ptr->size; if (ptr->layout.stream_structure & 2) remain--; ptr->layout.channels_count = 0; while (remain) { ISOM_DECREASE_SIZE(s, 1) ptr->layout.layouts[ptr->layout.channels_count].position = gf_bs_read_u8(bs); remain--; if (ptr->layout.layouts[ptr->layout.channels_count].position == 126) { ISOM_DECREASE_SIZE(s, 3) ptr->layout.layouts[ptr->layout.channels_count].azimuth = gf_bs_read_int(bs, 16); ptr->layout.layouts[ptr->layout.channels_count].elevation = gf_bs_read_int(bs, 8); remain-=3; } } } else { ISOM_DECREASE_SIZE(s, 8) ptr->layout.omittedChannelsMap = gf_bs_read_u64(bs); } } if (ptr->layout.stream_structure & 2) { ISOM_DECREASE_SIZE(s, 1) ptr->layout.object_count = gf_bs_read_u8(bs); } return GF_OK; }
Base
1
GF_Err chnl_box_write(GF_Box *s, GF_BitStream *bs) { GF_Err e; GF_ChannelLayoutBox *ptr = (GF_ChannelLayoutBox *) s; e = gf_isom_full_box_write(s, bs); if (e) return e; gf_bs_write_u8(bs, ptr->layout.stream_structure); if (ptr->layout.stream_structure & 1) { gf_bs_write_u8(bs, ptr->layout.definedLayout); if (ptr->layout.definedLayout==0) { u32 i; for (i=0; i<ptr->layout.channels_count; i++) { gf_bs_write_u8(bs, ptr->layout.layouts[i].position); if (ptr->layout.layouts[i].position==126) { gf_bs_write_int(bs, ptr->layout.layouts[i].azimuth, 16); gf_bs_write_int(bs, ptr->layout.layouts[i].elevation, 8); } } } else { gf_bs_write_u64(bs, ptr->layout.omittedChannelsMap); } } if (ptr->layout.stream_structure & 2) { gf_bs_write_u8(bs, ptr->layout.object_count); } return GF_OK; }
Base
1
GF_Err gf_isom_use_compact_size(GF_ISOFile *movie, u32 trackNumber, Bool CompactionOn) { GF_TrackBox *trak; u32 i, size; GF_SampleSizeBox *stsz; GF_Err e; e = CanAccessMovie(movie, GF_ISOM_OPEN_WRITE); if (e) return e; trak = gf_isom_get_track_from_file(movie, trackNumber); if (!trak) return GF_BAD_PARAM; if (!trak->Media || !trak->Media->information || !trak->Media->information->sampleTable || !trak->Media->information->sampleTable->SampleSize) return GF_ISOM_INVALID_FILE; stsz = trak->Media->information->sampleTable->SampleSize; //switch to regular table if (!CompactionOn) { if (stsz->type == GF_ISOM_BOX_TYPE_STSZ) return GF_OK; stsz->type = GF_ISOM_BOX_TYPE_STSZ; //invalidate the sampleSize and recompute it stsz->sampleSize = 0; if (!stsz->sampleCount) return GF_OK; //if the table is empty we can only assume the track is empty (no size indication) if (!stsz->sizes) return GF_OK; size = stsz->sizes[0]; //check whether the sizes are all the same or not for (i=1; i<stsz->sampleCount; i++) { if (size != stsz->sizes[i]) { size = 0; break; } } if (size) { gf_free(stsz->sizes); stsz->sizes = NULL; stsz->sampleSize = size; } return GF_OK; } //switch to compact table if (stsz->type == GF_ISOM_BOX_TYPE_STZ2) return GF_OK; //fill the table. Although it seems weird , this is needed in case of edition //after the function is called. NOte however than we force regular table //at write time if all samples are of same size if (stsz->sampleSize) { //this is a weird table indeed ;) if (stsz->sizes) gf_free(stsz->sizes); stsz->sizes = (u32*) gf_malloc(sizeof(u32)*stsz->sampleCount); if (!stsz->sizes) return GF_OUT_OF_MEM; memset(stsz->sizes, stsz->sampleSize, sizeof(u32)); } //set the SampleSize to 0 while the file is open stsz->sampleSize = 0; stsz->type = GF_ISOM_BOX_TYPE_STZ2; return GF_OK; }
Base
1
static GF_Err gf_isom_set_root_iod(GF_ISOFile *movie) { GF_IsomInitialObjectDescriptor *iod; GF_IsomObjectDescriptor *od; GF_Err e; e = gf_isom_insert_moov(movie); if (e) return e; if (!movie->moov->iods) { AddMovieIOD(movie->moov, 1); return GF_OK; } //if OD, switch to IOD if (movie->moov->iods->descriptor->tag == GF_ODF_ISOM_IOD_TAG) return GF_OK; od = (GF_IsomObjectDescriptor *) movie->moov->iods->descriptor; iod = (GF_IsomInitialObjectDescriptor*)gf_malloc(sizeof(GF_IsomInitialObjectDescriptor)); if (!iod) return GF_OUT_OF_MEM; memset(iod, 0, sizeof(GF_IsomInitialObjectDescriptor)); iod->ES_ID_IncDescriptors = od->ES_ID_IncDescriptors; od->ES_ID_IncDescriptors = NULL; //not used in root OD iod->ES_ID_RefDescriptors = NULL; iod->extensionDescriptors = od->extensionDescriptors; od->extensionDescriptors = NULL; iod->IPMP_Descriptors = od->IPMP_Descriptors; od->IPMP_Descriptors = NULL; iod->objectDescriptorID = od->objectDescriptorID; iod->OCIDescriptors = od->OCIDescriptors; od->OCIDescriptors = NULL; iod->tag = GF_ODF_ISOM_IOD_TAG; iod->URLString = od->URLString; od->URLString = NULL; gf_odf_desc_del((GF_Descriptor *) od); movie->moov->iods->descriptor = (GF_Descriptor *)iod; return GF_OK; }
Base
1
GF_Err gf_isom_update_sample_description_from_template(GF_ISOFile *file, u32 track, u32 sampleDescriptionIndex, u8 *data, u32 size) { GF_BitStream *bs; GF_TrackBox *trak; GF_Box *ent, *tpl_ent; GF_Err e; /*get orig sample desc and clone it*/ trak = gf_isom_get_track_from_file(file, track); if (!trak || !sampleDescriptionIndex) return GF_BAD_PARAM; if (!trak->Media || !trak->Media->handler || !trak->Media->information || !trak->Media->information->sampleTable || !trak->Media->information->sampleTable->SampleDescription) return GF_ISOM_INVALID_FILE; ent = gf_list_get(trak->Media->information->sampleTable->SampleDescription->child_boxes, sampleDescriptionIndex-1); if (!ent) return GF_BAD_PARAM; bs = gf_bs_new(data, size, GF_BITSTREAM_READ); // e = gf_isom_box_parse(&tpl_ent, bs); e = gf_isom_box_parse_ex(&tpl_ent, bs, GF_ISOM_BOX_TYPE_STSD, GF_FALSE, 0); gf_bs_del(bs); if (e) return e; while (gf_list_count(tpl_ent->child_boxes)) { u32 j=0; Bool found = GF_FALSE; GF_Box *abox = gf_list_pop_front(tpl_ent->child_boxes); switch (abox->type) { case GF_ISOM_BOX_TYPE_SINF: case GF_ISOM_BOX_TYPE_RINF: case GF_ISOM_BOX_TYPE_BTRT: found = GF_TRUE; break; } if (found) { gf_isom_box_del(abox); continue; } if (!ent->child_boxes) ent->child_boxes = gf_list_new(); for (j=0; j<gf_list_count(ent->child_boxes); j++) { GF_Box *b = gf_list_get(ent->child_boxes, j); if (b->type == abox->type) { found = GF_TRUE; break; } } if (!found) { gf_list_add(ent->child_boxes, abox); } else { gf_isom_box_del(abox); } } gf_isom_box_del(tpl_ent); //patch for old export GF_Box *abox = gf_isom_box_find_child(ent->child_boxes, GF_ISOM_BOX_TYPE_SINF); if (abox) { gf_list_del_item(ent->child_boxes, abox); gf_list_add(ent->child_boxes, abox); } return GF_OK; }
Base
1
static GF_SampleGroupDescriptionBox *get_sgdp(GF_SampleTableBox *stbl, void *traf, u32 grouping_type, Bool *is_traf_sgdp) #endif /* GPAC_DISABLE_ISOM_FRAGMENTS */ { GF_List *groupList=NULL; GF_List **parent=NULL; GF_SampleGroupDescriptionBox *sgdesc=NULL; u32 count, i; #ifndef GPAC_DISABLE_ISOM_FRAGMENTS if (!stbl && traf && traf->trex->track->Media->information->sampleTable) stbl = traf->trex->track->Media->information->sampleTable; #endif if (stbl) { if (!stbl->sampleGroupsDescription && !traf) stbl->sampleGroupsDescription = gf_list_new(); groupList = stbl->sampleGroupsDescription; if (is_traf_sgdp) *is_traf_sgdp = GF_FALSE; parent = &stbl->child_boxes; count = gf_list_count(groupList); for (i=0; i<count; i++) { sgdesc = (GF_SampleGroupDescriptionBox*)gf_list_get(groupList, i); if (sgdesc->grouping_type==grouping_type) break; sgdesc = NULL; } } #ifndef GPAC_DISABLE_ISOM_FRAGMENTS /*look in stbl or traf for sample sampleGroupsDescription*/ if (!sgdesc && traf) { if (!traf->sampleGroupsDescription) traf->sampleGroupsDescription = gf_list_new(); groupList = traf->sampleGroupsDescription; parent = &traf->child_boxes; if (is_traf_sgdp) *is_traf_sgdp = GF_TRUE; count = gf_list_count(groupList); for (i=0; i<count; i++) { sgdesc = (GF_SampleGroupDescriptionBox*)gf_list_get(groupList, i); if (sgdesc->grouping_type==grouping_type) break; sgdesc = NULL; } } #endif if (!sgdesc) { sgdesc = (GF_SampleGroupDescriptionBox *) gf_isom_box_new_parent(parent, GF_ISOM_BOX_TYPE_SGPD); if (!sgdesc) return NULL; sgdesc->grouping_type = grouping_type; assert(groupList); gf_list_add(groupList, sgdesc); } return sgdesc; }
Base
1
update_job_run (updateJobPtr job) { /* Here we decide on the source type and the proper execution methods which then do anything they want with the job and pass the processed job to update_process_finished_job() for result dequeuing */ /* everything starting with '|' is a local command */ if (*(job->request->source) == '|') { debug1 (DEBUG_UPDATE, "Recognized local command: %s", job->request->source); update_exec_cmd (job); return; } /* if it has a protocol "://" prefix, but not "file://" it is an URI */ if (strstr (job->request->source, "://") && strncmp (job->request->source, "file://", 7)) { network_process_request (job); return; } /* otherwise it must be a local file... */ { debug1 (DEBUG_UPDATE, "Recognized file URI: %s", job->request->source); update_load_file (job); return; } }
Base
1
p_ntp_time(netdissect_options *ndo, const struct l_fixedpt *lfp) { uint32_t i; uint32_t uf; uint32_t f; double ff; i = GET_BE_U_4(lfp->int_part); uf = GET_BE_U_4(lfp->fraction); ff = uf; if (ff < 0.0) /* some compilers are buggy */ ff += FMAXINT; ff = ff / FMAXINT; /* shift radix point by 32 bits */ f = (uint32_t)(ff * 1000000000.0); /* treat fraction as parts per billion */ ND_PRINT("%u.%09u", i, f); /* * print the UTC time in human-readable format. */ if (i) { int64_t seconds_64bit = (int64_t)i - JAN_1970; time_t seconds; struct tm *tm; char time_buf[128]; seconds = (time_t)seconds_64bit; if (seconds != seconds_64bit) { /* * It doesn't fit into a time_t, so we can't hand it * to gmtime. */ ND_PRINT(" (unrepresentable)"); } else { tm = gmtime(&seconds); if (tm == NULL) { /* * gmtime() can't handle it. * (Yes, that might happen with some version of * Microsoft's C library.) */ ND_PRINT(" (unrepresentable)"); } else { /* use ISO 8601 (RFC3339) format */ strftime(time_buf, sizeof (time_buf), "%Y-%m-%dT%H:%M:%SZ", tm); ND_PRINT(" (%s)", time_buf); } } } }
Base
1
ahcp_time_print(netdissect_options *ndo, const u_char *cp, uint8_t len) { time_t t; struct tm *tm; char buf[BUFSIZE]; if (len != 4) goto invalid; t = GET_BE_U_4(cp); if (NULL == (tm = gmtime(&t))) ND_PRINT(": gmtime() error"); else if (0 == strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm)) ND_PRINT(": strftime() error"); else ND_PRINT(": %s UTC", buf); return; invalid: nd_print_invalid(ndo); ND_TCHECK_LEN(cp, len); }
Base
1
arista_print_date_hms_time(netdissect_options *ndo, uint32_t seconds, uint32_t nanoseconds) { time_t ts; struct tm *tm; char buf[BUFSIZE]; ts = seconds + (nanoseconds / 1000000000); nanoseconds %= 1000000000; if (NULL == (tm = gmtime(&ts))) ND_PRINT("gmtime() error"); else if (0 == strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm)) ND_PRINT("strftime() error"); else ND_PRINT("%s.%09u", buf, nanoseconds); }
Base
1
static void zep_print_ts(netdissect_options *ndo, const u_char *p) { int32_t i; uint32_t uf; uint32_t f; float ff; i = GET_BE_U_4(p); uf = GET_BE_U_4(p + 4); ff = (float) uf; if (ff < 0.0) /* some compilers are buggy */ ff += FMAXINT; ff = (float) (ff / FMAXINT); /* shift radix point by 32 bits */ f = (uint32_t) (ff * 1000000000.0); /* treat fraction as parts per billion */ ND_PRINT("%u.%09d", i, f); /* * print the time in human-readable format. */ if (i) { time_t seconds = i - JAN_1970; struct tm *tm; char time_buf[128]; tm = localtime(&seconds); strftime(time_buf, sizeof (time_buf), "%Y/%m/%d %H:%M:%S", tm); ND_PRINT(" (%s)", time_buf); } }
Base
1
MakeFilename(char *buffer, char *orig_name, int cnt, int max_chars) { char *filename = malloc(PATH_MAX + 1); if (filename == NULL) error("%s: malloc", __func__); /* Process with strftime if Gflag is set. */ if (Gflag != 0) { struct tm *local_tm; /* Convert Gflag_time to a usable format */ if ((local_tm = localtime(&Gflag_time)) == NULL) { error("%s: localtime", __func__); } /* There's no good way to detect an error in strftime since a return * value of 0 isn't necessarily failure. */ strftime(filename, PATH_MAX, orig_name, local_tm); } else { strncpy(filename, orig_name, PATH_MAX); } if (cnt == 0 && max_chars == 0) strncpy(buffer, filename, PATH_MAX + 1); else if (snprintf(buffer, PATH_MAX + 1, "%s%0*d", filename, max_chars, cnt) > PATH_MAX) /* Report an error if the filename is too large */ error("too many output files or filename is too long (> %d)", PATH_MAX); free(filename); }
Base
1
ts_date_hmsfrac_print(netdissect_options *ndo, long sec, long usec, enum date_flag date_flag, enum time_flag time_flag) { time_t Time = sec; struct tm *tm; char timestr[32]; if ((unsigned)sec & 0x80000000) { ND_PRINT("[Error converting time]"); return; } if (time_flag == LOCAL_TIME) tm = localtime(&Time); else tm = gmtime(&Time); if (!tm) { ND_PRINT("[Error converting time]"); return; } if (date_flag == WITH_DATE) strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", tm); else strftime(timestr, sizeof(timestr), "%H:%M:%S", tm); ND_PRINT("%s", timestr); ts_frac_print(ndo, usec); }
Base
1
void hrandfieldCommand(client *c) { long l; int withvalues = 0; robj *hash; listpackEntry ele; if (c->argc >= 3) { if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return; if (c->argc > 4 || (c->argc == 4 && strcasecmp(c->argv[3]->ptr,"withvalues"))) { addReplyErrorObject(c,shared.syntaxerr); return; } else if (c->argc == 4) withvalues = 1; hrandfieldWithCountCommand(c, l, withvalues); return; } /* Handle variant without <count> argument. Reply with simple bulk string */ if ((hash = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp]))== NULL || checkType(c,hash,OBJ_HASH)) { return; } hashTypeRandomElement(hash,hashTypeLength(hash),&ele,NULL); hashReplyFromListpackEntry(c, &ele); }
Base
1
void zrandmemberCommand(client *c) { long l; int withscores = 0; robj *zset; listpackEntry ele; if (c->argc >= 3) { if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return; if (c->argc > 4 || (c->argc == 4 && strcasecmp(c->argv[3]->ptr,"withscores"))) { addReplyErrorObject(c,shared.syntaxerr); return; } else if (c->argc == 4) withscores = 1; zrandmemberWithCountCommand(c, l, withscores); return; } /* Handle variant without <count> argument. Reply with simple bulk string */ if ((zset = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp]))== NULL || checkType(c,zset,OBJ_ZSET)) { return; } zsetTypeRandomElement(zset, zsetLength(zset), &ele,NULL); zsetReplyFromListpackEntry(c,&ele); }
Base
1
void msetGenericCommand(client *c, int nx) { int j; int setkey_flags = 0; if ((c->argc % 2) == 0) { addReplyErrorArity(c); return; } /* Handle the NX flag. The MSETNX semantic is to return zero and don't * set anything if at least one key already exists. */ if (nx) { for (j = 1; j < c->argc; j += 2) { if (lookupKeyWrite(c->db,c->argv[j]) != NULL) { addReply(c, shared.czero); return; } } setkey_flags |= SETKEY_DOESNT_EXIST; } for (j = 1; j < c->argc; j += 2) { c->argv[j+1] = tryObjectEncoding(c->argv[j+1]); setKey(c, c->db, c->argv[j], c->argv[j + 1], setkey_flags); notifyKeyspaceEvent(NOTIFY_STRING,"set",c->argv[j],c->db->id); } server.dirty += (c->argc-1)/2; addReply(c, nx ? shared.cone : shared.ok); }
Class
2
static int _anetTcpServer(char *err, int port, char *bindaddr, int af, int backlog) { int s = -1, rv; char _port[6]; /* strlen("65535") */ struct addrinfo hints, *servinfo, *p; snprintf(_port,6,"%d",port); memset(&hints,0,sizeof(hints)); hints.ai_family = af; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; /* No effect if bindaddr != NULL */ if (bindaddr && !strcmp("*", bindaddr)) bindaddr = NULL; if (af == AF_INET6 && bindaddr && !strcmp("::*", bindaddr)) bindaddr = NULL; if ((rv = getaddrinfo(bindaddr,_port,&hints,&servinfo)) != 0) { anetSetError(err, "%s", gai_strerror(rv)); return ANET_ERR; } for (p = servinfo; p != NULL; p = p->ai_next) { if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == -1) continue; if (af == AF_INET6 && anetV6Only(err,s) == ANET_ERR) goto error; if (anetSetReuseAddr(err,s) == ANET_ERR) goto error; if (anetListen(err,s,p->ai_addr,p->ai_addrlen,backlog) == ANET_ERR) s = ANET_ERR; goto end; } if (p == NULL) { anetSetError(err, "unable to bind socket, errno: %d", errno); goto error; } error: if (s != -1) close(s); s = ANET_ERR; end: freeaddrinfo(servinfo); return s; }
Class
2
int anetUnixServer(char *err, char *path, mode_t perm, int backlog) { int s; struct sockaddr_un sa; if (strlen(path) > sizeof(sa.sun_path)-1) { anetSetError(err,"unix socket path too long (%zu), must be under %zu", strlen(path), sizeof(sa.sun_path)); return ANET_ERR; } if ((s = anetCreateSocket(err,AF_LOCAL)) == ANET_ERR) return ANET_ERR; memset(&sa,0,sizeof(sa)); sa.sun_family = AF_LOCAL; redis_strlcpy(sa.sun_path,path,sizeof(sa.sun_path)); if (anetListen(err,s,(struct sockaddr*)&sa,sizeof(sa),backlog) == ANET_ERR) return ANET_ERR; if (perm) chmod(sa.sun_path, perm); return s; }
Class
2
static int anetListen(char *err, int s, struct sockaddr *sa, socklen_t len, int backlog) { if (bind(s,sa,len) == -1) { anetSetError(err, "bind: %s", strerror(errno)); close(s); return ANET_ERR; } if (listen(s, backlog) == -1) { anetSetError(err, "listen: %s", strerror(errno)); close(s); return ANET_ERR; } return ANET_OK; }
Class
2
Tss2_RC_Decode(TSS2_RC rc) { static __thread char buf[TSS2_ERR_LAYER_NAME_MAX + TSS2_ERR_LAYER_ERROR_STR_MAX + 1]; clearbuf(buf); UINT8 layer = tss2_rc_layer_number_get(rc); TSS2_RC_HANDLER handler = layer_handler[layer].handler; const char *lname = layer_handler[layer].name; if (lname[0]) { catbuf(buf, "%s:", lname); } else { catbuf(buf, "%u:", layer); } handler = !handler ? unknown_layer_handler : handler; /* * Handlers only need the error bits. This way they don't * need to concern themselves with masking off the layer * bits or anything else. */ UINT16 err_bits = tpm2_error_get(rc); const char *e = err_bits ? handler(err_bits) : "success"; if (e) { catbuf(buf, "%s", e); } else { catbuf(buf, "0x%X", err_bits); } return buf; }
Base
1
unknown_layer_handler(TSS2_RC rc) { static __thread char buf[32]; clearbuf(buf); catbuf(buf, "0x%X", tpm2_error_get(rc)); return buf; }
Base
1
test_custom_handler(void **state) { (void) state; /* * Test registering a custom handler */ TSS2_RC_HANDLER old = Tss2_RC_SetHandler(1, "cstm", custom_err_handler); assert_null(old); /* * Test getting error strings */ unsigned i; for (i = 1; i < 4; i++) { // Make a layer 1 error with an error number of i. TSS2_RC rc = TSS2_RC_LAYER(1) | i; char buf[256]; snprintf(buf, sizeof(buf), "cstm:error %u", i); const char *e = Tss2_RC_Decode(rc); assert_string_equal(e, buf); } TSS2_RC rc = TSS2_RC_LAYER(1) | 42; /* * Test an unknown error */ const char *e = Tss2_RC_Decode(rc); assert_string_equal(e, "cstm:0x2A"); /* * Test clearing a handler */ old = Tss2_RC_SetHandler(1, "cstm", NULL); assert_ptr_equal(old, custom_err_handler); /* * Test an unknown layer */ e = Tss2_RC_Decode(rc); assert_string_equal(e, "1:0x2A"); }
Base
1
sigterm_handler(int sig) // I - Signal number (unused) { (void)sig; fprintf(stderr, "DEBUG: beh: Job canceled.\n"); if (job_canceled) _exit(CUPS_BACKEND_OK); else job_canceled = 1; }
Base
1
call_backend(char *uri, // I - URI of final destination int argc, // I - Number of command line // arguments char **argv, // I - Command-line arguments char *filename) // I - File name of input data { const char *cups_serverbin; // Location of programs char scheme[1024], // Scheme from URI *ptr, // Pointer into scheme cmdline[65536]; // Backend command line int retval; // // Build the backend command line... // strncpy(scheme, uri, sizeof(scheme) - 1); if (strlen(uri) > 1023) scheme[1023] = '\0'; if ((ptr = strchr(scheme, ':')) != NULL) *ptr = '\0'; if ((cups_serverbin = getenv("CUPS_SERVERBIN")) == NULL) cups_serverbin = CUPS_SERVERBIN; if (!strncasecmp(uri, "file:", 5) || uri[0] == '/') { fprintf(stderr, "ERROR: beh: Direct output into a file not supported.\n"); exit (CUPS_BACKEND_FAILED); } else snprintf(cmdline, sizeof(cmdline), "%s/backend/%s '%s' '%s' '%s' '%s' '%s' %s", cups_serverbin, scheme, argv[1], argv[2], argv[3], // Apply number of copies only if beh was called with a // file name and not with the print data in stdin, as // backends should handle copies only if they are called // with a file name (argc == 6 ? "1" : argv[4]), argv[5], filename); // // Overwrite the device URI and run the actual backend... // setenv("DEVICE_URI", uri, 1); fprintf(stderr, "DEBUG: beh: Executing backend command line \"%s\"...\n", cmdline); fprintf(stderr, "DEBUG: beh: Using device URI: %s\n", uri); retval = system(cmdline) >> 8; if (retval == -1) fprintf(stderr, "ERROR: Unable to execute backend command line: %s\n", strerror(errno)); return (retval); }
Base
1
_pdfioDictSetValue( pdfio_dict_t *dict, // I - Dictionary const char *key, // I - Key _pdfio_value_t *value) // I - Value { _pdfio_pair_t *pair; // Current pair PDFIO_DEBUG("_pdfioDictSetValue(dict=%p, key=\"%s\", value=%p)\n", dict, key, (void *)value); // See if the key is already set... if (dict->num_pairs > 0) { _pdfio_pair_t pkey; // Search key pkey.key = key; if ((pair = (_pdfio_pair_t *)bsearch(&pkey, dict->pairs, dict->num_pairs, sizeof(_pdfio_pair_t), (int (*)(const void *, const void *))compare_pairs)) != NULL) { // Yes, replace the value... PDFIO_DEBUG("_pdfioDictSetValue: Replacing existing value.\n"); if (pair->value.type == PDFIO_VALTYPE_BINARY) free(pair->value.value.binary.data); pair->value = *value; return (true); } } // Nope, add a pair... if (dict->num_pairs >= dict->alloc_pairs) { // Expand the dictionary... _pdfio_pair_t *temp = (_pdfio_pair_t *)realloc(dict->pairs, (dict->alloc_pairs + 8) * sizeof(_pdfio_pair_t)); if (!temp) { PDFIO_DEBUG("_pdfioDictSetValue: Out of memory.\n"); return (false); } dict->pairs = temp; dict->alloc_pairs += 8; } pair = dict->pairs + dict->num_pairs; dict->num_pairs ++; pair->key = key; pair->value = *value; // Re-sort the dictionary and return... if (dict->num_pairs > 1 && compare_pairs(pair - 1, pair) > 0) qsort(dict->pairs, dict->num_pairs, sizeof(_pdfio_pair_t), (int (*)(const void *, const void *))compare_pairs); #ifdef DEBUG PDFIO_DEBUG("_pdfioDictSetValue(%p): %lu pairs\n", (void *)dict, (unsigned long)dict->num_pairs); PDFIO_DEBUG("_pdfioDictSetValue(%p): ", (void *)dict); PDFIO_DEBUG_DICT(dict); PDFIO_DEBUG("\n"); #endif // DEBUG return (true); }
Base
1
_pdfioTokenGet(_pdfio_token_t *tb, // I - Token buffer/stack char *buffer, // I - String buffer size_t bufsize) // I - Size of string buffer { // See if we have a token waiting on the stack... if (tb->num_tokens > 0) { // Yes, return it... tb->num_tokens --; strncpy(buffer, tb->tokens[tb->num_tokens], bufsize - 1); buffer[bufsize - 1] = '\0'; PDFIO_DEBUG("_pdfioTokenGet(tb=%p, buffer=%p, bufsize=%u): Popping '%s' from stack.\n", tb, buffer, (unsigned)bufsize, buffer); free(tb->tokens[tb->num_tokens]); tb->tokens[tb->num_tokens] = NULL; return (true); } // No, read a new one... return (_pdfioTokenRead(tb, buffer, bufsize)); }
Base
1
static void _clean_slate_datagram(gnrc_sixlowpan_frag_fb_t *fbuf) { clist_node_t new_queue = { .next = NULL }; fbuf->sfr.arq_timeout_event.msg.content.ptr = NULL; /* remove potentially scheduled timers for this datagram */ evtimer_del((evtimer_t *)(&_arq_timer), &fbuf->sfr.arq_timeout_event.event); fbuf->sfr.arq_timeout_event.event.next = NULL; if (gnrc_sixlowpan_frag_sfr_congure_snd_has_inter_frame_gap()) { for (clist_node_t *node = clist_lpop(&_frame_queue); node != NULL; node = clist_lpop(&_frame_queue)) { _frame_queue_t *entry = (_frame_queue_t *)node; /* remove frames of this datagram from frame queue */ if (entry->datagram_tag == fbuf->tag) { gnrc_pktbuf_release(entry->frame); /* unset packet just to be safe */ entry->frame = NULL; clist_rpush(&_frag_descs_free, node); } else { clist_rpush(&new_queue, node); } } /* reset frame queue with remaining frames */ _frame_queue = new_queue; } fbuf->offset = 0U; fbuf->sfr.cur_seq = 0U; fbuf->sfr.frags_sent = 0U; for (clist_node_t *node = clist_lpop(&fbuf->sfr.window); node != NULL; node = clist_lpop(&fbuf->sfr.window)) { clist_rpush(&_frag_descs_free, node); } }
Class
2
static void _sched_arq_timeout(gnrc_sixlowpan_frag_fb_t *fbuf, uint32_t offset) { if (IS_ACTIVE(CONFIG_GNRC_SIXLOWPAN_SFR_MOCK_ARQ_TIMER)) { /* mock does not need to be scheduled */ return; } if (fbuf->sfr.arq_timeout_event.msg.content.ptr != NULL) { DEBUG("6lo sfr: ARQ timeout for datagram %u already scheduled\n", (uint8_t)fbuf->tag); return; } DEBUG("6lo sfr: arming ACK timeout in %lums for datagram %u\n", (long unsigned)offset, fbuf->tag); fbuf->sfr.arq_timeout_event.event.offset = offset; fbuf->sfr.arq_timeout_event.msg.content.ptr = fbuf; fbuf->sfr.arq_timeout_event.msg.type = GNRC_SIXLOWPAN_FRAG_SFR_ARQ_TIMEOUT_MSG; evtimer_add_msg(&_arq_timer, &fbuf->sfr.arq_timeout_event, _getpid()); }
Class
2
compat_cipher_proposal(struct ssh *ssh, char *cipher_prop) { if (!(ssh->compat & SSH_BUG_BIGENDIANAES)) return cipher_prop; debug2_f("original cipher proposal: %s", cipher_prop); if ((cipher_prop = match_filter_denylist(cipher_prop, "aes*")) == NULL) fatal("match_filter_denylist failed"); debug2_f("compat cipher proposal: %s", cipher_prop); if (*cipher_prop == '\0') fatal("No supported ciphers found"); return cipher_prop; }
Variant
0
compat_kex_proposal(struct ssh *ssh, char *p) { if ((ssh->compat & (SSH_BUG_CURVE25519PAD|SSH_OLD_DHGEX)) == 0) return p; debug2_f("original KEX proposal: %s", p); if ((ssh->compat & SSH_BUG_CURVE25519PAD) != 0) if ((p = match_filter_denylist(p, "[email protected]")) == NULL) fatal("match_filter_denylist failed"); if ((ssh->compat & SSH_OLD_DHGEX) != 0) { if ((p = match_filter_denylist(p, "diffie-hellman-group-exchange-sha256," "diffie-hellman-group-exchange-sha1")) == NULL) fatal("match_filter_denylist failed"); } debug2_f("compat KEX proposal: %s", p); if (*p == '\0') fatal("No supported key exchange algorithms found"); return p; }
Variant
0
compat_pkalg_proposal(struct ssh *ssh, char *pkalg_prop) { if (!(ssh->compat & SSH_BUG_RSASIGMD5)) return pkalg_prop; debug2_f("original public key proposal: %s", pkalg_prop); if ((pkalg_prop = match_filter_denylist(pkalg_prop, "ssh-rsa")) == NULL) fatal("match_filter_denylist failed"); debug2_f("compat public key proposal: %s", pkalg_prop); if (*pkalg_prop == '\0') fatal("No supported PK algorithms found"); return pkalg_prop; }
Variant
0
static int ntlm_decode_u16l_str_hdr(struct ntlm_ctx *ctx, struct wire_field_hdr *str_hdr, struct ntlm_buffer *buffer, size_t payload_offs, char **str) { char *in, *out = NULL; uint16_t str_len; uint32_t str_offs; size_t outlen; int ret = 0; str_len = le16toh(str_hdr->len); if (str_len == 0) goto done; str_offs = le32toh(str_hdr->offset); if ((str_offs < payload_offs) || (str_offs > buffer->length) || (UINT32_MAX - str_offs < str_len) || (str_offs + str_len > buffer->length)) { return ERR_DECODE; } in = (char *)&buffer->data[str_offs]; out = malloc(str_len * 2 + 1); if (!out) return ENOMEM; ret = ntlm_str_convert(ctx->to_oem, in, out, str_len, &outlen); /* make sure to terminate output string */ out[outlen] = '\0'; done: if (ret) { safefree(out); } *str = out; return ret; }
Base
1
void SetClipboardText(const char *text) { #if defined(PLATFORM_DESKTOP) glfwSetClipboardString(CORE.Window.handle, text); #endif #if defined(PLATFORM_WEB) emscripten_run_script(TextFormat("navigator.clipboard.writeText('%s')", text)); #endif }
Base
1
const char *GetClipboardText(void) { #if defined(PLATFORM_DESKTOP) return glfwGetClipboardString(CORE.Window.handle); #endif #if defined(PLATFORM_WEB) // Accessing clipboard data from browser is tricky due to security reasons // The method to use is navigator.clipboard.readText() but this is an asynchronous method // that will return at some moment after the function is called with the required data emscripten_run_script_string("navigator.clipboard.readText() \ .then(text => { document.getElementById('clipboard').innerText = text; console.log('Pasted content: ', text); }) \ .catch(err => { console.error('Failed to read clipboard contents: ', err); });" ); // The main issue is getting that data, one approach could be using ASYNCIFY and wait // for the data but it requires adding Asyncify emscripten library on compilation // Another approach could be just copy the data in a HTML text field and try to retrieve it // later on if available... and clean it for future accesses return NULL; #endif return NULL; }
Base
1
static memcached_return_t _read_one_response(memcached_instance_st *instance, char *buffer, const size_t buffer_length, memcached_result_st *result) { memcached_server_response_decrement(instance); if (result == NULL) { Memcached *root = (Memcached *) instance->root; result = &root->result; } memcached_return_t rc; if (memcached_is_binary(instance->root)) { do { rc = binary_read_one_response(instance, buffer, buffer_length, result); } while (rc == MEMCACHED_FETCH_NOTFINISHED); } else { rc = textual_read_one_response(instance, buffer, buffer_length, result); } if (memcached_fatal(rc) && rc != MEMCACHED_TIMEOUT) { memcached_io_reset(instance); } return rc; }
Class
2
sshsk_open(const char *path) { struct sshsk_provider *ret = NULL; uint32_t version; if (path == NULL || *path == '\0') { error("No FIDO SecurityKeyProvider specified"); return NULL; } if ((ret = calloc(1, sizeof(*ret))) == NULL) { error_f("calloc failed"); return NULL; } if ((ret->path = strdup(path)) == NULL) { error_f("strdup failed"); goto fail; } /* Skip the rest if we're using the linked in middleware */ if (strcasecmp(ret->path, "internal") == 0) { ret->sk_enroll = ssh_sk_enroll; ret->sk_sign = ssh_sk_sign; ret->sk_load_resident_keys = ssh_sk_load_resident_keys; return ret; } if ((ret->dlhandle = dlopen(path, RTLD_NOW)) == NULL) { error("Provider \"%s\" dlopen failed: %s", path, dlerror()); goto fail; } if ((ret->sk_api_version = dlsym(ret->dlhandle, "sk_api_version")) == NULL) { error("Provider \"%s\" dlsym(sk_api_version) failed: %s", path, dlerror()); goto fail; } version = ret->sk_api_version(); debug_f("provider %s implements version 0x%08lx", ret->path, (u_long)version); if ((version & SSH_SK_VERSION_MAJOR_MASK) != SSH_SK_VERSION_MAJOR) { error("Provider \"%s\" implements unsupported " "version 0x%08lx (supported: 0x%08lx)", path, (u_long)version, (u_long)SSH_SK_VERSION_MAJOR); goto fail; } if ((ret->sk_enroll = dlsym(ret->dlhandle, "sk_enroll")) == NULL) { error("Provider %s dlsym(sk_enroll) failed: %s", path, dlerror()); goto fail; } if ((ret->sk_sign = dlsym(ret->dlhandle, "sk_sign")) == NULL) { error("Provider \"%s\" dlsym(sk_sign) failed: %s", path, dlerror()); goto fail; } if ((ret->sk_load_resident_keys = dlsym(ret->dlhandle, "sk_load_resident_keys")) == NULL) { error("Provider \"%s\" dlsym(sk_load_resident_keys) " "failed: %s", path, dlerror()); goto fail; } /* success */ return ret; fail: sshsk_free(ret); return NULL; }
Base
1
wsemul_sun_output_control(struct wsemul_sun_emuldata *edp, struct wsemul_inputstate *instate) { int oargs; int rc; switch (instate->inchar) { case '0': case '1': case '2': case '3': case '4': /* argument digit */ case '5': case '6': case '7': case '8': case '9': /* * If we receive more arguments than we are expecting, * discard the earliest arguments. */ if (edp->nargs > SUN_EMUL_NARGS - 1) { bcopy(edp->args + 1, edp->args, (SUN_EMUL_NARGS - 1) * sizeof(edp->args[0])); edp->args[edp->nargs = SUN_EMUL_NARGS - 1] = 0; } edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) + (instate->inchar - '0'); break; case ';': /* argument terminator */ edp->nargs++; break; default: /* end of escape sequence */ oargs = edp->nargs++; if (edp->nargs > SUN_EMUL_NARGS) edp->nargs = SUN_EMUL_NARGS; rc = wsemul_sun_control(edp, instate); if (rc != 0) { /* undo nargs progress */ edp->nargs = oargs; return rc; } edp->state = SUN_EMUL_STATE_NORMAL; break; } return 0; }
Class
2
wsemul_vt100_output_csi(struct wsemul_vt100_emuldata *edp, struct wsemul_inputstate *instate) { u_int newstate = VT100_EMUL_STATE_CSI; int oargs; int rc = 0; switch (instate->inchar) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* argument digit */ if (edp->nargs > VT100_EMUL_NARGS - 1) break; edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) + (instate->inchar - '0'); break; case ';': /* argument terminator */ edp->nargs++; break; case '?': /* DEC specific */ case '>': /* DA query */ edp->modif1 = (char)instate->inchar; break; case '!': case '"': case '$': case '&': edp->modif2 = (char)instate->inchar; break; default: /* end of escape sequence */ oargs = edp->nargs++; if (edp->nargs > VT100_EMUL_NARGS) { #ifdef VT100_DEBUG printf("vt100: too many arguments\n"); #endif edp->nargs = VT100_EMUL_NARGS; } rc = wsemul_vt100_handle_csi(edp, instate); if (rc != 0) { edp->nargs = oargs; return rc; } newstate = VT100_EMUL_STATE_NORMAL; break; } if (COLS_LEFT != 0) edp->flags &= ~VTFL_LASTCHAR; edp->state = newstate; return 0; }
Class
2
wsemul_vt100_output_dcs(struct wsemul_vt100_emuldata *edp, struct wsemul_inputstate *instate) { u_int newstate = VT100_EMUL_STATE_DCS; switch (instate->inchar) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* argument digit */ if (edp->nargs > VT100_EMUL_NARGS - 1) break; edp->args[edp->nargs] = (edp->args[edp->nargs] * 10) + (instate->inchar - '0'); break; case ';': /* argument terminator */ edp->nargs++; break; default: edp->nargs++; if (edp->nargs > VT100_EMUL_NARGS) { #ifdef VT100_DEBUG printf("vt100: too many arguments\n"); #endif edp->nargs = VT100_EMUL_NARGS; } newstate = VT100_EMUL_STATE_STRING; switch (instate->inchar) { case '$': newstate = VT100_EMUL_STATE_DCS_DOLLAR; break; case '{': /* DECDLD soft charset */ /* } */ case '!': /* DECRQUPSS user preferred supplemental set */ /* 'u' must follow - need another state */ case '|': /* DECUDK program F6..F20 */ #ifdef VT100_PRINTNOTIMPL printf("DCS%c ignored\n", (char)instate->inchar); #endif break; default: #ifdef VT100_PRINTUNKNOWN printf("DCS %x (%d, %d) unknown\n", instate->inchar, ARG(0), ARG(1)); #endif break; } } edp->state = newstate; return 0; }
Class
2
static pj_status_t transport_destroy (pjmedia_transport *tp) { struct tp_adapter *adapter = (struct tp_adapter*)tp; /* Close the slave transport */ if (adapter->del_base) { pjmedia_transport_close(adapter->slave_tp); } /* Self destruct.. */ pj_pool_release(adapter->pool); return PJ_SUCCESS; }
Variant
0
static pj_status_t transport_destroy(pjmedia_transport *tp) { struct transport_loop *loop = (struct transport_loop*) tp; /* Sanity check */ PJ_ASSERT_RETURN(tp, PJ_EINVAL); pj_pool_release(loop->pool); return PJ_SUCCESS; }
Variant
0
static pj_status_t transport_destroy (pjmedia_transport *tp) { transport_srtp *srtp = (transport_srtp *) tp; pj_status_t status; unsigned i; PJ_ASSERT_RETURN(tp, PJ_EINVAL); /* Close all keying. Note that any keying should not be destroyed before * SRTP transport is destroyed as re-INVITE may initiate new keying method * without destroying SRTP transport. */ for (i=0; i < srtp->all_keying_cnt; i++) pjmedia_transport_close(srtp->all_keying[i]); /* Close member if configured */ if (srtp->setting.close_member_tp && srtp->member_tp) { pjmedia_transport_close(srtp->member_tp); } status = pjmedia_transport_srtp_stop(tp); /* In case mutex is being acquired by other thread */ pj_lock_acquire(srtp->mutex); pj_lock_release(srtp->mutex); pj_lock_destroy(srtp->mutex); pj_pool_release(srtp->pool); return status; }
Variant
0
static void clock_cb(const pj_timestamp *ts, void *user_data) { dtls_srtp_channel *ds_ch = (dtls_srtp_channel*)user_data; dtls_srtp *ds = ds_ch->dtls_srtp; unsigned idx = ds_ch->channel; PJ_UNUSED_ARG(ts); pj_lock_acquire(ds->ossl_lock); if (!ds->ossl_ssl[idx]) { pj_lock_release(ds->ossl_lock); return; } if (DTLSv1_handle_timeout(ds->ossl_ssl[idx]) > 0) { pj_lock_release(ds->ossl_lock); ssl_flush_wbio(ds, idx); } else { pj_lock_release(ds->ossl_lock); } }
Variant
0