spl::shared_ptr<shader> get_image_shader(bool& blend_modes) { tbb::mutex::scoped_lock lock(g_shader_mutex); if(g_shader) { blend_modes = g_blend_modes; return spl::make_shared_ptr(g_shader); } try { g_blend_modes = glTextureBarrierNV ? env::properties().get(L"configuration.blend-modes", true) : false; g_shader.reset(new shader(get_vertex(), get_fragment(g_blend_modes))); } catch(...) { CASPAR_LOG_CURRENT_EXCEPTION(); CASPAR_LOG(warning) << "Failed to compile shader. Trying to compile without blend-modes."; g_blend_modes = false; g_shader.reset(new shader(get_vertex(), get_fragment(g_blend_modes))); } //if(!g_blend_modes) //{ // ogl.blend_func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); // CASPAR_LOG(info) << L"[shader] Blend-modes are disabled."; //} blend_modes = g_blend_modes; return spl::make_shared_ptr(g_shader); }
// Construct a URL object from the string representation URL::URL(const std::string& url_str) { if (url_str.empty()) throw std::invalid_argument("empty url string"); const std::string sr = boost::trim_copy(url_str); try { token_rest scheme_rest = get_scheme(sr); scheme = scheme_rest.first; std::cout << scheme_rest.first << " : " << scheme_rest.second << std::endl; token_rest host_port_rest = get_host_port(scheme_rest.second); std::cout << host_port_rest.first << " : " << host_port_rest.second << std::endl; std::pair<std::string,uint16_t> host_port = split_host_port(host_port_rest.first); std::cout << host_port.first << " : " << host_port.second << std::endl; host = host_port.first; port = host_port.second; token_rest path_rest = get_path(host_port_rest.second); std::cout << path_rest.first << std::endl; path = path_rest.first; if (path_rest.second.empty()) return; token_rest query_rest = get_query(path_rest.second); std::cout << query_rest.first << " : " << query_rest.second << std::endl; if (!query_rest.first.empty()) { query_key_vals = make_query_map(query_rest.first); } std::string fragment = get_fragment(query_rest.second); std::cout << fragment << std::endl; } catch(const std::exception &e) { std::cerr << e.what() << std::endl; throw e; } // parsed successfully, we can copy over the original arg string_rep = url_str; }
struct file_buffer *get_fragment_cksum(struct file_info *file, char *data_buffer, int fd, unsigned short *checksum) { struct file_buffer *frag_buffer; struct append_file *append; int index = file->fragment->index; frag_buffer = get_fragment(file->fragment, data_buffer, fd); pthread_cleanup_push((void *)pthread_mutex_unlock, &dup_mutex); for (append = file_mapping[index]; append; append = append->next) { int offset = append->file->fragment->offset; int size = append->file->fragment->size; char *data = frag_buffer->data + offset; unsigned short cksum = get_checksum_mem(data, size); if (file == append->file) *checksum = cksum; pthread_mutex_lock(&dup_mutex); append->file->fragment_checksum = cksum; append->file->have_frag_checksum = TRUE; pthread_mutex_unlock(&dup_mutex); } pthread_cleanup_pop(0); return frag_buffer; }
safe_ptr<shader> get_image_shader( ogl_device& ogl, bool& blend_modes, bool& post_processing) { tbb::mutex::scoped_lock lock(g_shader_mutex); if(g_shader) { blend_modes = g_blend_modes; post_processing = g_post_processing; return make_safe_ptr(g_shader); } bool chroma_key = env::properties().get(L"configuration.mixer.chroma-key", false); bool straight_alpha = env::properties().get(L"configuration.mixer.straight-alpha", false); g_post_processing = straight_alpha; try { g_blend_modes = glTextureBarrierNV ? env::properties().get(L"configuration.mixer.blend-modes", false) : false; g_shader.reset(new shader(get_vertex(), get_fragment(g_blend_modes, chroma_key, g_post_processing))); } catch(...) { CASPAR_LOG_CURRENT_EXCEPTION(); CASPAR_LOG(warning) << "Failed to compile shader. Trying to compile without blend-modes."; g_blend_modes = false; g_shader.reset(new shader(get_vertex(), get_fragment(g_blend_modes, chroma_key, g_post_processing))); } ogl.enable(GL_TEXTURE_2D); if(!g_blend_modes) { ogl.enable(GL_BLEND); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); CASPAR_LOG(info) << L"[shader] Blend-modes are disabled."; } blend_modes = g_blend_modes; post_processing = g_post_processing; return make_safe_ptr(g_shader); }
int send_image_udp(int sock, struct sockaddr_in dest, char * rep, int image, int frag_size) { int len_ima = 0, len, sent = 0, read, start = 0, pos_pack = 0; char str[32], *buff_ima, header[32]; errno = 0; sprintf(str, "%s/%d.jpg", rep, image); frag_size -= 100; file_to_buffer(str, &buff_ima, &len_ima); int num_frag = len_ima / frag_size; char * buff, * buff_fin = malloc((len_ima + 20) * sizeof(char)); pos_pack = 0; do { //get next fragment read = get_fragment(buff_ima, len_ima, start, frag_size, &buff, &buff_fin); //build "header" sprintf(header, "%d\r\n%d\r\n%d\r\n%d\r\n", image, len_ima, start, read); len = strlen(header); //send "header" sendto(sock, header, len, MSG_MORE, (struct sockaddr*)&dest, sizeof(dest)); //send fragment sent += sendto(sock, buff, read, 0, (struct sockaddr*)&dest, sizeof(dest));; start += read; pos_pack += 1; } while(sent < len_ima); free(buff_ima); perror("free"); free(buff); perror("free"); free(buff_fin); perror("free"); }
uint8_t* fp_resize (fp_pool_t p, uint8_t* bp, fp_size_t new_size, uint8_t** fragment_endp) { fp_fragment_t f = get_fragment(p, bp); fp_fragment_t fe = p->fragment + p->fragment_count; fp_fragment_t nf; if ((NULL == f) || (!FRAGMENT_IS_ALLOCATED(f))) { return NULL; } nf = f+1; if (nf < fe) { fp_size_t cur_size = - f->length; if (FP_MAX_FRAGMENT_SIZE == new_size) { if (FRAGMENT_IS_AVAILABLE(nf)) { merge_adjacent_available(f, fe); } } else { new_size = align_size_up(p, new_size); if (new_size < cur_size) { /* Give back, if possible */ release_suffix(f, p->fragment + p->fragment_count, cur_size - new_size); } else if (new_size > cur_size) { /* Extend to following fragment? */ if (FRAGMENT_IS_AVAILABLE(nf)) { fp_size_t lacking = new_size - cur_size; if (nf->length > (fp_ssize_t)lacking) { /* More available than needed; take only what's requested */ nf->start += lacking; nf->length -= lacking; f->length -= lacking; } else { merge_adjacent_available(f, fe); } } } } } *fragment_endp = f->start - f->length; return f->start; }
int fp_release (fp_pool_t p, const uint8_t* bp) { fp_fragment_t f = get_fragment(p, bp); fp_fragment_t nf; const fp_fragment_t fe = p->fragment + p->fragment_count; if ((NULL == f) || (! FRAGMENT_IS_ALLOCATED(f))) { return FP_EINVAL; } f->length = -f->length; if ((p->fragment < f) && FRAGMENT_IS_AVAILABLE(f-1)) { merge_adjacent_available(--f, fe); } nf = f+1; if ((nf < fe) && FRAGMENT_IS_AVAILABLE(nf)) { merge_adjacent_available(f, fe); } return 0; }
void *frag_thrd(void *destination_file) { sigset_t sigmask, old_mask; char *data_buffer; int fd; sigemptyset(&sigmask); sigaddset(&sigmask, SIGINT); sigaddset(&sigmask, SIGTERM); sigaddset(&sigmask, SIGUSR1); pthread_sigmask(SIG_BLOCK, &sigmask, &old_mask); fd = open(destination_file, O_RDONLY); if (fd == -1) BAD_ERROR("frag_thrd: can't open destination for reading\n"); data_buffer = malloc(SQUASHFS_FILE_MAX_SIZE); if (data_buffer == NULL) MEM_ERROR(); pthread_cleanup_push((void *)pthread_mutex_unlock, &dup_mutex); while (1) { struct file_buffer *file_buffer = queue_get(to_process_frag); struct file_buffer *buffer; int sparse = checksum_sparse(file_buffer); struct file_info *dupl_ptr; long long file_size; unsigned short checksum; char flag; int res; if (sparse_files && sparse) { file_buffer->c_byte = 0; file_buffer->fragment = FALSE; } else file_buffer->c_byte = file_buffer->size; /* * Specutively pull into the fragment cache any fragment blocks * which contain fragments which *this* fragment may be * be a duplicate. * * By ensuring the fragment block is in cache ahead of time * should eliminate the parallelisation stall when the * main thread needs to read the fragment block to do a * duplicate check on it. * * If this is a fragment belonging to a larger file * (with additional blocks) then ignore it. Here we're * interested in the "low hanging fruit" of files which * consist of only a fragment */ if (file_buffer->file_size != file_buffer->size) { seq_queue_put(to_main, file_buffer); continue; } file_size = file_buffer->file_size; pthread_mutex_lock(&dup_mutex); dupl_ptr = dupl[DUP_HASH(file_size)]; pthread_mutex_unlock(&dup_mutex); file_buffer->dupl_start = dupl_ptr; file_buffer->duplicate = FALSE; for (; dupl_ptr; dupl_ptr = dupl_ptr->next) { if (file_size != dupl_ptr->file_size || file_size != dupl_ptr->fragment->size) continue; pthread_mutex_lock(&dup_mutex); flag = dupl_ptr->have_frag_checksum; checksum = dupl_ptr->fragment_checksum; pthread_mutex_unlock(&dup_mutex); /* * If we have the checksum and it matches then * read in the fragment block. * * If we *don't* have the checksum, then we are * appending, and the fragment block is on the * "old" filesystem. Read it in and checksum * the entire fragment buffer */ if (!flag) { buffer = get_fragment_cksum(dupl_ptr, data_buffer, fd, &checksum); if (checksum != file_buffer->checksum) { cache_block_put(buffer); continue; } } else if (checksum == file_buffer->checksum) buffer = get_fragment(dupl_ptr->fragment, data_buffer, fd); else continue; res = memcmp(file_buffer->data, buffer->data + dupl_ptr->fragment->offset, file_size); cache_block_put(buffer); if (res == 0) { struct file_buffer *dup = malloc(sizeof(*dup)); if (dup == NULL) MEM_ERROR(); memcpy(dup, file_buffer, sizeof(*dup)); cache_block_put(file_buffer); dup->dupl_start = dupl_ptr; dup->duplicate = TRUE; file_buffer = dup; break; } } seq_queue_put(to_main, file_buffer); } pthread_cleanup_pop(0); }
// main function for parsing a string url into a url struct url_t *parse_url(char const *const url_string,unsigned int *url_err_out) { *url_err_out = UPARSE_ERROR; url_t *url = (url_t *) malloc(sizeof(url_t)); if (NULL == url) { fprintf(stderr,"cannot allocate url\n"); return NULL; } init_url_t(url); url->original = strdup(url_string); if (NULL == url->original) { fprintf(stderr,"cannot allocate original\n"); free_url_t(url); return NULL; } char *mut_url_string = strdup(url_string); char *free_mut_url_string = mut_url_string; if (NULL == mut_url_string) { fprintf(stderr,"cannot allocate url\n"); free_url_t(url); return NULL; } unsigned int scheme_out_err = 0; url->scheme = get_scheme(&mut_url_string,&scheme_out_err); if (NO_UPARSE_ERROR != scheme_out_err) { fprintf(stderr,"fail from get_scheme\n"); free_url_t(url); free(free_mut_url_string); return NULL; } unsigned int host_port_out_err = 0; host_port_t *host_port = get_host_port(&mut_url_string,&host_port_out_err); if (NO_UPARSE_ERROR != host_port_out_err) { fprintf(stderr,"fail from get_host_port\n"); free_url_t(url); free(free_mut_url_string); return NULL; } url->host = strdup(host_port->host); if (NULL == url->host) { fprintf(stderr,"cannot allocate host\n"); free_url_t(url); free(free_mut_url_string); return NULL; } url->port = host_port->port; free_host_port_t(host_port); unsigned int path_err_out = 0; url->path_elt_list = get_path(&mut_url_string,&path_err_out); if (NO_UPARSE_ERROR != path_err_out) { fprintf(stderr,"fail from get_path\n"); free_url_t(url); free(free_mut_url_string); return NULL; } unsigned int query_err_out = 0; url->query_arg_list = get_query_arg_list(&mut_url_string,&query_err_out); if (UPARSE_ERROR == query_err_out) { fprintf(stderr,"fail from get_query_arg_list\n"); free_url_t(url); free(free_mut_url_string); return NULL; } unsigned int fragment_err_out = 0; url->fragment = get_fragment(&mut_url_string,&fragment_err_out); if (UPARSE_ERROR == fragment_err_out) { fprintf(stderr,"fail from get_fragment\n"); free_url_t(url); free(free_mut_url_string); return NULL; } free(free_mut_url_string); *url_err_out = NO_UPARSE_ERROR; return url; }
static int oss_driver_start (oss_driver_t *driver) { int flags = 0; int format; int channels; int samplerate; int infd = driver->infd; int outfd = driver->outfd; unsigned int period_size; size_t samplesize; size_t fragsize; const char *indev = driver->indev; const char *outdev = driver->outdev; switch (driver->bits) { case 24: case 32: samplesize = sizeof(int); break; case 64: samplesize = sizeof(double); break; case 16: default: samplesize = sizeof(short); break; } driver->trigger = 0; if (strcmp(indev, outdev) != 0) { if (driver->capture_channels > 0) { infd = open(indev, O_RDONLY|O_EXCL); if (infd < 0) { jack_error( "OSS: failed to open input device %s: %s@%i, errno=%d", indev, __FILE__, __LINE__, errno); } #ifndef OSS_NO_COOKED_MODE ioctl(infd, SNDCTL_DSP_COOKEDMODE, &flags); #endif fragsize = driver->period_size * driver->capture_channels * samplesize; set_fragment(infd, fragsize, driver->nperiods); } else infd = -1; if (driver->playback_channels > 0) { outfd = open(outdev, O_WRONLY|O_EXCL); if (outfd < 0) { jack_error( "OSS: failed to open output device %s: %s@%i, errno=%d", outdev, __FILE__, __LINE__, errno); } #ifndef OSS_NO_COOKED_MODE ioctl(outfd, SNDCTL_DSP_COOKEDMODE, &flags); #endif fragsize = driver->period_size * driver->playback_channels * samplesize; set_fragment(outfd, fragsize, driver->nperiods); } else outfd = -1; } else { if (driver->capture_channels != 0 && driver->playback_channels == 0) { infd = open(indev, O_RDWR|O_EXCL); outfd = -1; if (infd < 0) { jack_error( "OSS: failed to open device %s: %s@%i, errno=%d", indev, __FILE__, __LINE__, errno); return -1; } #ifndef OSS_NO_COOKED_MODE ioctl(infd, SNDCTL_DSP_COOKEDMODE, &flags); #endif } else if (driver->capture_channels == 0 && driver->playback_channels != 0) { infd = -1; outfd = open(outdev, O_RDWR|O_EXCL); if (outfd < 0) { jack_error( "OSS: failed to open device %s: %s@%i, errno=%d", outdev, __FILE__, __LINE__, errno); return -1; } #ifndef OSS_NO_COOKED_MODE ioctl(outfd, SNDCTL_DSP_COOKEDMODE, &flags); #endif } else { infd = outfd = open(indev, O_RDWR|O_EXCL); if (infd < 0) { jack_error( "OSS: failed to open device %s: %s@%i, errno=%d", indev, __FILE__, __LINE__, errno); return -1; } #ifndef OSS_NO_COOKED_MODE ioctl(infd, SNDCTL_DSP_COOKEDMODE, &flags); #endif } if (infd >= 0 && outfd >= 0) { ioctl(outfd, SNDCTL_DSP_SETTRIGGER, &driver->trigger); driver->trigger = (PCM_ENABLE_INPUT|PCM_ENABLE_OUTPUT); if (ioctl(infd, SNDCTL_DSP_SETDUPLEX, 0) < 0) { if (errno != EINVAL) /* Dont care */ jack_error( "OSS: failed to enable full duplex for %s: %s@%i, errno=%d", indev, __FILE__, __LINE__, errno); } } if (infd >= 0) { fragsize = driver->period_size * driver->capture_channels * samplesize; set_fragment(infd, fragsize, driver->nperiods); } if (outfd >= 0 && infd < 0) { fragsize = driver->period_size * driver->playback_channels * samplesize; set_fragment(outfd, fragsize, driver->nperiods); } } driver->infd = infd; driver->outfd = outfd; if (infd >= 0) { format = driver->format; if (ioctl(infd, SNDCTL_DSP_SETFMT, &format) < 0) jack_error( "OSS: failed to set format for %s: %s@%i, errno=%d", indev, __FILE__, __LINE__, errno); channels = driver->capture_channels; if (ioctl(infd, SNDCTL_DSP_CHANNELS, &channels) < 0) jack_error( "OSS: failed to set channels for %s: %s@%i, errno=%d", indev, __FILE__, __LINE__, errno); samplerate = driver->sample_rate; if (ioctl(infd, SNDCTL_DSP_SPEED, &samplerate) < 0) jack_error( "OSS: failed to set samplerate for %s: %s@%i, errno=%d", indev, __FILE__, __LINE__, errno); jack_info("oss_driver: %s : 0x%x/%i/%i (%i)", indev, format, channels, samplerate, get_fragment(infd)); period_size = get_fragment(infd) / samplesize / channels; if (period_size != driver->period_size && !driver->ignorehwbuf) { jack_info("oss_driver: period size update: %u", period_size); driver->period_size = period_size; driver->period_usecs = ((double) driver->period_size / (double) driver->sample_rate) * 1e6; if (driver->engine->set_buffer_size(driver->engine, driver->period_size)) { jack_error ("OSS: cannot set engine buffer size to %d (check MIDI)", driver->period_size); return -1; } } } if (outfd >= 0 && infd != outfd) { format = driver->format; if (ioctl(outfd, SNDCTL_DSP_SETFMT, &format) < 0) jack_error( "OSS: failed to set format for %s: %s@%i, errno=%d", outdev, __FILE__, __LINE__, errno); channels = driver->playback_channels; if (ioctl(outfd, SNDCTL_DSP_CHANNELS, &channels) < 0) jack_error( "OSS: failed to set channels for %s: %s@%i, errno=%d", outdev, __FILE__, __LINE__, errno); samplerate = driver->sample_rate; if (ioctl(outfd, SNDCTL_DSP_SPEED, &samplerate) < 0) jack_error( "OSS: failed to set samplerate for %s: %s@%i, errno=%d", outdev, __FILE__, __LINE__, errno); jack_info("oss_driver: %s : 0x%x/%i/%i (%i)", outdev, format, channels, samplerate, get_fragment(outfd)); period_size = get_fragment(outfd) / samplesize / channels; if (period_size != driver->period_size && !driver->ignorehwbuf) { jack_info("oss_driver: period size update: %u", period_size); driver->period_size = period_size; driver->period_usecs = ((double) driver->period_size / (double) driver->sample_rate) * 1e6; if (driver->engine->set_buffer_size(driver->engine, driver->period_size)) { jack_error ("OSS: cannot set engine buffer size to %d (check MIDI)", driver->period_size); return -1; } } } if (driver->capture_channels > 0) { driver->indevbufsize = driver->period_size * driver->capture_channels * samplesize; driver->indevbuf = malloc(driver->indevbufsize); if (driver->indevbuf == NULL) { jack_error( "OSS: malloc() failed: %s@%i", __FILE__, __LINE__); return -1; } memset(driver->indevbuf, 0x00, driver->indevbufsize); } else { driver->indevbufsize = 0; driver->indevbuf = NULL; } if (driver->playback_channels > 0) { driver->outdevbufsize = driver->period_size * driver->playback_channels * samplesize; driver->outdevbuf = malloc(driver->outdevbufsize); if (driver->outdevbuf == NULL) { jack_error("OSS: malloc() failed: %s@%i", __FILE__, __LINE__); return -1; } memset(driver->outdevbuf, 0x00, driver->outdevbufsize); } else { driver->outdevbufsize = 0; driver->outdevbuf = NULL; } jack_info("oss_driver: indevbuf %zd B, outdevbuf %zd B", driver->indevbufsize, driver->outdevbufsize); pthread_mutex_init(&driver->mutex_in, NULL); pthread_mutex_init(&driver->mutex_out, NULL); # ifdef USE_BARRIER puts("oss_driver: using barrier mode, (dual thread)"); pthread_barrier_init(&driver->barrier, NULL, 2); # else puts("oss_driver: not using barrier mode, (single thread)"); # endif sem_init(&driver->sem_start, 0, 0); driver->run = 1; driver->threads = 0; if (infd >= 0) { if (jack_client_create_thread(NULL, &driver->thread_in, driver->engine->rtpriority, driver->engine->control->real_time, io_thread, driver) < 0) { jack_error("OSS: jack_client_create_thread() failed: %s@%i", __FILE__, __LINE__); return -1; } driver->threads |= 1; } # ifdef USE_BARRIER if (outfd >= 0) { if (jack_client_create_thread(NULL, &driver->thread_out, driver->engine->rtpriority, driver->engine->control->real_time, io_thread, driver) < 0) { jack_error("OSS: jack_client_create_thread() failed: %s@%i", __FILE__, __LINE__); return -1; } driver->threads |= 2; } # endif if (driver->threads & 1) sem_post(&driver->sem_start); if (driver->threads & 2) sem_post(&driver->sem_start); driver->last_periodtime = driver->engine->get_microseconds(); driver->next_periodtime = 0; driver->iodelay = 0.0F; return 0; }
fp_fragment_t fp_get_fragment (fp_pool_t p, uint8_t* bp) { return get_fragment(p, bp); }
uint8_t* fp_reallocate (fp_pool_t p, uint8_t* bp, fp_size_t min_size, fp_size_t max_size, uint8_t** fragment_endp) { fp_fragment_t f = get_fragment(p, bp); fp_fragment_t frs; fp_fragment_t fre; fp_size_t original_min_size; fp_size_t frlen; fp_fragment_t bf; fp_size_t bflen; const fp_fragment_t fe = p->fragment + p->fragment_count; fp_size_t copy_len; /* Validate arguments */ if ((NULL == f) || (! FRAGMENT_IS_ALLOCATED(f)) || (0 >= min_size) || (min_size > max_size) || (NULL == fragment_endp)) { return NULL; } original_min_size = min_size; min_size = align_size_up(p, min_size); if (FP_MAX_FRAGMENT_SIZE != max_size) { max_size = align_size_up(p, max_size); } /* Create hooks for a pseudo-slot at f0 for flen octets, * representing what would happen if this fragment were released. */ frs = fre = f; frlen = -f->length; if ((frs > p->fragment) && FRAGMENT_IS_AVAILABLE(frs-1)) { frs = f-1; frlen += frs->length; } if (((fre+1) < fe) && FRAGMENT_IS_AVAILABLE(fre+1)) { fre = f+1; frlen += fre->length; } bf = NULL; bflen = 0; { fp_fragment_t xf = p->fragment; /* Same logic as find_best_fragment, but treat the sequence around * the current fragment as a single fragment */ do { fp_ssize_t flen = xf->length; if (xf == frs) { flen = frlen; } if (min_size <= flen) { if ((NULL == bf) || PREFER_NEW_SIZE(flen, bflen, max_size)) { bf = xf; bflen = flen; } } if (xf == frs) { xf = fre; } } while (++xf < fe); } /* If nothing can satisfy the minimum, fail. */ if (NULL == bf) { return NULL; } /* Save the minimum of the current fragment length and the desired * new size */ copy_len = -f->length; if (copy_len > original_min_size) { copy_len = original_min_size; } /* If best is same fragment, just resize */ if (bf == f) { /* == frs */ return fp_resize(p, bp, max_size, fragment_endp); } /* If best is available fragment preceding this fragment, shift the * data. */ if (bf == frs) { fp_size_t ffrs_len; fp_size_t new_len; if (f < fre) { merge_adjacent_available(f, fe); } memmove(frs->start, f->start, copy_len); ffrs_len = frs->length - f->length; new_len = ffrs_len; if (new_len > max_size) { new_len = max_size; } frs->length = -new_len; *fragment_endp = frs->start + new_len; if (ffrs_len == new_len) { while ((++f < fe) && (! FRAGMENT_IS_INACTIVE(f))) { f[-1] = f[0]; } f[-1].length = 0; } else { f->start = *fragment_endp; f->length = ffrs_len - new_len; } return frs->start; } bp = complete_allocation(p, bf, max_size, fragment_endp); memmove(bp, f->start, copy_len); fp_release(p, f->start); return bp; }
url_t *parse_url(char const *const url_string,unsigned int *err_out) { *err_out = NO_UPARSE_ERROR; url_t *url = (url_t *) malloc(sizeof(url_t)); if (NULL == url) { fprintf(stderr,"cannot allocate url\n"); return NULL; } init_url_t(url); // get a mutable pointer to the url string, and set a copy that can be freed char const *s = strdup(url_string); if (NULL == s) { fprintf(stderr,"cannot copy url_string\n"); free_url_t(url); return NULL; } char const *const free_s = s; char *scheme = get_protocol_scheme(&s,err_out); if (NULL == scheme) { fprintf(stderr,"cannot get scheme from %s\n",url_string); free_url_t(url); free((void *) free_s); return NULL; } if (NO_UPARSE_ERROR != *err_out) { fprintf(stderr,"cannot get scheme from %s\n",url_string); free_url_t(url); free((void *) free_s); free(scheme); return NULL; } url->scheme = scheme; char *host = get_host(&s,err_out); if (NULL == host) { fprintf(stderr,"cannot get host from %s\n",url_string); free_url_t(url); free((void *) free_s); return NULL; } if (NO_UPARSE_ERROR != *err_out) { fprintf(stderr,"cannot get host from %s\n",url_string); free_url_t(url); free((void *) free_s); free(host); return NULL; } url->host = host; int const port = get_port(&s,err_out); if (ERROR_PORT == port) { fprintf(stderr,"cannot get port from %s\n",url_string); free_url_t(url); free((void *) free_s); return NULL; } if (NO_UPARSE_ERROR != *err_out) { fprintf(stderr,"cannot get port from %s\n",url_string); free_url_t(url); free((void *) free_s); return NULL; } url->port = port; char *path = get_path(&s,err_out); if (NULL == path) { fprintf(stderr,"cannot get path from %s\n",url_string); free_url_t(url); free((void *) free_s); return NULL; } if (NO_UPARSE_ERROR != *err_out) { fprintf(stderr,"cannot get path from %s\n",url_string); free_url_t(url); free((void *) free_s); free(path); return NULL; } url->path = path; char *query = get_query(&s,err_out); if ((NULL != query) && (UPARSE_ERROR != *err_out)) { url->query = query; } char *fragment = get_fragment(&s,err_out); if ((NULL != fragment) && (UPARSE_ERROR != *err_out)) { url->fragment = fragment; } free((void *) free_s); return url; }