PJ_DEF(pjsip_proxy_authorization_hdr*) pjsip_proxy_authorization_hdr_create(pj_pool_t *pool) { pjsip_proxy_authorization_hdr *hdr; hdr = PJ_POOL_ZALLOC_T(pool, pjsip_proxy_authorization_hdr); init_hdr(hdr, PJSIP_H_PROXY_AUTHORIZATION, &authorization_hdr_vptr); pj_list_init(&hdr->credential.common.other_param); return hdr; }
PJ_DEF(pjsip_proxy_authenticate_hdr*) pjsip_proxy_authenticate_hdr_create(pj_pool_t *pool) { pjsip_proxy_authenticate_hdr *hdr; hdr = PJ_POOL_ZALLOC_T(pool, pjsip_proxy_authenticate_hdr); init_hdr(hdr, PJSIP_H_PROXY_AUTHENTICATE, &www_authenticate_hdr_vptr); pj_list_init(&hdr->challenge.common.other_param); return hdr; }
void start_write(char *dirname, char *prefix) { struct dirent* dirp; DIR* d; char *path; int infd; struct stat st; struct fs_hdr *fsh; int fseek = START_OFFSET; int size; if ((d = opendir(dirname)) == NULL) err(1, "opendir"); while ((dirp = readdir(d)) != NULL) { switch (dirp->d_type) { case DT_REG: size = strlen(dirname) + strlen(dirp->d_name) + 2; path = malloc(size); if(!path) err(1, "%s", path); snprintf(path, size, "%s/%s", dirname, dirp->d_name); //Open the file and write to dst infd = open(path, O_RDONLY); if (infd < 0) err(1, "open"); free(path); if(fstat(infd, &st)!=0) err(1, "fstat"); lseek(outfd, fseek, SEEK_SET); size = fcopy(infd, outfd, roundup(st.st_size,SECTOR_SIZE)); if (size < st.st_size) printf("Short file write [%s,%lu,%d]\n",dirp->d_name,st.st_size,size); close(infd); //Seek to location and Write FS metadata char *fname = malloc(512); if (!fname) err(1, "malloc"); snprintf(fname, 512, "%s%s", prefix, dirp->d_name); fsh = init_hdr(fname, st.st_size, fseek); free(fname); lseek(outfd, mseek, SEEK_SET); write(outfd, fsh, sizeof(struct fs_hdr)); //Reset FD pointers mseek += SECTOR_SIZE; fseek += roundup(size,PAGE_SIZE); free(fsh); close(infd); break; case DT_DIR: if (!strcmp(dirp->d_name,".") || !strcmp(dirp->d_name,"..")) break; char *subdir, *newprefix; subdir=malloc(4096); if (!subdir) err(1, "malloc"); newprefix=malloc(512); if (!newprefix) err(1, "malloc"); snprintf(subdir, 4096, "%s/%s", dirname, dirp->d_name); snprintf(newprefix, 512, "%s%s/", prefix, dirp->d_name); start_write(subdir, newprefix); free(subdir); free(newprefix); break; default: break; } } closedir(d); }
int main(int argc, char *argv[]) { struct dirent* dirp; DIR* d; char *dir, *path; int outfd, infd; struct stat st; struct fs_hdr *fsh; int mseek = 0; int size; u_int32_t offset; struct fs_ctx *fsc; if (argc != 4) { usage(); return -1; } outfd = open(argv[2],O_WRONLY); if (outfd == -1 && errno == ENOENT) { outfd = open(argv[2],O_CREAT|O_WRONLY); } if (outfd == -1) { printf("Failed to open output file\n"); return -1; } printf("Opened output file %s\n",argv[2]); //Zero out metadata region and reset filehandle fzero(outfd, START_OFFSET); lseek(outfd,mseek,SEEK_SET); //Initialise the blockstore fsc = init_fs_ctx(); printf("Initialising blockstore...\n"); if (init_blockstore(argv[3],fsc)!=1) { printf("Failed to initialise blockstore\n"); return -1; } fsc->next_fs_block = 1024; fsc->fsfd = outfd; dir = strdup(argv[1]); if ((d = opendir(argv[1])) == NULL) { return -1; } while ((dirp = readdir(d)) != NULL) { if (dirp->d_type == DT_REG) { printf("%s/%s\n", dir, dirp->d_name); size = strlen(dir) + strlen(dirp->d_name) + 2; path = malloc(size); if(!path) { printf("Failed to malloc %d bytes\n",size); continue; } snprintf(path,size,"%s/%s", dir, dirp->d_name); //Open the file and write to dst infd = open(path, O_RDONLY); free(path); if(fstat(infd, &st)!=0) { printf("Failed to stat input file, continuing...\n"); continue; } offset = fcopy_to_blockstore(infd,fsc,roundup(st.st_size,PAGE_SIZE)); close(infd); //Seek to location and Write FS metadata fsh = init_hdr(dirp->d_name, st.st_size, offset, BLOCKSUM_MAGIC_HDR); lseek(outfd,mseek,SEEK_SET); write(outfd, fsh, sizeof(struct fs_hdr)); printf("Wrote Node: %s, size: %llu, offset: %llu\n", fsh->filename, fsh->length, fsh->offset); //Reset FD pointers mseek += SECTOR_SIZE; free(fsh); close(infd); } } close(outfd); closedir(d); close_blockstore(fsc); return 0; }