예제 #1
0
//main function
int main (int argc, char* argv[]) {
	ENTER();

	PROGRESS("Create the wpa_supplicant mgr");
	wpaHandle mgrHandle = wpa_supplicant_mgr_Init();
	if (!mgrHandle){
		ALLOC_FAIL("mgrHandle");
		EXIT_WITH_ERROR();
		return -1;
	}

	PROGRESS("Start the Manager Operation");
	wpa_supplicant_mgr_Start(mgrHandle);
    //This function will not return until operation is complete


	//Perform needed Cleanup
	//The program enters here before it exits
	PROGRESS("Cleanup: Stop and Destroy the Mgr");
	wpa_supplicant_mgr_Stop(mgrHandle);
	wpa_supplicant_mgr_Destroy (mgrHandle);

	EXIT();
	return 0;
}
void wpa_supplicantClient_bssManager_AddBss(wpa_supplicantClient_bssManager* mgr, char* pathName) {
	ENTER();

	bssList *bssRec = (bssList *)&(mgr->m_bssGroup);

	while (bssRec->m_next) {
		bssRec = bssRec->m_next;
	}

	//Create a new Record;
	bssRec->m_next = (bssList *)malloc(sizeof(bssList));
	if(!bssRec) {
		ALLOC_FAIL("bssRec");
		EXIT_WITH_ERROR();
	    return;
	}
	bssRec = bssRec->m_next;
    memset(bssRec, 0, sizeof(bssList));

    //Now initializing the BSS
    bssRec->m_bss = wpa_supplicantClient_bss_Init(mgr->m_busName,
    		                                      pathName,
												  mgr->m_dbusConnection);
    if (!bssRec->m_bss) {
    	ERROR("Failed to initialize the BSS Record .. exit");
    	EXIT_WITH_ERROR();
    	return;
    }

    //Now starting the BSS
    wpa_supplicantClient_bss_Start(bssRec->m_bss);

    EXIT();
	return;
}
wpa_supplicantClient_bssManager *wpa_supplicantClient_bssManager_Init (char *busName, void* connection) {
	ENTER();

	wpa_supplicantClient_bssManager *manager = malloc(sizeof(wpa_supplicantClient_bssManager));
    if (!manager) {
    	ALLOC_FAIL("manager");
    	EXIT_WITH_ERROR();
    	return NULL;
    }
    memset(manager, 0, sizeof(wpa_supplicantClient_bssManager));

    strcpy(manager->m_busName, busName);
    manager->m_dbusConnection = connection;

    EXIT();
    return manager;
}
wpa_supplicantClient_ProxyIntrospectable *wpa_supplicantClient_proxyIntrospectable_Init(char *busName,
		                                                                                char *objectPath) {
	ENTER();

	//First Create the object
	wpa_supplicantClient_ProxyIntrospectable *proxy = malloc(sizeof(wpa_supplicantClient_ProxyIntrospectable));
	if (!proxy){
		ALLOC_FAIL("Can not allocate a wpa_supplicantClient_ProxyIntrospectable Object ...Exiting");
		EXIT_WITH_ERROR();
		return NULL;
	}
	memset(proxy, 0, sizeof(wpa_supplicantClient_ProxyIntrospectable));

	strcpy(proxy->m_busName, busName);
	strcpy(proxy->m_objectPath, objectPath);

	EXIT();
	return proxy;
}
void wpa_supplicantClient_ifManager_AddIf(wpa_supplicantClient_ifManager* mgr, char* ifPathName) {

	ENTER();

	interfaceList *ifRec = (interfaceList *)&(mgr->m_interfaceGroup);

	while (ifRec->m_next) {
		ifRec = ifRec->m_next;
	}

	//Create a new Record;
	ifRec->m_next = (interfaceList *)malloc(sizeof(interfaceList));
	if(!ifRec) {
		ALLOC_FAIL("ifRec");
		EXIT_WITH_ERROR();
	    return;
	}
	ifRec = ifRec->m_next;
    memset(ifRec, 0, sizeof(interfaceList));

    //Now initializing the Interface
    ifRec->m_interface = wpa_supplicantClient_if_Init(mgr->m_busName,
    		                                          ifPathName,
													  mgr->m_dbusConnection);
    if (!ifRec->m_interface) {
    	ERROR("Failed to initialize the Interface Record .. exit");
    	EXIT_WITH_ERROR();
    	return;
    }

    //Now starting the interface
    wpa_supplicantClient_if_Start(ifRec->m_interface);

    EXIT();
	return;
}
예제 #6
0
파일: be_local.c 프로젝트: moben/pacman
static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
{
	FILE *fp = NULL;
	char line[1024];
	char *pkgpath;
	alpm_db_t *db = info->origin_data.db;

	/* bitmask logic here:
	 * infolevel: 00001111
	 * inforeq:   00010100
	 * & result:  00000100
	 * == to inforeq? nope, we need to load more info. */
	if((info->infolevel & inforeq) == inforeq) {
		/* already loaded all of this info, do nothing */
		return 0;
	}

	if(info->infolevel & INFRQ_ERROR) {
		/* We've encountered an error loading this package before. Don't attempt
		 * repeated reloads, just give up. */
		return -1;
	}

	_alpm_log(db->handle, ALPM_LOG_FUNCTION, "loading package data for %s : level=0x%x\n",
			info->name, inforeq);

	pkgpath = _alpm_local_db_pkgpath(db, info, NULL);
	if(!pkgpath || access(pkgpath, F_OK)) {
		/* directory doesn't exist or can't be opened */
		_alpm_log(db->handle, ALPM_LOG_DEBUG, "cannot find '%s-%s' in db '%s'\n",
				info->name, info->version, db->treename);
		goto error;
	}
	free(pkgpath);

	/* clear out 'line', to be certain - and to make valgrind happy */
	memset(line, 0, sizeof(line));

	/* DESC */
	if(inforeq & INFRQ_DESC && !(info->infolevel & INFRQ_DESC)) {
		char *path = _alpm_local_db_pkgpath(db, info, "desc");
		if(!path || (fp = fopen(path, "r")) == NULL) {
			_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
			free(path);
			goto error;
		}
		free(path);
		while(!feof(fp)) {
			if(fgets(line, sizeof(line), fp) == NULL && !feof(fp)) {
				goto error;
			}
			if(_alpm_strip_newline(line) == 0) {
				/* length of stripped line was zero */
				continue;
			}
			if(strcmp(line, "%NAME%") == 0) {
				READ_NEXT();
				if(strcmp(line, info->name) != 0) {
					_alpm_log(db->handle, ALPM_LOG_ERROR, _("%s database is inconsistent: name "
								"mismatch on package %s\n"), db->treename, info->name);
				}
			} else if(strcmp(line, "%VERSION%") == 0) {
				READ_NEXT();
				if(strcmp(line, info->version) != 0) {
					_alpm_log(db->handle, ALPM_LOG_ERROR, _("%s database is inconsistent: version "
								"mismatch on package %s\n"), db->treename, info->name);
				}
			} else if(strcmp(line, "%DESC%") == 0) {
				READ_AND_STORE(info->desc);
			} else if(strcmp(line, "%GROUPS%") == 0) {
				READ_AND_STORE_ALL(info->groups);
			} else if(strcmp(line, "%URL%") == 0) {
				READ_AND_STORE(info->url);
			} else if(strcmp(line, "%LICENSE%") == 0) {
				READ_AND_STORE_ALL(info->licenses);
			} else if(strcmp(line, "%ARCH%") == 0) {
				READ_AND_STORE(info->arch);
			} else if(strcmp(line, "%BUILDDATE%") == 0) {
				READ_NEXT();
				info->builddate = _alpm_parsedate(line);
			} else if(strcmp(line, "%INSTALLDATE%") == 0) {
				READ_NEXT();
				info->installdate = _alpm_parsedate(line);
			} else if(strcmp(line, "%PACKAGER%") == 0) {
				READ_AND_STORE(info->packager);
			} else if(strcmp(line, "%REASON%") == 0) {
				READ_NEXT();
				info->reason = (alpm_pkgreason_t)atoi(line);
			} else if(strcmp(line, "%SIZE%") == 0) {
				READ_NEXT();
				info->isize = _alpm_strtoofft(line);
			} else if(strcmp(line, "%REPLACES%") == 0) {
				READ_AND_SPLITDEP(info->replaces);
			} else if(strcmp(line, "%DEPENDS%") == 0) {
				READ_AND_SPLITDEP(info->depends);
			} else if(strcmp(line, "%OPTDEPENDS%") == 0) {
				READ_AND_STORE_ALL(info->optdepends);
			} else if(strcmp(line, "%CONFLICTS%") == 0) {
				READ_AND_SPLITDEP(info->conflicts);
			} else if(strcmp(line, "%PROVIDES%") == 0) {
				READ_AND_SPLITDEP(info->provides);
			}
		}
		fclose(fp);
		fp = NULL;
		info->infolevel |= INFRQ_DESC;
	}

	/* FILES */
	if(inforeq & INFRQ_FILES && !(info->infolevel & INFRQ_FILES)) {
		char *path = _alpm_local_db_pkgpath(db, info, "files");
		if(!path || (fp = fopen(path, "r")) == NULL) {
			_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
			free(path);
			goto error;
		}
		free(path);
		while(fgets(line, sizeof(line), fp)) {
			_alpm_strip_newline(line);
			if(strcmp(line, "%FILES%") == 0) {
				size_t files_count = 0, files_size = 0;
				alpm_file_t *files = NULL;

				while(fgets(line, sizeof(line), fp) && _alpm_strip_newline(line)) {
					if(files_count >= files_size) {
						size_t old_size = files_size;
						if(files_size == 0) {
							files_size = 8;
						} else {
							files_size *= 2;
						}
						files = realloc(files, sizeof(alpm_file_t) * files_size);
						if(!files) {
							ALLOC_FAIL(sizeof(alpm_file_t) * files_size);
							goto error;
						}
						/* ensure all new memory is zeroed out, in both the initial
						 * allocation and later reallocs */
						memset(files + old_size, 0,
								sizeof(alpm_file_t) * (files_size - old_size));
					}
					STRDUP(files[files_count].name, line, goto error);
					/* TODO: lstat file, get mode/size */
					files_count++;
				}
				/* attempt to hand back any memory we don't need */
				files = realloc(files, sizeof(alpm_file_t) * files_count);
				info->files.count = files_count;
				info->files.files = files;
			} else if(strcmp(line, "%BACKUP%") == 0) {
예제 #7
0
gyHandle gy86_Init (Gy86_ChipType chip) {

	ENTER();

	retcode retVal = 0;
	Gy86 *gy = (Gy86 *)malloc(sizeof(Gy86));
	if (!gy) {
		ALLOC_FAIL("gy");
		goto END;
	}
	memset(gy, 0x00, sizeof(Gy86));

	resetGyData(gy);

	if (chip & CHIP_TYPE_MPU60X0) {
		gy->m_mpu = mpu60x0_Init();
		if (!gy->m_mpu) {
			ERROR("Failed to Initialize the MPU Chip");
			goto FAIL_MPU;
		}
	}

	//Register the Interrupt Functions
	retVal = mpu60x0_RegDataRdyCb (gy->m_mpu, mpuDataRdyIntHandler, (uint32)gy);
	if (retVal) {
		ERROR("Failed in Registering the Interrupt Handler for the MPU:DataRdy");
	}

	retVal = mpu60x0_RegFifoOvrflowCb (gy->m_mpu, mpuFifoIntHandler, (uint32)gy);
	if (retVal) {
		ERROR("Failed in Registering the Interrupt Handler for the MPU:FIFO");
	}

	retVal = mpu60x0_RegMotDetCb (gy->m_mpu, mpuMotDetIntHandler, (uint32)gy);
	if (retVal) {
		ERROR("Failed in Registering the Interrupt Handler for the MPU:MotDet");
	}

	retVal = mpu60x0_RegFsynchCb (gy->m_mpu, mpuFsyncIntHandler, (uint32)gy);
	if (retVal) {
		ERROR("Failed in Registering the Interrupt Handler for the MPU:Fsync");
	}

	retVal = mpu60x0_RegAuxI2cCb (gy->m_mpu, mpuAuxI2cIntHandler, (uint32)gy);
	if (retVal) {
		ERROR("Failed in Registering the Interrupt Handler for the MPU:AuxI2c");
	}


	if (chip & CHIP_TYPE_HMC5883) {
		gy->m_hmc = hmc5883_Init();
		if (!gy->m_hmc) {
			ERROR("Failed to Initialize the HMC Chip");
			goto FAIL_HMC;
		}
	}

	//Register the Interrupt Functions
	retVal = hmc5883_RegDataRdyCb (gy->m_hmc, hmcDataRdyIntHandler, (uint32)gy);
	if (retVal) {
		ERROR("Failed in Registering the Interrupt Handler for the HMC:DataRdy");
	}

	retVal = hmc5883_RegLockCb (gy->m_hmc, hmcRegLockIntHandler, (uint32)gy);
	if (retVal) {
		ERROR("Failed in Registering the Interrupt Handler for the HMC:Reg Lock");
	}


	if (chip & CHIP_TYPE_MS5611) {
		gy->m_ms = ms5611_Init();
		if (!gy->m_ms) {
			ERROR("Failed to Initialize the MS Chip");
			goto FAIL_MS;
		}
	}

	//Init Completed Successfully
	goto END;

FAIL_MS:
	hmc5883_Destroy(gy->m_hmc);
FAIL_HMC:
	mpu60x0_Destroy(gy->m_mpu);
FAIL_MPU:
	free(gy);
	gy = NULL;
END:
	EXIT();
	return (gyHandle)gy;
}