void swap(struct student *first, struct student *second)
{
	int temp; char string[10];
	temp = first->score;
	first->score = second->score;
	second->score = temp;
	stringcopy(string, first->name);
	stringcopy(first->name, second->name);
	stringcopy(second->name, string);
}
void structclientAcopy(struct clientA source, struct clientA *destination){
	
	destination->numero = source.numero;
	
	stringcopy(source.nom, destination->nom);
	stringcopy(source.prenom, destination->prenom);
	stringcopy(source.datenaiss, destination->datenaiss);
	stringcopy(source.num_compte, destination->num_compte);
	stringcopy(source.num_reg_nat, destination->num_reg_nat);
	
	
}
Exemple #3
0
process_id_t process_spawn(const char* executable)
{
  TID_t thread;
  interrupt_status_t intr_status;
  process_id_t my_pid = process_get_current_process();
  process_id_t pid = alloc_process_id(PROCESS_RUNNING);

  if (pid < 0) { /* Process table full */
    return -1;
  }
  stringcopy(process_table[pid].executable, executable, PROCESS_NAME_MAX);
  process_table[pid].retval = 0;
  process_table[pid].first_zombie = -1;
  process_table[pid].prev_zombie = -1;
  process_table[pid].next_zombie = -1;
  process_table[pid].parent = my_pid;
  process_table[pid].children = 0;

  intr_status = _interrupt_disable();
  spinlock_acquire(&process_table_slock);

  if (my_pid >= 0) {
    process_table[my_pid].children++;
  }

  spinlock_release(&process_table_slock);
  _interrupt_set_state(intr_status);

  thread = thread_create((void (*)(uint32_t))(&process_start), (uint32_t)pid);
  thread_run(thread);
  return pid;
}
Exemple #4
0
/**
 * Obtains and initializes a free process table slot.
 */
process_id_t process_obtain_slot(const char *executable) {
    interrupt_status_t intr_status;
    process_id_t pid = -1;

    // Ensure that we're the only ones touching the process table.
    intr_status = _interrupt_disable();
    spinlock_acquire(&process_table_slock);

    // Find a free process slot.
    int i;
	for(i = 0; i < MAX_PROCESSES; i++) {
		if(process_table[i].state == PROCESS_SLOT_AVAILABLE) {
			pid = i;
            break;
        }
	}

	// No free process slots.
	KERNEL_ASSERT(pid != -1);

	process_table[pid].state = PROCESS_RUNNING;
	stringcopy(process_table[pid].name, executable, MAX_NAME_LENGTH);
    process_table[pid].threads = 1;
    process_table[pid].stack_end = (USERLAND_STACK_TOP & PAGE_SIZE_MASK) -
                                        (CONFIG_USERLAND_STACK_SIZE-1)*PAGE_SIZE;
    process_table[pid].bot_free_stack = 0;

	// Free our locks.
    spinlock_release(&process_table_slock);
    _interrupt_set_state(intr_status);

    return pid;
}
Exemple #5
0
void stringcat(void *dest, const void *src, int n)
{
    for ( ; (*((u_char *) dest) != '\0'); ((u_char *) dest)++)
	;

    stringcopy(dest, src, n);
}
Exemple #6
0
/**
 * Reads the MD block and writes all the filenames in the buffer.
 * It reads at most numfiles names.
 * @param fs Pointer to datastructure on device.
 * @param buffer A 2 dimensional array to hold filenames.
 * @param numfiles Maximum number of files to read (usually size of buffer).
 * @return The actual number of files read from MD (can be lower than numfiles.)
 */
int tfs_getfiles(fs_t *fs, char buffer[][20], int numfiles) {
    tfs_t *tfs;
    gbd_request_t req;
    uint32_t i;
    int r;
    int files = 0;
    tfs = (tfs_t *)fs->internal;

    semaphore_P(tfs->lock);

    req.block     = TFS_DIRECTORY_BLOCK;
    req.buf       = ADDR_KERNEL_TO_PHYS((uint32_t)tfs->buffer_md);
    req.sem       = NULL;
    r = tfs->disk->read_block(tfs->disk,&req);
    if(r == 0) {
	    /* An error occured during read. */
	    semaphore_V(tfs->lock);
	    return VFS_ERROR;
    }
    for(i=0;i < TFS_MAX_FILES && (int)i < numfiles;i++) {
        if (strlen(tfs->buffer_md[i].name) > 0) {
            files++;
            stringcopy(buffer[i], tfs->buffer_md[i].name, 100);
        }
    }
    semaphore_V(tfs->lock);
    return files;
}
Exemple #7
0
TypeError::TypeError(const char * const pFuncName, const int pLine,
                     const int pIndex, const fg::dtype pType)
    : Error(pFuncName, pLine, "Invalid data type", FG_ERR_INVALID_TYPE), mArgIndex(pIndex)
{
    std::string str = getName(pType); /* TODO getName has to be defined */
    size_t len = std::min(MAX_ERR_STR_LEN - 1, (int)str.length());
    stringcopy(mErrTypeName, str.c_str(), len);
    mErrTypeName[len] = '\0';
}
int main() {
    char s1[300],s2[100];
    printf("Input the string1(length<100):");
    scanf("%s",s1);
    printf("Input the string2(length<100):");
    scanf("%s",s2);
    stringcopy(s1,s2);
    printf("%s",s1);
}
Exemple #9
0
Error::Error(const char * const pFuncName, const int pLine,
             const char * const pMessage, ErrorCode pErrCode)
    : logic_error(pMessage),
      mLineNumber(pLine), mErrCode(pErrCode)
{
    size_t len = std::min(MAX_ERR_STR_LEN - 1, (int)strlen(pFuncName));
    stringcopy(mFuncName, pFuncName, len);
    mFuncName[len] = '\0';
}
Exemple #10
0
ArgumentError::ArgumentError(const char * const pFuncName,
                             const int pLine,
                             const int pIndex,
                             const char * const pExpectString)
    : Error(pFuncName, pLine, "Invalid argument", FG_ERR_INVALID_ARG), mArgIndex(pIndex)
{
    size_t len = std::min(MAX_ERR_STR_LEN - 1, (int)strlen(pExpectString));
    stringcopy(mExpected, pExpectString, len);
    mExpected[len] = '\0';
}
Exemple #11
0
DimensionError::DimensionError(const char * const pFuncName,
                               const int pLine,
                               const int pIndex,
                               const char * const pExpectString)
    : Error(pFuncName, pLine, "Invalid dimension", FG_ERR_SIZE), mArgIndex(pIndex)
{
    size_t len = std::min(MAX_ERR_STR_LEN - 1, (int)strlen(pExpectString));
    stringcopy(mExpected, pExpectString, len);
    mExpected[len] = '\0';
}
Exemple #12
0
void InitNotifyIconData()
{
  memset( &g_notifyIconData, 0, sizeof( NOTIFYICONDATA ) ) ;
  g_notifyIconData.cbSize = sizeof(NOTIFYICONDATA);

  g_notifyIconData.hWnd = g_hwnd;
  g_notifyIconData.uID = ID_TRAY_APP_ICON;
  g_notifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  g_notifyIconData.uCallbackMessage = WM_TRAYICON;
  g_notifyIconData.hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 0, 0, LR_SHARED);
  stringcopy(g_notifyIconData.szTip, TEXT("Wormhole"));
}
Exemple #13
0
node * create_node(char *text)
{
	node *new_node = (node*) malloc (sizeof(node));
	if(new_node != NULL)
	{
		stringcopy(new_node->text,text);
		new_node -> next = NULL;
		new_node -> prev = NULL;
		new_node -> text_length = get_string_length(text);
	}
	return new_node;
}
Exemple #14
0
void main(){
	
	char str1[31], str2[31];
	
	printf("Entrez une phrase dans la var string1 : ");
	gets(str1);
	
	stringcopy(str1, str2);
	
	printf("Contenu de str2 : ");
	puts(str2);
}
Exemple #15
0
int vfs_file(char *pathname, int idx, char *buffer)
{
    char volumename[VFS_NAME_LENGTH];
    char dirname[VFS_NAME_LENGTH];
    fs_t *fs = NULL;
    int ret;

    if (vfs_start_op() != VFS_OK)
        return VFS_UNUSABLE;

    if (pathname == NULL) {
        semaphore_P(vfs_table.sem);
        for (ret = 0; ret < CONFIG_MAX_FILESYSTEMS && idx != 0; ret++) {
            if (vfs_table.filesystems[ret].filesystem != NULL)
                idx--;
        }
        /* Error can be caused if idx was <= 0 or idx was higher than the
         * number of mounted volumes
         */
        if (idx != 0) {
            semaphore_V(vfs_table.sem);
            vfs_end_op();
            return VFS_ERROR;
        }
        stringcopy(buffer, vfs_table.filesystems[ret].mountpoint, VFS_NAME_LENGTH);
        semaphore_V(vfs_table.sem);
        vfs_end_op();
        return VFS_OK;
    }

    if (vfs_parse_pathname(pathname, volumename, dirname) != VFS_OK) {
        vfs_end_op();
        return VFS_ERROR;
    }

    semaphore_P(vfs_table.sem);

    fs = vfs_get_filesystem(volumename);

    if(fs == NULL) {
        semaphore_V(vfs_table.sem);
        vfs_end_op();
        return VFS_NO_SUCH_FS;
    }

    ret = fs->file(fs, dirname, idx, buffer);

    semaphore_V(vfs_table.sem);

    vfs_end_op();
    return ret;
}
Exemple #16
0
int subjectaltnameregexp(X509 *cert, int type, const char *exact,  const regex_t *regex) {
    int loc, i, l, n, r = 0;
    char *s, *v;
    X509_EXTENSION *ex;
    STACK_OF(GENERAL_NAME) *alt;
    GENERAL_NAME *gn;

    debug(DBG_DBG, "subjectaltnameregexp");

    loc = X509_get_ext_by_NID(cert, NID_subject_alt_name, -1);
    if (loc < 0)
	return r;

    ex = X509_get_ext(cert, loc);
    alt = X509V3_EXT_d2i(ex);
    if (!alt)
	return r;

    n = sk_GENERAL_NAME_num(alt);
    for (i = 0; i < n; i++) {
	gn = sk_GENERAL_NAME_value(alt, i);
	if (gn->type != type)
	    continue;
	r = -1;
	v = (char *)ASN1_STRING_data(gn->d.ia5);
	l = ASN1_STRING_length(gn->d.ia5);
	if (l <= 0)
	    continue;
#ifdef DEBUG
	printfchars(NULL, gn->type == GEN_DNS ? "dns" : "uri", NULL, v, l);
#endif
	if (exact) {
	    if (memcmp(v, exact, l))
		continue;
	} else {
	    s = stringcopy((char *)v, l);
	    if (!s) {
		debug(DBG_ERR, "malloc failed");
		continue;
	    }
	    if (regexec(regex, s, 0, NULL, 0)) {
		free(s);
		continue;
	    }
	    free(s);
	}
	r = 1;
	break;
    }
    GENERAL_NAMES_free(alt);
    return r;
}
int main (void)
{
	int i;
	fp = fopen ("dictionary.dic", "w");
	if (fp == NULL)
	{
		printf("Error!");
		exit(1);
	}
	char* src = loadFile();
	int inp_l = strlen(src) - 1;
	char* inp = malloc (inp_l); stringcopy(inp,src,inp_l);
	char* inp_c = malloc (inp_l); stringcopy(inp_c,src,inp_l);
	int size = no_of_distinct_char(inp, inp_l);
	char* arr = (char*)malloc(size*sizeof(char));
	int* freq = (int*)malloc(size*sizeof(int));
	createCharFreqArray(inp_c, inp_l, arr, freq, size);
	HuffmanCodes(arr, freq, size);
	fclose(fp);
	free(src);
	return 0;
}
Exemple #18
0
label & label::operator=(const label & src)
{
    if (&src == this) return *this;
    positionable::operator=(src);
    freelabel(string);
    string = stringcopy(src.string);
    position = src.position;
    rotation = src.rotation;
    scale = src.scale;
    justify = src.justify;
    free(cycle);
    copycycles(&cycle, &src.cycle);
    pin = src.pin;
    return *this;
}
Exemple #19
0
process_id_t process_spawn(const char *executable) {
    TID_t thread;
    process_id_t pid = alloc_process_id();

    if (pid == PROCESS_MAX_PROCESSES)
        return PROCESS_PTABLE_FULL;

    /* Remember to copy the executable name for use in process_start */
    stringcopy(process_table[pid].executable, executable, PROCESS_MAX_FILELENGTH);
    process_table[pid].parent = process_get_current_process();

    thread = thread_create((void (*)(uint32_t))(&process_start), pid);
    thread_run(thread);
    return pid;
}
//Init icon
void InitNotifyIconData()
{
	memset(&g_notifyIconData, 0, sizeof(NOTIFYICONDATA));
	g_notifyIconData.cbSize = sizeof(NOTIFYICONDATA);
	g_notifyIconData.hWnd = g_hwnd;
	g_notifyIconData.uID = ID_TRAY_APP_ICON;
	// Set up flags.
	g_notifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;     

	g_notifyIconData.uCallbackMessage = WM_TRAYICON; //this message must be handled in hwnd's window procedure. more info below.

	// Load the icon.  Be sure to include an icon "arrow_refresh.ico"
	g_notifyIconData.hIcon = (HICON)LoadImage(NULL, TEXT("arrow_refresh.ico"), IMAGE_ICON, 0, 0, LR_LOADFROMFILE);

	// set the tooltip text.  
	stringcopy(g_notifyIconData.szTip, TEXT("Connect"));
}
Exemple #21
0
/* A messy not very good buffer overflow example. A little bit too
 * contrieved. */
static int getline (char* destination)
{
  char line[200];
  int i = 0;
  char* dst = destination;

//#define DEBUG_CODE
#ifdef DEBUG_CODE
  int r, c;
  unsigned* ret = (unsigned*)(&dst - 1);

  printf ("Return address address: 0x%08x\n", (unsigned)&ret);
  printf ("Return address content: 0x%08x\n", *ret);
  printf ("Main function address : 0x%08x\n", (unsigned)main);
  printf ("Line buffer address   : 0x%08x\n", (unsigned)line);
#endif
  
  do /* !!! Buffer overflow when i >= 200 !!! */
  {
    if ( read (STDIN_FILENO, &line[i], 1) != 1)
      break; /* failed to read requested number of characters */
  }
  while ( line[i++] != '\n' );
  
  line[i-1] = '\0';
  
#ifdef DEBUG_CODE
  /* hex dump of read data */
  for (r = 0; r < 16; ++r)
  {
    printf ("0x%08x: ", (unsigned)&line[ 16*r ]);
    for (c = 0; c < 16; ++c)
    {
      int code = line[ 16*r + c ] & 0xff;
      printf("\\x%02x", code);
    }
    printf("\n");
  }
        
  printf ("Return address content: 0x%08x\n", *ret);
#endif

  stringcopy(dst, line);

  return ( strlen(line) > 1 );
}
Exemple #22
0
usr_sem_t* usr_sem_open(const char* name, int value) {

  interrupt_status_t intr_status;
  intr_status = _interrupt_disable();

  spinlock_acquire(&sem_table_slock);

  if (value >= 0) {
    for (int i = 0; i < MAX_SEMAPHORES; i++) {
      if (usr_sem_table[i].name != NULL) {
        if (!stringcmp(usr_sem_table[i].name, name)) {
          spinlock_release(&sem_table_slock);
          _interrupt_set_state(intr_status);
          return NULL;
        }
      }
    }

    for (int j = 0; j < MAX_SEMAPHORES; j++) {
      if (usr_sem_table[j].name == NULL) {
        stringcopy(usr_sem_table[j].name, name, 8);
        usr_sem_table[j].value = value;
        spinlock_release(&sem_table_slock);
        return &usr_sem_table[j];
      }
    }

    spinlock_release(&sem_table_slock);
    _interrupt_set_state(intr_status);
    return NULL;
  }
  else {
    for (int k = 0; k < MAX_SEMAPHORES; k++) {
      if (stringcmp(usr_sem_table[k].name, name)) {

        spinlock_release(&sem_table_slock);
        return &usr_sem_table[k]; // return handle already in use
      }
    }
    spinlock_release(&sem_table_slock);
    _interrupt_set_state(intr_status);
    return NULL;
  }
}
Exemple #23
0
int vfs_mount(fs_t *fs, char *name)
{
    int i;
    int row;

    KERNEL_ASSERT(name != NULL && name[0] != '\0');

    if (vfs_start_op() != VFS_OK)
        return VFS_UNUSABLE;

    semaphore_P(vfs_table.sem);

    for (i = 0; i < CONFIG_MAX_FILESYSTEMS; i++) {
        if (vfs_table.filesystems[i].filesystem == NULL)
            break;
    }

    row = i;

    if(row >= CONFIG_MAX_FILESYSTEMS) {
        semaphore_V(vfs_table.sem);
        kprintf("VFS: Warning, maximum mount count exceeded, mount failed.\n");
        vfs_end_op();
        return VFS_LIMIT;
    }

    for (i = 0; i < CONFIG_MAX_FILESYSTEMS; i++) {
        if(stringcmp(vfs_table.filesystems[i].mountpoint, name) == 0) {
            semaphore_V(vfs_table.sem);
            kprintf("VFS: Warning, attempt to mount 2 filesystems "
                    "with same name\n");
            vfs_end_op();
            return VFS_ERROR;
        }
    }

    stringcopy(vfs_table.filesystems[row].mountpoint, name, VFS_NAME_LENGTH);
    vfs_table.filesystems[row].filesystem = fs;

    semaphore_V(vfs_table.sem);
    vfs_end_op();
    return VFS_OK;
}
Exemple #24
0
process_id_t process_spawn(const char* executable)
{
    TID_t thread;
    interrupt_status_t intr_status;
    process_id_t my_pid = process_get_current_process();
    process_id_t pid = alloc_process_id(PROCESS_RUNNING);

    if (pid < 0) { /* Process table full */
        return -1;
    }
    stringcopy(process_table[pid].executable, executable, PROCESS_NAME_MAX);
    process_table[pid].retval = 0;
    process_table[pid].first_zombie = -1;
    process_table[pid].prev_zombie = -1;
    process_table[pid].next_zombie = -1;
    process_table[pid].parent = my_pid;

    intr_status = _interrupt_disable();
    spinlock_acquire(&process_table_slock);

    if (my_pid >= 0) {
        process_table[my_pid].children++;
    }

    spinlock_release(&process_table_slock);
    _interrupt_set_state(intr_status);

    process_table[pid].children = 0;
    process_table[pid].threads = 1;
    process_table[pid].stack_end =
        (USERLAND_STACK_TOP & PAGE_SIZE_MASK)
        - CONFIG_USERLAND_STACK_SIZE*PAGE_SIZE;
    process_table[pid].bot_free_stack = 0;

    for(int i = 0 ; i < MAX_OPEN_FILES ; i++) {
        process_table[pid].open_files[i] = -1;
    }

    thread = thread_create((void (*)(uint32_t))(&process_start), (uint32_t)pid);
    thread_run(thread);
    return pid;
}
Exemple #25
0
LONG_DOUBLE eval_emit_error(eval_context *ctx, const char *format, ...) {
    // Fehlerstring aufbauen, printf-Syntax
    va_list args;
    va_start(args, format);
    char fmtbuf[256];
    vsnprintf(fmtbuf, 256, format, args);

    // Fehlerstruktur füllen
    eval_error *e = malloc(sizeof(eval_error));
    e->__next = NULL;
    e->message = stringcopy(fmtbuf);

    // Letzten Eintrag in der Fehlerliste finden und e anhängen
    eval_error **it = &ctx->error;
    while (*it != NULL) it = &((*it)->__next);
    *it = e;
    
    // Fehlerflag setzen.
    ctx->success = false;

    return -NAN;
}
Exemple #26
0
int cnregexp(X509 *cert, const char *exact, const regex_t *regex) {
    int loc, l;
    char *v, *s;
    X509_NAME *nm;
    X509_NAME_ENTRY *e;
    ASN1_STRING *t;

    nm = X509_get_subject_name(cert);
    loc = -1;
    for (;;) {
	loc = X509_NAME_get_index_by_NID(nm, NID_commonName, loc);
	if (loc == -1)
	    break;
	e = X509_NAME_get_entry(nm, loc);
	t = X509_NAME_ENTRY_get_data(e);
	v = (char *) ASN1_STRING_data(t);
	l = ASN1_STRING_length(t);
	if (l < 0)
	    continue;
	if (exact) {
	    if (l == strlen(exact) && !strncasecmp(exact, v, l))
		return 1;
	} else {
	    s = stringcopy((char *)v, l);
	    if (!s) {
		debug(DBG_ERR, "malloc failed");
		continue;
	    }
	    if (regexec(regex, s, 0, NULL, 0)) {
		free(s);
		continue;
	    }
	    free(s);
	    return 1;
	}
    }
    return 0;
}
void menufunction(int)
{
	switch(stringmenu)
	{
		case 1:
			stringcopy();
			break;

		case 2:
			stringcharcopy();
			break;

		case 3:
         stringcompare();
			break;

		case 4:
         stringcharcompare();
			break;

		case 5:
			stringmerge();
			break;

		case 6:
			stringcharmerge();
			break;

		case 7:
         stringlength();
			break;

		default:
			cout<<"This is not a valid option! \n";
			cout<<"Choose again! \n";
         break;
	}
}
int Handle_Head(Dictionary *dictHttpRequest, SOCKET scClientSocket)
{
	int nReturnValue = 0;
	char *szURI = 0;
	char *szQueryString = 0;
	char* szPathOfFile = 0;
	char szIndex = "index.html";
	char szPathAfterAdding[260] = { '\0' };
	int bFoundFile = 0;
	
	LogMessage(LOG_DEBUG, "Started to hanlde head http request");

	szURI = GetValueFromDictionary(dictHttpRequest, "URI");
	if (NULL != szURI)
	{
		//Check if the uri has query string. If so then it needs to be handled by cgi.

		//Based on the URI - search in the local path for the file. If found then send 200 else send 404 not found error

		LogMessage(LOG_DEBUG, "Got URI of request");
		LogMessage(LOG_DEBUG, szURI);

		szQueryString = szURI;
		while ((*szQueryString) != '?' && (*szQueryString) != '\0')
		{
			szQueryString++;
		}
		if ((*szQueryString) == '?')
		{
			//This is a query string so handle it in a different way.
			szQueryString++;
			LogMessage(LOG_DEBUG, "URI has a query string in it");
			LogMessage(LOG_DEBUG, szQueryString);
		}
		else
		{
			LogMessage(LOG_DEBUG, "request does not have query string");
			bFoundFile = FindFileInLocalPath(szURI, strMappedLocalPath);
			if (bFoundFile == 0)
			{
				LogMessage(LOG_ERROR, "Could not find the file in the local path");
				nReturnValue = HandleFileNotFound(dictHttpRequest, scClientSocket);
			}
			else
			{
				//printf_s("\nBHS:INFO:Able to find the file in the local path:%s\n", szURI);
				LogMessage(LOG_DEBUG, "Able to find the file in the local path");
				szPathOfFile = GetFilePathFromURI(szURI, strMappedLocalPath);
				LogMessage(LOG_DEBUG, szPathOfFile);
				if (szPathOfFile[strnlen_s(szPathOfFile, 260) - 1] == '/')
				{
					//Add index.html file
					stringcopy(szPathAfterAdding, strlen(szPathOfFile), szPathOfFile);
					strcat_s(szPathAfterAdding, 260, szIndex);
					free(szPathOfFile);
					if (FileExists(szPathAfterAdding) == 1)
					{
						LogMessage(LOG_DEBUG, "Path is directory, so added index.html to path");
						
						szPathOfFile = (char*)malloc(sizeof(char)*strlen(szPathAfterAdding) + 1);
						memset(szPathOfFile, '\0', strlen(szPathAfterAdding) + 1);
						stringcopy(szPathOfFile, strlen(szPathAfterAdding), szPathAfterAdding);
						LogMessage(LOG_DEBUG, szPathOfFile);
						nReturnValue = HandleHeadFileResponse(dictHttpRequest, scClientSocket);

						free(szPathOfFile);
						szPathOfFile = 0;
					}
					else
					{
						LogMessage(LOG_DEBUG, "Found to be directory, so added index.html, But file not in local path");
						LogMessage(LOG_DEBUG, szPathOfFile);
						nReturnValue = HandleHeadFileNotFound(dictHttpRequest, scClientSocket);
					}

				}
				else
				{
					LogMessage(LOG_DEBUG, "Going to send the head response");
					nReturnValue = HandleHeadFileResponse(dictHttpRequest, scClientSocket);

					free(szPathOfFile);
					szPathOfFile = 0;
				}

			}
		}
	}

	LogMessage(LOG_DEBUG, "Returning after handling head request");
	return nReturnValue;
}
Exemple #29
0
/**
 * Starts one userland process. The thread calling this function will
 * be used to run the process and will therefore never return from
 * this function. This function asserts that no errors occur in
 * process startup (the executable file exists and is a valid ecoff
 * file, enough memory is available, file operations succeed...).
 * Therefore this function is not suitable to allow startup of
 * arbitrary processes.
 *
 * @executable The name of the executable to be run in the userland
 * process
 */
void process_start(process_id_t pid) {
    thread_table_t *my_entry;
    pagetable_t *pagetable;
    uint32_t phys_page;
    context_t user_context;
    uint32_t stack_bottom;
    elf_info_t elf;
    openfile_t file;
    char executable[MAX_NAME_LENGTH];

    int i;

    interrupt_status_t intr_status;

    my_entry = thread_get_current_thread_entry();

    // Set process id on thread
    my_entry->process_id = pid;

    // Ensure that we're the only ones touching the process table.
    intr_status = _interrupt_disable();
    spinlock_acquire(&process_table_slock);

    // Copy over the name of file we're supposed to execute.
    stringcopy(executable, process_table[pid].name, MAX_NAME_LENGTH);

    // Free our locks.
    spinlock_release(&process_table_slock);
    _interrupt_set_state(intr_status);

    /* If the pagetable of this thread is not NULL, we are trying to
       run a userland process for a second time in the same thread.
       This is not possible. */
    KERNEL_ASSERT(my_entry->pagetable == NULL);

    pagetable = vm_create_pagetable(thread_get_current_thread());
    KERNEL_ASSERT(pagetable != NULL);

    intr_status = _interrupt_disable();
    my_entry->pagetable = pagetable;
    _interrupt_set_state(intr_status);

    file = vfs_open((char *)executable);
    /* Make sure the file existed and was a valid ELF file */
    KERNEL_ASSERT(file >= 0);
    KERNEL_ASSERT(elf_parse_header(&elf, file));

    /* Trivial and naive sanity check for entry point: */
    KERNEL_ASSERT(elf.entry_point >= PAGE_SIZE);

    /* Calculate the number of pages needed by the whole process
       (including userland stack). Since we don't have proper tlb
       handling code, all these pages must fit into TLB. */
    KERNEL_ASSERT(elf.ro_pages + elf.rw_pages + CONFIG_USERLAND_STACK_SIZE
		  <= _tlb_get_maxindex() + 1);

    /* Allocate and map stack */
    for(i = 0; i < CONFIG_USERLAND_STACK_SIZE; i++) {
        phys_page = pagepool_get_phys_page();
        KERNEL_ASSERT(phys_page != 0);
        vm_map(my_entry->pagetable, phys_page,
               (USERLAND_STACK_TOP & PAGE_SIZE_MASK) - i*PAGE_SIZE, 1);
    }

    /* Allocate and map pages for the segments. We assume that
       segments begin at page boundary. (The linker script in tests
       directory creates this kind of segments) */
    for(i = 0; i < (int)elf.ro_pages; i++) {
        phys_page = pagepool_get_phys_page();
        KERNEL_ASSERT(phys_page != 0);
        vm_map(my_entry->pagetable, phys_page,
               elf.ro_vaddr + i*PAGE_SIZE, 1);
    }

    for(i = 0; i < (int)elf.rw_pages; i++) {
        phys_page = pagepool_get_phys_page();
        KERNEL_ASSERT(phys_page != 0);
        vm_map(my_entry->pagetable, phys_page,
               elf.rw_vaddr + i*PAGE_SIZE, 1);
    }

    /* Put the mapped pages into TLB. Here we again assume that the
       pages fit into the TLB. After writing proper TLB exception
       handling this call should be skipped. */
    intr_status = _interrupt_disable();
    tlb_fill(my_entry->pagetable);
    _interrupt_set_state(intr_status);

    /* Now we may use the virtual addresses of the segments. */

    /* Zero the pages. */
    memoryset((void *)elf.ro_vaddr, 0, elf.ro_pages*PAGE_SIZE);
    memoryset((void *)elf.rw_vaddr, 0, elf.rw_pages*PAGE_SIZE);

    stack_bottom = (USERLAND_STACK_TOP & PAGE_SIZE_MASK) -
        (CONFIG_USERLAND_STACK_SIZE-1)*PAGE_SIZE;
    memoryset((void *)stack_bottom, 0, CONFIG_USERLAND_STACK_SIZE*PAGE_SIZE);

    /* Copy segments */

    if (elf.ro_size > 0) {
	/* Make sure that the segment is in proper place. */
        KERNEL_ASSERT(elf.ro_vaddr >= PAGE_SIZE);
        KERNEL_ASSERT(vfs_seek(file, elf.ro_location) == VFS_OK);
        KERNEL_ASSERT(vfs_read(file, (void *)elf.ro_vaddr, elf.ro_size)
		      == (int)elf.ro_size);
    }

    if (elf.rw_size > 0) {
	/* Make sure that the segment is in proper place. */
        KERNEL_ASSERT(elf.rw_vaddr >= PAGE_SIZE);
        KERNEL_ASSERT(vfs_seek(file, elf.rw_location) == VFS_OK);
        KERNEL_ASSERT(vfs_read(file, (void *)elf.rw_vaddr, elf.rw_size)
		      == (int)elf.rw_size);
    }


    /* Set the dirty bit to zero (read-only) on read-only pages. */
    for(i = 0; i < (int)elf.ro_pages; i++) {
        vm_set_dirty(my_entry->pagetable, elf.ro_vaddr + i*PAGE_SIZE, 0);
    }

    /* Insert page mappings again to TLB to take read-only bits into use */
    intr_status = _interrupt_disable();
    tlb_fill(my_entry->pagetable);
    _interrupt_set_state(intr_status);

    /* Initialize the user context. (Status register is handled by
       thread_goto_userland) */
    memoryset(&user_context, 0, sizeof(user_context));
    user_context.cpu_regs[MIPS_REGISTER_SP] = USERLAND_STACK_TOP;
    user_context.pc = elf.entry_point;

    thread_goto_userland(&user_context);

    KERNEL_PANIC("thread_goto_userland failed.");
}
main(){
	
	int nbClientA=3, i, nbClientB=2;
	
	struct clientA sourceA[M];
	struct clientA trinumA[M];
	struct clientA trinomA[M];
	struct clientB sourceB[P];

//	Rappel acces ? un memebre d'une structure d'un tableau	
//	sourceA[1].numero = 10;
//	stringcopy("Jean", sourceA[1].prenom);
//	stringcopy("17/12/1985", sourceA[1].datenaiss);
//	puts(sourceA[1].prenom);
//	puts(sourceA[1].datenaiss);


/*	do{																									
		printf("Interface d'encodage des clients\n");
		printf("--------------------------------\n");
		printf("\nCombien de client(s) de la banque A souhaitez-vous encod%c ? ", 130);
		scanf("%d", &nbClientA);
		if(nbClientA>M) {
			printf("\nErreur ! Le nombre doit etre inf%rieur ? %d", M);
		}
	} while(nbClientA>M);
	
	
	
	for(i=0; i<nbClientA; ++i){
		system("cls");
		printf("Interface d'encodage des clients\n");
		printf("--------------------------------\n");
		cA = encodenouvclientA();
		structclientAcopy(cA, &sourceA[i]);
		structclientAcopy(cA, &trinumA[i]);
		structclientAcopy(cA, &trinomA[i]);
	}
	trinom(trinomA,nbClientA);
	tri_numero(trinumA, nbClientA);
    for (i=0;i<nbClientA;i++)
        {
         printf("Nom %d) : %s\n",i+1, trinomA[i].nom);  
        }
	for(i=0; i<nbClientA; ++i)	{
		
		printf("\nSource :\n%d\n", sourceA[i].numero);
		puts(sourceA[i].prenom);
		puts(sourceA[i].nom);
		puts(sourceA[i].datenaiss);
		puts(sourceA[i].num_compte);
		puts(sourceA[i].num_reg_nat);
		
		printf("\nTrinum :\n%d\n", trinumA[i].numero);
		puts(trinumA[i].prenom);
		puts(trinumA[i].nom);
		puts(trinumA[i].datenaiss);
		puts(trinumA[i].num_compte);
		puts(trinumA[i].num_reg_nat);
		
		printf("\nTrinom :\n%d\n", trinomA[i].numero);
		puts(trinomA[i].prenom);
		puts(trinomA[i].nom);
		puts(trinomA[i].datenaiss);
		puts(trinomA[i].num_compte);
		puts(trinomA[i].num_reg_nat);
		
		
	}
*/

trinomA[1].numero = 1;
stringcopy("LOPEZ", trinomA[1].nom);
stringcopy("JULIEN", trinomA[1].prenom);
stringcopy("14/09/1989", trinomA[1].datenaiss);
stringcopy("BE54 5555 5555 5555", trinomA[1].num_compte);
stringcopy("890914-103-51", trinomA[1].num_reg_nat);

trinomA[0].numero = 2;
stringcopy("ANDERSON", trinomA[0].nom);
stringcopy("PAMELA", trinomA[0].prenom);
stringcopy("15/10/1990", trinomA[0].datenaiss);
stringcopy("BE54 4444 3333 5555", trinomA[0].num_compte);
stringcopy("901015-103-51", trinomA[0].num_reg_nat);

trinomA[2].numero = 5;
stringcopy("ROGER", trinomA[2].nom);
stringcopy("MARCEL", trinomA[2].prenom);
stringcopy("14/08/1985", trinomA[2].datenaiss);
stringcopy("BE54 5555 1211 5555", trinomA[2].num_compte);
stringcopy("850814-103-51", trinomA[2].num_reg_nat);


stringcopy("ANDERSON", sourceB[0].nom);
stringcopy("PAMELA", sourceB[0].prenom);
stringcopy("15/10/1990", sourceB[0].datenaiss);



stringcopy("ROGER", sourceB[1].nom);
stringcopy("MARCEL", sourceB[1].prenom);
stringcopy("14/08/1985", sourceB[1].datenaiss);



//printf("%d", stringcomp(trinomA[0].datenaiss, sourceB[0].datenaiss));


for (i=0;i<2;++i){

recherchedicho(trinomA,nbClientA,&sourceB[i]);
}

//printf("\n%d",recherchedichonom(trinomA,nbClientA,sourceB[0].nom));
//printf("\n%d",recherchedichonom(trinomA,nbClientA,sourceB[1].nom));
system("pause");	
	
}